unit U_BpRklist;

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, cxContainer, cxTextEdit, cxCurrencyEdit, cxCheckBox,
  RM_System, RM_Dataset, RM_Common, RM_Class, RM_GridReport;

type
  TfrmBpRklist = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: 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;
    v1MJXH: TcxGridDBColumn;
    v1CPType: TcxGridDBColumn;
    ckName: TComboBox;
    Label6: TLabel;
    v1P_Color: TcxGridDBColumn;
    v1P_Code: TcxGridDBColumn;
    v1custName: TcxGridDBColumn;
    v1Price: TcxGridDBColumn;
    v1money: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    gangNo: TEdit;
    Label10: TLabel;
    v1Column3: TcxGridDBColumn;
    RMDB_Main: TRMDBDataSet;
    v1Column4: TcxGridDBColumn;
    ADOQueryPrint: TADOQuery;
    RM1: TRMGridReport;
    v1Column5: TcxGridDBColumn;
    CheckBox1: TCheckBox;
    OrderNo: TEdit;
    conNo: TEdit;
    Label13: TLabel;
    Label14: TLabel;
    P_Code: TEdit;
    Label15: TLabel;
    RMDB_MD: TRMDBDataSet;
    ADOPrint1: TADOQuery;
    RMGridReport1: TRMGridReport;
    v1Column6: TcxGridDBColumn;
    v1Column7: 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 TBPrintClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
  private
    procedure InitGrid();
    procedure SetComboBox();
    { Private declarations }
  public
    fCKName:string;
    fCRType:string;
    { Public declarations }
  end;

var
  frmBpRklist: TfrmBpRklist;

implementation
uses
  U_DataLink,U_Fun10,U_ZDYHelp;
{$R *.dfm}
procedure TfrmBpRklist.SetComboBox();
begin
  ckName.Items.Clear;
  with adoQueryTmp do
  begin
    close;
    sql.Clear;
    sql.Add('select * from KH_ZDY where Type=''CPCK'' ');
    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=''CPRKTYPE''');
    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;

  IF trim(fCRType)<>'' then
  begin
    CRType.ItemIndex:=CRType.Items.IndexOf(trim(fCRType));
    CRType.Enabled:=false;
  end;
end;

procedure TfrmBpRklist.InitGrid();
begin
  try
    with adoqueryTmp do
    begin
      close;
      sql.Clear;
      sql.Add('select A.*,B.OrderNo,B.ConNo  ');
      sql.Add('from CP_InOut1 A');
      sql.Add('left join JYorder_main B on B.MainID=A.MainiD ');
      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 A.ckName=''面料仓库''');
      sql.Add(' and A.CRType=''采购入库''');
      open;
    end;
    SCreateCDS20(adoqueryTmp,CDS_Main);
    SInitCDSData20(adoqueryTmp,CDS_Main);
    TBFind.Click;
  finally;
  end;
end;

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

procedure TfrmBpRklist.FormDestroy(Sender: TObject);
begin
  frmBpRklist:=nil;
end;

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

procedure TfrmBpRklist.FormShow(Sender: TObject);
begin
  readCxGrid(self.Caption,Tv1,'成品仓库');
  SetComboBox();
  InitGrid();
end;

procedure TfrmBpRklist.FormCreate(Sender: TObject);
begin
  BegDate.Date:=SGetServerDate(ADOQueryCmd)-7;
  EndDate.Date:=SGetServerDate(ADOQueryCmd);
  cxGrid1.Align:=alclient;

end;

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

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

procedure TfrmBpRklist.TBPrintClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  TcxGridToExcel(self.Caption,cxgrid1);
end;

procedure TfrmBpRklist.TBExportClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  if CDS_Main.Locate('Ssel',True,[])=False then
  begin
    application.MessageBox('没有选择数据','提示');
    exit;
  end;
  ModalResult:=1;
end;

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

procedure TfrmBpRklist.CheckBox1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,checkbox1.Checked);
end;

end.
