unit U_FinishedLSCLList;

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, MovePanel, Menus, cxCheckBox, Clipbrd, cxPC, Math;

type
  TfrmFinishedLSCLList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    MovePanel2: TMovePanel;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Panel1: TPanel;
    Label3: TLabel;
    Label9: TLabel;
    Y_CodeName: TEdit;
    MachNo: TEdit;
    Panel2: TPanel;
    Panel3: TPanel;
    cxTabControl1: TcxTabControl;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v2Column1: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxgrdPS: TcxGridDBColumn;
    cxgrdMJLen: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    v1Column1: TcxGridDBColumn;
    TBFind: TToolButton;
    v1Column2: TcxGridDBColumn;
    Label1: TLabel;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure BTLPClick(Sender: TObject);
    procedure BTNPClick(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure TCBNORChange(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure ordernoChange(Sender: TObject);
    procedure Y_CodeNameChange(Sender: TObject);
    procedure Y_CodeChange(Sender: TObject);
    procedure MachNoChange(Sender: TObject);
    procedure Y_ColNoChange(Sender: TObject);
  private
    FLeft, FTop: Integer;
    CurrentPage, RecordsNumber: Integer;
    procedure InitGrid();
    procedure SetStatus();
    { Private declarations }
  public
    { Public declarations }
    FMainid, FSubId, FConNo, FColor, FCodeName: string;
    canshu1: string;
  end;

var
  frmFinishedLSCLList: TfrmFinishedLSCLList;

implementation

uses
  U_DataLink, U_Fun, U_SysLogHelp;

{$R *.dfm}
procedure TfrmFinishedLSCLList.SetStatus();
var
  i: Integer;
begin
  v1Column12.Visible := True;
  v1Column1.Visible := True;
  case cxTabControl1.TabIndex of
    0:
      begin
        v1Column1.Visible := False;
      end;

    1:
      begin
        v1Column12.Visible := False;
      end;
  end;
end;

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

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

//      case cxTabControl1.TabIndex of
//        0:   /////////////////////////机台汇总//////////////////////////////
//          begin
      sql.Add('exec P_LSCL_HZ');
      sql.Add('@flag=''' + IntToStr(cxTabControl1.TabIndex) + ''' ');
      sql.Add(',@BegDate=' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)));
      sql.Add(',@Enddate=' + quotedstr(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1)));
//          end;
//        1:   /////////////////////////员工汇总//////////////////////////////
//          begin
//            sql.Add('exec P_LSCL_HZ');
//            sql.Add('@flag=''' + IntToStr(cxTabControl1.TabIndex) + ''' ');
//            sql.Add(',@BegDate=' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)));
//            sql.Add(',@Enddate=' + quotedstr(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1)));
//          end;
//      end;
//      showmessage(sql.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmFinishedLSCLList.TBRafreshClick(Sender: TObject);
begin
  BegDate.SetFocus;
  ToolBar1.SetFocus;
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  InitGrid();
  MovePanel2.Visible := False;
end;

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

procedure TfrmFinishedLSCLList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(self.Caption, Tv1, '成品仓库');
  Close;
end;

procedure TfrmFinishedLSCLList.FormShow(Sender: TObject);
var
  fsj: string;
begin

  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime;
  ReadCxGrid(self.Caption, Tv1, '成品仓库');
  SetStatus();
  InitGrid();
end;

procedure TfrmFinishedLSCLList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    exit;
  TcxGridToExcel('库存列表', cxGrid2);
end;

procedure TfrmFinishedLSCLList.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, True);
end;

procedure TfrmFinishedLSCLList.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, False);
end;

procedure TfrmFinishedLSCLList.BTLPClick(Sender: TObject);
begin
  if CurrentPage > 1 then
    CurrentPage := CurrentPage - 1;
  InitGrid();
end;

procedure TfrmFinishedLSCLList.BTNPClick(Sender: TObject);
begin
  if CurrentPage < CDS_Main.FieldByName('TotalCount').AsInteger / RecordsNumber then
    CurrentPage := CurrentPage + 1;
  InitGrid();
end;

procedure TfrmFinishedLSCLList.Tv1DblClick(Sender: TObject);
var
  Tabint: integer;
begin
  Tabint := cxTabControl1.TabIndex;
  case Tabint of
    0:
      begin
        AssignmentControls(Panel1, CDS_Main, '0');
        cxTabControl1.TabIndex := 1;
      end;
  end;
end;

procedure TfrmFinishedLSCLList.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();
  InitGrid();
end;

procedure TfrmFinishedLSCLList.TCBNORChange(Sender: TObject);
begin
//  RecordsNumber := StrToInt(TCBNOR.Text);
//  CurrentPage := 1;
//  InitGrid();
end;

procedure TfrmFinishedLSCLList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, cds_main);
  SInitCDSData20(ADOQueryMain, cds_main);
end;

procedure TfrmFinishedLSCLList.ordernoChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmFinishedLSCLList.Y_CodeNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmFinishedLSCLList.Y_CodeChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmFinishedLSCLList.MachNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmFinishedLSCLList.Y_ColNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

end.

