Ver código fonte

修改编号,同步其子项编号

MaiXinRong 9 anos atrás
pai
commit
2675e9958b

+ 20 - 14
DataModules/BillsCompileDm.pas

@@ -101,7 +101,7 @@ type
 implementation
 
 uses
-  ProjectData, Math, ZhAPI, UtilMethods, ConstUnit, mDataRecord;
+  ProjectData, Math, ZhAPI, UtilMethods, ConstUnit, mDataRecord, Variants;
 
 {$R *.dfm}
 
@@ -596,7 +596,7 @@ procedure TBillsCompileData.sdvBillsCompileSetText(var Text: String;
     ARecord.ValueByName('CalcType').AsInteger := 0;
   end;
 
-  procedure DoCurChanged;
+  procedure DoCurChanged(ANode: TBillsIDTreeNode);
   begin
     if SameText(AColumn.FieldName, 'OrgQuantity') or
         SameText(AColumn.FieldName, 'MisQuantity') or
@@ -609,7 +609,11 @@ procedure TBillsCompileData.sdvBillsCompileSetText(var Text: String;
     else if Pos('DgnQuantity', AColumn.FieldName) = 1 then
       SetDgnQuantity
     else if SameText(AColumn.FieldName, 'Price') then
-      SetPrice;
+      SetPrice
+    else if SameText(AColumn.FieldName, 'Code') then
+      BillsCompileTree.RecodeChildrenCode(ANode, AValue.AsString, Text)
+    else if SameText(AColumn.FieldName, 'B_Code') then
+      BillsCompileTree.RecodeChildrenB_Code(ANode, AValue.AsString, Text);
   end;
 
   procedure CheckLockedData;
@@ -630,19 +634,17 @@ procedure TBillsCompileData.sdvBillsCompileSetText(var Text: String;
          SetTextErrorHint('清单信息已被锁定,不允许修改编号、名称、单位、清单单价、0号台账数量与金额、图号!');
   end;
 
-  procedure CheckNodeWritable;
+  procedure CheckNodeWritable(ANode: TBillsIDTreeNode);
   var
-    vNode: TBillsIDTreeNode;
     iCreatePhase: Integer;
   begin
     if not Allow then Exit;
-    vNode := TBillsIDTreeNode(BillsCompileTree.FindNode(ARecord.ValueByName('ID').AsInteger));
-    iCreatePhase := vNode.Rec.ValueByName('CreatePhaseID').AsInteger;
+    iCreatePhase := ANode.Rec.ValueByName('CreatePhaseID').AsInteger;
 
-    if vNode.ID = iPriceMarginID then
+    if ANode.ID = iPriceMarginID then
       SetTextErrorHint(sBills_PMHint);
 
-    if vNode.HasChildren then
+    if ANode.HasChildren then
     begin
       if Text = '' then
         Exit
@@ -659,7 +661,7 @@ procedure TBillsCompileData.sdvBillsCompileSetText(var Text: String;
           SameText('MisTotalPrice', AColumn.FieldName) or
           SameText('OthTotalPrice', AColumn.FieldName) then
       begin
-        if not vNode.TotalPriceEnable then
+        if not ANode.TotalPriceEnable then
           SetTextErrorHint('该清单不可直接输入金额,如需直接输入金额,请先清空所有数量、单价!');
       end;
       if not Allow then Exit;
@@ -669,7 +671,7 @@ procedure TBillsCompileData.sdvBillsCompileSetText(var Text: String;
           SameText('MisQuantity', AColumn.FieldName) or
           SameText('OthQuantity', AColumn.FieldName) then
       begin
-        if not vNode.CountPriceEnable then
+        if not ANode.CountPriceEnable then
           SetTextErrorHint('该清单不可输入数量单价,如需使用数量×单价计算,请先清空所有直接输入的金额!');
       end;
       if not Allow then Exit;
@@ -710,7 +712,7 @@ procedure TBillsCompileData.sdvBillsCompileSetText(var Text: String;
        SameText('Name', AColumn.FieldName) or
        SameText('Units', AColumn.FieldName) or
        SameText('Price', AColumn.FieldName) then
-      if TBillsIDTreeNode(vNode).HasMeasure then
+      if TBillsIDTreeNode(ANode).HasMeasure then
         SetTextErrorHint('该清单已经计量,不可修改清单编号');
   end;
 
@@ -730,6 +732,8 @@ procedure TBillsCompileData.sdvBillsCompileSetText(var Text: String;
     end;
   end;
 
+var
+  vNode: TBillsIDTreeNode;
 begin
   if not Assigned(AValue) then Exit;
   // 修改后数据与原数据相同则不提交
@@ -737,17 +741,19 @@ begin
     Allow := False;
   if not Allow then Exit;
 
+  vNode := TBillsIDTreeNode(BillsCompileTree.FindNode(ARecord.ValueByName('ID').AsInteger));
+
   CheckLockedData;
   if not Allow then Exit;
 
-  CheckNodeWritable;
+  CheckNodeWritable(vNode);
   if not Allow then Exit;
 
   Text := Trim(Text);
   if Pos('=', Text) = 1 then
     Text := Copy(Text, 2, Length(Text) - 1);
 
-  DoCurChanged;
+  DoCurChanged(vNode);
 end;
 
 function TBillsCompileData.GetActive: Boolean;

+ 43 - 38
DataModules/BillsMeasureDm.pas

@@ -84,7 +84,7 @@ implementation
 
 uses
   ProjectData, PhaseData, Math, ZhAPI, BillsCommand, BGLSelectFrm,
-  BGLDm, UtilMethods, mDataRecord, ConstUnit;
+  BGLDm, UtilMethods, mDataRecord, ConstUnit, Variants;
 
 {$R *.dfm}
 
@@ -274,35 +274,33 @@ procedure TBillsMeasureData.sdvBillsMeasureSetText(var Text: String;
         DataSetErrorMessage(Allow, '变更单价已被锁定,不允许修改!');
   end;
 
-  procedure CheckNodeWritable;
+  procedure CheckNodeWritable(ANode: TBillsIDTreeNode);
   var
-    vNode: TBillsIDTreeNode;
     iCreatePhase: Integer;
   begin
-    vNode := TBillsIDTreeNode(BillsMeasureTree.FindNode(GetBillsID));
-    iCreatePhase := vNode.Rec.ValueByName('CreatePhaseID').AsInteger;
+    iCreatePhase := ANode.Rec.ValueByName('CreatePhaseID').AsInteger;
 
-    if vNode.ID = iPriceMarginID then
+    if ANode.ID = iPriceMarginID then
       DataSetErrorMessage(Allow, sBills_PMHint);
 
     if SameText('B_Code', AColumn.FieldName) or
         SameText('Name', AColumn.FieldName) or
         SameText('Units', AColumn.FieldName) then
-      if vNode.Rec.ValueByName('AddQcQuantity').AsFloat <> 0 then
+      if ANode.Rec.ValueByName('AddQcQuantity').AsFloat <> 0 then
         DataSetErrorMessage(Allow, '该清单已进行过变更,不可修改清单编号、名称、单位!');
     if not Allow then Exit;
 
     if SameText('Price', AColumn.FieldName) then
-      if vNode.Rec.ValueByName('AddGatherTotalPrice').AsFloat <> 0 then
+      if ANode.Rec.ValueByName('AddGatherTotalPrice').AsFloat <> 0 then
         DataSetErrorMessage(Allow, '该清单已经计量,不可修改清单单价!');
     if not Allow then Exit;
 
     if SameText('NewPrice', AColumn.FieldName) then
-      if vNode.Rec.ValueByName('AddPcTotalPrice').AsFloat <> 0 then
+      if ANode.Rec.ValueByName('AddPcTotalPrice').AsFloat <> 0 then
         DataSetErrorMessage(Allow, '该清单已经计量,不可修改清单变更单价!');
     if not Allow then Exit;
 
-    if vNode.HasChildren then
+    if ANode.HasChildren then
     begin
       if Text = '' then
         Exit
@@ -317,7 +315,7 @@ procedure TBillsMeasureData.sdvBillsMeasureSetText(var Text: String;
       // 目前仅允许本期合同计量,可直接输入金额
       if SameText('CurDealTotalPrice', AColumn.FieldName) then
       begin
-        if not vNode.TotalPriceEnable then
+        if not ANode.TotalPriceEnable then
           DataSetErrorMessage(Allow, '该清单不可直接输入金额,如需直接输入金额,请先清空所有数量、单价!');
       end
       else if SameText('CurDealQuantity', AColumn.FieldName) or
@@ -325,7 +323,7 @@ procedure TBillsMeasureData.sdvBillsMeasureSetText(var Text: String;
           SameText('CurPcQuantity', AColumn.FieldName) or
           SameText('Price', AColumn.FieldName) then
       begin
-        if not vNode.CountPriceEnable then
+        if not ANode.CountPriceEnable then
           DataSetErrorMessage(Allow, '该清单不可输入数量单价,如需使用数量×单价计算,请先清空所有直接输入的金额!');
       end;
     end;
@@ -337,7 +335,7 @@ procedure TBillsMeasureData.sdvBillsMeasureSetText(var Text: String;
       DataSetErrorMessage(Allow, Format('该清单为第%d期新增清单,不可填写本期合同计量数据!', [iCreatePhase]));}
   end;
 
-  procedure SetQuantity(const AField: string);
+  procedure SetQuantity(ANode: TBillsIDTreeNode; const AField: string);
   var
     vNode: TBillsIDTreeNode;
   begin
@@ -358,15 +356,11 @@ procedure TBillsMeasureData.sdvBillsMeasureSetText(var Text: String;
       AValue.Owner.ValueByName(AField + 'Formula').AsString := Text;
       Text := FloatToStr(QuantityRoundTo(EvaluateExprs(Text)));
     end;
-    
-    vNode := TBillsIDTreeNode(BillsMeasureTree.FindNode(GetBillsID));
-    if vNode.Rec.CalcType.AsInteger <> 0 then
-      vNode.Rec.CalcType.AsInteger := 0;
+
+    ANode.Rec.SetIntValue(ANode.Rec.CalcType, 0);
   end;
 
-  procedure SetTotalPrice(const AField: string);
-  var
-    vNode: TBillsIDTreeNode;
+  procedure SetTotalPrice(ANode: TBillsIDTreeNode; const AField: string);
   begin
     // 变更应选择变更令
     if SameText(AField , 'Qc') or SameText(AField , 'Pc') then
@@ -386,31 +380,33 @@ procedure TBillsMeasureData.sdvBillsMeasureSetText(var Text: String;
       Text := FloatToStr(TotalPriceRoundTo(EvaluateExprs(Text)));
     end;
 
-    vNode := TBillsIDTreeNode(BillsMeasureTree.FindNode(GetBillsID));
-    if vNode.Rec.CalcType.AsInteger <> 1 then
-      vNode.Rec.CalcType.AsInteger := 1;
+    ANode.Rec.SetIntValue(ANode.Rec.CalcType, 1);
   end;
 
-  procedure DoCurChanged;
+  procedure DoCurChanged(ANode: TBillsIDTreeNode);
   begin
     if SameText(AColumn.FieldName, 'CurDealQuantity') then
-      SetQuantity('Deal')
+      SetQuantity(ANode, 'Deal')
     else if SameText(AColumn.FieldName, 'CurQcQuantity') then
-      SetQuantity('Qc')
+      SetQuantity(ANode, 'Qc')
     else if SameText(AColumn.FieldName, 'CurPcQuantity') then
-      SetQuantity('Pc')
+      SetQuantity(ANode, 'Pc')
     else if SameText(AColumn.FieldName, 'CurDealTotalPrice') then
-      SetTotalPrice('Deal')
+      SetTotalPrice(ANode, 'Deal')
     else if SameText(AColumn.FieldName, 'CurQcTotalPrice') then
-      SetTotalPrice('Qc')
+      SetTotalPrice(ANode, 'Qc')
     else if SameText(AColumn.FieldName, 'CurPcTotalPrice') then
-      SetTotalPrice('Pc')
+      SetTotalPrice(ANode, 'Pc')
     else if (Pos('DgnQuantity', AColumn.FieldName) > 0) or
         SameText(AColumn.FieldName, 'Quantity') then
       Text := FloatToStr(QuantityRoundTo(StrToFloatDef(Text, 0)))
     else if SameText(AColumn.FieldName, 'NewPrice') or
         SameText(AColumn.FieldName, 'Price') then
-      Text := FloatToStr(PriceRoundTo(StrToFloatDef(Text, 0)));
+      Text := FloatToStr(PriceRoundTo(StrToFloatDef(Text, 0)))
+    else if SameText(AColumn.FieldName, 'Code') then
+      BillsMeasureTree.RecodeChildrenCode(ANode, AValue.AsString, Text)
+    else if SameText(AColumn.FieldName, 'B_Code') then
+      BillsMeasureTree.RecodeChildrenB_Code(ANode, AValue.AsString, Text);
   end;
 
   function CheckValidData: Boolean;
@@ -424,23 +420,28 @@ procedure TBillsMeasureData.sdvBillsMeasureSetText(var Text: String;
     end;
   end;
 
+var
+  vNode: TBillsIDTreeNode;
 begin
   if not Assigned(AValue) then Exit;
   // 修改后数据与原数据相同则不提交
   if not CheckValidData then
     Allow := False;
   if not Allow then Exit;
+  
+  vNode := TBillsIDTreeNode(BillsMeasureTree.FindNode(GetBillsID));
 
   CheckLockedData;
   if not Allow then Exit;
 
-  CheckNodeWritable;
+  CheckNodeWritable(vNode);
   if not Allow then Exit;
 
   Text := Trim(Text);
   if Pos('=', Text) = 1 then
     Text := Copy(Text, 2, Length(Text) - 1);
-  DoCurChanged;
+
+  DoCurChanged(vNode);
 end;
 
 procedure TBillsMeasureData.sdvBillsMeasureNeedLookupRecord(
@@ -804,8 +805,10 @@ end;
 procedure TBillsMeasureData.sdvBillsMeasureAfterValueChanged(
   AValue: TsdValue);
 var
-  stnNode: TsdIDTreeNode;
+  vNode: TBillsIDTreeNode;
 begin
+  vNode := TBillsIDTreeNode(BillsMeasureTree.FindNode(AValue.Owner.ValueByName('ID').AsInteger));
+
   if TProjectData(FProjectData).PhaseData.Active then
   begin
     if AValue.FieldName = 'Price' then
@@ -814,10 +817,12 @@ begin
       StageData.ReCalculate(AValue.Owner.ValueByName('ID').AsInteger);
   end;
   if Pos('DgnQuantity1', AValue.FieldName) > 0 then
-  begin
-    stnNode := BillsMeasureTree.FindNode(AValue.Owner.ValueByName('ID').AsInteger);
-    CalcAddDgnPrice(stnNode);
-  end;
+    CalcAddDgnPrice(vNode);
+
+  if (AValue.FieldName = 'Code') then
+    BillsMeasureTree.RecodeChildrenCode(vNode, VarToStrDef(AValue.OldValue, ''), AValue.AsString)
+  else if (AValue.FieldName = 'B_Code') then
+    BillsMeasureTree.RecodeChildrenB_Code(vNode, VarToStrDef(AValue.OldValue, ''), AValue.AsString);
 end;
 
 procedure TBillsMeasureData.ExpandCurPhase;

+ 59 - 0
Units/BillsTree.pas

@@ -64,6 +64,9 @@ type
 
     function Add(AParentID, ANextSiblingID: TsdTreeNodeID): TsdIDTreeNode; override;
 
+    procedure RecodeChildrenCode(ANode: TBillsIDTreeNode; AOrgCode, ANewCode: string);
+    procedure RecodeChildrenB_Code(ANode: TBillsIDTreeNode; AOrgCode, ANewCode: string);
+
     procedure DoOnReCalcNode(AID: Integer); overload; virtual; abstract;
     procedure DoOnReCalcNode(ANode: TsdIDTreeNode); overload; virtual; abstract;
   end;
@@ -110,6 +113,8 @@ type
 
 implementation
 
+uses SysUtils;
+
 { TBillsIDTree }
 
 function TBillsIDTree.Add(AParentID,
@@ -149,6 +154,60 @@ begin
   DoOnReCalcNode(vParent);
 end;
 
+procedure TBillsIDTree.RecodeChildrenB_Code(ANode: TBillsIDTreeNode;
+  AOrgCode, ANewCode: string);
+var
+  iCount, iTotal: Integer;
+  vChild: TBillsIDTreeNode;
+begin
+  if (ANewCode = '') or (AOrgCode = '') or (AOrgCode = ANewCode) then Exit;
+
+  iCount := 0;
+  iTotal := ANode.PosterityCount;
+  vChild := TBillsIDTreeNode(ANode.NextNode);
+  while (iCount < iTotal) and Assigned(vChild) do
+  begin
+    if vChild.Rec.B_Code.AsString <> '' then
+    begin
+      if Pos(AOrgCode+'-', vChild.Rec.B_Code.AsString) = 1 then
+      begin
+        vChild.Rec.B_Code.AsString := StringReplace(vChild.Rec.B_Code.AsString,
+            AOrgCode+'-', ANewCode+'-', []);
+        vChild.Rec.SetBoolValue(vChild.Rec.LockedInfo, False);
+      end;
+    end;
+    vChild := TBillsIDTreeNode(vChild.NextNode);
+    Inc(iCount);
+  end;
+end;
+
+procedure TBillsIDTree.RecodeChildrenCode(ANode: TBillsIDTreeNode;
+  AOrgCode, ANewCode: string);
+var
+  iCount, iTotal: Integer;
+  vChild: TBillsIDTreeNode;
+begin
+  if (ANewCode = '') or (AOrgCode = '') or (AOrgCode = ANewCode) then Exit;
+
+  iCount := 0;
+  iTotal := ANode.PosterityCount;
+  vChild := TBillsIDTreeNode(ANode.NextNode);
+  while (iCount < iTotal) and Assigned(vChild) do
+  begin
+    if vChild.Rec.Code.AsString <> '' then
+    begin
+      if Pos(AOrgCode+'-', vChild.Rec.Code.AsString) = 1 then
+      begin
+        vChild.Rec.Code.AsString := StringReplace(vChild.Rec.Code.AsString,
+            AOrgCode+'-', ANewCode+'-', []);
+        vChild.Rec.SetBoolValue(vChild.Rec.LockedInfo, False);
+      end;
+    end;
+    vChild := TBillsIDTreeNode(vChild.NextNode);
+    Inc(iCount);
+  end;
+end;
+
 { TBillsIDTreeNode }
 
 function TBillsIDTreeNode.CanDownLevel: Boolean;

+ 9 - 9
Units/mDataRecord.pas

@@ -68,9 +68,9 @@ type
     FAddGatherQuantity: TsdValue;
     FAddGatherTotalPrice: TsdValue;
 
-    FLockLevel: TsdValue;
-    FLockInfo: TsdValue;
-    FLockNewPrice: TsdValue;
+    FLockedLevel: TsdValue;
+    FLockedInfo: TsdValue;
+    FLockedNewPrice: TsdValue;
     FCreatePhaseID: TsdValue;
     FIsMeasureAdd: TsdValue;
 
@@ -155,9 +155,9 @@ type
     property AddGatherQuantity: TsdValue read FAddGatherQuantity;
     property AddGatherTotalPrice: TsdValue read FAddGatherTotalPrice;
 
-    property LockLevel: TsdValue read FLockLevel;
-    property LockInfo: TsdValue read FLockInfo;
-    property LockNewPrice: TsdValue read FLockNewPrice;
+    property LockedLevel: TsdValue read FLockedLevel;
+    property LockedInfo: TsdValue read FLockedInfo;
+    property LockedNewPrice: TsdValue read FLockedNewPrice;
     property CreatePhaseID: TsdValue read FCreatePhaseID;
     property IsMeasureAdd: TsdValue read FIsMeasureAdd;
 
@@ -519,9 +519,9 @@ begin
   FAddGatherQuantity := ValueByName('AddGatherQuantity');
   FAddGatherTotalPrice := ValueByName('AddGatherTotalPrice');
 
-  FLockLevel := ValueByName('LockLevel');
-  FLockInfo := ValueByName('LockInfo');
-  FLockNewPrice := ValueByName('LockNewPrice');
+  FLockedLevel := ValueByName('LockedLevel');
+  FLockedInfo := ValueByName('LockedInfo');
+  FLockedNewPrice := ValueByName('LockedNewPrice');
   FCreatePhaseID := ValueByName('CreatePhaseID');
   FIsMeasureAdd := ValueByName('IsMeasureAdd');