unit U_CrkAccount;

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

type
  TfrmCrkAccount = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label3: TLabel;
    Label4: TLabel;
    C_CodeName: TEdit;
    C_Color: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    Label5: TLabel;
    conNO: TEdit;
    Label6: TLabel;
    MJID: TEdit;
    Label8: TLabel;
    KZ: TEdit;
    Label9: TLabel;
    MF: TEdit;
    Label7: TLabel;
    CPType: TComboBox;
    MovePanel2: TMovePanel;
    Label10: TLabel;
    BCgangNo: TEdit;
    Label11: TLabel;
    factoryName: TEdit;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    ToolButton1: TToolButton;
    RMGridReport1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    Label12: TLabel;
    CRType: TComboBox;
    v1Column6: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    customerNoName: TEdit;
    Label13: TLabel;
    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 TBExportClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure C_CodeNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmCrkAccount: TfrmCrkAccount;

implementation
uses
  U_DataLink,U_Fun;

{$R *.dfm}

procedure TfrmCrkAccount.FormDestroy(Sender: TObject);
begin
  frmCrkAccount:=nil;
end;

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

procedure TfrmCrkAccount.FormCreate(Sender: TObject);
begin
  cxGrid2.Align:=alClient;
  BegDate.DateTime:=SGetServerDateTime(ADOQueryTemp);
  EndDate.DateTime:=SGetServerDateTime(ADOQueryTemp)
end;

procedure TfrmCrkAccount.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      Filtered:=False;
      sql.Add(' exec P_get_CpCrkAccount ');
      SQL.Add(' @begdate='''+formatdateTime('yyyy-MM-dd',BegDate.DateTime)+''' ');
      SQL.Add(',@enddate='''+formatdateTime('yyyy-MM-dd',enddate.DateTime+1)+''' ');
      Open;
    end;
  //  SCreateCDS20(ADOQueryMain,CDS_Main);
  //  SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
    TBFind.Click;
  end;
end;

procedure TfrmCrkAccount.TBRafreshClick(Sender: TObject);
begin
  //BegDate.SetFocus;
  MovePanel2.Visible:=True;
  MovePanel2.Refresh;
  InitGrid();
  MovePanel2.Visible:=False;
end;

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

procedure TfrmCrkAccount.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(self.Caption,Tv1,'成品仓库');
  Close;
end;

procedure TfrmCrkAccount.FormShow(Sender: TObject);
begin

  ReadCxGrid(self.Caption,Tv1,'成品仓库');
  
  //InitGrid();
end;

procedure TfrmCrkAccount.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  TcxGridToExcel(self.Caption,cxGrid2);
end;

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

procedure TfrmCrkAccount.ToolButton1Click(Sender: TObject);
var
   fPrintFile:string;
begin
  if ADOQueryMain.IsEmpty then Exit;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\成品出入库流水账.rmf' ;
  if FileExists(fPrintFile) then
  begin
    RMVariables['begdate']:=formatdateTime('yyyy-MM-dd',BegDate.Date)+' - '+formatdateTime('yyyy-MM-dd',enddate.Date);
    RMVariables['dtxz']:=formatdateTime('yyyy-MM-dd',Now);
    RMVariables['zdr']:=Trim(dName);
    RMGridReport1.LoadFromFile(fPrintFile);
    RMGridReport1.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+fPrintFile),'提示',MB_ICONERROR);
  end;
end;
end.
