unit U_CYPBCKKCSelListW;

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, cxPC;

type
  TfrmCYPBCKKCSelListW = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ToolButton1: TToolButton;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label8: TLabel;
    Label12: TLabel;
    Label6: TLabel;
    SPName: TEdit;
    FactoryName: TEdit;
    OrderNo: TEdit;
    SPSpec: TEdit;
    CRType: TComboBox;
    SPCF: TEdit;
    Label1: TLabel;
    FromFactoryName: TEdit;
    Label14: TLabel;
    SPCode: TEdit;
    Label2: TLabel;
    FromOrderNo: TEdit;
    Label7: TLabel;
    KHName: TEdit;
    cxTabControl1: TcxTabControl;
    cxGrid3: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column1: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    vFromOrderNo: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    vFtyName: TcxGridDBColumn;
    vFromFtyName: TcxGridDBColumn;
    vFromKHName: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridDBColumn20: TcxGridDBColumn;
    cxGridDBColumn21: TcxGridDBColumn;
    cxGridDBColumn22: TcxGridDBColumn;
    cxGridDBColumn45: TcxGridDBColumn;
    cxGridDBColumn46: TcxGridDBColumn;
    cxGridDBColumn47: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    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 TBFindClick(Sender: TObject);
    procedure MPRTCodeNameChange(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure SXBatchNOChange(Sender: TObject);
    procedure FactoryNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure cxTabControl1Change(Sender: TObject);
  private
    procedure InitGrid();
    procedure InitGridStatus();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmCYPBCKKCSelListW: TfrmCYPBCKKCSelListW;

implementation
uses
  U_DataLink,U_RTFun,U_SXCKInPut;

{$R *.dfm}

procedure TfrmCYPBCKKCSelListW.FormDestroy(Sender: TObject);
begin
  frmCYPBCKKCSelListW:=nil;
end;

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

procedure TfrmCYPBCKKCSelListW.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      sql.Add(' from CK_SXPB_CR A where isnull(CKName,'''')=''坯布仓库'' and isnull(DeptName,'''')=''外围总仓''  ');
      SQL.Add(' and A.CRFlag=''入库'' and MXKCQty>0');
      if cxTabControl1.TabIndex<>0 then
          sql.Add(' and isnull(A.CRType,'''')='''+Trim(cxTabControl1.Tabs[cxTabControl1.TabIndex].Caption)+'''');
      Open;
      //ShowMessage(SQL.Text);
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

procedure TfrmCYPBCKKCSelListW.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(Self.Caption+'库存选择列表',Tv1,Self.Caption);
  Close;
end;

procedure TfrmCYPBCKKCSelListW.FormShow(Sender: TObject);
begin
  ReadCxGrid(Self.Caption+'库存选择列表',Tv1,Self.Caption);
  //InitGrid();
end;

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

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

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

procedure TfrmCYPBCKKCSelListW.SXBatchNOChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmCYPBCKKCSelListW.FactoryNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmCYPBCKKCSelListW.ToolButton1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  ModalResult:=1;
end;
procedure TfrmCYPBCKKCSelListW.InitGridStatus();
var
  FFCRType:string;
begin
  FFCRType:=Trim(cxTabControl1.Tabs[cxTabControl1.TabIndex].Caption);
  if Trim(FFCRType)='采购入库' then
  begin
    vFtyName.Visible:=True;
    vFtyName.Hidden:=false;
    vFromFtyName.Visible:=False;
    vFromFtyName.Hidden:=True;
    vFromKHName.Visible:=False;
    vFromKHName.Hidden:=True;
    vFromOrderNo.Visible:=false;
    vFromOrderNo.Hidden:=True;
  end else
  if Trim(FFCRType)='织造入库' then
  begin
    vFtyName.Visible:=True;
    vFtyName.Hidden:=false;
    vFromFtyName.Visible:=False;
    vFromFtyName.Hidden:=True;
    vFromKHName.Visible:=False;
    vFromKHName.Hidden:=True;
    vFromOrderNo.Visible:=false;
    vFromOrderNo.Hidden:=True;
  end else
  if Trim(FFCRType)='半加工完成入库' then
  begin
    vFtyName.Visible:=True;
    vFtyName.Hidden:=false;
    vFromFtyName.Visible:=True;
    vFromFtyName.Hidden:=false;
    vFromFtyName.Caption:='加工厂';
    vFromKHName.Visible:=False;
    vFromKHName.Hidden:=True;
    vFromOrderNo.Visible:=false;
    vFromOrderNo.Hidden:=True;
  end else
  if Trim(FFCRType)='半加工未做回仓' then
  begin
    vFtyName.Visible:=True;
    vFtyName.Hidden:=false;
    vFromFtyName.Visible:=True;
    vFromFtyName.Hidden:=false;
    vFromFtyName.Caption:='加工厂';
    vFromKHName.Visible:=False;
    vFromKHName.Hidden:=True;
    vFromOrderNo.Visible:=false;
    vFromOrderNo.Hidden:=True;
  end else
  if Trim(FFCRType)='客户退回' then
  begin
    vFtyName.Visible:=True;
    vFtyName.Hidden:=false;
    vFromFtyName.Visible:=False;
    vFromFtyName.Hidden:=True;
    vFromKHName.Visible:=True;
    vFromKHName.Hidden:=False;
    vFromOrderNo.Visible:=false;
    vFromOrderNo.Hidden:=True;
  end else
  if Trim(FFCRType)='转单入库' then
  begin
    vFtyName.Visible:=True;
    vFtyName.Hidden:=false;
    vFromFtyName.Visible:=True;
    vFromFtyName.Hidden:=false;
    vFromKHName.Visible:=false;
    vFromKHName.Hidden:=True;
    vFromOrderNo.Visible:=True;
    vFromOrderNo.Hidden:=False;
  end else
  if Trim(FFCRType)='全部' then
  begin
    vFtyName.Visible:=True;
    vFtyName.Hidden:=false;
    vFromFtyName.Visible:=True;
    vFromFtyName.Hidden:=false;
    vFromKHName.Visible:=True;
    vFromKHName.Hidden:=false;
    vFromOrderNo.Visible:=True;
    vFromOrderNo.Hidden:=False;
  end;

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

procedure TfrmCYPBCKKCSelListW.cxTabControl1Change(Sender: TObject);
begin
  InitGridStatus();
  InitGrid();
end;

end.
