unit U_WarpRollerkCList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, StdCtrls, ExtCtrls, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData,
  cxButtonEdit, cxDropDownEdit, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView,
  cxGrid, DBClient, ADODB, cxGridCustomPopupMenu, cxGridPopupMenu, cxCheckBox,
  RM_Common, RM_Class, RM_GridReport, RM_System, RM_Dataset, MMSystem, Menus,
  BtnEdit, cxPC, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmWarpRollerkCList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label3: TLabel;
    WBCode: TEdit;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    DataSource1: TDataSource;
    CDS_Main: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    TOk: TToolButton;
    Label7: TLabel;
    ADOQueryPrint: TADOQuery;
    RMDB_Main: TRMDBDataSet;
    RM1: TRMGridReport;
    ADOQueryMain: TADOQuery;
    Label31: TLabel;
    FactoryName: TEdit;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ToolButton2: TToolButton;
    Label5: TLabel;
    Label6: TLabel;
    fromFactoryName: TEdit;
    CDS_KCYJ: TClientDataSet;
    DS_KCYJ: TDataSource;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Label15: TLabel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Ssel: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1CRTime: TcxGridDBColumn;
    v1CRType: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Note: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure WBCodeChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TOkClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure cxPageControl1Change(Sender: TObject);
  private
    procedure InitGrid();
    procedure SetStatus();
    { Private declarations }
  public
    fCKName, canshu1: string;
    fType: Integer;
    { Public declarations }
  end;

var
  frmWarpRollerkCList: TfrmWarpRollerkCList;

implementation

uses
  U_DataLink, U_Fun10, U_ZDYHelp;
{$R *.dfm}

procedure TfrmWarpRollerkCList.SetStatus();
begin
  if fType = 10 then
  begin
    TOk.Visible := true;
    v1Ssel.Visible := true;
  end
  else
  begin
    TOk.Visible := False;
    v1Ssel.Visible := False;
  end;
end;

procedure TfrmWarpRollerkCList.InitGrid();
begin
  with adoqueryMain do
  begin
    close;
    sql.Clear;
    sql.Add(' select A.* from CK_WarpBeam_CR A ');
    sql.Add(' where A.Valid=''Y'' ');
    sql.Add(' and A.CRFlag=''入库'' ');
    sql.Add('and exists(select * from BS_WarpBeam e where e.wbid=a.wbid and isnull(e.kCvalid,''Y'')<>''N'')');
//    SQL.Add(' AND A.KCID not in (SELECT B.KCID FROM CK_WarpBeam_CR B where B.Valid= ''Y'' and B.CRFlag= ''出库'' AND B.KCID=A.KCID)');
    //ShowMessage(SQL.Text);
    open;
  end;
  SCreateCDS20(adoqueryMain, CDS_Main);
  SInitCDSData20(adoqueryMain, CDS_Main);

end;

procedure TfrmWarpRollerkCList.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  writeCxGrid(self.Caption, Tv1, '仓储管理');
  Action := cafree;
end;

procedure TfrmWarpRollerkCList.FormDestroy(Sender: TObject);
begin
  frmWarpRollerkCList := nil;
end;

procedure TfrmWarpRollerkCList.WBCodeChange(Sender: TObject);
begin
  if adoqueryMain.Active = False then
    Exit;
  SDofilter(adoqueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(adoqueryMain, CDS_Main);
  SInitCDSData20(adoqueryMain, CDS_Main);
end;

procedure TfrmWarpRollerkCList.FormShow(Sender: TObject);
begin
  readCxGrid(self.Caption, Tv1, '仓储管理');
  SetStatus();
  InitGrid();
end;

procedure TfrmWarpRollerkCList.TBCloseClick(Sender: TObject);
begin
  close;
end;

procedure TfrmWarpRollerkCList.TBRafreshClick(Sender: TObject);
begin
  initGrid();
end;

procedure TfrmWarpRollerkCList.TBExportClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxgrid1);
end;

procedure TfrmWarpRollerkCList.TOkClick(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 TfrmWarpRollerkCList.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, true);
end;

procedure TfrmWarpRollerkCList.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, false);

end;

procedure TfrmWarpRollerkCList.ToolButton2Click(Sender: TObject);
begin
  if adoqueryMain.Active = False then
    Exit;
  SDofilter(adoqueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(adoqueryMain, CDS_Main);
  SInitCDSData20(adoqueryMain, CDS_Main);
end;

procedure TfrmWarpRollerkCList.cxPageControl1Change(Sender: TObject);
begin
  InitGrid();
end;

end.

