unit U_JCCRClist;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin, StdCtrls,
  cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, ShellAPI, IniFiles, cxCheckBox, cxCalendar, cxButtonEdit,
  cxTextEdit, cxDropDownEdit, RM_e_Xls, cxGridBandedTableView,
  cxGridDBBandedTableView, BtnEdit, cxPC, Menus, Clipbrd, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator;

type
  TfrmJCCRClist = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    OrderNo: TEdit;
    cxGrid2: TcxGrid;
    cxGridLevel1: TcxGridLevel;
    Label2: TLabel;
    Label6: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    Label5: TLabel;
    RMGridReport1: TRMGridReport;
    RMDBDataSet1: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    ADOQueryPrint: TADOQuery;
    Panetime: TPanel;
    TV1: TcxGridDBBandedTableView;
    V1Column1: TcxGridDBBandedColumn;
    V1Column2: TcxGridDBBandedColumn;
    V1Column4: TcxGridDBBandedColumn;
    V1Column5: TcxGridDBBandedColumn;
    V1Column6: TcxGridDBBandedColumn;
    V1Column7: TcxGridDBBandedColumn;
    V1Column8: TcxGridDBBandedColumn;
    V1Column9: TcxGridDBBandedColumn;
    V1Column12: TcxGridDBBandedColumn;
    V1Column15: TcxGridDBBandedColumn;
    V1Column3: TcxGridDBBandedColumn;
    FromFactoryName: TBtnEditA;
    V1Column10: TcxGridDBBandedColumn;
    V1Column11: TcxGridDBBandedColumn;
    V1Column13: TcxGridDBBandedColumn;
    V1Column14: TcxGridDBBandedColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    V1Column16: TcxGridDBBandedColumn;
    lbl1: TLabel;
    CPName: TEdit;
    cxgrdbndclmnV1Column17: TcxGridDBBandedColumn;
    Label7: TLabel;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FromFactoryNameBtnClick(Sender: TObject);
    procedure CPNameKeyPress(Sender: TObject; var Key: Char);
    procedure OrderNoChange(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure CPNameChange(Sender: TObject);
  private
    { Private declarations }

    procedure InitGrid();
  public
    { Public declarations }
    RKFlag, FCYID: string;
    fType: string;
  end;

var
  frmJCCRClist: TfrmJCCRClist;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_ZdyAttachGYS;

{$R *.dfm}

procedure TfrmJCCRClist.InitGrid();
begin
//  IF trim(factoryName.Text)='' then
//  begin
//    application.MessageBox('请输入供应商，以便提高查询速度！','提示信息',MB_ICONERROR);
//    exit;
//  end;
  screen.Cursor := crsqlwait;
  Panetime.Visible := true;
  Panetime.Left := (Width - Panetime.Width) div 2;
  Panetime.top := (Height - Panetime.Height - 200) div 2;
  application.ProcessMessages;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      Filtered := False;
      sql.Add(' exec  P_View_JCCRClist ');
      sql.Add(' @begdate=' + quotedstr(Trim(FormatDateTime('yyyy-MM-dd', begdate.DateTime))));
      sql.Add(',@Enddate=' + quotedstr(Trim(FormatDateTime('yyyy-MM-dd', Enddate.DateTime + 1))));
      sql.Add(',@DQFactoryName=' + quotedstr(Trim(FromFactoryName.Text)));
      sql.Add(',@CPName =' + quotedstr(Trim(CPName.Text)));
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
    Panetime.Visible := false;
    screen.Cursor := crdefault;
  end;
end;

procedure TfrmJCCRClist.FormDestroy(Sender: TObject);
begin
//  frmYFMXlist:=nil;
end;

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

procedure TfrmJCCRClist.TBCloseClick(Sender: TObject);
begin
  WriteCxBandedGrid(trim(self.Caption), Tv1, '财务管理');
  Close;
end;

procedure TfrmJCCRClist.FormShow(Sender: TObject);
begin
  readCxBandedGrid(trim(self.Caption), Tv1, '财务管理');

end;

procedure TfrmJCCRClist.TBRafreshClick(Sender: TObject);
begin
  begdate.SetFocus;
  InitGrid();
end;

procedure TfrmJCCRClist.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxgrid2);
end;

procedure TfrmJCCRClist.FormCreate(Sender: TObject);
begin
  cxGrid2.Align := AlClient;
  Enddate.DateTime := SGetServerDate(ADOQueryTemp);
  begdate.DateTime := Enddate.DateTime;
end;

procedure TfrmJCCRClist.FromFactoryNameBtnClick(Sender: TObject);
begin
  try
    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      FFactType := '染厂';
      if ShowModal = 1 then
      begin
        FromFactoryName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
        InitGrid();
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
end;

procedure TfrmJCCRClist.CPNameKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    begdate.SetFocus;
    InitGrid();
  end;
end;

procedure TfrmJCCRClist.OrderNoChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  end;
end;

procedure TfrmJCCRClist.N1Click(Sender: TObject);
begin
  Clipboard.SetTextBuf(PChar(Trim(CDS_HZ.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

procedure TfrmJCCRClist.CPNameChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  end;
end;

end.

