BatchReplaceBillsFrm.pas 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. unit BatchReplaceBillsFrm;
  2. interface
  3. uses
  4. sdDB, BillsDm, ZhAPI,
  5. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  6. Dialogs, StdCtrls, ZJGrid, ExtCtrls;
  7. type
  8. TBatchReplaceBillsForm = class(TForm)
  9. pnlBills: TPanel;
  10. lblBills: TLabel;
  11. zgBills: TZJGrid;
  12. pnlBillsSpr: TPanel;
  13. pnlOther: TPanel;
  14. btnOk: TButton;
  15. btnCancel: TButton;
  16. pnlOrgBills: TPanel;
  17. lblOrgBills: TLabel;
  18. zgOrgBills: TZJGrid;
  19. pnlOrgBillsSpr: TPanel;
  20. procedure zgOrgBillsCellCanEdit(Sender: TObject; const ACoord: TPoint;
  21. var Allow: Boolean);
  22. procedure btnOkClick(Sender: TObject);
  23. procedure zgBillsCellTextChanged(Sender: TObject; Col, Row: Integer);
  24. private
  25. FBillsData: TBillsData;
  26. procedure InitGrid(AGrid: TZJGrid; ARec: TsdDataRecord);
  27. public
  28. procedure Init(ARec: TsdDataRecord);
  29. procedure Execute;
  30. property BillsData: TBillsData read FBillsData write FBillsData;
  31. end;
  32. procedure BatchReplaceBillsInfo(ARec: TsdDataRecord; ABillsData: TBillsData);
  33. implementation
  34. uses
  35. UtilMethods, ProjectData;
  36. procedure BatchReplaceBillsInfo(ARec: TsdDataRecord; ABillsData: TBillsData);
  37. var
  38. ReplaceBillsFrm: TBatchReplaceBillsForm;
  39. begin
  40. ReplaceBillsFrm := TBatchReplaceBillsForm.Create(nil);
  41. try
  42. ReplaceBillsFrm.Init(ARec);
  43. ReplaceBillsFrm.BillsData := ABillsData;
  44. if ReplaceBillsFrm.ShowModal = mrOk then
  45. ReplaceBillsFrm.Execute;
  46. finally
  47. ReplaceBillsFrm.Free;
  48. end;
  49. end;
  50. {$R *.dfm}
  51. { TBatchReplaceBillsForm }
  52. procedure TBatchReplaceBillsForm.Execute;
  53. var
  54. iIndex: Integer;
  55. Rec: TsdDataRecord;
  56. bHasChange: Boolean;
  57. begin
  58. FBillsData.sddBills.BeginUpdate;
  59. try
  60. bHasChange := False;
  61. for iIndex := 0 to FBillsData.sddBills.RecordCount - 1 do
  62. begin
  63. Rec := FBillsData.sddBills.Records[iIndex];
  64. if SameText(Rec.ValueByName('B_Code').AsString, zgOrgBills.Cells[1, 1].Text) and
  65. SameText(Rec.ValueByName('Name').AsString, zgOrgBills.Cells[2, 1].Text) and
  66. SameText(Rec.ValueByName('Units').AsString, zgOrgBills.Cells[3, 1].Text) then
  67. begin
  68. Rec.ValueByName('B_Code').AsString := zgBills.Cells[1, 1].Text;
  69. Rec.ValueByName('Name').AsString := zgBills.Cells[2, 1].Text;
  70. Rec.ValueByName('Units').AsString := zgBills.Cells[3, 1].Text;
  71. if Rec.ValueByName('Price').AsString <> zgBills.Cells[4, 1].Text then
  72. begin
  73. bHasChange := True;
  74. Rec.ValueByName('Price').AsString := zgBills.Cells[4, 1].Text;
  75. end;
  76. end;
  77. end;
  78. if bHasChange then
  79. TProjectData(FBillsData.ProjectData).BillsCompileData.CalculateAll;
  80. finally
  81. FBillsData.sddBills.EndUpdate;
  82. end;
  83. end;
  84. procedure TBatchReplaceBillsForm.Init(ARec: TsdDataRecord);
  85. begin
  86. InitGrid(zgOrgBills, ARec);
  87. InitGrid(zgBills, ARec);
  88. end;
  89. procedure TBatchReplaceBillsForm.InitGrid(AGrid: TZJGrid; ARec: TsdDataRecord);
  90. procedure InitGridHead;
  91. begin
  92. AGrid.Cells[1, 0].Text := '헌데긍뵀';
  93. AGrid.ColWidths[1] := 80;
  94. AGrid.Cells[2, 0].Text := '츰냔';
  95. AGrid.ColWidths[2] := 120;
  96. AGrid.Cells[3, 0].Text := '데貫';
  97. AGrid.ColWidths[3] := 50;
  98. AGrid.Cells[4, 0].Text := '데송';
  99. AGrid.ColWidths[4] := 60;
  100. end;
  101. procedure InitGridInfo;
  102. begin
  103. AGrid.Cells[1, 1].Text := ARec.ValueByName('B_Code').AsString;
  104. AGrid.Cells[1, 1].TextAlign := gaCenterLeft;
  105. AGrid.Cells[2, 1].Text := ARec.ValueByName('Name').AsString;
  106. AGrid.Cells[2, 1].TextAlign := gaCenterLeft;
  107. AGrid.Cells[3, 1].Text := ARec.ValueByName('Units').AsString;
  108. AGrid.Cells[3, 1].TextAlign := gaCenterLeft;
  109. AGrid.Cells[4, 1].Text := ARec.ValueByName('Price').AsString;
  110. AGrid.Cells[4, 1].TextAlign := gaCenterRight;
  111. end;
  112. begin
  113. InitGridHead;
  114. InitGridInfo;
  115. end;
  116. procedure TBatchReplaceBillsForm.zgOrgBillsCellCanEdit(Sender: TObject;
  117. const ACoord: TPoint; var Allow: Boolean);
  118. begin
  119. Allow := False;
  120. end;
  121. procedure TBatchReplaceBillsForm.btnOkClick(Sender: TObject);
  122. begin
  123. if zgBills.Cells[1, 1].Text = '' then
  124. ErrorMessage('헝渴흙헌데긍뵀!')
  125. else
  126. ModalResult := mrOK;
  127. end;
  128. procedure TBatchReplaceBillsForm.zgBillsCellTextChanged(Sender: TObject;
  129. Col, Row: Integer);
  130. var
  131. fPrice: Double;
  132. begin
  133. if (Col = 4) and (Row = 1) then
  134. begin
  135. if (zgBills.Cells[Col, Row].Text <> '') and not TryStrToFloat(zgBills.Cells[Col, Row].Text, fPrice) then
  136. begin
  137. ErrorMessage('데송怜豚冀渴흙鑒俚');
  138. zgBills.Cells[Col, Row].Text := '';
  139. end
  140. else
  141. zgBills.Cells[Col, Row].Value := PriceRoundTo(
  142. StrToFloatDef(zgBills.Cells[Col, Row].Text, 0));
  143. end;
  144. end;
  145. end.