unit U_ProductOrderNewList_HTJD;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxGrid, DBClient, cxCheckBox, cxCalendar, cxSplitter,
  RM_Dataset, RM_System, RM_Common, RM_Class, RM_GridReport, RM_e_Xls,
  Menus, cxPC, cxCurrencyEdit, Mask, DBCtrls, cxContainer, cxTextEdit,
  cxDBEdit, cxButtonEdit;

type
  TfrmProductOrderNewList_HTJD = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    cxGridPopupMenu1: TcxGridPopupMenu;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    Label2: TLabel;
    Label11: TLabel;
    OrdDefStr1: TEdit;
    Label6: TLabel;
    ISPH: TComboBox;
    PrtColor: TEdit;
    Label7: TLabel;
    orderType: TComboBox;
    Label24: TLabel;
    khConNo: TEdit;
    Label10: TLabel;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Order_Sub: TClientDataSet;
    DataSource2: TDataSource;
    ADOQuery1: TADOQuery;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxStyle_gridRow: TcxStyle;
    cxStyle_gridFoot: TcxStyle;
    cxStyle_gridHead: TcxStyle;
    cxStyle_gridGroupBox: TcxStyle;
    cxStyle_yellow: TcxStyle;
    cxStyle_Red: TcxStyle;
    cxStyle_fontBlack: TcxStyle;
    cxStyle_fontclFuchsia: TcxStyle;
    cxStyle_fontclPurple: TcxStyle;
    cxStyle_fontclGreen: TcxStyle;
    cxStyle_fontclBlue: TcxStyle;
    cxStyle_fontclTeal: TcxStyle;
    ADOQueryMain: TADOQuery;
    DataSource3: TDataSource;
    Order_WJG: TClientDataSet;
    ADOQuery2: TADOQuery;
    cxGridPopupMenu3: TcxGridPopupMenu;
    Label14: TLabel;
    cxGrid3: TcxGrid;
    TV1: TcxGridDBTableView;
    cxGridLevel2: TcxGridLevel;
    Panel2: TPanel;
    V3ConNo: TcxGridDBColumn;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    Order_Print: TClientDataSet;
    V1OrderGS: TcxGridDBColumn;
    V1GX: TcxGridDBColumn;
    V1MD: TcxGridDBColumn;
    V1CPRK: TcxGridDBColumn;
    V1CPCK: TcxGridDBColumn;
    V1OrdDate: TcxGridDBColumn;
    V1ConNoGS: TcxGridDBColumn;
    cxStyle3: TcxStyle;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    ToolButton7: TToolButton;
    Label9: TLabel;
    ConNo: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure ComboBox2Change(Sender: TObject);
    procedure ThanChange(Sender: TObject);
    procedure V1OrderGSCustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure V1MDCustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure V1CPRKCustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure V1CPCKCustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ConNoChange(Sender: TObject);
    procedure TV1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
  private
    DQdate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
        { Private declarations }
  public

    canshu1:string;
    { Public declarations }
  end;

var
  frmProductOrderNewList_HTJD: TfrmProductOrderNewList_HTJD;

implementation
uses
  U_DataLink,U_Fun,U_ConInPutXF,U_ProductOrderMoneyList_CX,U_ProductOrderMoneyList_GXCX,U_ContractCGJGViewList_CX
  ,U_WJGMDList_CX,U_CPRKList_CX,U_CPCKOutList_CX;

{$R *.dfm}
procedure TfrmProductOrderNewList_HTJD.FormDestroy(Sender: TObject);
begin
  frmProductOrderNewList_HTJD:=nil;
end;

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

procedure TfrmProductOrderNewList_HTJD.FormCreate(Sender: TObject);
begin
  canshu1:=trim(DParameters1);
  DQdate:=SGetServerDate(ADOQuery1);
end;

procedure TfrmProductOrderNewList_HTJD.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid(self.Caption+tv1.Name+'1',Tv1,'生产指示单管理');
end;

procedure TfrmProductOrderNewList_HTJD.InitGrid();
var
  strwhere,Tthan:string;
begin
  Panel2.Visible:=true;
  Panel2.Refresh;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('exec P_ConJDCX :Begdate,:endDate ');
      Parameters.ParamByName('Begdate').Value:=Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date));
      Parameters.ParamByName('endDate').Value:=Trim(FormatDateTime('yyyy-MM-dd',endDate.Date+1));
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
    //TBFind.Click;
  end;
  Panel2.Visible:=false;
end;


procedure TfrmProductOrderNewList_HTJD.InitForm();
begin
  readCxGrid(self.Caption+tv1.Name+'1',Tv1,'生产指示单管理');
  BegDate.DateTime:=SGetServerDate10(ADOQuery1)-15;
  EndDate.DateTime:=SGetServerDate10(ADOQuery1);
 // InitGrid();
end;

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

procedure TfrmProductOrderNewList_HTJD.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  SelExportData(Tv1,ADOQueryMain,'生产指示单列表');
end;

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

procedure TfrmProductOrderNewList_HTJD.OrderNoChange(Sender: TObject);
begin
 TBFind.Click;
end;

procedure TfrmProductOrderNewList_HTJD.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmProductOrderNewList_HTJD.CheckBox1Click(Sender: TObject);
begin
   TBFind.Click;
end;

procedure TfrmProductOrderNewList_HTJD.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmProductOrderNewList_HTJD.ComboBox2Change(Sender: TObject);
begin
  initGrid();
end;

procedure TfrmProductOrderNewList_HTJD.ThanChange(Sender: TObject);
begin
  initgrid();
end;

procedure TfrmProductOrderNewList_HTJD.V1OrderGSCustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var Id,Id10:integer;
begin
  Id:=TV1.GetColumnByFieldName('ConNoGS').Index;
  Id10:=TV1.GetColumnByFieldName('OrderGS').Index;
  if Id<0 then Exit;
  if AViewInfo.GridRecord.Values[id]>AViewInfo.GridRecord.Values[id10] then
  begin
    if AViewInfo.GridRecord.Values[id10]<>0 then
    ACanvas.Brush.Color:=clYellow
    else
    ACanvas.Brush.Color:=clRed;
  end
  else
  begin
    ACanvas.Brush.Color:=clGreen;
  end;
end;

procedure TfrmProductOrderNewList_HTJD.V1MDCustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var ID,Id10,Id20,Id30,Id40: integer;
begin
  Id:=TV1.GetColumnByFieldName('GX').Index;
  Id20:=TV1.GetColumnByFieldName('ConNoGS').Index;
  Id30:=TV1.GetColumnByFieldName('OrderGS').Index;
  Id40:=TV1.GetColumnByFieldName('MD').Index;
  if Id<0 then Exit;
  if AViewInfo.GridRecord.Values[id20]=AViewInfo.GridRecord.Values[id30] then
  begin
    if AViewInfo.GridRecord.Values[id]=AViewInfo.GridRecord.Values[id40] then
    begin
      if AViewInfo.GridRecord.Values[Id40]<>0 then
      ACanvas.Brush.Color:=ClYellow
      else
      ACanvas.Brush.Color:=clRed;

    end;
  end;
end;

procedure TfrmProductOrderNewList_HTJD.V1CPRKCustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var ID,Id10,Id20,Id30,Id40,Id50: integer;
begin
  Id:=TV1.GetColumnByFieldName('GX').Index;
  Id20:=TV1.GetColumnByFieldName('ConNoGS').Index;
  Id30:=TV1.GetColumnByFieldName('OrderGS').Index;
  Id40:=TV1.GetColumnByFieldName('MD').Index;
  Id50:=TV1.GetColumnByFieldName('CPRK').Index;
  if Id<0 then Exit;
  if AViewInfo.GridRecord.Values[id20]=AViewInfo.GridRecord.Values[id30] then
  begin
    if AViewInfo.GridRecord.Values[id]=AViewInfo.GridRecord.Values[id20] then
    begin

        if AViewInfo.GridRecord.Values[Id20]>AViewInfo.GridRecord.Values[Id50] then
        begin
          if AViewInfo.GridRecord.Values[Id50]<>0 then
          ACanvas.Brush.Color:=ClYellow
          else
          ACanvas.Brush.Color:=clRed;
        end
        else
        begin
          ACanvas.Brush.Color:=clGreen;
        end;
    end;
  end;
end;

procedure TfrmProductOrderNewList_HTJD.V1CPCKCustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var ID,Id10,Id20,Id30,Id40,Id50,ID60: integer;
begin
  Id:=TV1.GetColumnByFieldName('GX').Index;
  Id20:=TV1.GetColumnByFieldName('ConNoGS').Index;
  Id30:=TV1.GetColumnByFieldName('OrderGS').Index;
  Id40:=TV1.GetColumnByFieldName('MD').Index;
  Id50:=TV1.GetColumnByFieldName('CPRK').Index;
  ID60:=TV1.GetColumnByFieldName('CPCK').Index;
  if Id<0 then Exit;
  if AViewInfo.GridRecord.Values[id20]=AViewInfo.GridRecord.Values[id30] then
  begin

      if AViewInfo.GridRecord.Values[Id30]=AViewInfo.GridRecord.Values[Id40] then
      begin
        if AViewInfo.GridRecord.Values[Id20]=AViewInfo.GridRecord.Values[Id50] then
        begin
          if AViewInfo.GridRecord.Values[Id20]>AViewInfo.GridRecord.Values[Id60] then
          begin
            if AViewInfo.GridRecord.Values[Id60]<>0 then
            ACanvas.Brush.Color:=ClYellow
            else
            ACanvas.Brush.Color:=clRed;
          end
          else
          begin
            ACanvas.Brush.Color:=clGreen;
          end;
        end;
      end;
  end;
end;

procedure TfrmProductOrderNewList_HTJD.ToolButton1Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  try
    frmConInPutXF:=TfrmConInPutXF.Create(Application);
    with frmConInPutXF do
    begin
      PState:=1;
      FMainId:=Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      ToolBar2.Visible:=False;
      TBSave.Visible:=False;
      ScrollBox1.Enabled:=False;
      Tv1.OptionsSelection.CellSelect:=False;
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmConInPutXF.Free;
  end;
end;

procedure TfrmProductOrderNewList_HTJD.ToolButton2Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  frmProductOrderMoneyList_CX:=TfrmProductOrderMoneyList_CX.create(self);
  with frmProductOrderMoneyList_CX do
  begin
    FConNO:=trim(self.Order_Main.fieldbyname('ConnO').AsString);
    if ShowModal=1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmProductOrderNewList_HTJD.ToolButton3Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  frmProductOrderMoneyList_GXCX:=TfrmProductOrderMoneyList_GXCX.create(self);
  with frmProductOrderMoneyList_GXCX do
  begin
    FConNO:=trim(self.Order_Main.fieldbyname('ConnO').AsString);
    if ShowModal=1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmProductOrderNewList_HTJD.ConNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmProductOrderNewList_HTJD.TV1CellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var Fieldname:string;
begin
  Fieldname:=Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  if Fieldname='ConNoGS' then
  begin
    ToolButton1.Click;
  end;
  if Fieldname='OrderGS' then
  begin
    ToolButton2.Click;
  end;
  if Fieldname='GX' then
  begin
    ToolButton3.Click;
  end;
  
  if Fieldname='MD' then
  begin
    ToolButton5.Click;
  end;
  if Fieldname='CPRK' then
  begin
    ToolButton6.Click;
  end;
  if Fieldname='CPCK' then
  begin
    ToolButton7.Click;
  end;
end;

procedure TfrmProductOrderNewList_HTJD.ToolButton5Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  frmWJGMDList:=TfrmWJGMDList.create(self);
  with frmWJGMDList do
  begin
    FConNO:=Trim(self.Order_Main.fieldbyname('ConNO').AsString);
    if showmodal=1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmProductOrderNewList_HTJD.ToolButton6Click(Sender: TObject);
begin
  if Order_Main.isempty then Exit;
  frmCPRKList_CX:=TfrmCPRKList_CX.Create(self);
  with frmCPRKList_CX do
  begin
    FConNO:=Trim(self.Order_Main.fieldbyname('ConNO').AsString);
    if ShowModal=1 then
    begin
    
    end;
    free;
  end;
end;

procedure TfrmProductOrderNewList_HTJD.ToolButton7Click(Sender: TObject);
begin
  if Order_Main.isempty then Exit;
  frmCPCKOutList_CX:=TfrmCPCKOutList_CX.Create(self);
  with frmCPCKOutList_CX do
  begin
    FConNO:=Trim(self.Order_Main.fieldbyname('ConNO').AsString);
    if ShowModal=1 then
    begin
    
    end;
    free;
  end;
end;

end.
