unit U_TradePlanScheduleDetail;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, cxStyles, cxCustomData, cxGraphics, cxFilter,
  cxData, cxDataStorage, cxEdit, DB, cxDBData, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGrid, cxCheckBox, cxCalendar, ADODB, DBClient,
  cxGridCustomPopupMenu, cxGridPopupMenu, Menus, cxTextEdit, cxButtonEdit,
  ComCtrls, cxContainer, cxMaskEdit, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator,   dxDateRanges,
  dxBarBuiltInMenu, cxDropDownEdit, BtnEdit, Vcl.ToolWin, math, 
  dxScrollbarAnnotations;

type
  TfrmTradePlanScheduleDetail = class(TForm)
    GroupBox1: TGroupBox;
    CDS_1: TClientDataSet;
    DS_1: TDataSource;
    ADOQueryMain: TADOQuery;
    CDS_2: TClientDataSet;
    DS_2: TDataSource;
    CDS_4: TClientDataSet;
    DS_4: TDataSource;
    GroupBox3: TGroupBox;
    GPM_2: TcxGridPopupMenu;
    GPM_1: TcxGridPopupMenu;
    GPM_4: TcxGridPopupMenu;
    GPM_5: TcxGridPopupMenu;
    CDS_5: TClientDataSet;
    DS_5: TDataSource;
    GPM_6: TcxGridPopupMenu;
    CDS_6: TClientDataSet;
    DS_6: TDataSource;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DS_3: TDataSource;
    CDS_3: TClientDataSet;
    GPM_3: TcxGridPopupMenu;
    GPM_CKKC: TcxGridPopupMenu;
    PM_CKKC: TPopupMenu;
    MenuItem1: TMenuItem;
    MenuItem2: TMenuItem;
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    ToolButton3: TToolButton;
    TBClose: TToolButton;
    GroupBox4: TGroupBox;
    cxGrid3: TcxGrid;
    TV3: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxGrid5: TcxGrid;
    TV5: TcxGridDBTableView;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridDBColumn19: TcxGridDBColumn;
    cxGridDBColumn20: TcxGridDBColumn;
    cxGridDBColumn21: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    cxGrid4: TcxGrid;
    TV4: TcxGridDBTableView;
    cxGridDBColumn28: TcxGridDBColumn;
    cxGridDBColumn29: TcxGridDBColumn;
    cxGridDBColumn30: TcxGridDBColumn;
    cxGridDBColumn31: TcxGridDBColumn;
    cxGridDBColumn32: TcxGridDBColumn;
    cxGridDBColumn33: TcxGridDBColumn;
    cxGridDBColumn34: TcxGridDBColumn;
    cxGridDBColumn35: TcxGridDBColumn;
    cxGridDBColumn48: TcxGridDBColumn;
    cxGridLevel4: TcxGridLevel;
    cxGrid7: TcxGrid;
    TV7: TcxGridDBTableView;
    cxGridDBColumn49: TcxGridDBColumn;
    cxGridDBColumn50: TcxGridDBColumn;
    cxGridDBColumn51: TcxGridDBColumn;
    cxGridDBColumn52: TcxGridDBColumn;
    cxGridDBColumn53: TcxGridDBColumn;
    cxGridDBColumn54: TcxGridDBColumn;
    cxGridDBColumn55: TcxGridDBColumn;
    cxGridDBColumn56: TcxGridDBColumn;
    cxGridDBColumn57: TcxGridDBColumn;
    cxGridLevel6: TcxGridLevel;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    cxGrid8: TcxGrid;
    TV8: TcxGridDBTableView;
    cxGridDBColumn58: TcxGridDBColumn;
    cxGridDBColumn59: TcxGridDBColumn;
    cxGridDBColumn60: TcxGridDBColumn;
    cxGridDBColumn62: TcxGridDBColumn;
    cxGridDBColumn63: TcxGridDBColumn;
    cxGridDBColumn64: TcxGridDBColumn;
    cxGridDBColumn65: TcxGridDBColumn;
    cxGridLevel7: TcxGridLevel;
    GPM_7: TcxGridPopupMenu;
    CDS_7: TClientDataSet;
    DS_7: TDataSource;
    GPM_8: TcxGridPopupMenu;
    CDS_8: TClientDataSet;
    DS_8: TDataSource;
    TV1Column1: TcxGridDBColumn;
    TV1Column2: TcxGridDBColumn;
    TV8Column1: TcxGridDBColumn;
    TV5Column1: TcxGridDBColumn;
    TV4Column1: TcxGridDBColumn;
    TV5Column2: TcxGridDBColumn;
    TV4Column2: TcxGridDBColumn;
    TV4Column3: TcxGridDBColumn;
    pnl1: TPanel;
    GroupBox2: TGroupBox;
    cxGrid6: TcxGrid;
    TV6: TcxGridDBTableView;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn22: TcxGridDBColumn;
    cxGridDBColumn23: TcxGridDBColumn;
    cxGridDBColumn24: TcxGridDBColumn;
    cxGridDBColumn25: TcxGridDBColumn;
    cxGridDBColumn26: TcxGridDBColumn;
    cxGridDBColumn27: TcxGridDBColumn;
    cxGridDBColumn36: TcxGridDBColumn;
    cxGridDBColumn37: TcxGridDBColumn;
    cxGridDBColumn38: TcxGridDBColumn;
    cxGridLevel5: TcxGridLevel;
    cxGrid9: TcxGrid;
    TV9: TcxGridDBTableView;
    cxGridDBColumn39: TcxGridDBColumn;
    cxGridDBColumn40: TcxGridDBColumn;
    cxGridDBColumn41: TcxGridDBColumn;
    cxGridDBColumn42: TcxGridDBColumn;
    cxGridDBColumn43: TcxGridDBColumn;
    cxGridDBColumn44: TcxGridDBColumn;
    cxGridDBColumn45: TcxGridDBColumn;
    cxGridDBColumn46: TcxGridDBColumn;
    cxGridDBColumn47: TcxGridDBColumn;
    cxGridLevel8: TcxGridLevel;
    DS_9: TDataSource;
    CDS_9: TClientDataSet;
    GPM_9: TcxGridPopupMenu;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    v1XHNo: TcxGridDBColumn;
    VC_SCSCode: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    cxGridDBColumn61: TcxGridDBColumn;
    cxGridDBColumn66: TcxGridDBColumn;
    cxGridDBColumn67: TcxGridDBColumn;
    cxGridDBColumn68: TcxGridDBColumn;
    cxGridDBColumn69: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    TV2Column4: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    v1PRTPrice: TcxGridDBColumn;
    cxGridDBColumn70: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    TV2Column1: TcxGridDBColumn;
    TV2Column2: TcxGridDBColumn;
    TV2Column3: TcxGridDBColumn;
    TV2Column5: TcxGridDBColumn;
    TV2Column6: TcxGridDBColumn;
    TV2Column7: TcxGridDBColumn;
    TV2Column8: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormResize(Sender: TObject);
  private
    procedure InitOrder();
    { Private declarations }
  public
    FConNo, FConMainId: string;
    { Public declarations }
  end;

var
  frmTradePlanScheduleDetail: TfrmTradePlanScheduleDetail;

implementation

uses
  U_DataLink, U_RTFun;
{$R *.dfm}

procedure TfrmTradePlanScheduleDetail.InitOrder();
begin

//  with ADOQueryTemp do
//  begin
//    Close;
//    SQL.Clear;
//    sql.Add('exec P_Trade_Plan_ScheduleDetail    ');
//    sql.Add(' @DataFlag=''计划单'' ');
//    sql.Add(',@ConNo= ' + quotedstr(trim(FConNo)));
//    Open;
//  end;
//  SCSHData(ADOQueryTemp, pnl2, 2);

  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('exec P_Trade_Plan_ScheduleDetail    ');
    sql.Add(' @DataFlag=''计划单明细'' ');
    sql.Add(',@ConNo= ' + quotedstr(trim(FConNo)));
    Open;
  end;

  SCreateCDS(ADOQueryTemp, CDS_2);
  SInitCDSData(ADOQueryTemp, CDS_2);

  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('exec P_Trade_Plan_ScheduleDetail    ');
    sql.Add(' @DataFlag=''坯布入库'' ');
    sql.Add(',@ConNo= ' + quotedstr(trim(FConNo)));
    Open;
  end;

  SCreateCDS(ADOQueryTemp, CDS_3);
  SInitCDSData(ADOQueryTemp, CDS_3);

  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('exec P_Trade_Plan_ScheduleDetail    ');
    sql.Add(' @DataFlag=''坯布出库'' ');
    sql.Add(',@ConNo= ' + quotedstr(trim(FConNo)));
    Open;
  end;
  SCreateCDS(ADOQueryTemp, CDS_5);
  SInitCDSData(ADOQueryTemp, CDS_5);

  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('exec P_Trade_Plan_ScheduleDetail    ');
    sql.Add(' @DataFlag=''后加工入库'' ');
    sql.Add(',@ConNo= ' + quotedstr(trim(FConNo)));
    Open;
  end;

  SCreateCDS(ADOQueryTemp, CDS_6);
  SInitCDSData(ADOQueryTemp, CDS_6);

  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('exec P_Trade_Plan_ScheduleDetail    ');
    sql.Add(' @DataFlag=''后加工出库'' ');
    sql.Add(',@ConNo= ' + quotedstr(trim(FConNo)));
    Open;
  end;

  SCreateCDS(ADOQueryTemp, CDS_9);
  SInitCDSData(ADOQueryTemp, CDS_9);

  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('exec P_Trade_Plan_ScheduleDetail    ');
    sql.Add(' @DataFlag=''染厂入库'' ');
    sql.Add(',@ConNo= ' + quotedstr(trim(FConNo)));
    Open;
  end;

  SCreateCDS(ADOQueryTemp, CDS_4);
  SInitCDSData(ADOQueryTemp, CDS_4);

  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('exec P_Trade_Plan_ScheduleDetail    ');
    sql.Add(' @DataFlag=''染厂出库'' ');
    sql.Add(',@ConNo= ' + quotedstr(trim(FConNo)));
    Open;
  end;

  SCreateCDS(ADOQueryTemp, CDS_7);
  SInitCDSData(ADOQueryTemp, CDS_7);

  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('exec P_Trade_Plan_ScheduleDetail    ');
    sql.Add(' @DataFlag=''成品检验'' ');
    sql.Add(',@ConNo= ' + quotedstr(trim(FConNo)));
    Open;
  end;
  SCreateCDS(ADOQueryTemp, CDS_1);
  SInitCDSData(ADOQueryTemp, CDS_1);

  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('exec P_Trade_Plan_ScheduleDetail    ');
    sql.Add(' @DataFlag=''成品出库'' ');
    sql.Add(',@ConNo= ' + quotedstr(trim(FConNo)));
    Open;
  end;
  SCreateCDS(ADOQueryTemp, CDS_8);
  SInitCDSData(ADOQueryTemp, CDS_8);
end;

procedure TfrmTradePlanScheduleDetail.FormDestroy(Sender: TObject);
begin
  frmTradePlanScheduleDetail := nil;
end;

procedure TfrmTradePlanScheduleDetail.FormResize(Sender: TObject);
begin
  cxGrid3.Width := ceil(Self.Width / 2);
  cxGrid4.Width := ceil(Self.Width / 2);
  cxGrid1.Width := ceil(Self.Width / 2);
  cxGrid6.Width := ceil(Self.Width / 2);
  GroupBox2.Height := ceil((Self.Height - ToolBar1.Height - pnl1.Height) / 4);
  GroupBox3.Height := ceil((Self.Height - ToolBar1.Height - pnl1.Height) / 4);
  GroupBox4.Height := ceil((Self.Height - ToolBar1.Height - pnl1.Height) / 4);
end;

procedure TfrmTradePlanScheduleDetail.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := cafree;
end;

procedure TfrmTradePlanScheduleDetail.TBCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmTradePlanScheduleDetail.TBRafreshClick(Sender: TObject);
begin
  InitOrder();
end;

procedure TfrmTradePlanScheduleDetail.ToolButton3Click(Sender: TObject);
begin
  WriteCxGrid('订单明细进度Tv1', Tv1, '订单明细进度管理');
  WriteCxGrid('订单明细进度Tv3', Tv3, '订单明细进度管理');
  WriteCxGrid('订单明细进度Tv4', Tv4, '订单明细进度管理');
  WriteCxGrid('订单明细进度Tv5', Tv5, '订单明细进度管理');
  WriteCxGrid('订单明细进度Tv6', Tv5, '订单明细进度管理');
  WriteCxGrid('订单明细进度Tv7', Tv7, '订单明细进度管理');
  WriteCxGrid('订单明细进度Tv8', Tv8, '订单明细进度管理');
  WriteCxGrid('订单明细进度Tv9', Tv9, '订单明细进度管理');
end;

procedure TfrmTradePlanScheduleDetail.FormShow(Sender: TObject);
begin
  ReadCxGrid('订单明细进度Tv1', Tv1, '订单明细进度管理');
  ReadCxGrid('订单明细进度Tv3', Tv3, '订单明细进度管理');
  ReadCxGrid('订单明细进度Tv4', Tv4, '订单明细进度管理');
  ReadCxGrid('订单明细进度Tv5', Tv5, '订单明细进度管理');
  ReadCxGrid('订单明细进度Tv6', Tv6, '订单明细进度管理');
  ReadCxGrid('订单明细进度Tv7', Tv7, '订单明细进度管理');
  ReadCxGrid('订单明细进度Tv8', Tv8, '订单明细进度管理');
  ReadCxGrid('订单明细进度Tv9', Tv9, '订单明细进度管理');
  InitOrder();
end;

end.

