unit U_KuWeiKCList;

interface

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

type
  TfrmKuWeiKCList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    Panel1: TPanel;
    v1Column7: TcxGridDBColumn;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport2: TRMXLSExport;
    CDS_PRT: TClientDataSet;
    Label2: TLabel;
    QuYu: TEdit;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    Label1: TLabel;
    FenQu: TEdit;
    Label5: TLabel;
    Pai: TEdit;
    Label6: TLabel;
    KWName: TEdit;
    Label7: TLabel;
    Ceng: TEdit;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    v1Column4: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ZJStatusChange(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
  private
    canshu1:string;
    DQdate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    FFInt,FCloth:Integer;

    { Public declarations }
  end;

var
  frmKuWeiKCList: TfrmKuWeiKCList;

implementation
uses
  U_DataLink,U_RTFun,U_ZDYHelp,U_ZHCPViewList;

{$R *.dfm}

procedure TfrmKuWeiKCList.FormDestroy(Sender: TObject);
begin
  frmKuWeiKCList:=nil;
end;

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

procedure TfrmKuWeiKCList.FormCreate(Sender: TObject);
begin
  cxgrid1.Align:=alClient;
  canshu1:=Trim(DParameters1);
end;

procedure TfrmKuWeiKCList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('库位库存列表',Tv1,'库位管理');
  Close;
end;

procedure TfrmKuWeiKCList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('Select A.*,KC.GGQty from(');
      sql.Add('select KWID,GGQty=Sum(GGQty) ');
      sql.Add(' from ZH_CP_Info_KC where isnull(GGQty,0)>0 Group by KWID )KC');
      sql.Add(' inner join KuWei A on KC.KWID=A.KWID ');
      sql.Add(' where KWType=''GG'' and Valid=''Y'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;


procedure TfrmKuWeiKCList.InitForm();
begin
  ReadCxGrid('库位库存列表',Tv1,'库位管理');
  InitGrid();
end;

procedure TfrmKuWeiKCList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;



procedure TfrmKuWeiKCList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  TcxGridToExcel(Self.Caption,cxGrid1);
end;

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

procedure TfrmKuWeiKCList.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmKuWeiKCList.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmKuWeiKCList.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmKuWeiKCList.CustomerNoNameChange(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmKuWeiKCList.N1Click(Sender: TObject);
begin
  try
    frmZHCPViewList:=TfrmZHCPViewList.Create(Application);
    with frmZHCPViewList do
    begin
      FKWID:=Trim(Self.Order_Main.fieldbyname('KWID').AsString);
      LabKWName.Caption:=Trim(Self.Order_Main.fieldbyname('KWName').AsString);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmZHCPViewList.Free;
  end;
end;

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

procedure TfrmKuWeiKCList.ZJStatusChange(Sender: TObject);
begin
  TBFind.Click;
end;



procedure TfrmKuWeiKCList.Tv1DblClick(Sender: TObject);
begin
  ModalResult:=1;
end;

end.
