unit U_DJBCRKList;

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, cxCheckBox, RM_Common,
  RM_Class, RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, Menus,
  cxCalendar, cxButtonEdit, cxTextEdit, RM_BarCode;

type
  TfrmDJBCRKList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    RMDBHZ: TRMDBDataSet;
    CDS_HZ: TClientDataSet;
    CDS_PRT: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column6: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label8: TLabel;
    Label12: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    SPName: TEdit;
    FactoryName: TEdit;
    SPID: TEdit;
    SPSpec: TEdit;
    CRType: TComboBox;
    SPCF: TEdit;
    QCorderNo: TEdit;
    Label10: TLabel;
    CKorderNo: TEdit;
    Label11: TLabel;
    FromFactoryName: TEdit;
    Label13: TLabel;
    ToFactoryName: TEdit;
    Label9: TLabel;
    Label14: TLabel;
    RCGangNo: TEdit;
    GangNo: TEdit;
    ADOQueryPrint: TADOQuery;
    Label15: TLabel;
    PRTColor: TEdit;
    Label16: TLabel;
    SOrddefstr1: TEdit;
    Label17: TLabel;
    PRTHX: TEdit;
    RM1: TRMGridReport;
    RMBarCodeObject1: TRMBarCodeObject;
    prtkuanNo: TEdit;
    Label18: TLabel;
    v1Column27: TcxGridDBColumn;
    v1Column28: TcxGridDBColumn;
    v1Column29: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    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 TBFindClick(Sender: TObject);
    procedure SPNameChange(Sender: TObject);
    procedure SPIDChange(Sender: TObject);
    procedure SPIDKeyPress(Sender: TObject; var Key: Char);
    procedure N2Click(Sender: TObject);
    procedure PRTColorChange(Sender: TObject);
    procedure SOrddefstr1Change(Sender: TObject);
    procedure PRTHXChange(Sender: TObject);
    procedure QCorderNoKeyPress(Sender: TObject; var Key: Char);
    procedure CKorderNoKeyPress(Sender: TObject; var Key: Char);
  private
    canshu1,canshu2:string;
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmDJBCRKList: TfrmDJBCRKList;

implementation
uses
  U_DataLink,U_RTFun,U_DJBCKOutPut;

{$R *.dfm}


procedure TfrmDJBCRKList.FormDestroy(Sender: TObject);
begin
  frmDJBCRKList:=nil;
end;

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

procedure TfrmDJBCRKList.FormCreate(Sender: TObject);
begin
  //cxGrid1.Align:=alClient;
  canshu1:=Trim(DParameters1);
  canshu2:=Trim(DParameters2);
  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime:=EndDate.DateTime-1;
end;

procedure TfrmDJBCRKList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ,B.SOrddefstr1,B.PRTColor,B.PRTHX,B.PrtkuanNo,piNum=piQty * CRQtyFlag,Num=Qty * CRQtyFlag');
      sql.Add(' from CK_SXPB_CR A');
      sql.Add(' left join JYOrder_Sub B on A.ORDSubIdCK=B.SubId');
      sql.add(' where A.CRTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+'''');
      sql.add(' and A.CRTime<'''+Trim(FormatDateTime('yyyy-MM-dd',enddate.DateTime+1))+'''');
   //   SQL.Add(' and CRFlag=''出库''  ');
      SQL.Add(' and isnull(CKName,'''')=''待检布'' ');
      SQL.Add(' order by A.FillTime ');
      Open;
      //ShowMessage(SQL.Text);
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

procedure TfrmDJBCRKList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(self.caption,Tv1,'外加工仓库');
  Close;
end;

procedure TfrmDJBCRKList.FormShow(Sender: TObject);
begin

  ReadCxGrid(self.caption,Tv1,'外加工仓库');
  //InitGrid();
end;

procedure TfrmDJBCRKList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  TcxGridToExcel('外加工出库列表',cxGrid2);
end;

procedure TfrmDJBCRKList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmDJBCRKList.SPNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmDJBCRKList.SPIDChange(Sender: TObject);
begin
  if Length(Trim(SPID.Text))<4 then
  begin
    if Trim(SPID.Text)<>'' then Exit;
  end;
  TBFind.Click;
end;

procedure TfrmDJBCRKList.SPIDKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key=#13 then
  begin
    {if Length(Trim(SPID.Text))<4 then Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        sql.Clear;
        sql.Add(' select A.* ');
        sql.Add(' from CK_SXPB_CR A');
        sql.add(' where SPID like :SXID');
        Parameters.ParamByName('SXID').Value:='%'+Trim(SXID.Text)+'%';
        Open;
        //ShowMessage(SQL.Text);
      end;
      SCreateCDS20(ADOQueryMain,CDS_Main);
      SInitCDSData20(ADOQueryMain,CDS_Main);
    finally
      ADOQueryMain.EnableControls;
    end; }
  end;
end;

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

procedure TfrmDJBCRKList.PRTColorChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmDJBCRKList.SOrddefstr1Change(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmDJBCRKList.PRTHXChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmDJBCRKList.QCorderNoKeyPress(Sender: TObject; var Key: Char);
begin
  IF trim(QCorderNo.Text)='' then exit;
  IF Key=#13 then
  begin
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Close;
        Filtered:=False;
        sql.Clear;
        sql.Add(' select A.* ,B.SOrddefstr1,B.PRTColor,B.PRTHX,B.PrtkuanNo,piNum=piQty * CRQtyFlag,Num=Qty * CRQtyFlag');
        sql.Add(' from CK_SXPB_CR A');
        sql.Add(' left join JYOrder_Sub B on A.ORDSubIdCK=B.SubId');
        sql.add(' where A.QCorderNo like '+quotedstr('%'+trim(QCorderNo.text)+'%'));
        SQL.Add(' and isnull(CKName,'''')=''待检布'' ');
        SQL.Add(' order by A.FillTime ');
        Open;
      //ShowMessage(SQL.Text);
        end;
        SCreateCDS20(ADOQueryMain,CDS_Main);
        SInitCDSData20(ADOQueryMain,CDS_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

procedure TfrmDJBCRKList.CKorderNoKeyPress(Sender: TObject; var Key: Char);
begin
  IF trim(CKorderNo.Text)='' then exit;
  IF Key=#13 then
  begin
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Close;
        Filtered:=False;
        sql.Clear;
        sql.Add(' select A.* ,B.SOrddefstr1,B.PRTColor,B.PRTHX,B.PrtkuanNo,piNum=piQty * CRQtyFlag,Num=Qty * CRQtyFlag');
        sql.Add(' from CK_SXPB_CR A');
        sql.Add(' left join JYOrder_Sub B on A.ORDSubIdCK=B.SubId');
        sql.add(' where A.CKorderNo like '+quotedstr('%'+trim(CKorderNo.text)+'%'));
        SQL.Add(' and isnull(CKName,'''')=''待检布'' ');
        SQL.Add(' order by A.FillTime ');
        Open;
      //ShowMessage(SQL.Text);
        end;
        SCreateCDS20(ADOQueryMain,CDS_Main);
        SInitCDSData20(ADOQueryMain,CDS_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

end.
