unit stgGclImportHintFrm;

interface

uses
  stgGclImportHint,
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ZJGrid;

type
  TstgGclImportHintForm = class(TForm)
    zgFails: TZJGrid;
    pnlButton: TPanel;
    btnSave: TButton;
    btnCance: TButton;
    procedure btnSaveClick(Sender: TObject);
  private
    procedure InitGrid;
  public
    procedure LoadFailsData(AFails: TstgGclFailList);
  end;

procedure ShowGclImportForm(AFails: TstgGclFailList);

implementation

uses
  UtilMethods, ExportExcel;

procedure ShowGclImportForm(AFails: TstgGclFailList);
var
  vForm: TstgGclImportHintForm;
begin
  vForm := TstgGclImportHintForm.Create(nil);
  try
    vForm.LoadFailsData(AFails);
    vForm.ShowModal;
  finally
    vForm.Free;
  end;
end;

{$R *.dfm}

{ TstgGclImportHintForm }

procedure TstgGclImportHintForm.InitGrid;
begin
  zgFails.ColCount := 6;
  zgFails.ColWidths[1] := 120;
  zgFails.ColWidths[2] := 250;
  zgFails.ColWidths[3] := 60;
  zgFails.ColWidths[4] := 80;
  zgFails.ColWidths[5] := 100;
  zgFails.Cells[1, 0].Text := '清单编号';
  zgFails.Cells[2, 0].Text := '名称';
  zgFails.Cells[3, 0].Text := '单位';
  zgFails.Cells[4, 0].Text := '单价';
  zgFails.Cells[5, 0].Text := '合同计量';
end;

procedure TstgGclImportHintForm.LoadFailsData(AFails: TstgGclFailList);
var
  i: Integer;
  vFailGcl: TstgGclFail;
begin
  zgFails.RowCount := AFails.Count + 1;
  InitGrid;
  for i := 0 to AFails.Count - 1 do
  begin
    vFailGcl := AFails.Gcl[i];
    zgFails.Cells[1, 1+i].Text := vFailGcl.B_Code;
    zgFails.Cells[2, 1+i].Text := vFailGcl.Name;
    zgFails.Cells[3, 1+i].Text := vFailGcl.Units;
    zgFails.Cells[4, 1+i].Text := FloatToStr(vFailGcl.Price);
    zgFails.Cells[5, 1+i].Text := FloatToStr(vFailGcl.DealQuantity);
  end;
end;

procedure TstgGclImportHintForm.btnSaveClick(Sender: TObject);
var
  sFileName: string;
  ExcelExportor: TExcelExportor;
begin
  if SaveExcelFile(sFileName) then
  begin
    ExcelExportor := TExcelExportor.Create;
    try
      ExcelExportor.ExportToFile(zgFails, sFileName);
      ModalResult := mrOk;
    finally
      ExcelExportor.Free;
    end;
  end;
end;

end.
