unit U_BaoGuanCRKCX;

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, cxPC;

type
  TfrmBaoGuanCRKCX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: 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;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    CDS_HZ: TClientDataSet;
    CDS_PRT: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Panel2: TPanel;
    Label6: TLabel;
    Label8: TLabel;
    Label3: TLabel;
    C3BGName: TEdit;
    A5ConNO: TEdit;
    A1ChuKouShang: TEdit;
    v1A7FPDate: TcxGridDBColumn;
    v1A1ChuKouShang: TcxGridDBColumn;
    v1A5ConNO: TcxGridDBColumn;
    v1C3BGName: TcxGridDBColumn;
    v1YSChenFen: TcxGridDBColumn;
    v1C5BGUnit: TcxGridDBColumn;
    v1C4BGQty: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    Label4: TLabel;
    YSChenFen: TEdit;
    v1Column1: TcxGridDBColumn;
    v1JC: TcxGridDBColumn;
    TPrint: TToolButton;
    ComboBox1: TComboBox;
    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 cxTabControl1Change(Sender: TObject);
    procedure v2Column1CompareRowValuesForCellMerging(
      Sender: TcxGridColumn; ARow1: TcxGridDataRow;
      AProperties1: TcxCustomEditProperties; const AValue1: Variant;
      ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties;
      const AValue2: Variant; var AAreEqual: Boolean);
    procedure TPrintClick(Sender: TObject);
    procedure A1ChuKouShangChange(Sender: TObject);
    procedure A5ConNOChange(Sender: TObject);
  private
    procedure InitGrid();
    procedure GetColor(color:TColor);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmBaoGuanCRKCX: TfrmBaoGuanCRKCX;

implementation
uses
  U_DataLink,U_RTFun;

{$R *.dfm}

procedure TfrmBaoGuanCRKCX.FormDestroy(Sender: TObject);
begin
  frmBaoGuanCRKCX:=nil;
end;

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

procedure TfrmBaoGuanCRKCX.FormCreate(Sender: TObject);
begin
  //cxGrid1.Align:=alClient;
  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime:=SGetServerDateMBeg(ADOQueryTemp);
end;

procedure TfrmBaoGuanCRKCX.InitGrid();
var
  fsj:string;
begin
  Panel2.Visible:=True;
  Panel2.Refresh;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select A.*,B.*,JC=cast(0 as decimal(18,2)) from JYOrder_BaoGuan_Main A inner join JYOrder_BaoGuan_Sub B on A.BGId=B.BGId ');
      sql.Add(' where A7FPDate>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
      sql.Add(' and A7FPDate<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally;
    ADOQueryMain.EnableControls;
    Panel2.Visible:=False;
  end;
  Panel2.Visible:=False;
end;

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

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

procedure TfrmBaoGuanCRKCX.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('财务报关销售报表',Tv1,'财务管理');
  Close;
end;

procedure TfrmBaoGuanCRKCX.FormShow(Sender: TObject);
begin
  ReadCxGrid('财务报关销售报表',Tv1,'财务管理');
  //InitGrid();
end;

procedure TfrmBaoGuanCRKCX.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  TcxGridToExcel('财务报关销售报表',cxGrid2);
end;

procedure TfrmBaoGuanCRKCX.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 TfrmBaoGuanCRKCX.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmBaoGuanCRKCX.v2Column1CompareRowValuesForCellMerging(
  Sender: TcxGridColumn; ARow1: TcxGridDataRow;
  AProperties1: TcxCustomEditProperties; const AValue1: Variant;
  ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties;
  const AValue2: Variant; var AAreEqual: Boolean);

var
   colIdx0:integer;
begin
  colIdx0:= tv1.GetColumnByFieldName('A4FPNO').Index;
  if ARow1.Values[colIdx0] = ARow2.Values[colIdx0] then
    AAreEqual := True
  else
    AAreEqual := False;
end;


procedure TfrmBaoGuanCRKCX.GetColor(color:TColor);
begin
  
end;

procedure TfrmBaoGuanCRKCX.TPrintClick(Sender: TObject);
var
   fPrintFile,fsj:string;
begin
  if CDS_Main.IsEmpty then Exit;
  if ComboBox1.Text='入库单' then
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\财务报关入库单.rmf';
  if ComboBox1.Text='出库单' then
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\财务报关出库单.rmf';
  if FileExists(fPrintFile) then
  begin
    //RMVariables['TaiTou']:=cxTabControl1.Tabs[cxTabControl1.TabIndex].Caption;
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\财务报关入库单.rmf'),'提示',0);
  end;
end;

procedure TfrmBaoGuanCRKCX.A1ChuKouShangChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmBaoGuanCRKCX.A5ConNOChange(Sender: TObject);
begin
  TBFind.Click;
end;

end.
