unit U_JGCklistSel;

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, RM_Common, RM_Class, RM_e_Xls, RM_GridReport, RM_System,
  RM_Dataset;

type
  TfrmJGCklistSel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TOK: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1P_CodeName: TcxGridDBColumn;
    v1P_SPEC: TcxGridDBColumn;
    v1P_MF: TcxGridDBColumn;
    v1P_KZ: TcxGridDBColumn;
    v1RollNum: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1QtyUnit: TcxGridDBColumn;
    v1Note: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1CRType: TcxGridDBColumn;
    v1CRTime: TcxGridDBColumn;
    v1Filler: TcxGridDBColumn;
    v1FillTime: TcxGridDBColumn;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    P_CodeName: TEdit;
    P_Color: TEdit;
    CRType: TComboBox;
    Label5: TLabel;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    DataSource1: TDataSource;
    CDS_Main: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    v1MJID: TcxGridDBColumn;
    v1MJXH: TcxGridDBColumn;
    v1CPTYPE: TcxGridDBColumn;
    ckName: TComboBox;
    Label6: TLabel;
    v1P_Color: TcxGridDBColumn;
    ADOPrint: TADOQuery;
    RMDB_MD: TRMDBDataSet;
    RMGridReport1: TRMGridReport;
    RMXLSExport1: TRMXLSExport;
    v1customerNoname: TcxGridDBColumn;
    cust: TEdit;
    Label7: TLabel;
    Label8: TLabel;
    v1Column1: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure P_CodeNameChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TOKClick(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
  private
    procedure InitGrid();
    procedure SetComboBox();
    { Private declarations }
  public
    fCKName:string;
    { Public declarations }
  end;

var
  frmJGCklistSel: TfrmJGCklistSel;
implementation
uses
  U_DataLink,U_Fun10,U_ZDYHelp;
{$R *.dfm}
procedure TfrmJGCklistSel.SetComboBox();
begin
  ckName.Items.Clear;
  with adoQueryTmp do
  begin
    close;
    sql.Clear;
    sql.Add('select * from KH_ZDY where Type=''BPCK'' ');
    if trim(fCKName)<>'' then
    sql.Add('and zdyName='+quotedstr(trim(fCKName)));
    open;
    while not eof do
    begin
      ckName.Items.Add(trim(fieldbyname('zdyName').AsString));
      next;
    end;
  end;
  if ckName.Items.Count>0 then ckName.ItemIndex:=0;

  CRType.Items.Clear;
  CRType.Items.Add('');
  with adoQueryTmp do
  begin
    close;
    sql.Clear;
    sql.Add('select * from KH_ZDY where Type=''BPCKTYPE''');
    if trim(fCKName)<>'' then
    sql.Add('and note='+quotedstr(trim(fCKName)));
    open;
    while not eof do
    begin
      CRType.Items.Add(trim(fieldbyname('zdyName').AsString));
      next;
    end;
  end;
  if CRType.Items.Count>0 then CRType.ItemIndex:=0;
end;
procedure TfrmJGCklistSel.InitGrid();
begin
  try
    with adoqueryTmp do
    begin
      close;
      sql.Clear;
      sql.Add('select A.* from BP_InOut A');
      sql.Add('where CRTime>='''+formatdateTime('yyyy-MM-dd',begdate.Date)+''' ');
      sql.Add('and CRTime<'''+formatdateTime('yyyy-MM-dd',enddate.Date+1)+''' ');
      sql.Add('and CRFlag=''出库'' ');
      sql.Add('and CRType=''加工出库'' ');
      sql.Add('and ckName='+quotedstr(trim('坯布仓库')) );
      open;
    end;
    SCreateCDS20(adoqueryTmp,CDS_Main);
    SInitCDSData20(adoqueryTmp,CDS_Main);
  finally
  end;
end;

procedure TfrmJGCklistSel.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  writeCxGrid(self.Caption,Tv1,'布匹仓库');
  Action:=cafree;
end;

procedure TfrmJGCklistSel.FormDestroy(Sender: TObject);
begin
  frmJGCklistSel:=nil;
end;

procedure TfrmJGCklistSel.P_CodeNameChange(Sender: TObject);
var
  m:string;
begin
  if ADOQueryTmp.Active=False then Exit;
  SDofilter(ADOQueryTmp,SGetFilters(Panel1,1,2));
  m:= SGetFilters(Panel1,1,2);
  SCreateCDS20(ADOQueryTmp,CDS_Main);
  SInitCDSData20(ADOQueryTmp,CDS_Main);
end;

procedure TfrmJGCklistSel.FormShow(Sender: TObject);
begin
  readCxGrid(self.Caption,Tv1,'布匹仓库');
  SetComboBox();
  try
    with adoqueryTmp do
    begin
      close;
      sql.Clear;
      sql.Add('select top 50 A.* from BP_InOut A');
      sql.Add('where CRFlag=''出库'' ');
      sql.Add('and CRType=''加工出库'' ');
      sql.Add('and ckName='+quotedstr(trim('坯布仓库')));
      sql.Add('order by A.FillTime desc');
      open;
    end;
    SCreateCDS20(adoqueryTmp,CDS_Main);
    SInitCDSData20(adoqueryTmp,CDS_Main);
  finally
  end;
end;

procedure TfrmJGCklistSel.FormCreate(Sender: TObject);
begin
  BegDate.Date:=DServerDate-30;
  EndDate.Date:=DServerDate;
  cxGrid1.Align:=alclient;
end;

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

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

procedure TfrmJGCklistSel.TOKClick(Sender: TObject);
begin
  IF CDS_Main.IsEmpty then exit;
  ModalResult:=1;
end;

procedure TfrmJGCklistSel.Tv1DblClick(Sender: TObject);
begin
  tok.Click;
end;

end.
