unit U_DDDJBCKKCSelList;

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;

type
  TfrmDDDJBCKKCSelList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DS_Main: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    RMDBHZ: TRMDBDataSet;
    CDS_Order: TClientDataSet;
    CDS_PRT: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ToolButton1: TToolButton;
    Panel2: TPanel;
    Panel3: TPanel;
    Panel4: TPanel;
    Panel1: TPanel;
    Label7: TLabel;
    Label2: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label13: TLabel;
    KuWei: TEdit;
    RCGangNo: TEdit;
    PRTColor: TEdit;
    PRTHX: TEdit;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column20: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column22: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    TV2cxGridDBColumn1: TcxGridDBColumn;
    TV2cxGridDBColumn3: TcxGridDBColumn;
    TV2cxGridDBColumn5: TcxGridDBColumn;
    TV2cxGridDBColumn8: TcxGridDBColumn;
    TV2cxGridDBColumn9: TcxGridDBColumn;
    TV2cxGridDBColumn10: TcxGridDBColumn;
    TV2cxGridDBColumn11: TcxGridDBColumn;
    TV2cxGridDBColumn12: TcxGridDBColumn;
    TV2cxGridDBColumn13: TcxGridDBColumn;
    TV2cxGridDBColumn14: TcxGridDBColumn;
    TV2cxGridDBColumn15: TcxGridDBColumn;
    TV2cxGridDBColumn16: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Panel6: TPanel;
    Label27: TLabel;
    Edit13: TEdit;
    TV2: TcxGridDBTableView;
    DS_Order: TDataSource;
    Panel5: TPanel;
    Label24: TLabel;
    Label26: TLabel;
    Edit10: TEdit;
    Edit12: TEdit;
    ADOQueryOrder: TADOQuery;
    Label18: TLabel;
    Edit7: TEdit;
    Label3: TLabel;
    Label6: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    PopupMenu2: TPopupMenu;
    MenuItem1: TMenuItem;
    MenuItem2: TMenuItem;
    OrderNo: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure MenuItem1Click(Sender: TObject);
    procedure MenuItem2Click(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
  private
    procedure InitGrid();
    procedure InitGrid2();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmDDDJBCKKCSelList: TfrmDDDJBCKKCSelList;

implementation
uses
  U_DataLink,U_RTFun,U_SXCKInPut;

{$R *.dfm}

procedure TfrmDDDJBCKKCSelList.FormDestroy(Sender: TObject);
begin
  frmDDDJBCKKCSelList:=nil;
end;

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

procedure TfrmDDDJBCKKCSelList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      sql.Add(' ,OrderNo=(select OrderNo from JYOrder_Main JM where JM.MainId=A.OrdMainIdRK )');
      sql.Add(' ,SOrddefstr1=(select SOrddefstr1 from JYOrder_Sub JM where JM.SubId=A.OrdSubIdRK )');
      sql.Add(' ,PRTColor=(select PRTColor from JYOrder_Sub JM where JM.SubId=A.OrdSubIdRK )');
      sql.Add(' ,PRTHX=(select PRTHX from JYOrder_Sub JM where JM.SubId=A.OrdSubIdRK )');
      sql.Add(' from CK_SXPB_CR A where isnull(CKName,'''')=''待检布'' ');
      SQL.Add(' and A.CRFlag=''入库'' and MXKCQty>0');
      if Trim(Edit7.Text) <>'' then sql.Add(' and A.SPCode like '+quotedstr('%'+Trim(Edit7.Text)+'%'));
      if Trim(OrderNo.Text) <>'' then sql.Add(' and A.QCorderNo like '+quotedstr('%'+Trim(OrderNo.Text)+'%'));
      if Trim(KuWei.Text) <>'' then sql.Add(' and A.KuWei like '+quotedstr('%'+Trim(KuWei.Text)+'%'));
      if Trim(RCGangNo.Text) <>'' then sql.Add(' and A.RCGangNo like '+quotedstr('%'+Trim(RCGangNo.Text)+'%'));
      if Trim(PRTColor.Text) <>'' then sql.Add(' and A.PRTColor like '+quotedstr('%'+Trim(PRTColor.Text)+'%'));
      if Trim(PRTHX.Text) <>'' then sql.Add(' and A.PRTHX like '+quotedstr('%'+Trim(PRTHX.Text)+'%'));
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmDDDJBCKKCSelList.InitGrid2();
begin
  try
    if CDS_Order.IsEmpty=False then  CDS_Order.EmptyDataSet;
    ADOQueryOrder.DisableControls;
    with ADOQueryOrder do
    begin
      Close;
      sql.Clear;
      sql.Add(' select A.*,B.* from JYOrder_Main A left join JYOrder_Sub B on A.MainId=B.MainId  where A.Status=''1''');
      if Trim(Edit7.Text) <>'' then sql.Add(' and A.MPRTCode like '+quotedstr('%'+Trim(Edit7.Text)+'%'));
      if Trim(Edit1.Text) <>'' then sql.Add(' and A.orderno like '+quotedstr('%'+Trim(Edit1.Text)+'%'));
      if Trim(Edit2.Text) <>'' then sql.Add(' and A.customernoname like '+quotedstr('%'+Trim(Edit2.Text)+'%'));
      if Trim(Edit10.Text) <>'' then sql.Add(' and A.MPRTColor like '+quotedstr('%'+Trim(Edit10.Text)+'%'));
      if Trim(Edit12.Text) <>'' then sql.Add(' and A.MPRThx like '+quotedstr('%'+Trim(Edit12.Text)+'%'));
      Open;
    end;
    SCreateCDS20(ADOQueryOrder,CDS_Order);
    SInitCDSData20(ADOQueryOrder,CDS_Order);
  finally
    ADOQueryOrder.EnableControls;
  end;
end;

procedure TfrmDDDJBCKKCSelList.TBRafreshClick(Sender: TObject);
begin
//  if Trim(Edit7.Text)='' then Exit;
  InitGrid2();
  InitGrid();

end;

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

procedure TfrmDDDJBCKKCSelList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('待检布库存选择列表',Tv1,'待检布仓库');
  Close;
end;

procedure TfrmDDDJBCKKCSelList.FormShow(Sender: TObject);
begin
  ReadCxGrid('待检布库存选择列表',Tv1,'待检布仓库');
  //InitGrid();
end;

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

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

procedure TfrmDDDJBCKKCSelList.ToolButton1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  if CDS_Order.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  ModalResult:=1;
end;

procedure TfrmDDDJBCKKCSelList.Tv1CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  ModalResult:=1;
end;

procedure TfrmDDDJBCKKCSelList.MenuItem1Click(Sender: TObject);
begin
  SelOKNo(CDS_Order,True);
end;

procedure TfrmDDDJBCKKCSelList.MenuItem2Click(Sender: TObject);
begin
  SelOKNo(CDS_Order,False);
end;

procedure TfrmDDDJBCKKCSelList.Edit1KeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key=#13 then InitGrid2();
end;

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

end.
