unit U_PBDHList;

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,
  IniFiles, jpeg, U_SLT;

type
  TfrmPBDHList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    RMDBHZ: TRMDBDataSet;
    CDS_HZ: TClientDataSet;
    CDS_PRT: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    adoqueryPicture: TADOQuery;
    PopupMenu2: TPopupMenu;
    N3: TMenuItem;
    N4: TMenuItem;
    RMDBDataSet1: TRMDBDataSet;
    ClientDataSet1: TClientDataSet;
    RMGridReport1: TRMGridReport;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column6: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1CRType: TcxGridDBColumn;
    v1FactoryName: TcxGridDBColumn;
    v2SPName: TcxGridDBColumn;
    v1SPSpec: TcxGridDBColumn;
    v1SPCF: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1BatchNo: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    cxTabControl1: TcxTabControl;
    v1Column4: TcxGridDBColumn;
    Panel1: TPanel;
    lbl1: TLabel;
    lbl2: TLabel;
    lbl3: TLabel;
    lbl4: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CPName: TEdit;
    SupplierName: TEdit;
    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 N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure SPIDChange(Sender: TObject);
    procedure SPSpecChange(Sender: TObject);
    procedure SupplierNameChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
  private
    canshu1, canshu2, canshu3: string;
    procedure InitGrid();
    procedure ReadINIFile();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmPBDHList: TfrmPBDHList;

var
  Mach: array of TfrmSlt;

implementation

uses
  U_DataLink, U_RTFun; 

{$R *.dfm}

procedure TfrmPBDHList.FormDestroy(Sender: TObject);
begin
  frmPBDHList := nil;
end;

procedure TfrmPBDHList.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caHide;
end;

procedure TfrmPBDHList.ReadINIFile();
var
  programIni: Tinifile;  //配置文件名
  FileName: string;
begin
  FileName := ExtractFilePath(Paramstr(0)) + 'SYSTEMSET.INI';
  programIni := Tinifile.create(FileName);
  server := programIni.ReadString('SERVER', '服务器地址', '127.0.0.1');
  programIni.Free;
end;

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

procedure TfrmPBDHList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      sql.Add(' from SupplierDeliver A');
      sql.add(' where A.FHDate>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + '''');
      sql.Add(' and A.FHDate<''' + Trim(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1)) + '''');
      sql.Add(' and ChkStatus in (''仓库已确认'',''业务已确认'') ');
      if cxTabControl1.TabIndex = 0 then
        SQL.Add(' and not exists(select YFPZNO from YF_Money_CR_Sub X where X.YFPZNO=A.FHID ) ')
      else
        SQL.Add(' and  exists(select YFPZNO from YF_Money_CR_Sub X where X.YFPZNO=A.FHID )');

      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

procedure TfrmPBDHList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('纱线入库列表', Tv1, '纱线仓库');
  Close;
end;

procedure TfrmPBDHList.FormShow(Sender: TObject);
begin
  ReadCxGrid('纱线入库列表', Tv1, '纱线仓库');

end;

procedure TfrmPBDHList.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 TfrmPBDHList.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, True);
end;

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

procedure TfrmPBDHList.SPIDChange(Sender: TObject);
begin

  TBFind.Click;
end;

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

procedure TfrmPBDHList.SupplierNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmPBDHList.cxTabControl1Change(Sender: TObject);
begin
  INITGrid();
end;

procedure TfrmPBDHList.ToolButton4Click(Sender: TObject);
var
  fPrintFile: string;
begin
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    SQL.Add('exec P_Print_SXRK' + quotedstr(Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date))));
    SQL.Add(',''年'' ');
    Open;
//    ShowMessage(SQL.Text);
  end;
  SCreateCDS20(ADOQueryTemp, ClientDataSet1);
  SInitCDSData20(ADOQueryTemp, ClientDataSet1);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\纱线入库年报表.rmf';
  if FileExists(fPrintFile) then
  begin
//    RMVariables['ConNo']:=Order_Main.fieldbyname('ConNo').Value;
    RMGridReport1.LoadFromFile(fPrintFile);
    RMGridReport1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\纱线入库年报表.rmf'), '提示', 0);
  end;
end;

procedure TfrmPBDHList.TBExportClick(Sender: TObject);
begin
  if cxTabControl1.TabIndex <> 0 then
    Exit;
  ModalResult := 1;
end;

end.

