unit U_OrderProgress;

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, cxDBLookupComboBox, cxGridBandedTableView, cxGridDBBandedTableView,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmOrderProgress = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDBHZ: TRMDBDataSet;
    Label3: TLabel;
    MPRTCodeName: TEdit;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Label1: TLabel;
    MPRTCode: TEdit;
    EndDate: TDateTimePicker;
    Label4: TLabel;
    Label5: TLabel;
    Begdate: TDateTimePicker;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBBandedTableView;
    cxGridDBBandedColumn35: TcxGridDBBandedColumn;
    cxGridDBBandedColumn42: TcxGridDBBandedColumn;
    cxGridDBBandedColumn51: TcxGridDBBandedColumn;
    cxGridDBBandedColumn52: TcxGridDBBandedColumn;
    cxGridDBBandedColumn56: TcxGridDBBandedColumn;
    cxGridDBBandedColumn57: TcxGridDBBandedColumn;
    cxGridDBBandedColumn59: TcxGridDBBandedColumn;
    cxGridDBBandedColumn60: TcxGridDBBandedColumn;
    cxGridDBBandedColumn61: TcxGridDBBandedColumn;
    cxGridDBBandedColumn62: TcxGridDBBandedColumn;
    cxGridDBBandedColumn63: TcxGridDBBandedColumn;
    cxGridDBBandedColumn64: TcxGridDBBandedColumn;
    cxGridDBBandedColumn77: TcxGridDBBandedColumn;
    cxGridDBBandedColumn79: TcxGridDBBandedColumn;
    cxGridDBBandedColumn81: TcxGridDBBandedColumn;
    cxGridDBBandedColumn87: TcxGridDBBandedColumn;
    cxGridDBBandedColumn91: TcxGridDBBandedColumn;
    V1Column1: TcxGridDBBandedColumn;
    V1Column2: TcxGridDBBandedColumn;
    V1Column6: TcxGridDBBandedColumn;
    cxGridLevel2: TcxGridLevel;
    V1Column25: TcxGridDBBandedColumn;
    V1Column26: TcxGridDBBandedColumn;
    V1Column27: TcxGridDBBandedColumn;
    V1Column28: TcxGridDBBandedColumn;
    Label2: TLabel;
    OrderNoX: TEdit;
    V1Column4: TcxGridDBBandedColumn;
    V1Column5: TcxGridDBBandedColumn;
    V1Column7: TcxGridDBBandedColumn;
    Label6: TLabel;
    Conno: TEdit;
    ToolButton3: TToolButton;
    CDSPRTHZ: TClientDataSet;
    CDSPRTMX: TClientDataSet;
    RMDBMX: TRMDBDataSet;
    ADOQueryMain: TADOQuery;
    DataSource1: TDataSource;
    CDS_HZ: TClientDataSet;
    V1Column3: TcxGridDBBandedColumn;
    V1Column8: TcxGridDBBandedColumn;
    V1Column9: TcxGridDBBandedColumn;
    V1Column10: TcxGridDBBandedColumn;
    V1Column11: TcxGridDBBandedColumn;
    TV1Column1: TcxGridDBBandedColumn;
    TV1Column2: TcxGridDBBandedColumn;
    TV1Column3: TcxGridDBBandedColumn;
    TV1Column6: TcxGridDBBandedColumn;
    TV1Column7: TcxGridDBBandedColumn;
    TV1Column8: TcxGridDBBandedColumn;
    TV1Column4: TcxGridDBBandedColumn;
    TV1Column5: TcxGridDBBandedColumn;
    TV1Column9: TcxGridDBBandedColumn;
    TV1Column10: TcxGridDBBandedColumn;
    TV1Column11: TcxGridDBBandedColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure MPRTCodeNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
  private

    { Private declarations }
    canshu1: string;
    procedure InitGrid();
  public
    fkhType: string;
    Fmanage: string;
  end;

var
  frmOrderProgress: TfrmOrderProgress;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp;

{$R *.dfm}

procedure TfrmOrderProgress.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add(' exec P_View_OrderProgress @Begdate=' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', Begdate.DateTime))));
      sql.Add(' ,@enddate=' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', EndDate.DateTime + 1))));
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
//    CDS_HZ.Last;
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmOrderProgress.FormDestroy(Sender: TObject);
begin
  frmOrderProgress := nil;
end;

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

procedure TfrmOrderProgress.TBCloseClick(Sender: TObject);
begin
  WriteCxBandedGrid(trim(self.caption) + '1', Tv1, '进度管理');
  Close;
end;

procedure TfrmOrderProgress.FormShow(Sender: TObject);
begin
  ReadCxBandedGrid(trim(self.caption) + '1', Tv1, '进度管理');
//  InitGrid();
end;

procedure TfrmOrderProgress.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmOrderProgress.ToolButton2Click(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 TfrmOrderProgress.MPRTCodeNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

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

procedure TfrmOrderProgress.FormCreate(Sender: TObject);
begin
  canshu1 := Trim(DParameters1);
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime - 90;
end;

procedure TfrmOrderProgress.ToolButton3Click(Sender: TObject);
var
  fPrintFile, fPrintFile10, FMainID, FKHName, FFPNo: string;
  i: Integer;
begin
  ExportFtErpFile('跟进表.rmf', ADOQueryTemp);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.add('exec P_Print_CRJD_HZ ');
    sql.add('@MainId=' + quotedstr(Trim(CDS_HZ.fieldbyname('MainId').AsString)));
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDSPRTHZ);
  SInitCDSData20(ADOQueryTemp, CDSPRTHZ);

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.add('exec P_Print_CRJD_CD ');
    sql.add('@MainId=' + quotedstr(Trim(CDS_HZ.fieldbyname('MainId').AsString)));
    Open;
  end;
  RMVariables['HZCD'] := ADOQueryTemp.fieldbyname('HZCD').Value;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.add('exec P_Print_CRJD ');
    sql.add('@MainId=' + quotedstr(Trim(CDS_HZ.fieldbyname('MainId').AsString)));
    sql.add(',@Falg=''明细''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDSPRTMX);
  SInitCDSData20(ADOQueryTemp, CDSPRTMX);

  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\跟进表.rmf';
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找到' + fPrintFile), '提示', 0);
  end;
end;

end.

