unit U_AllOrderProgress2023;

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,
  RM_e_Xls, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxSkinsCore,
  dxSkinBlack, dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee,
  dxSkinDarkRoom, dxSkinDarkSide, dxSkinDevExpressDarkStyle,
  dxSkinDevExpressStyle, dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast,
  dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky,
  dxSkinMcSkin, dxSkinMetropolis, dxSkinMetropolisDark, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin, dxSkinSeven,
  dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus, dxSkinSilver,
  dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008, dxSkinTheAsphaltWorld,
  dxSkinsDefaultPainters, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue, dxSkinscxPCPainter;

type
  TfrmAllOrderProgress2023 = 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;
    CDS_PB: TClientDataSet;
    RMDB_PB: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    TV1Column1: TcxGridDBBandedColumn;
    TV1Column2: TcxGridDBBandedColumn;
    TV1Column3: TcxGridDBBandedColumn;
    Panel2: TPanel;
    ToolButton4: TToolButton;
    TV1Column4: TcxGridDBBandedColumn;
    Panel3: TPanel;
    Panel4: TPanel;
    Panel5: TPanel;
    CheckBox1: TCheckBox;
    TV1Column6: TcxGridDBBandedColumn;
    TV1Column7: TcxGridDBBandedColumn;
    TV1Column5: TcxGridDBBandedColumn;
    CheckBox2: TCheckBox;
    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 TV1DblClick(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure TV1Column4CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure Panel3Click(Sender: TObject);
    procedure Panel4Click(Sender: TObject);
    procedure Panel5Click(Sender: TObject);
  private

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

var
  frmAllOrderProgress2023: TfrmAllOrderProgress2023;

implementation

uses                            
  U_DataLink, U_Fun, U_ZDYHelp, U_ZGJBMX;

{$R *.dfm}

procedure TfrmAllOrderProgress2023.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      if Trim(DName) <> 'ADMIN' then
      begin
        if CheckBox1.Checked = True then
        begin
          sql.Add(' exec P_View_Order_JD_HZ_Filler_copy1 @Begdate=' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', Begdate.DateTime))));
          sql.Add(' ,@enddate=' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', EndDate.DateTime + 1))));
          sql.Add(' ,@Filler=' + quotedstr(trim(DName)));
          if CheckBox2.Checked = True then
          begin
            sql.Add(' ,@PL=''1''   ');
          end
          else
          begin
            sql.Add(' ,@PL=''0''   ');
          end;

        end
        else
        begin
          sql.Add(' exec P_View_Order_JD_HZ_copy1 @Begdate=' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', Begdate.DateTime))));
          sql.Add(' ,@enddate=' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', EndDate.DateTime + 1))));
            if CheckBox2.Checked = True then
          begin
            sql.Add(' ,@PL=''1''   ');
          end
          else
          begin
            sql.Add(' ,@PL=''0''   ');
          end;
        end;

      end
      else
      begin
        sql.Add(' exec P_View_Order_JD_HZ_copy1 @Begdate=' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', Begdate.DateTime))));
        sql.Add(' ,@enddate=' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', EndDate.DateTime + 1))));
          if CheckBox2.Checked = True then
          begin
            sql.Add(' ,@PL=''1''   ');
          end
          else
          begin                              
            sql.Add(' ,@PL=''0''   ');
          end;
      end;
//      ShowMessage(SQL.text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
//    CDS_HZ.Last;
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmAllOrderProgress2023.FormDestroy(Sender: TObject);
begin
  frmAllOrderProgress2023 := nil;
end;

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

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

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

procedure TfrmAllOrderProgress2023.TBRafreshClick(Sender: TObject);
begin
  Panel2.Visible := True;
  Panel2.Refresh;
  InitGrid();
  Panel2.Visible := False;
end;

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

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

procedure TfrmAllOrderProgress2023.FormCreate(Sender: TObject);
var
  FYear: string;
  FMonth: string;
  FDate: TDate;
begin
  EndDate.Date := SGetServerDate10(ADOQueryTemp);
  BegDate.Date := EndDate.Date - 180;
//  FDate := SGetServerDate10(ADOQueryTemp);
//  FYear := FormatDateTime('yyyy', FDate);
//  FMonth := FormatDateTime('MM', FDate);
//  if StrToInt(FMonth) < 2 then
//  begin
//    BegDate.Date := StrToDate(IntToStr(strtoint(FYear) - 1) + '-02-01');
//    EndDate.Date := StrToDate(FYear + '-01-31');
//  end
//  else
//  begin
//    BegDate.Date := StrToDate(FYear + '-02-01');
//    EndDate.Date := StrToDate(IntToStr(strtoint(FYear) + 1) + '-01-31');
//  end;
  canshu1 := Trim(DParameters1);
end;

procedure TfrmAllOrderProgress2023.ToolButton3Click(Sender: TObject);
var
  fPrintFile, fPrintFile10, FMainID, FKHName, FFPNo, mfieldName: string;
  i, j, msize: Integer;
  PBRS, PBJZ: Double;
begin
  if ((CDS_HZ.fieldbyname('DHPS').AsFloat > 0) and (CDS_HZ.fieldbyname('KKSL').AsFloat > 0) and (CDS_HZ.fieldbyname('KKPS').AsFloat > 0)) then
    PBRS := 1 - (CDS_HZ.fieldbyname('KKSL').AsFloat / CDS_HZ.fieldbyname('KKPS').AsFloat) / (CDS_HZ.fieldbyname('DHQty').AsFloat / CDS_HZ.fieldbyname('DHPS').AsFloat)
  else
    PBRS := 0;

  if CDS_HZ.fieldbyname('DHPS').AsFloat > 0 then
    PBJZ := CDS_HZ.fieldbyname('DHQty').AsFloat / CDS_HZ.fieldbyname('DHPS').AsFloat
  else
    PBJZ := 1;

  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;
  RMVariables['ZJCD1'] := ADOQueryTemp.fieldbyname('ZJCD1').Value;
  RMVariables['ZJCD2'] := ADOQueryTemp.fieldbyname('ZJCD2').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;
    RMVariables['OrderDetail'] := CDS_HZ.fieldbyname('OrderDetail').Value;
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找到' + fPrintFile), '提示', 0);
  end;
end;

procedure TfrmAllOrderProgress2023.TV1DblClick(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    Exit;
  Panel2.Visible := True;
  Panel2.Refresh;
  try
    frmZGJBMX := TfrmZGJBMX.Create(Application);
    with frmZGJBMX do
    begin
      FMainID := Trim(Self.CDS_HZ.fieldbyname('MainId').AsString);
      FConNo := Trim(Self.CDS_HZ.fieldbyname('Conno').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmZGJBMX.Free;
  end;
  Panel2.Visible := False;
end;

procedure TfrmAllOrderProgress2023.ToolButton4Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    Exit;
  Panel2.Visible := True;
  Panel2.Refresh;
  try
    frmZGJBMX := TfrmZGJBMX.Create(Application);
    with frmZGJBMX do
    begin
      FMainID := Trim(Self.CDS_HZ.fieldbyname('MainId').AsString);
      FConNo := Trim(Self.CDS_HZ.fieldbyname('Conno').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmZGJBMX.Free;
  end;
  Panel2.Visible := False;
end;

procedure TfrmAllOrderProgress2023.TV1Column4CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  id: Integer;
  Fsunhao10: string;
  Fsunhao: Double;
begin

  id := TV1.GetColumnByFieldName('PCBFB').Index;

  if id < 0 then
    Exit;

  if AViewInfo.GridRecord.Values[id] = null then
    Exit;

  Fsunhao10 := AViewInfo.GridRecord.Values[id];

  Fsunhao := StrToInt(Fsunhao10);
  if Fsunhao >= 15 then
    ACanvas.Brush.Color := $4763FF
  else if (Fsunhao >= 10) and (Fsunhao < 15) then
  begin
    ACanvas.Brush.Color := $00FFFF
  end
  else
  begin

  end;
end;

procedure TfrmAllOrderProgress2023.Panel3Click(Sender: TObject);
begin
  CDS_HZ.Filter := ' PCBFBInt>14 ';
  CDS_HZ.Filtered := True;
end;

procedure TfrmAllOrderProgress2023.Panel4Click(Sender: TObject);
begin
  CDS_HZ.Filter := ' PCBFBInt>10 and PCBFBInt<15 ';
  CDS_HZ.Filtered := True;
end;

procedure TfrmAllOrderProgress2023.Panel5Click(Sender: TObject);
begin
  CDS_HZ.Filtered := False;
end;

end.

