unit U_AllOrderProgress;

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

type
  TfrmAllOrderProgress = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    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;
    Label6: TLabel;
    Conno: TEdit;
    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;
    Label2: TLabel;
    Label3: TLabel;
    SFKGyiDan: TComboBox;
    SFPaiZ: TComboBox;
    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;
    PopupMenu2: TPopupMenu;
    N11: TMenuItem;
    N1: TMenuItem;
    CDS_PM: TClientDataSet;
    RMDB_Main: TRMDBDataSet;
    CDS_QZ: TClientDataSet;
    RMDB_QZ: TRMDBDataSet;
    CDS_PJS: TClientDataSet;
    RMDB_JS: TRMDBDataSet;
    CDS_PWS: TClientDataSet;
    RMDB_WS: TRMDBDataSet;
    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 SFKGyiDanChange(Sender: TObject);
    procedure N11Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
  private

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

var
  frmAllOrderProgress: TfrmAllOrderProgress;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp;

{$R *.dfm}

procedure TfrmAllOrderProgress.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;
      //ShowMessage(SQL.Text);
    end;
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmAllOrderProgress.FormDestroy(Sender: TObject);
begin
  frmAllOrderProgress := nil;
end;

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

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

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

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

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

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

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

procedure TfrmAllOrderProgress.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;

procedure TfrmAllOrderProgress.N11Click(Sender: TObject);
var
  fPrintFile, fPrintFileQZ,fPrintFileYWB: string;
begin
  if CDS_HZ.IsEmpty then
    Exit;

    fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\织造工艺单.rmf';
    ExportFtErpFile('织造工艺单.rmf', ADOQueryTemp);

    with ADOQueryTemp do
    begin
     // Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select *  ');
      sql.Add(' from PD_Plan_Main A inner join PD_Plan_Sub B on A.Mainid=B.MainId');
      sql.Add(' where B.P_Code='+ quotedstr(Trim(CDS_HZ.fieldbyname('P_Code').AsString)));
      sql.Add(' and A.ConNo='+ quotedstr(Trim(CDS_HZ.fieldbyname('ConNO').AsString)));
     //   ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryTemp, CDS_PM);
    SInitCDSData20(ADOQueryTemp, CDS_PM);

    if Trim(ADOQueryTemp.fieldbyname('YWBian').AsString)<> '' then
    begin
      fPrintFileYWB := ExtractFilePath(Application.ExeName) + 'Report\英文边.rmf';
      ExportFtErpFile('英文边.rmf', ADOQueryTemp);
    end;

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from PD_Plan_QZ where MainId=(select A.MainId from PD_Plan_Main A ');
      sql.Add(' inner join PD_Plan_Sub B on A.Mainid=B.MainId ');
      sql.Add(' where B.P_Code='+quotedstr(Trim(CDS_HZ.fieldbyname('P_Code').AsString)));
      sql.Add(' and A.ConNo='+ quotedstr(Trim(CDS_HZ.fieldbyname('ConNO').AsString)));
      sql.Add(')');
      //ShowMessage(SQL.Text);
      Open;
    end;
    if not ADOQueryTemp.IsEmpty then
    begin
      SCreateCDS20(ADOQueryTemp, CDS_QZ);
      SInitCDSData20(ADOQueryTemp, CDS_QZ);
      fPrintFileQZ := ExtractFilePath(Application.ExeName) + 'Report\起综工艺单.rmf';
      ExportFtErpFile('起综工艺单.rmf', ADOQueryTemp);
    end;


    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from PD_Plan_Yarn where PYType=''经丝'' and MainId=(select A.MainId from PD_Plan_Main A ');
      sql.Add(' inner join PD_Plan_Sub B on A.Mainid=B.MainId ');
      sql.Add(' where B.P_Code='+quotedstr(Trim(CDS_HZ.fieldbyname('P_Code').AsString)));
      sql.Add(' and A.ConNo='+ quotedstr(Trim(CDS_HZ.fieldbyname('ConNO').AsString)));
      sql.Add(')');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp, CDS_PJS);
    SInitCDSData20(ADOQueryTemp, CDS_PJS);

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from PD_Plan_Yarn where PYType=''纬丝'' and MainId=(select A.MainId from PD_Plan_Main A ');
      sql.Add(' inner join PD_Plan_Sub B on A.Mainid=B.MainId ');
      sql.Add(' where B.P_Code='+quotedstr(Trim(CDS_HZ.fieldbyname('P_Code').AsString)));
      sql.Add(' and A.ConNo='+ quotedstr(Trim(CDS_HZ.fieldbyname('ConNO').AsString)));
      sql.Add(')');
      //ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryTemp, CDS_PWS);
    SInitCDSData20(ADOQueryTemp, CDS_PWS);

    if FileExists(fPrintFile)then
    begin
      RM1.LoadFromFile(fPrintFile);
      RM1.ShowReport;
      if FileExists(fPrintFileQZ) then
      begin
        RM1.LoadFromFile(fPrintFileQZ);
        RM1.ShowReport;
      end ;

      if FileExists(fPrintFileYWB) then
        begin
          RM1.LoadFromFile(fPrintFileYWB);
          RM1.ShowReport;
        end;
    end
    else
    begin
      Application.MessageBox(PChar('没有找' + fPrintFile), '提示', 0);
    end;
end;

procedure TfrmAllOrderProgress.N1Click(Sender: TObject);
var
  fPrintFile, fPrintFileQZ,fPrintFileYWB: string;
  i, j, k: integer;
begin
    if CDS_HZ.IsEmpty then
    Exit;

    fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\整经工艺单.rmf';
    ExportFtErpFile('整经工艺单.rmf', ADOQueryTemp);

    with ADOQueryTemp do
    begin
     // Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select A.*,B.*  ');
      sql.Add(' from PD_Plan_Main A inner join PD_Plan_Sub B on A.Mainid=B.MainId');
      sql.Add(' where B.P_Code='+ quotedstr(Trim(CDS_HZ.fieldbyname('P_Code').AsString)));
      sql.Add(' and A.ConNo='+ quotedstr(Trim(CDS_HZ.fieldbyname('ConNO').AsString)));
        //ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryTemp, CDS_PM);
    SInitCDSData20(ADOQueryTemp, CDS_PM);

    if Trim(ADOQueryTemp.fieldbyname('YWBian').AsString)<> '' then
    begin
      fPrintFileYWB := ExtractFilePath(Application.ExeName) + 'Report\英文边.rmf';
      ExportFtErpFile('英文边.rmf', ADOQueryTemp);
    end;

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from PD_Plan_QZ where MainId=(select A.MainId from PD_Plan_Main A ');
      sql.Add(' inner join PD_Plan_Sub B on A.Mainid=B.MainId ');
      sql.Add(' where B.P_Code='+quotedstr(Trim(CDS_HZ.fieldbyname('P_Code').AsString)));
      sql.Add(' and A.ConNo='+ quotedstr(Trim(CDS_HZ.fieldbyname('ConNO').AsString)));
      sql.Add(')');
      //ShowMessage(SQL.Text);
      Open;
    end;
    if not ADOQueryTemp.IsEmpty then
    begin
      SCreateCDS20(ADOQueryTemp, CDS_QZ);
      SInitCDSData20(ADOQueryTemp, CDS_QZ);
      fPrintFileQZ := ExtractFilePath(Application.ExeName) + 'Report\起综工艺单.rmf';
      ExportFtErpFile('起综工艺单.rmf', ADOQueryTemp);
    end;


    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from PD_Plan_Yarn where PYType=''经丝'' and MainId=(select A.MainId from PD_Plan_Main A ');
      sql.Add(' inner join PD_Plan_Sub B on A.Mainid=B.MainId ');
      sql.Add(' where B.P_Code='+quotedstr(Trim(CDS_HZ.fieldbyname('P_Code').AsString)));
      sql.Add(' and A.ConNo='+ quotedstr(Trim(CDS_HZ.fieldbyname('ConNO').AsString)));
      sql.Add(')');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp, CDS_PJS);
    SInitCDSData20(ADOQueryTemp, CDS_PJS);

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from PD_Plan_Yarn where PYType=''纬丝'' and MainId=(select A.MainId from PD_Plan_Main A ');
      sql.Add(' inner join PD_Plan_Sub B on A.Mainid=B.MainId ');
      sql.Add(' where B.P_Code='+quotedstr(Trim(CDS_HZ.fieldbyname('P_Code').AsString)));
      sql.Add(' and A.ConNo='+ quotedstr(Trim(CDS_HZ.fieldbyname('ConNO').AsString)));
      sql.Add(')');
      //ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryTemp, CDS_PWS);                                               
    SInitCDSData20(ADOQueryTemp, CDS_PWS);

    if FileExists(fPrintFile)then
    begin
      RM1.LoadFromFile(fPrintFile);
      RM1.ShowReport;
      if FileExists(fPrintFileQZ) then
      begin
        RM1.LoadFromFile(fPrintFileQZ);
        RM1.ShowReport;
      end ;

      if FileExists(fPrintFileYWB) then
        begin
          RM1.LoadFromFile(fPrintFileYWB);
          RM1.ShowReport;
        end;
    end
    else
    begin
      Application.MessageBox(PChar('没有找' + fPrintFile), '提示', 0);
    end;
end;

end.

