unit U_DJBCKOutList_CX;

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
  TfrmDJBCKOutList_CX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: 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;
    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;
    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;
    RCGangNo: TEdit;
    ADOQueryPrint: TADOQuery;
    Label15: TLabel;
    PRTColorEng: TEdit;
    Label16: TLabel;
    PRTColorNo: TEdit;
    Label17: TLabel;
    PRTHX: TEdit;
    RM1: TRMGridReport;
    RMBarCodeObject1: TRMBarCodeObject;
    v1ConNo: TcxGridDBColumn;
    v1KuanNO: TcxGridDBColumn;
    CDS_Print: TClientDataSet;
    RM2: TRMGridReport;
    v1PRTColorEng: TcxGridDBColumn;
    v1SOrddefstr4: TcxGridDBColumn;
    v1BPType: TcxGridDBColumn;
    v1DRQty: TcxGridDBColumn;
    v1DRPS: TcxGridDBColumn;
    v1IFFY: 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 N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure PRTColorEngChange(Sender: TObject);
    procedure PRTColorNoChange(Sender: TObject);
    procedure PRTHXChange(Sender: TObject);
  private
    canshu1,canshu2,canShu3:string;
    procedure InitGrid();
    { Private declarations }
  public
    FDJConNO:string;
    { Public declarations }
  end;

var
  frmDJBCKOutList_CX: TfrmDJBCKOutList_CX;

implementation
uses
  U_DataLink,U_RTFun;

{$R *.dfm}

procedure TfrmDJBCKOutList_CX.FormDestroy(Sender: TObject);
begin
  frmDJBCKOutList_CX:=nil;
end;

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

procedure TfrmDJBCKOutList_CX.FormCreate(Sender: TObject);
begin
  //cxGrid1.Align:=alClient;
  canshu1:=Trim(DParameters1);
  canshu2:=Trim(DParameters2);
  canShu3:=trim(DParameters3);
  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime:=EndDate.DateTime-30;
end;

procedure TfrmDJBCKOutList_CX.InitGrid();
begin
  Toolbar1.SetFocus;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select isnull(D.SOrddefstr4,D.PrtColor) SOrddefstr4,E.Qty DRQty,E.PiQty DRPS,E.CRTime,isnull(B.PRTColorEng,B.PRTColor) PRTColorEng,');
      sql.add(' D.PRTColorNo,B.PRTColor,B.PRTHX,D.PRTOrderQty,A.*,C.*,');
      sql.add(' IFFY=(case when isnull(F.YFID,'''')='''' then '''' else ''是'' end)');
      sql.Add(' from CK_SXPB_CR A');
      sql.add(' inner join CK_SXPB_CR E on E.SPID=A.FZSPID and E.CRFlag=''入库''');
      sql.Add(' left join JYOrder_Sub B on A.ORDSubIdCK=B.SubId');
      sql.add(' left join JYOrderCon_Sub D on D.Subid=A.conCKID');
      sql.add(' left join JYOrderCon_Main C on C.Mainid=D.Mainid');
      sql.add(' left join YF_Money_CR F on F.Mainid=E.SPID and F.Status=''2''');
      sql.add(' where A.CRFlag=''出库'' and C.ConNO='''+trim(FDJConNO)+''' ');
      SQL.Add(' and isnull(A.CKName,'''')=''待检布'' ');
      SQL.Add(' order by A.CRTime');
      Open;
      //ShowMessage(SQL.Text);
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmDJBCKOutList_CX.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

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

procedure TfrmDJBCKOutList_CX.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('待检查询',Tv1,'外加工仓库');
  Close;
end;

procedure TfrmDJBCKOutList_CX.FormShow(Sender: TObject);
begin
  ReadCxGrid('待检查询',Tv1,'外加工仓库');
  InitGrid();
end;

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

procedure TfrmDJBCKOutList_CX.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 TfrmDJBCKOutList_CX.SPNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

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

procedure TfrmDJBCKOutList_CX.N1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  CDS_Main.DisableControls;
  with CDS_Main do
  begin
    First;
    while not eof do
    begin
      if Trim(CDS_Main.fieldbyname('CRType').AsString)='检验出库' then
      begin
        Edit;
        FieldByName('SSel').Value:=True;
        Post;
      end;
      Next;
    end;
  end;
  CDS_Main.EnableControls;
end;

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

procedure TfrmDJBCKOutList_CX.PRTColorEngChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmDJBCKOutList_CX.PRTColorNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

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

end.
