unit U_FinishedLSInList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridCustomTableView, cxGridTableView,
  cxGridBandedTableView, cxGridDBBandedTableView, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridDBTableView, cxGrid, StdCtrls, ComCtrls,
  ExtCtrls, ToolWin, cxGridCustomPopupMenu, cxGridPopupMenu, ADODB, DBClient,
  cxDropDownEdit, RM_Common, RM_Class, RM_e_Xls, RM_Dataset, RM_System,
  RM_GridReport, cxCheckBox, Menus, MovePanel, BtnEdit, cxPC, Math,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmFinishedLSInList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    cxgrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column5: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    cxgrdMJLen: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    cxgrid1Level1: TcxGridLevel;
    MovePanel2: TMovePanel;
    Label5: TLabel;
    Label3: TLabel;
    Y_CodeName: TEdit;
    Y_Spec: TEdit;
    Label4: TLabel;
    FactoryName: TEdit;
    Label6: TLabel;
    BatchNo: TEdit;
    Label7: TLabel;
    Edit1: TEdit;
    Label8: TLabel;
    Y_CodeNameCP: TEdit;
    v1Column1: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure FormDestroy(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmFinishedLSInList: TfrmFinishedLSInList;
implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp;

{$R *.dfm}



procedure TfrmFinishedLSInList.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TfrmFinishedLSInList.FormCreate(Sender: TObject);
begin
  //cxGrid1.Align:=alClient;
  BegDate.DateTime := SGetServerDateTime(ADOQueryTemp)-7;
  EndDate.DateTime := SGetServerDateTime(ADOQueryTemp)
end;

procedure TfrmFinishedLSInList.InitGrid();
var
  fwhere, Pwhere: string;
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      Pwhere := SGetFilters(Panel1, 1, 2);
      if trim(Pwhere) <> '' then
        fwhere := fwhere + ' where ' + trim(Pwhere);

      sql.Add('exec P_YTCK_Get_RKHZ ');
      sql.add('''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + ''' ');
      sql.Add(',''' + Trim(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1)) + '''');
      sql.Add(',''' + fwhere + ''' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmFinishedLSInList.TBRafreshClick(Sender: TObject);
begin
  BegDate.SetFocus;
  InitGrid();
end;

procedure TfrmFinishedLSInList.ConNoMChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  end;
end;

procedure TfrmFinishedLSInList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(Self.Caption+'11', Tv1, '¼Óµ¯Ë¿²Ö¿â');
  Close;
end;

procedure TfrmFinishedLSInList.FormShow(Sender: TObject);
begin
  ReadCxGrid(Self.Caption+'11', Tv1, '¼Óµ¯Ë¿²Ö¿â');
  InitGrid();
end;

procedure TfrmFinishedLSInList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    exit;
  SelExportData(Tv1, ADOQueryMain, '');
end;

procedure TfrmFinishedLSInList.OrderNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    InitGrid();
  end;
end;

procedure TfrmFinishedLSInList.FormDestroy(Sender: TObject);
begin
  frmFinishedLSInList:=nil;
end;

end.

