unit U_TradePlanSchedule;

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, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator,   dxDateRanges,
  dxBarBuiltInMenu, U_BaseList, cxPC, Vcl.Menus, Clipbrd, 
      
    
     
     
     
    
    
    
    
    
     
     
     
    
    
     dxScrollbarAnnotations,
  cxContainer, FrameDateSel;

type
  TfrmTradePlanSchedule = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    cxGrid1: TcxGrid;
    cxGridLevel1: TcxGridLevel;
    GPM_1: TcxGridPopupMenu;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    ToolButton3: TToolButton;
    RMGridReport1: TRMGridReport;
    RMDBDataSet1: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    ADOQueryPrint: TADOQuery;
    TV1: TcxGridDBBandedTableView;
    V1Column1: TcxGridDBBandedColumn;
    V1Column2: TcxGridDBBandedColumn;
    V1Column6: TcxGridDBBandedColumn;
    VCConNo: TcxGridDBBandedColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    TV1Column4: TcxGridDBBandedColumn;
    TV1Column6: TcxGridDBBandedColumn;
    VGC_Name: TcxGridDBBandedColumn;
    TV1Column26: TcxGridDBBandedColumn;
    cxTabControl1: TcxTabControl;
    ToolButton5: TToolButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    TV1Column29: TcxGridDBBandedColumn;
    TV1Column30: TcxGridDBBandedColumn;
    TV1Column32: TcxGridDBBandedColumn;
    TV1Column27: TcxGridDBBandedColumn;
    TV1Column3: TcxGridDBBandedColumn;
    TV1Column20: TcxGridDBBandedColumn;
    TV1Column2: TcxGridDBBandedColumn;
    TV1Column7: TcxGridDBBandedColumn;
    TV1Column8: TcxGridDBBandedColumn;
    TV1Column9: TcxGridDBBandedColumn;
    TV1Column11: TcxGridDBBandedColumn;
    TV1Column10: TcxGridDBBandedColumn;
    TV1Column14: TcxGridDBBandedColumn;
    TV1Column16: TcxGridDBBandedColumn;
    TV1Column15: TcxGridDBBandedColumn;
    TV1Column17: TcxGridDBBandedColumn;
    TV1Column18: TcxGridDBBandedColumn;
    TV1Column19: TcxGridDBBandedColumn;
    TV1Column21: TcxGridDBBandedColumn;
    TV1Column22: TcxGridDBBandedColumn;
    TV1Column23: TcxGridDBBandedColumn;
    TV1Column24: TcxGridDBBandedColumn;
    Panel1: TPanel;
    Label3: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    OrderNo: TcxTextEdit;
    CustName: TcxTextEdit;
    C_Name: TcxTextEdit;
    ConNo: TcxTextEdit;
    frmFrameDateSel1: TfrmFrameDateSel;
    N2: TMenuItem;
    TV1Column1: TcxGridDBBandedColumn;
    TV1Column5: TcxGridDBBandedColumn;
    TV1Column12: 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 P_OrderNo_YSK(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure MPRTCodeNameChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure CustNameChange(Sender: TObject);
    procedure ConNoChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure VCConNoCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
    procedure N2Click(Sender: TObject);
  private
    { Private declarations }

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

var
  frmTradePlanSchedule: TfrmTradePlanSchedule;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp;               //, U_ClothScheduleDetailList

{$R *.dfm}

procedure TfrmTradePlanSchedule.InitGrid();
begin

  screen.Cursor := crsqlwait;

  application.ProcessMessages;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      Filtered := False;
      sql.Add(' exec  P_Trade_Plan_Schedule  ');
      sql.Add('  @begdate=' + QuotedStr(Trim(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.begdate.Date))));
      sql.Add(' ,@Enddate=' + QuotedStr(Trim(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.Enddate.Date + 1))));
      case cxTabControl1.TabIndex of
        0:
          begin
            sql.Add(' ,@WCFlag=''未完成'' ');
          end;
        1:
          begin
            sql.Add(' ,@WCFlag=''已完成'' ');
          end;
        2:
          begin
            sql.Add(' ,@WCFlag=''全部'' ');
          end;
      end;

      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  finally
    ADOQueryMain.EnableControls;
    ToolButton2.Click;
    screen.Cursor := crdefault;
    TV1.DataController.Filter.Clear;
  end;
end;

procedure TfrmTradePlanSchedule.FormDestroy(Sender: TObject);
begin
  inherited;
  frmTradePlanSchedule := nil;
end;

procedure TfrmTradePlanSchedule.ConNoChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmTradePlanSchedule.cxTabControl1Change(Sender: TObject);
begin

  InitGrid();
end;

procedure TfrmTradePlanSchedule.CustNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

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

procedure TfrmTradePlanSchedule.TBCloseClick(Sender: TObject);
begin

  Close;
end;

procedure TfrmTradePlanSchedule.FormShow(Sender: TObject);
begin
  inherited;
  readCxBandedGrid(self.Caption + '2', Tv1, '进度统计查询');
  InitGrid();
end;

procedure TfrmTradePlanSchedule.TBRafreshClick(Sender: TObject);
begin
  toolbar1.SetFocus;
  InitGrid();
end;

procedure TfrmTradePlanSchedule.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  end;
end;

procedure TfrmTradePlanSchedule.P_OrderNo_YSK(Sender: TObject);
begin
  ToolButton2.Click;
end;

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

procedure TfrmTradePlanSchedule.MPRTCodeNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmTradePlanSchedule.N1Click(Sender: TObject);
begin

  Clipboard.SetTextBuf(PChar(Trim(CDS_1.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

procedure TfrmTradePlanSchedule.N2Click(Sender: TObject);
begin
//  if Trim(self.CDS_1.FieldByName('TPFId').AsString) = '' then
//    Exit;
//
//  try
//    frmClothScheduleList := TfrmClothScheduleList.Create(Application);
//    with frmClothScheduleList do
//    begin
//      FTPFId := self.CDS_1.FieldByName('TPFId').AsString;
//      FOrderNo := self.CDS_1.FieldByName('OrderNo').AsString;
//      if ShowModal = 1 then
//      begin
//        Self.InitGrid();
//      end;
//    end;
//  finally
//    frmClothScheduleList.Free;
//  end;
end;

procedure TfrmTradePlanSchedule.FormCreate(Sender: TObject);
begin
  inherited;
  frmFrameDateSel1.Enddate.Date := SGetServerDate(ADOQueryTemp);
  frmFrameDateSel1.begdate.Date := frmFrameDateSel1.Enddate.Date - 60;
end;

procedure TfrmTradePlanSchedule.ToolButton3Click(Sender: TObject);
var
  filepath: string;
  mBegdate, mEnddate: string;
begin
  mBegdate := FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.begdate.Date);
  mEnddate := FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.enddate.Date);
  if CDS_1.IsEmpty then
    exit;

  try

    filepath := ExtractFilePath(Application.ExeName) + 'report\订单利润表.rmf';
    if not FileExists(Pchar(filepath)) then
    begin
      application.MessageBox(pchar('文件[' + filepath + ']不存在！'), '提示信息', MB_IConError);
      exit;
    end;

    RMGridReport1.LoadFromFile(filepath);

    RMGridReport1.ShowReport;
  finally

  end;

end;

procedure TfrmTradePlanSchedule.ToolButton5Click(Sender: TObject);
begin

  WriteCxBandedGrid(self.Caption + '2', Tv1, '进度统计查询');
end;

procedure TfrmTradePlanSchedule.VCConNoCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
begin
  if (ARow1.Values[VCConNo.Index] = ARow2.Values[VCConNo.Index]) and (ARow1.Values[VGC_Name.Index] = ARow2.Values[VGC_Name.Index]) then
    AAreEqual := True
  else
    AAreEqual := False;
end;

end.

