BatchReplaceBillsFrm.pas 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. ClientHeight := 218;
  87. ClientWidth := 375;
  88. InitGrid(zgOrgBills, ARec);
  89. InitGrid(zgBills, ARec);
  90. end;
  91. procedure TBatchReplaceBillsForm.InitGrid(AGrid: TZJGrid; ARec: TsdDataRecord);
  92. procedure InitGridHead;
  93. begin
  94. AGrid.Cells[1, 0].Text := '헌데긍뵀';
  95. AGrid.ColWidths[1] := 80;
  96. AGrid.Cells[2, 0].Text := '츰냔';
  97. AGrid.ColWidths[2] := 120;
  98. AGrid.Cells[3, 0].Text := '데貫';
  99. AGrid.ColWidths[3] := 50;
  100. AGrid.Cells[4, 0].Text := '데송';
  101. AGrid.ColWidths[4] := 60;
  102. end;
  103. procedure InitGridInfo;
  104. begin
  105. AGrid.Cells[1, 1].Text := ARec.ValueByName('B_Code').AsString;
  106. AGrid.Cells[1, 1].TextAlign := gaCenterLeft;
  107. AGrid.Cells[2, 1].Text := ARec.ValueByName('Name').AsString;
  108. AGrid.Cells[2, 1].TextAlign := gaCenterLeft;
  109. AGrid.Cells[3, 1].Text := ARec.ValueByName('Units').AsString;
  110. AGrid.Cells[3, 1].TextAlign := gaCenterLeft;
  111. AGrid.Cells[4, 1].Text := ARec.ValueByName('Price').AsString;
  112. AGrid.Cells[4, 1].TextAlign := gaCenterRight;
  113. end;
  114. begin
  115. InitGridHead;
  116. InitGridInfo;
  117. end;
  118. procedure TBatchReplaceBillsForm.zgOrgBillsCellCanEdit(Sender: TObject;
  119. const ACoord: TPoint; var Allow: Boolean);
  120. begin
  121. Allow := False;
  122. end;
  123. procedure TBatchReplaceBillsForm.btnOkClick(Sender: TObject);
  124. begin
  125. if zgBills.Cells[1, 1].Text = '' then
  126. ErrorMessage('헝渴흙헌데긍뵀!')
  127. else
  128. ModalResult := mrOK;
  129. end;
  130. procedure TBatchReplaceBillsForm.zgBillsCellTextChanged(Sender: TObject;
  131. Col, Row: Integer);
  132. var
  133. fPrice: Double;
  134. begin
  135. if (Col = 4) and (Row = 1) then
  136. begin
  137. if (zgBills.Cells[Col, Row].Text <> '') and not TryStrToFloat(zgBills.Cells[Col, Row].Text, fPrice) then
  138. begin
  139. ErrorMessage('데송怜豚冀渴흙鑒俚');
  140. zgBills.Cells[Col, Row].Text := '';
  141. end
  142. else
  143. zgBills.Cells[Col, Row].Value := PriceRoundTo(
  144. StrToFloatDef(zgBills.Cells[Col, Row].Text, 0));
  145. end;
  146. end;
  147. end.