unit U_OrderProgressDay;

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,
  cxMemo, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmOrderProgressDay = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDBHZ: TRMDBDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Label1: TLabel;
    P_Code: TEdit;
    EndDate: TDateTimePicker;
    Label4: TLabel;
    Label5: TLabel;
    Begdate: TDateTimePicker;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBBandedTableView;
    cxGridDBBandedColumn42: TcxGridDBBandedColumn;
    cxGridDBBandedColumn51: TcxGridDBBandedColumn;
    cxGridDBBandedColumn52: TcxGridDBBandedColumn;
    cxGridDBBandedColumn60: TcxGridDBBandedColumn;
    cxGridDBBandedColumn61: TcxGridDBBandedColumn;
    cxGridDBBandedColumn63: TcxGridDBBandedColumn;
    cxGridDBBandedColumn64: TcxGridDBBandedColumn;
    cxGridDBBandedColumn77: TcxGridDBBandedColumn;
    cxGridDBBandedColumn79: TcxGridDBBandedColumn;
    cxGridDBBandedColumn81: TcxGridDBBandedColumn;
    cxGridDBBandedColumn87: TcxGridDBBandedColumn;
    cxGridDBBandedColumn91: TcxGridDBBandedColumn;
    V1Column6: TcxGridDBBandedColumn;
    cxGridLevel2: TcxGridLevel;
    V1Column28: TcxGridDBBandedColumn;
    V1Column5: TcxGridDBBandedColumn;
    ToolButton3: TToolButton;
    CDSPRTHZ: TClientDataSet;
    CDSPRTMX: TClientDataSet;
    RMDBMX: TRMDBDataSet;
    ADOQueryMain: TADOQuery;
    DataSource1: TDataSource;
    CDS_HZ: TClientDataSet;
    V1Column3: TcxGridDBBandedColumn;
    CDS_PB: TClientDataSet;
    RMDB_PB: TRMDBDataSet;
    V1Column2: TcxGridDBBandedColumn;
    V1Column10: TcxGridDBBandedColumn;
    V1Column11: TcxGridDBBandedColumn;
    V1Column12: TcxGridDBBandedColumn;
    V1Column13: TcxGridDBBandedColumn;
    V1Column14: TcxGridDBBandedColumn;
    V1Column1: TcxGridDBBandedColumn;
    V1Column4: TcxGridDBBandedColumn;
    V1Column7: TcxGridDBBandedColumn;
    V1Column8: TcxGridDBBandedColumn;
    V1Column9: TcxGridDBBandedColumn;
    V1Column15: TcxGridDBBandedColumn;
    V1Column16: TcxGridDBBandedColumn;
    V1Column17: TcxGridDBBandedColumn;
    V1Column18: TcxGridDBBandedColumn;
    V1Column19: TcxGridDBBandedColumn;
    V1Column20: TcxGridDBBandedColumn;
    V1Column21: TcxGridDBBandedColumn;
    V1Column22: TcxGridDBBandedColumn;
    V1Column23: TcxGridDBBandedColumn;
    Label7: TLabel;
    BuyName: TEdit;
    TV1Column1: TcxGridDBBandedColumn;
    TV1Column2: TcxGridDBBandedColumn;
    TV1Column3: TcxGridDBBandedColumn;
    TV1Column5: TcxGridDBBandedColumn;
    TV1Column6: TcxGridDBBandedColumn;
    TV1Column7: TcxGridDBBandedColumn;
    TV1Column8: TcxGridDBBandedColumn;
    TV1Column4: TcxGridDBBandedColumn;
    TV1Column9: TcxGridDBBandedColumn;
    Label2: TLabel;
    Conno: TEdit;
    TV1Column10: TcxGridDBBandedColumn;
    TV1Column11: TcxGridDBBandedColumn;
    TV1Column12: TcxGridDBBandedColumn;
    TV1Column13: TcxGridDBBandedColumn;
    TV1Column14: TcxGridDBBandedColumn;
    TV1Column15: TcxGridDBBandedColumn;
    TV1Column16: TcxGridDBBandedColumn;
    TV1Column17: TcxGridDBBandedColumn;
    TV1Column18: TcxGridDBBandedColumn;
    TV1Column19: TcxGridDBBandedColumn;
    TV1Column20: TcxGridDBBandedColumn;
    TV1Column21: TcxGridDBBandedColumn;
    TV1Column22: 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);
    procedure SFKGyiDanChange(Sender: TObject);
  private

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

var
  frmOrderProgressDay: TfrmOrderProgressDay;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp;

{$R *.dfm}

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

procedure TfrmOrderProgressDay.FormDestroy(Sender: TObject);
begin
  frmOrderProgressDay := nil;
end;

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

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

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

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

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

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

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

procedure TfrmOrderProgressDay.ToolButton3Click(Sender: TObject);
var
  fPrintFile, fPrintFile10, FMainID, FKHName, FFPNo, mfieldName: string;
  i, j, msize: Integer;
  PBRS: Double;
begin
  if CDS_HZ.fieldbyname('DHPS').AsFloat > 0 then
    PBRS := CDS_HZ.fieldbyname('DHQty').AsFloat / CDS_HZ.fieldbyname('DHPS').AsFloat / (CDS_HZ.fieldbyname('KKSL').AsFloat / CDS_HZ.fieldbyname('KKPS').AsFloat)
  else
    PBRS := 0;
  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);
 //添加坯布到货
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.add('exec P_Print_CRJD_PB' + quotedstr(Trim(CDS_HZ.fieldbyname('Conno').AsString)));
//    showmessage(SQL.Text);
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_PB);
  SInitCDSData20(ADOQueryTemp, CDS_PB);
 //添加坯布到货
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\总跟进表.rmf';
  if FileExists(fPrintFile) then
  begin
    RMVariables['PBRS'] := PBRS;
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找到' + fPrintFile), '提示', 0);
  end;
end;

procedure TfrmOrderProgressDay.SFKGyiDanChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, CDS_HZ);
  SInitCDSData20(ADOQueryMain, CDS_HZ);
end;

end.

