unit U_MianWFBKCList;

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, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxSkinsCore,  
     dxSkinDarkRoom,
    
     
     
    
    
    
    
   dxSkinOffice2013White, 
     dxSkinSharpPlus,
   dxSkinSpringTime,  
   dxSkinsDefaultPainters, 
     dxSkinscxPCPainter;

type
  TfrmMianWFBKCList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    Panel1: TPanel;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport2: TRMXLSExport;
    CDS_PRT: TClientDataSet;
    Label2: TLabel;
    MYName: TEdit;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    V2MYName: TcxGridDBColumn;
    V2MYCode: TcxGridDBColumn;
    V2Qty: TcxGridDBColumn;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DataSource2: TDataSource;
    PB_MX: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    Label6: TLabel;
    MYCode: TEdit;
    V2MYMF: TcxGridDBColumn;
    V2Column1: TcxGridDBColumn;
    V2Column2: TcxGridDBColumn;
    V2Column3: TcxGridDBColumn;
    Label3: TLabel;
    DataType: TComboBox;
    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 cxTabControl1Change(Sender: TObject);
    procedure ZJStatusChange(Sender: TObject);
    procedure MYCodeChange(Sender: TObject);
    procedure DataTypeChange(Sender: TObject);
  private
    canshu1:string;
    DQdate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    FFInt,FCloth:Integer;

    { Public declarations }
  end;

var
  frmMianWFBKCList: TfrmMianWFBKCList;

implementation
uses
  U_DataLink,U_RTFun;

{$R *.dfm}

procedure TfrmMianWFBKCList.FormDestroy(Sender: TObject);
begin
  frmMianWFBKCList:=nil;
end;

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

procedure TfrmMianWFBKCList.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
end;

procedure TfrmMianWFBKCList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('棉WFB库存1',Tv2,'贸易生产管理');
  Close;
end;

procedure TfrmMianWFBKCList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select AAA.*,M.* from(');
      sql.Add('select MYCode,DataType ,Qty=sum(isnull(Qty,0)),QtyPlan=Sum(isnull(QtyPlan,0)) from(');

      SQL.Add(' select A.MYCode,DataType=''棉'',Qty=MXKCQty*CRQtyFlag,QtyPlan=MXKCQty*CRQtyFlag');
      sql.Add(' from CK_MYSC_CR A  ');
      sql.Add(' where isnull(MYType,'''')=''采购棉'' and MYName like ''%棉%'' ');

      sql.Add(' union all ');

      SQL.Add(' select A.MYCode,DataType=''无纺布'',Qty=MXKCQty*CRQtyFlag,QtyPlan=MXKCQty*CRQtyFlag');
      sql.Add(' from CK_MYSC_CR A  ');
      sql.Add(' where isnull(MYType,'''')=''采购棉'' and MYName like ''%布%'' ');

      sql.Add(' union all ');

      SQL.Add(' select MYCode=MLCode,DataType=''棉'',Qty=MLJYQty*(-1),QtyPlan=MLJHQty*(-1)');
      sql.Add(' from ML_OrderZuHe A  ');
      sql.Add(' where isnull(MLType,'''')=''棉'' and isnull(SSGS,'''')=''自己''  ');

      sql.Add(' union all ');

      SQL.Add(' select MYCode=MLCode,DataType=''无纺布'',Qty=MLJYQty*(-1),QtyPlan=MLJHQty*(-1)');
      sql.Add(' from ML_OrderZuHe A  ');
      sql.Add(' where isnull(MLType,'''')=''无纺布'' and isnull(SSGS,'''')=''自己''  ');

      sql.Add(')AA Group by MYCode,DataType');
      sql.Add(')AAA');
      sql.Add('inner join M_ZDY M on AAA.MYCode=M.BPCode');

      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmMianWFBKCList.InitForm();
begin
  ReadCxGrid('棉WFB库存1',Tv2,'贸易生产管理');
  InitGrid();
end;

procedure TfrmMianWFBKCList.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 TfrmMianWFBKCList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  TcxGridToExcel(Self.Caption,cxGrid2);
end;

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

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

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

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

procedure TfrmMianWFBKCList.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 TfrmMianWFBKCList.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

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

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

end.
