Jelajahi Sumber

节点展开收起优化,更新该条后,须更新SmartCost代码,方可编译

MaiXinRong 9 tahun lalu
induk
melakukan
37ab838f35

+ 2 - 3
DataModules/BillsCompileDm.pas

@@ -4,7 +4,7 @@ interface
 
 uses
   BillsDm, StandardBillsFme,
-  SysUtils, Classes, sdDB, BillsTree, sdIDTree;
+  SysUtils, Classes, sdDB, BillsTree, sdIDTree, DB;
 
 type
   TBillsCompileData = class(TDataModule)
@@ -146,8 +146,7 @@ procedure TBillsCompileData.sdvBillsCompileGetText(var Text: String;
 var
   fDgnPrice: Double;
 begin
-  if (Pos('Price', AColumn.FieldName) > 0) or
-     (Pos('Quantity', AColumn.FieldName) > 0) then
+  if AValue.DataType = ftFloat then
   begin
     if Assigned(AValue) and (AValue.AsFloat = 0) then
       Text := '';

+ 7 - 17
DataModules/BillsMeasureDm.pas

@@ -4,7 +4,7 @@ interface
 
 uses
   BillsDm, BillsTree, FormulaCalc, sdIDTree, StageDm,
-  SysUtils, Classes, sdDB;
+  SysUtils, Classes, sdDB, DB;
 
 type
   TBillsMeasureData = class(TDataModule)
@@ -39,7 +39,7 @@ type
     function SelectAndUpdateBGL(ABillsID: Integer; ARec: TsdDataRecord;
       ANewValue: Double; const AType: string): Boolean;
 
-    procedure CalculateNode(ANode: TBillsIDTreeNode);            
+    procedure CalculateNode(ANode: TBillsIDTreeNode);
     procedure UpdateRecordGather(ANode: TsdIDTreeNode; AQuantity, ATotalPrice: Double);
 
     function GetStageData: TStageData;
@@ -110,7 +110,7 @@ begin
 end;
 
 destructor TBillsMeasureData.Destroy;
-begin
+begin   
   FFormulaCalc.Free;
   FBillsMeasureTree.Free;
   inherited;
@@ -202,23 +202,12 @@ procedure TBillsMeasureData.sdvBillsMeasureGetText(var Text: String;
   var
     stnNode: TsdIDTreeNode;
   begin
-    if (Pos('TotalPrice', AColumn.FieldName) > 0) or
-       (Pos('Quantity', AColumn.FieldName) > 0) or
-       (Pos('Price', AColumn.FieldName) > 0) then
+    if Assigned(AValue) and (AValue.DataType = ftFloat) and (AValue.AsFloat = 0) then
     begin
-      if AValue.AsFloat = 0 then
-        Text := '';
+      Text := '';
+      Exit;
     end;
 
-    if SameText('Quantity', AColumn.FieldName) or
-        SameText('Price', AColumn.FieldName) or
-        SameText('NewPrice', AColumn.FieldName) or
-        SameText('AddGatherQuantity', AColumn.FieldName) then
-    begin
-      stnNode := BillsMeasureTree.FindNode(AValue.Owner.ValueByName('ID').AsInteger);
-      if stnNode.HasChildren then
-        Text := '';
-    end;
     // 所有本期数据,当节点为父节点时,不显示值(实际上需要计算其中的金额值,但又不能显示)
     // 有病。每天都在变。
     if not ShowParentData and (Pos('Cur', AColumn.FieldName) > 0) and (Pos('Gather', AColumn.FieldName) = 0) then
@@ -894,6 +883,7 @@ var
   i: Integer;
   vNode: TBillsIDTreeNode;
 begin
+  if not StageData.Active then Exit;
   for i := 0 to BillsMeasureTree.Count - 1 do
   begin
     vNode := TBillsIDTreeNode(BillsMeasureTree.Items[i]);

+ 44 - 8
Frames/BillsCompileFme.pas

@@ -5,7 +5,7 @@ interface
 uses
   BillsCompileDm, UtilMethods, BillsClipboard, sdIDTree, BatchReplaceBillsFrm,
   CheckAndClearFrm, DealBillsFrm, BillsPasteSelectFrm,
-  sdDB,
+  sdDB, sdIDTreeCells,
   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
   Dialogs, ActnList, sdGridDBA, sdGridTreeDBA, dxBar, ZJGrid, StdCtrls,
   ExtCtrls;
@@ -78,6 +78,8 @@ type
 
     procedure SetShowIDField(AValue: Boolean);
 
+    procedure ExpandMouseDown(AGridCell: TzjCell);
+
     procedure BeginExpandNode;
     procedure EndExpandNode;
 
@@ -107,7 +109,7 @@ implementation
 
 uses
   MainFrm, BatchInsertBillsFrm, ExportExcel, ProjectData, mEncryptEditions,
-  ExcelImport;
+  ExcelImport, BillsTree;
 
 {$R *.dfm}
 
@@ -208,6 +210,7 @@ begin
   stdBillsCompile.IDTree := FBillsCompileData.BillsCompileTree;
   with TProjectData(FBillsCompileData.ProjectData) do
     stdBillsCompile.Column('LockedInfo').ReadOnly := ProjProperties.PhaseCount > 0;
+  zgBillsCompile.OnExpandMouseDown := ExpandMouseDown;
 end;
 
 destructor TBillsCompileFrame.Destroy;
@@ -236,19 +239,19 @@ end;
 procedure TBillsCompileFrame.zgBillsCompileCellGetColor(Sender: TObject;
   ACoord: TPoint; var AColor: TColor);
 var
-  stnNode: TsdIDTreeNode;
+  stnNode: TBillsIDTreeNode;
   iCreatePhaseID: Integer;
 begin
   if ACoord.Y > stdBillsCompile.IDTree.Count + 1 then Exit;
-  stnNode := stdBillsCompile.IDTree.Items[ACoord.Y - 3];
+  stnNode := TBillsIDTreeNode(stdBillsCompile.IDTree.Items[ACoord.Y - 3]);
   if not Assigned(stnNode) then Exit;
-  iCreatePhaseID := stnNode.Rec.ValueByName('CreatePhaseID').AsInteger;
+  iCreatePhaseID := stnNode.Rec.CreatePhaseID.AsInteger;
   if stnNode.ParentID = 1 then
     AColor := $00FBCAC4
-  else if (stnNode.Rec.ValueByName('B_Code').AsString = '') and (stnNode.Level > 0) then
+  else if (stnNode.Rec.B_Code.AsString = '') and (stnNode.Level > 0) then
     AColor := $00F9E8DF;
   // 书签
-  if stnNode.Rec.ValueByName('HasBookmark').AsBoolean then
+  if stnNode.Rec.HasBookmark.AsBoolean then
     AColor := $00CFE2F9;
   // 根据节点创建期数底色不同
   if iCreatePhaseID > 0 then
@@ -534,6 +537,7 @@ end;
 
 procedure TBillsCompileFrame.BeginExpandNode;
 begin
+  zgBillsCompile.BeginUpdate;
   zgBillsCompile.OnCellGetColor := nil;
   BeginUpdateWindow(zgBillsCompile.Handle);
   stdBillsCompile.DisableControl;
@@ -544,7 +548,7 @@ begin
   stdBillsCompile.EnableControl;
   EndUpdateWindow(zgBillsCompile.Handle);
   zgBillsCompile.OnCellGetColor := zgBillsCompileCellGetColor;
-  zgBillsCompile.Invalidate;
+  zgBillsCompile.EndUpdate;
 end;
 
 procedure TBillsCompileFrame.RefreshPhase_Stage;
@@ -574,4 +578,36 @@ begin
   stdBillsCompile.Column('DrawingCode').ReadOnly := AReadOnly;
 end;
 
+procedure TBillsCompileFrame.ExpandMouseDown(AGridCell: TzjCell);
+
+  procedure CommonExpand(vNode: TsdIDTreeNode);
+  begin
+    AGridCell.Grid.BeginUpdate;
+    vNode.Expanded := not vNode.Expanded;
+    AGridCell.Grid.EndUpdate;
+    AGridCell.Grid.InvalidateView(AGridCell.ViewRect);
+  end;
+
+  procedure QuikExpand(vNode: TsdIDTreeNode);
+  begin
+    Screen.Cursor := crHourGlass;
+    BeginExpandNode;
+    try
+      vNode.Expanded := not vNode.Expanded;
+    finally
+      EndExpandNode;
+      Screen.Cursor := crDefault;
+    end;
+  end;
+
+var
+  stnNode: TsdIDTreeNode;
+begin
+  stnNode := TsdIDTreeCell(AGridCell).TreeNode;
+  if stnNode.PosterityCount > 10000 then
+    QuikExpand(stnNode)
+  else
+    CommonExpand(stnNode);
+end;
+
 end.

+ 46 - 11
Frames/BillsMeasureFme.pas

@@ -3,7 +3,7 @@ unit BillsMeasureFme;
 interface
 
 uses
-  BillsMeasureDm, UtilMethods, BillsClipboard,
+  BillsMeasureDm, UtilMethods, BillsClipboard, sdIDTreeCells,
   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Dialogs, ZJGrid, ComCtrls, ToolWin, StdCtrls, ExtCtrls, sdGridDBA,
   sdGridTreeDBA, sdDB, ActnList, dxBar, sdIDTree, JimLabels;
@@ -60,6 +60,8 @@ type
     FOnAfterSetBookmark: TBookmarkRefreshEvent;
     FShowAlias: Boolean;
 
+    procedure ExpandMouseDown(AGridCell: TzjCell);
+
     function CheckExprsColumn(ACol: Integer): Boolean;
 
     procedure SetColumnVisible(const AColumn: string; AVisible: Boolean);
@@ -114,6 +116,7 @@ begin
   inherited Create(AProjectFrame);
   FBillsMeasureData := ABillsMeasureData;
   stdBillsMeasure.IDTree := FBillsMeasureData.BillsMeasureTree;
+  zgBillsMeasure.OnExpandMouseDown := ExpandMouseDown;
 end;
 
 destructor TBillsMeasureFrame.Destroy;
@@ -183,26 +186,26 @@ end;
 procedure TBillsMeasureFrame.zgBillsMeasureCellGetColor(Sender: TObject; ACoord: TPoint;
   var AColor: TColor);
 var
-  stnNode: TsdIDTreeNode;
+  stnNode: TBillsIDTreeNode;
   iCreatePhaseID: Integer;
-  StageRec: TsdDataRecord;
+  StageRec: TStageRecord;
   fQtyDiffer: Double;
 begin
   AColor := clWindow;
   if ACoord.Y > stdBillsMeasure.IDTree.Count + 1 then Exit;
-  stnNode := stdBillsMeasure.IDTree.Items[ACoord.Y - 2];
+  stnNode := TBillsIDTreeNode(stdBillsMeasure.IDTree.Items[ACoord.Y - 2]);
   if not Assigned(stnNode) then Exit;
-  iCreatePhaseID := stnNode.Rec.ValueByName('CreatePhaseID').AsInteger;
+  iCreatePhaseID := stnNode.Rec.CreatePhaseID.AsInteger;
   // 根据层次底色不同
   if stnNode.ParentID = 1 then
     AColor := $00FBCAC4
-  else if (stnNode.Rec.ValueByName('B_Code').AsString = '') and (stnNode.Level > 0) then
+  else if (stnNode.Rec.B_Code.AsString = '') and (stnNode.Level > 0) then
     AColor := $00F9E8DF;
   // 书签
   if TProjectData(FBillsMeasureData.ProjectData).ProjProperties.PhaseCount > 0 then
   begin
-    StageRec := TBillsIDTreeNode(stnNode).StageRec;
-    if Assigned(StageRec) and StageRec.ValueByName('HasBookmark').AsBoolean then
+    StageRec := stnNode.StageRec;
+    if Assigned(StageRec) and StageRec.HasBookmark.AsBoolean then
       AColor := $00CFE2F9;
   end;
   // 根据节点创建期数底色不同
@@ -219,8 +222,7 @@ begin
   if not stnNode.HasChildren then
   begin
     with stnNode.Rec do
-      fQtyDiffer := QuantityRoundTo(
-          ValueByName('AddDealQuantity').AsFloat - ValueByName('Quantity').AsFloat);
+      fQtyDiffer := QuantityRoundTo(AddDealQuantity.AsFloat - Quantity.AsFloat);
     if fQtyDiffer > 0 then
       AColor := $00646AFE;
   end;
@@ -570,6 +572,7 @@ end;
 
 procedure TBillsMeasureFrame.BeginExpandNode;
 begin
+  zgBillsMeasure.BeginUpdate;
   zgBillsMeasure.OnCellGetColor := nil;
   BeginUpdateWindow(zgBillsMeasure.Handle);
   stdBillsMeasure.DisableControl;
@@ -580,7 +583,7 @@ begin
   stdBillsMeasure.EnableControl;
   EndUpdateWindow(zgBillsMeasure.Handle);
   zgBillsMeasure.OnCellGetColor := zgBillsMeasureCellGetColor;
-  zgBillsMeasure.Invalidate;
+  zgBillsMeasure.EndUpdate;
 end;
 
 procedure TBillsMeasureFrame.ExpandCurPhase;
@@ -638,4 +641,36 @@ begin
   stdBillsMeasure.Column('PM_AddTotalPrice').Visible := AValue;
 end;
 
+procedure TBillsMeasureFrame.ExpandMouseDown(AGridCell: TzjCell);
+
+  procedure CommonExpand(vNode: TsdIDTreeNode);
+  begin
+    AGridCell.Grid.BeginUpdate;
+    vNode.Expanded := not vNode.Expanded;
+    AGridCell.Grid.EndUpdate;
+    AGridCell.Grid.InvalidateView(AGridCell.ViewRect);
+  end;
+
+  procedure QuikExpand(vNode: TsdIDTreeNode);
+  begin
+    Screen.Cursor := crHourGlass;
+    BeginExpandNode;
+    try
+      vNode.Expanded := not vNode.Expanded;
+    finally
+      EndExpandNode;
+      Screen.Cursor := crDefault;
+    end;
+  end;
+
+var
+  stnNode: TsdIDTreeNode;
+begin
+  stnNode := TsdIDTreeCell(AGridCell).TreeNode;
+  if stnNode.PosterityCount > 10000 then
+    QuikExpand(stnNode)
+  else
+    CommonExpand(stnNode);
+end;
+
 end.