Browse Source

价差调整,应可在项目属性界面设置价格相关的小数位数。
具体有:基础价、本期(价格,价差,有效价差)

MaiXinRong 9 years ago
parent
commit
7cc469ea5d

+ 9 - 5
DataModules/ProjectGLDm.pas

@@ -74,7 +74,8 @@ implementation
 
 uses
   ProjectData, UtilMethods, DB, Variants, PhaseData, DetailGLDm,
-  BillsMeasureDm, BillsTree, sdIDTree, PhasePayDm, DateUtils, ZhAPI;
+  BillsMeasureDm, BillsTree, sdIDTree, PhasePayDm, DateUtils, ZhAPI,
+  CalcDecimal;
 
 {$R *.dfm}
 
@@ -268,10 +269,13 @@ begin
   else
     ValidDeltaC := 0;
 
-  if DeltaC <> ARec.DeltaPrice.AsFloat then
-    ARec.DeltaPrice.AsFloat := PriceRoundTo(DeltaC);
-  if ValidDeltaC <> ARec.ValidDeltaPrice.AsFloat then
-    ARec.ValidDeltaPrice.AsFloat := PriceRoundTo(ValidDeltaC);
+  with TProjectData(FProjectData).ProjProperties.DecimalManager do
+  begin
+    if DeltaC <> ARec.DeltaPrice.AsFloat then
+      ARec.DeltaPrice.AsFloat := PriceMargin.Price.RoundTo(DeltaC);
+    if ValidDeltaC <> ARec.ValidDeltaPrice.AsFloat then
+      ARec.ValidDeltaPrice.AsFloat := PriceMargin.Price.RoundTo(ValidDeltaC);
+  end;
 end;
 
 procedure TProjectGLData.sdvProjectGLGetText(var Text: String;

+ 28 - 0
Forms/ProjectPropertiesFrm.dfm

@@ -929,6 +929,34 @@ object ProjectPropertiesForm: TProjectPropertiesForm
             Max = 10
             TabOrder = 30
           end
+          object gbPM_Digit: TGroupBox
+            Left = 52
+            Top = 830
+            Width = 349
+            Height = 49
+            Caption = #20215#24046
+            TabOrder = 31
+            object lePM_PriceDigit: TLabeledEdit
+              Left = 49
+              Top = 19
+              Width = 87
+              Height = 18
+              EditLabel.Width = 36
+              EditLabel.Height = 12
+              EditLabel.Caption = #21333#20215#65306
+              LabelPosition = lpLeft
+              TabOrder = 0
+            end
+            object udPM_PriceDigit: TUpDown
+              Left = 136
+              Top = 19
+              Width = 16
+              Height = 18
+              Associate = lePM_PriceDigit
+              Max = 10
+              TabOrder = 1
+            end
+          end
         end
       end
     end

+ 9 - 0
Forms/ProjectPropertiesFrm.pas

@@ -99,6 +99,9 @@ type
     leTotalPriceDigit: TLabeledEdit;
     udQuantity: TUpDown;
     udTotalPrice: TUpDown;
+    gbPM_Digit: TGroupBox;
+    lePM_PriceDigit: TLabeledEdit;
+    udPM_PriceDigit: TUpDown;
     procedure btnOkClick(Sender: TObject);
     procedure leContractPriceClick(Sender: TObject);
     procedure msbBaseMouseWheel(Sender: TObject; Shift: TShiftState;
@@ -533,6 +536,8 @@ begin
     FProjProperties.TotalPriceDigit := udTotalPrice.Position;
     FProjectData.ResetFloatDigitView;
   end;
+  if (FProjProperties.PhaseCount = 1) and not FProjectData.PriceMarginReadOnly then
+    FProjProperties.DecimalManager.PriceMargin.Price.Digit := udPM_PriceDigit.Position;
 end;
 
 procedure TProjectPropertiesForm.InitCalcParameters;
@@ -543,6 +548,10 @@ begin
   udTotalPrice.Position := FProjProperties.TotalPriceDigit;
   leTotalPriceDigit.ReadOnly := FProjProperties.PhaseCount > 0;
   udTotalPrice.Enabled := FProjProperties.PhaseCount = 0;
+
+  udPM_PriceDigit.Position := FProjProperties.DecimalManager.PriceMargin.Price.Digit;
+  lePM_PriceDigit.ReadOnly := FProjectData.PriceMarginReadOnly and (FProjProperties.PhaseCount > 1);
+  udPM_PriceDigit.Enabled := not lePM_PriceDigit.ReadOnly;
 end;
 
 procedure TProjectPropertiesForm.SaveProjectView;

+ 54 - 17
Units/CalcDecimal.pas

@@ -18,6 +18,8 @@ type
     constructor Create;
     destructor Destroy; override;
 
+    function RoundTo(AValue: Double): Double;
+
     procedure ClearLinkViewCols;
     procedure AddLinkViewCol(ACol: TObject);
 
@@ -36,6 +38,9 @@ type
     constructor Create;
     destructor Destroy; override;
 
+    procedure ResetLinkViewColumns(AProjectData: TObject);
+    procedure RefreshLinkViewColumnsFormat;
+
     property Quantity: TDecimal read FQuantity;
     property TotalPrice: TDecimal read FTotalPrice;
     property Price: TDecimal read FPrice;
@@ -46,6 +51,7 @@ type
     FProjectData: TObject;
     FCommon: TCalcDecimal;
     FCompile:TCalcDecimal;
+    FPriceMargin: TCalcDecimal;
   public
     constructor Create(AProjectData: TObject);
     destructor Destroy; override;
@@ -55,12 +61,13 @@ type
 
     property Common: TCalcDecimal read FCommon;
     property Compile: TCalcDecimal read FCompile;
+    property PriceMargin: TCalcDecimal read FPriceMargin;
   end;
 
 implementation
 
 uses
-  ProjectData;
+  ProjectData, ScUtils;
 
 { TDecimal }
 
@@ -88,18 +95,18 @@ end;
 function TDecimal.GetDisplayFormat(ADigit: Integer): string;
 begin
   case ADigit of
-    0: Result := '0';
-    1: Result := '0.#';
-    2: Result := '0.##';
-    3: Result := '0.###';
-    4: Result := '0.####';
-    5: Result := '0.#####';
-    6: Result := '0.######';
-    7: Result := '0.#######';
-    8: Result := '0.########';
-    9: Result := '0.#########';
+    0: Result := '#';
+    1: Result := '#.#';
+    2: Result := '#.##';
+    3: Result := '#.###';
+    4: Result := '#.####';
+    5: Result := '#.#####';
+    6: Result := '#.######';
+    7: Result := '#.#######';
+    8: Result := '#.########';
+    9: Result := '#.#########';
   else
-    Result := '0.##########';
+    Result := '#.##########';
   end;
 end;
 
@@ -111,16 +118,26 @@ begin
   for i := 0 to FLinkViewCols.Count - 1 do
   begin
     ViewCol := TsdViewColumn(FLinkViewCols.Items[i]);
+    if not Assigned(ViewCol) then Continue;
+
     ViewCol.DisplayFormat := FFormat;
     ViewCol.EditFormat := FFormat;
   end;
 end;
 
+function TDecimal.RoundTo(AValue: Double): Double;
+begin
+  Result := ScRoundTo(AValue, -Digit);
+end;
+
 procedure TDecimal.SetDigit(const Value: Integer);
 begin
-  FDigit := Value;
-  FFormat := GetDisplayFormat(FDigit);
-  RefreshLinkViewColsFormat;
+  if FDigit <> Value then
+  begin
+    FDigit := Value;
+    FFormat := GetDisplayFormat(FDigit);
+    RefreshLinkViewColsFormat;
+  end;
 end;
 
 { TCalcDecimal }
@@ -140,6 +157,23 @@ begin
   inherited;
 end;
 
+procedure TCalcDecimal.RefreshLinkViewColumnsFormat;
+begin
+  Price.RefreshLinkViewColsFormat;
+end;
+
+procedure TCalcDecimal.ResetLinkViewColumns(AProjectData: TObject);
+begin
+  Price.ClearLinkViewCols;
+  with TProjectData(AProjectData).ProjectGLData.sdvProjectGL do
+  begin
+    Price.AddLinkViewCol(Columns.FindColumn('BasePrice'));
+    Price.AddLinkViewCol(Columns.FindColumn('InfoPrice'));
+    Price.AddLinkViewCol(Columns.FindColumn('DeltaPrice'));
+    Price.AddLinkViewCol(Columns.FindColumn('ValidDeltaPrice'));
+  end;
+end;
+
 { TDecimalManager }
 
 constructor TDecimalManager.Create(AProjectData: TObject);
@@ -147,10 +181,12 @@ begin
   FProjectData := AProjectData;
   FCommon := TCalcDecimal.Create;
   FCompile := TCalcDecimal.Create;
+  FPriceMargin := TCalcDecimal.Create;
 end;
 
 destructor TDecimalManager.Destroy;
 begin
+  FPriceMargin.Free;
   FCompile.Free;
   FCommon.Free;
   inherited;
@@ -245,8 +281,9 @@ procedure TDecimalManager.ResetLinkViewColumns;
   end;
 
 begin
-  ResetCommonLink;
-  ResetCompileLink;
+  //ResetCommonLink;
+  //ResetCompileLink;
+  FPriceMargin.ResetLinkViewColumns(FProjectData);
 end;
 
 end.

+ 1 - 0
Units/ProjectData.pas

@@ -397,6 +397,7 @@ begin
     FProjProperties.UpdateFlag := 1;
   UpdateOldData;
   ResetFloatDigitView;
+  FProjProperties.DecimalManager.ResetLinkViewColumns;
   UpdateSysProgress(25, 'ÕýÔÚ¶ÁÈ¡Êý¾Ý');
   FBillsData.Open(FConnection.Connection);
   if FIsNewFile then

+ 28 - 20
Units/ProjectProperty.pas

@@ -348,18 +348,18 @@ end;
 function TProjProperties.GetDisplayFormat(ADigit: Integer): string;
 begin
   case ADigit of
-    0: Result := '0';
-    1: Result := '0.#';
-    2: Result := '0.##';
-    3: Result := '0.###';
-    4: Result := '0.####';
-    5: Result := '0.#####';
-    6: Result := '0.######';
-    7: Result := '0.#######';
-    8: Result := '0.########';
-    9: Result := '0.#########';
+    0: Result := '#';
+    1: Result := '#.#';
+    2: Result := '#.##';
+    3: Result := '#.###';
+    4: Result := '#.####';
+    5: Result := '#.#####';
+    6: Result := '#.######';
+    7: Result := '#.#######';
+    8: Result := '#.########';
+    9: Result := '#.#########';
   else
-    Result := '0.##########';
+    Result := '#.##########';
   end;
 end;
 
@@ -408,6 +408,13 @@ end;
 
 procedure TProjProperties.LoadCalcParameters;
 begin
+  FQuantityDigit := GetIntPropertyDef('QuantityDigit', 3);
+  FQuantityFormat := GetDisplayFormat(FQuantityDigit);
+  FTotalPriceDigit := GetIntPropertyDef('TotalPriceDigit', 0);
+  FTotalPriceFormat := GetDisplayFormat(FTotalPriceDigit);
+  FPriceDigit := 2;
+  FPriceFormat := GetDisplayFormat(FPriceDigit);
+
   with FDecimalManager.Common do
   begin
     Quantity.Digit := GetIntPropertyDef('QuantityDigit', 3);
@@ -420,13 +427,12 @@ begin
     Compile.TotalPrice.Digit := GetIntPropertyDef('TotalPriceDigit1', Common.TotalPrice.Digit);
     Compile.Price.Digit := 2;
   end;
-
-  FQuantityDigit := GetIntPropertyDef('QuantityDigit', 3);
-  FQuantityFormat := GetDisplayFormat(FQuantityDigit);
-  FTotalPriceDigit := GetIntPropertyDef('TotalPriceDigit', 0);
-  FTotalPriceFormat := GetDisplayFormat(FTotalPriceDigit);
-  FPriceDigit := 2;
-  FPriceFormat := GetDisplayFormat(FPriceDigit);
+  with FDecimalManager do
+  begin
+    PriceMargin.Quantity.Digit := Common.Quantity.Digit;
+    PriceMargin.TotalPrice.Digit := Common.TotalPrice.Digit;
+    PriceMargin.Price.Digit := GetIntPropertyDef('PM_PriceDigit', Common.Price.Digit);
+  end;
 end;
 
 procedure TProjProperties.LoadDealInfo;
@@ -488,10 +494,12 @@ procedure TProjProperties.SaveCalcParameters;
 begin
   with FDecimalManager do
   begin
-    FPropertyInqurity.Value['QuantityDigit'] := Common.Quantity.Digit;
+    {FPropertyInqurity.Value['QuantityDigit'] := Common.Quantity.Digit;
     FPropertyInqurity.Value['TotalPriceDigit'] := Common.TotalPrice.Digit;
     FPropertyInqurity.Value['QuantityDigit1'] := Compile.Quantity.Digit;
-    FPropertyInqurity.Value['TotalPriceDigit1'] := Compile.TotalPrice.Digit;
+    FPropertyInqurity.Value['TotalPriceDigit1'] := Compile.TotalPrice.Digit;}
+    
+    FPropertyInqurity.Value['PM_PriceDigit'] := PriceMargin.Price.Digit;
   end;
 end;