unit U_OutListSel3;

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
  TfrmOutListSel3 = 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;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column6: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    Label3: TLabel;
    Label5: TLabel;
    Label8: TLabel;
    Label12: TLabel;
    Label6: TLabel;
    SPName: TEdit;
    SPID: TEdit;
    SPSpec: TEdit;
    CRType: TComboBox;
    SPCF: TEdit;
    Label13: TLabel;
    ToFactoryName: TEdit;
    Label14: TLabel;
    BatchNO: TEdit;
    Label4: TLabel;
    FactoryName: TEdit;
    v1Column5: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    v1Column15: TcxGridDBColumn;
    ToolButton1: TToolButton;
    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 SPNameChange(Sender: TObject);
    procedure SPIDChange(Sender: TObject);
    procedure SPIDKeyPress(Sender: TObject; var Key: Char);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure SPSpecChange(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private
    canshu1, canshu2: string;
    procedure InitGrid();
    { Private declarations }
  public
    FCRType: string;
    { Public declarations }
  end;

var
  frmOutListSel3: TfrmOutListSel3;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmOutListSel3.FormDestroy(Sender: TObject);
begin
  frmOutListSel3 := nil;
end;

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

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

procedure TfrmOutListSel3.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');
      sql.Add(' where A.CRTime>=' + quotedstr(Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime))) + ' and A.CRTime<' + quotedstr(Trim(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1))));
      SQL.Add(' and CRFlag=''出库''   and Valid=''Y'' and ckname=''纱线''  and shtag=''损耗''    ');

      if cxTabControl1.TabIndex = 0 then
        SQL.Add(' and not exists(select FZSPID from CK_SXPB_CR X where X.FromSPID=A.SPID ) ')
      else
        SQL.Add(' and  exists(select FZSPID from CK_SXPB_CR X where X.FromSPID=A.SPID )');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

procedure TfrmOutListSel3.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('坯布出库列表PMD', Tv1, '坯布仓库');
  Close;
end;

procedure TfrmOutListSel3.FormShow(Sender: TObject);
var
  fsj: string;
begin

  ReadCxGrid('坯布出库列表PMD', Tv1, '坯布仓库');
  fsj := 'select distinct(CRType) name from CK_SXPB_CR where CRFlag=''出库''  ';
  SInitComBoxBySql(ADOQueryTemp, CRType, False, fsj);
  InitGrid();
end;

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

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

procedure TfrmOutListSel3.SPIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    {if Length(Trim(SPID.Text))<4 then Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        sql.Clear;
        sql.Add(' select A.* ');
        sql.Add(' from CK_SXPB_CR A');
        sql.add(' where SPID like :SXID');
        Parameters.ParamByName('SXID').Value:='%'+Trim(SPID.Text)+'%';
        Open;
        //ShowMessage(SQL.Text);
      end;
      SCreateCDS20(ADOQueryMain,CDS_Main);
      SInitCDSData20(ADOQueryMain,CDS_Main);
    finally
      ADOQueryMain.EnableControls;
    end; }
  end;
end;

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

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

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

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

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

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

end.

