unit U_ZZJWLCKListSel;

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
  TfrmZZJWLCKListSel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    RMDBHZ: TRMDBDataSet;
    CDS_HZ: TClientDataSet;
    CDS_PRT: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label8: TLabel;
    Label12: TLabel;
    SPName: TEdit;
    FactoryName: TEdit;
    SPID: TEdit;
    SPSpec: TEdit;
    CRType: TComboBox;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column6: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    v1Column1: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    Label10: TLabel;
    SXPinPai: TEdit;
    v1Column7: TcxGridDBColumn;
    Label6: TLabel;
    SPType: TEdit;
    v1Column9: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    ToolButton1: TToolButton;
    v1Column13: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure SPIDChange(Sender: TObject);
    procedure SPSpecChange(Sender: TObject);
    procedure FactoryNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private
    canshu1, canshu2, canshu3: string;
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmZZJWLCKListSel: TfrmZZJWLCKListSel;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmZZJWLCKListSel.FormDestroy(Sender: TObject);
begin
  frmZZJWLCKListSel := nil;
end;

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

procedure TfrmZZJWLCKListSel.FormCreate(Sender: TObject);
begin
  //cxGrid1.Align:=alClient;
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime - 30;
  canshu1 := Trim(DParameters1);
  canshu2 := Trim(DParameters2);
  canshu3 := Trim(DParameters3);
end;

procedure TfrmZZJWLCKListSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' select A.*,XSMoney=Price*Qty ');
      sql.Add(' from CK_SXPB_CR A');
      sql.add(' where A.CRTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + '''');
      sql.Add(' and A.CRTime<''' + Trim(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1)) + '''');
      sql.Add(' and isnull(CKName,'''')=''机物料''');
      SQL.Add(' and CRType in(''销售出库'',''销售退货'')  ');
      Sql.Add(' and ZFFlag=0 ');
      if cxTabControl1.TabIndex = 0 then
        SQL.Add(' and not exists(select YFPZNO from YF_Money_CR_Sub X where X.YFPZNO=A.SPID ) ')
      else
        SQL.Add(' and  exists(select YFPZNO from YF_Money_CR_Sub X where X.YFPZNO=A.SPID )');
      SQL.Add(' order by CRTime desc');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmZZJWLCKListSel.TBRafreshClick(Sender: TObject);
begin
  BegDate.SetFocus;
  InitGrid();
end;

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

procedure TfrmZZJWLCKListSel.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(trim(self.caption), Tv1, '机物料仓库');
  Close;
end;

procedure TfrmZZJWLCKListSel.FormShow(Sender: TObject);
begin
  ReadCxGrid(trim(self.caption), Tv1, '机物料仓库');

  InitGrid();
end;

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

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

procedure TfrmZZJWLCKListSel.SPIDChange(Sender: TObject);
begin
  if Length(Trim(SPID.Text)) < 4 then
  begin
    if Trim(SPID.Text) <> '' then
      Exit;
  end;
  TBFind.Click;
end;

procedure TfrmZZJWLCKListSel.SPSpecChange(Sender: TObject);
begin
  TBFind.Click;
end;

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

procedure TfrmZZJWLCKListSel.ToolButton1Click(Sender: TObject);
begin
  ModalResult := 1;
end;

end.

