unit CalcDecimal; interface uses Classes, sdDB; type TDecimal = class private FDigit: Integer; FFormat: string; FLinkViewCols: TList; procedure SetDigit(const Value: Integer); function GetDisplayFormat(ADigit: Integer): string; public constructor Create; destructor Destroy; override; function RoundTo(AValue: Double): Double; procedure ClearLinkViewCols; procedure AddLinkViewCol(ACol: TObject); procedure RefreshLinkViewColsFormat; property Digit: Integer read FDigit write SetDigit; property Format: string read FFormat; end; TCalcDecimal = class private FQuantity: TDecimal; FTotalPrice: TDecimal; FPrice: TDecimal; public 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; end; TDecimalManager = class private FProjectData: TObject; FCommon: TCalcDecimal; FCompile:TCalcDecimal; FPriceMargin: TCalcDecimal; public constructor Create(AProjectData: TObject); destructor Destroy; override; procedure ResetLinkViewColumns; procedure RefreshLinkViewColumnsFormat; property Common: TCalcDecimal read FCommon; property Compile: TCalcDecimal read FCompile; property PriceMargin: TCalcDecimal read FPriceMargin; end; implementation uses ProjectData, ScUtils; { TDecimal } procedure TDecimal.AddLinkViewCol(ACol: TObject); begin FLinkViewCols.Add(ACol); end; procedure TDecimal.ClearLinkViewCols; begin FLinkViewCols.Clear; end; constructor TDecimal.Create; begin FLinkViewCols := TList.Create; end; destructor TDecimal.Destroy; begin FLinkViewCols.Free; inherited; end; function TDecimal.GetDisplayFormat(ADigit: Integer): string; begin case ADigit of 0: Result := '#'; 1: Result := '#.#'; 2: Result := '#.##'; 3: Result := '#.###'; 4: Result := '#.####'; 5: Result := '#.#####'; 6: Result := '#.######'; 7: Result := '#.#######'; 8: Result := '#.########'; 9: Result := '#.#########'; else Result := '#.##########'; end; end; procedure TDecimal.RefreshLinkViewColsFormat; var i: Integer; ViewCol: TsdViewColumn; 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 if FDigit <> Value then begin FDigit := Value; FFormat := GetDisplayFormat(FDigit); RefreshLinkViewColsFormat; end; end; { TCalcDecimal } constructor TCalcDecimal.Create; begin FQuantity := TDecimal.Create; FTotalPrice := TDecimal.Create; FPrice := TDecimal.Create; end; destructor TCalcDecimal.Destroy; begin FPrice.Free; FTotalPrice.Free; FQuantity.Free; 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; Price.RefreshLinkViewColsFormat; end; { TDecimalManager } constructor TDecimalManager.Create(AProjectData: TObject); begin FProjectData := AProjectData; FCommon := TCalcDecimal.Create; FCompile := TCalcDecimal.Create; FPriceMargin := TCalcDecimal.Create; end; destructor TDecimalManager.Destroy; begin FPriceMargin.Free; FCompile.Free; FCommon.Free; inherited; end; procedure TDecimalManager.RefreshLinkViewColumnsFormat; begin FCommon.Quantity.RefreshLinkViewColsFormat; FCommon.TotalPrice.RefreshLinkViewColsFormat; FCommon.Price.RefreshLinkViewColsFormat; FCompile.Quantity.RefreshLinkViewColsFormat; FCompile.TotalPrice.RefreshLinkViewColsFormat; FCompile.Price.RefreshLinkViewColsFormat; end; procedure TDecimalManager.ResetLinkViewColumns; procedure ResetCommonLink; begin FCommon.Quantity.ClearLinkViewCols; FCommon.TotalPrice.ClearLinkViewCols; FCommon.Price.ClearLinkViewCols; with TProjectData(FProjectData).BillsCompileData.sdvBillsCompile do begin // Quantity FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('OrgQuantity')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('MisQuantity')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('OthQuantity')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('Quantity')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('DgnQuantity1')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('DgnQuantity2')); // TotalPrice FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('OrgTotalPrice')); FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('MisTotalPrice')); FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('OthTotalPrice')); FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('TotalPrice')); // Price FCommon.Price.AddLinkViewCol(Columns.FindColumn('Price')); FCommon.Price.AddLinkViewCol(Columns.FindColumn('NewPrice')); end; with TProjectData(FProjectData).BillsMeasureData.sdvBillsMeasure do begin // Quantity FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('Quantity')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('CurDealQuantity')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('CurQcQuantity')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('CurPcQuantity')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('CurGatherQuantity')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('EndDealQuantity')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('EndQcQuantity')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('EndPcQuantity')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('EndGahterQuantity')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('AddDealQuantity')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('AddQcQuantity')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('AddPcQuantity')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('AddGahterQuantity')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('DealDgnQuantity1')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('DealDgnQuantity2')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('CDgnQuantity1')); FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('CDgnQuantity2')); // TotalPrice FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('TotalPrice')); FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('CurDealTotalPrice')); FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('CurQcTotalPrice')); FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('CurPcTotalPrice')); FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('CurGatherTotalPrice')); FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('EndDealTotalPrice')); FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('EndQcTotalPrice')); FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('EndPcTotalPrice')); FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('EndGahterTotalPrice')); FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('AddDealTotalPrice')); FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('AddQcTotalPrice')); FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('AddPcTotalPrice')); FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('AddGahterTotalPrice')); // Price FCommon.Price.AddLinkViewCol(Columns.FindColumn('Price')); FCommon.Price.AddLinkViewCol(Columns.FindColumn('NewPrice')); end; end; procedure ResetCompileLink; begin // TODO end; begin //ResetCommonLink; //ResetCompileLink; FPriceMargin.ResetLinkViewColumns(FProjectData); end; end.