unit U_JYCXList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCheckBox, cxCalendar, cxSplitter, RM_Dataset, RM_System,
  RM_Common, RM_Class, RM_GridReport, RM_e_Xls, Menus, MovePanel, cxTextEdit,
  cxContainer, cxCurrencyEdit, BtnEdit, RM_e_main, RM_e_htm, RM_e_Graphic,
  RM_e_Jpeg, RM_e_txt, RM_e_csv, RM_E_llPDF, Math, Clipbrd, cxPC,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu;

type
  TfrmJYCXList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    MovePanel2: TMovePanel;
    RMXLSExport1: TRMXLSExport;
    Panel6: TPanel;
    Label31: TLabel;
    LBCPAP: TLabel;
    BTLP: TButton;
    BTNP: TButton;
    TCBNOR: TComboBox;
    Panel1: TPanel;
    Label3: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label12: TLabel;
    Label19: TLabel;
    lbl1: TLabel;
    Label2: TLabel;
    Label11: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    OrderNo: TEdit;
    conNO: TEdit;
    MJID: TEdit;
    MJType: TComboBox;
    MPRTCodeName: TEdit;
    factoryName: TEdit;
    Filler: TComboBox;
    Mjstr4: TEdit;
    PrtColor: TEdit;
    KHConNO: TEdit;
    IsJYTime: TCheckBox;
    APID: TEdit;
    RCGangNo: TEdit;
    lidan: TEdit;
    YWY: TEdit;
    KuanHao: TEdit;
    IsOutRange: TEdit;
    chkDP: TCheckBox;
    PBLY: TEdit;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column22: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    v1Column32: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column50: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column35: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column23: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column28: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    v1Column24: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column25: TcxGridDBColumn;
    v1Column26: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column27: TcxGridDBColumn;
    v1Column42: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column31: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1MKXS: TcxGridDBColumn;
    v1Column29: TcxGridDBColumn;
    v1Column33: TcxGridDBColumn;
    v1Column34: TcxGridDBColumn;
    v1Column36: TcxGridDBColumn;
    v1Column39: TcxGridDBColumn;
    v1Column30: TcxGridDBColumn;
    v1Column37: TcxGridDBColumn;
    v1Column38: TcxGridDBColumn;
    v1Column40: TcxGridDBColumn;
    v1Column43: TcxGridDBColumn;
    v1Column41: TcxGridDBColumn;
    v1Column44: TcxGridDBColumn;
    v1Column45: TcxGridDBColumn;
    v1Column46: TcxGridDBColumn;
    v1Column47: TcxGridDBColumn;
    v1Column48: TcxGridDBColumn;
    v1Column49: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure MJIDKeyPress(Sender: TObject; var Key: Char);
    procedure BTLPClick(Sender: TObject);
    procedure BTNPClick(Sender: TObject);
    procedure TCBNORChange(Sender: TObject);
    procedure conNOKeyPress(Sender: TObject; var Key: Char);
    procedure MJStr2Change(Sender: TObject);
    procedure MJTypeChange(Sender: TObject);
    procedure KHConNOKeyPress(Sender: TObject; var Key: Char);
    procedure RKOrdIDKeyPress(Sender: TObject; var Key: Char);
    procedure cxTabControl1Change(Sender: TObject);
    procedure chkDPClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    DQdate: TDateTime;
    FLeft, FTop: Integer;
    CurrentPage, RecordsNumber: Integer;
    procedure InitGrid();
    procedure InitForm();
    procedure SetStatus();
    { Private declarations }
  public
    FFInt: Integer;
    canshu1: string;
    { Public declarations }
  end;

var
  frmJYCXList: TfrmJYCXList;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp,U_RTFun;

{$R *.dfm}
procedure TfrmJYCXList.SetStatus();
begin

end;

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

procedure TfrmJYCXList.FormCreate(Sender: TObject);
begin
  cxgrid1.Align := alClient;
  DQdate := SGetServerDate(ADOQueryTemp);
end;

procedure TfrmJYCXList.TBCloseClick(Sender: TObject);
begin
  if Trim(DName)='ADMIN' then
  begin
    WriteCxGridAll(trim(self.Caption), Tv1,ADOQueryCmd,ADOQueryTemp);
  end;
  Close;
end;



procedure TfrmJYCXList.InitGrid();
var
  fwhere, Pwhere: string;
begin
  MovePanel2.Left := (self.Width - MovePanel2.Width) div 2;
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  if IsJYTime.Checked then
  begin
    fwhere := ' where CXtime>' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime));
    fwhere := fwhere + ' and CXtime<=' + quotedstr(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1));
  end;

  Pwhere := SGetFilters(Panel1, 1, 2);

  



  if trim(fwhere) <> '' then
  begin
    fwhere := fwhere;
  end
  else
  begin
    fwhere := ' where ' + trim(Pwhere);
  end;

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('exec P_Page_ClothInfo_CX ');
      sql.Add('@pageIndex=' + inttostr(CurrentPage));
      sql.Add(',@pageSize=' + inttostr(RecordsNumber));
      sql.Add(',@criteria= ' + quotedstr(fwhere));

      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
    LBCPAP.Caption := inttostr(CurrentPage) + '/' + inttostr(ceil(Order_Main.FieldByName('TotalCount').AsInteger / RecordsNumber));
    MovePanel2.Visible := false;
  finally
    ADOQueryMain.EnableControls;
    MovePanel2.Visible := false;
  end;
end;

procedure TfrmJYCXList.InitForm();
var
  fsj: string;
begin
  ReadCxGridAll(trim(self.Caption), Tv1);
  fsj := 'select distinct(Filler) name from WFB_MJJY_CX   ';
  SInitComBoxBySql(ADOQueryCmd, Filler, False, fsj);
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
end;

procedure TfrmJYCXList.TBExportClick(Sender: TObject);
var
  i:Integer;
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  for i:=0 to Tv1.ColumnCount-1 do
  begin
    if Tv1.Columns[i].Tag<>999 then
    begin
      Tv1.Columns[i].Visible:=False
    end else
    begin
      Tv1.Columns[i].Visible:=True;
    end;
  end;
  TcxGridToExcel('´ò¾í³·Ïú¼ÇÂ¼',cxGrid1);
end;

procedure TfrmJYCXList.TBRafreshClick(Sender: TObject);
begin
  OrderNo.SetFocus;

  CurrentPage := 1;
  InitGrid();

end;

procedure TfrmJYCXList.FormShow(Sender: TObject);
begin
  CurrentPage := 1;
  RecordsNumber := 500;
  InitForm();
  SetStatus();
end;

procedure TfrmJYCXList.OrderNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    if Length(OrderNo.Text) < 4 then
      Exit;
    CurrentPage := 1;
    InitGrid();
  end;
end;



procedure TfrmJYCXList.MJIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    if Length(MJID.Text) < 4 then
      Exit;
    CurrentPage := 1;
    InitGrid();
  end;
end;

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

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

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

procedure TfrmJYCXList.conNOKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmJYCXList.MJStr2Change(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmJYCXList.MJTypeChange(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmJYCXList.KHConNOKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmJYCXList.RKOrdIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmJYCXList.cxTabControl1Change(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
  SetStatus();
end;

procedure TfrmJYCXList.chkDPClick(Sender: TObject);
begin
  OrderNo.SetFocus;

  CurrentPage := 1;
  InitGrid();

end;

procedure TfrmJYCXList.FormDestroy(Sender: TObject);
begin
  frmJYCXList := nil;
end;

end.

