unit U_ProductOrderJdList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls,
  cxGridCustomView, cxGrid, cxMemo, cxRichEdit, ComCtrls, cxContainer,
  cxTextEdit, cxMaskEdit, cxButtonEdit, StdCtrls, ToolWin, DBClient, ADODB,
  ExtCtrls, BtnEdit, cxCalendar,StrUtils, cxCurrencyEdit, cxImage,
  cxDBEdit, Menus, RM_Common, RM_Class, RM_e_Xls, RM_Dataset, RM_System,
  RM_GridReport, cxGridCustomPopupMenu, cxGridPopupMenu, cxPC, cxSplitter,
  IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdFTP,ShellAPI,
  cxCheckBox, cxLookAndFeelPainters, cxButtons, cxGridBandedTableView,
  cxGridDBBandedTableView,Math;

type
  TfrmProductOrderJdList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label1: TLabel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    OrderNo: TEdit;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    Label4: TLabel;
    CustomerNoName: TEdit;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    Label8: TLabel;
    MPRTCodeName: TEdit;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    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;
    cxStyle_fontclOlive: TcxStyle;
    ADOQuerySub: TADOQuery;
    DataSource2: TDataSource;
    ADOQueryImage: TADOQuery;
    DSImage: TDataSource;
    IdFTP1: TIdFTP;
    MPRTCode: TEdit;
    Label17: TLabel;
    CDS_Sub: TClientDataSet;
    cxTabControl1: TcxTabControl;
    Label5: TLabel;
    Label7: TLabel;
    ToolButton1: TToolButton;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBBandedTableView;
    cxGridDBBandedColumn1: TcxGridDBBandedColumn;
    cxGridDBBandedColumn2: TcxGridDBBandedColumn;
    cxGridDBBandedColumn7: TcxGridDBBandedColumn;
    cxGridDBBandedColumn8: TcxGridDBBandedColumn;
    cxGridDBBandedColumn9: TcxGridDBBandedColumn;
    cxGridDBBandedColumn10: TcxGridDBBandedColumn;
    cxGridDBBandedColumn11: TcxGridDBBandedColumn;
    cxGridDBBandedColumn12: TcxGridDBBandedColumn;
    cxGridDBBandedColumn13: TcxGridDBBandedColumn;
    cxGridDBBandedColumn14: TcxGridDBBandedColumn;
    cxGridDBBandedColumn15: TcxGridDBBandedColumn;
    cxGridDBBandedColumn16: TcxGridDBBandedColumn;
    cxGridDBBandedColumn17: TcxGridDBBandedColumn;
    cxGridDBBandedColumn18: TcxGridDBBandedColumn;
    cxGridDBBandedColumn19: TcxGridDBBandedColumn;
    cxGridDBBandedColumn20: TcxGridDBBandedColumn;
    cxGridDBBandedColumn21: TcxGridDBBandedColumn;
    cxGridDBBandedColumn23: TcxGridDBBandedColumn;
    cxGridDBBandedColumn25: TcxGridDBBandedColumn;
    cxGridDBBandedColumn31: TcxGridDBBandedColumn;
    cxGridDBBandedColumn32: TcxGridDBBandedColumn;
    cxGridDBBandedColumn33: TcxGridDBBandedColumn;
    cxGridDBBandedColumn34: TcxGridDBBandedColumn;
    cxGridDBBandedColumn36: TcxGridDBBandedColumn;
    cxGridDBBandedColumn37: TcxGridDBBandedColumn;
    cxGridDBBandedColumn39: TcxGridDBBandedColumn;
    cxGridDBBandedColumn40: TcxGridDBBandedColumn;
    cxGridDBBandedColumn41: TcxGridDBBandedColumn;
    cxGridLevel1: TcxGridLevel;
    V2Column1: TcxGridDBBandedColumn;
    V2Column2: TcxGridDBBandedColumn;
    V2Column3: TcxGridDBBandedColumn;
    V2Column4: TcxGridDBBandedColumn;
    V2Column5: TcxGridDBBandedColumn;
    V2Column6: TcxGridDBBandedColumn;
    V2Column7: TcxGridDBBandedColumn;
    V2Column8: TcxGridDBBandedColumn;
    V2Column9: TcxGridDBBandedColumn;
    V2Column12: TcxGridDBBandedColumn;
    V2Column14: TcxGridDBBandedColumn;
    V2Column15: TcxGridDBBandedColumn;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBBandedTableView;
    cxGridDBBandedColumn26: TcxGridDBBandedColumn;
    cxGridDBBandedColumn27: TcxGridDBBandedColumn;
    cxGridDBBandedColumn35: TcxGridDBBandedColumn;
    cxGridDBBandedColumn42: TcxGridDBBandedColumn;
    cxGridDBBandedColumn43: TcxGridDBBandedColumn;
    cxGridDBBandedColumn44: TcxGridDBBandedColumn;
    cxGridDBBandedColumn45: TcxGridDBBandedColumn;
    cxGridDBBandedColumn46: TcxGridDBBandedColumn;
    cxGridDBBandedColumn47: TcxGridDBBandedColumn;
    cxGridDBBandedColumn48: TcxGridDBBandedColumn;
    cxGridDBBandedColumn49: TcxGridDBBandedColumn;
    cxGridDBBandedColumn50: TcxGridDBBandedColumn;
    cxGridDBBandedColumn51: TcxGridDBBandedColumn;
    cxGridDBBandedColumn52: TcxGridDBBandedColumn;
    cxGridDBBandedColumn53: TcxGridDBBandedColumn;
    cxGridDBBandedColumn54: TcxGridDBBandedColumn;
    cxGridDBBandedColumn55: TcxGridDBBandedColumn;
    cxGridDBBandedColumn56: TcxGridDBBandedColumn;
    cxGridDBBandedColumn57: TcxGridDBBandedColumn;
    cxGridDBBandedColumn58: TcxGridDBBandedColumn;
    cxGridDBBandedColumn59: TcxGridDBBandedColumn;
    cxGridDBBandedColumn60: TcxGridDBBandedColumn;
    cxGridDBBandedColumn61: TcxGridDBBandedColumn;
    cxGridDBBandedColumn62: TcxGridDBBandedColumn;
    cxGridDBBandedColumn63: TcxGridDBBandedColumn;
    cxGridDBBandedColumn64: TcxGridDBBandedColumn;
    cxGridDBBandedColumn65: TcxGridDBBandedColumn;
    cxGridDBBandedColumn66: TcxGridDBBandedColumn;
    cxGridDBBandedColumn67: TcxGridDBBandedColumn;
    cxGridDBBandedColumn68: TcxGridDBBandedColumn;
    cxGridDBBandedColumn69: TcxGridDBBandedColumn;
    cxGridDBBandedColumn70: TcxGridDBBandedColumn;
    cxGridDBBandedColumn71: TcxGridDBBandedColumn;
    cxGridDBBandedColumn72: TcxGridDBBandedColumn;
    cxGridDBBandedColumn73: TcxGridDBBandedColumn;
    cxGridDBBandedColumn74: TcxGridDBBandedColumn;
    cxGridDBBandedColumn75: TcxGridDBBandedColumn;
    cxGridDBBandedColumn76: TcxGridDBBandedColumn;
    cxGridDBBandedColumn77: TcxGridDBBandedColumn;
    cxGridDBBandedColumn78: TcxGridDBBandedColumn;
    cxGridDBBandedColumn79: TcxGridDBBandedColumn;
    cxGridDBBandedColumn80: TcxGridDBBandedColumn;
    cxGridDBBandedColumn81: TcxGridDBBandedColumn;
    cxGridDBBandedColumn82: TcxGridDBBandedColumn;
    cxGridDBBandedColumn83: TcxGridDBBandedColumn;
    cxGridDBBandedColumn84: TcxGridDBBandedColumn;
    cxGridDBBandedColumn85: TcxGridDBBandedColumn;
    cxGridDBBandedColumn86: TcxGridDBBandedColumn;
    cxGridDBBandedColumn87: TcxGridDBBandedColumn;
    cxGridDBBandedColumn88: TcxGridDBBandedColumn;
    cxGridDBBandedColumn89: TcxGridDBBandedColumn;
    cxGridDBBandedColumn90: TcxGridDBBandedColumn;
    cxGridDBBandedColumn91: TcxGridDBBandedColumn;
    cxGridLevel2: TcxGridLevel;
    V1Column1: TcxGridDBBandedColumn;
    Label2: TLabel;
    conno: TEdit;
    cxGridPopupMenu2: TcxGridPopupMenu;
    V2Column10: TcxGridDBBandedColumn;
    V2Column11: TcxGridDBBandedColumn;
    V2Column13: TcxGridDBBandedColumn;
    V1Column2: TcxGridDBBandedColumn;
    V1Column3: TcxGridDBBandedColumn;
    V1Column4: TcxGridDBBandedColumn;
    V1Column5: TcxGridDBBandedColumn;
    V1Column6: TcxGridDBBandedColumn;
    V1Column7: TcxGridDBBandedColumn;
    V1Column8: TcxGridDBBandedColumn;
    V2Column16: TcxGridDBBandedColumn;
    V2Column17: TcxGridDBBandedColumn;
    V2Column18: TcxGridDBBandedColumn;
    V2Column19: TcxGridDBBandedColumn;
    V1Column9: TcxGridDBBandedColumn;
    V1Column10: TcxGridDBBandedColumn;
    V1Column11: TcxGridDBBandedColumn;
    V1Column12: TcxGridDBBandedColumn;
    V1Column13: TcxGridDBBandedColumn;
    V1Column14: TcxGridDBBandedColumn;
    V1Column15: TcxGridDBBandedColumn;
    V1Column16: TcxGridDBBandedColumn;
    V1Column17: TcxGridDBBandedColumn;
    V1Column18: TcxGridDBBandedColumn;
    V1Column19: TcxGridDBBandedColumn;
    V1Column20: TcxGridDBBandedColumn;
    V1Column21: TcxGridDBBandedColumn;
    V1Column22: TcxGridDBBandedColumn;
    V1Column23: TcxGridDBBandedColumn;
    V1Column24: TcxGridDBBandedColumn;
    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 cxTabControl1Change(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure TV1FocusedRecordChanged(Sender: TcxCustomGridTableView;
      APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
    procedure TV1DblClick(Sender: TObject);
  private
    DQdate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    procedure InitSub();
    procedure SetStatus();
        { Private declarations }
  public
    FFInt,FCloth:Integer;
    canshu1:string;
    canshu2:string;
    { Public declarations }
  end;

var
  frmProductOrderJdList: TfrmProductOrderJdList;

implementation
uses
  U_DataLink,U_OrderInPut,U_Fun, U_OrderJD,U_CkCrMxList;

{$R *.dfm}
 procedure TfrmProductOrderJdList.SetStatus();
begin
//  ToolButton1.Visible:=false;
//  ToolButton2.Visible:=false;
//  ToolButton3.Visible:=false;
//  ToolButton4.Visible:=false;
//  IF trim(canshu1)='高权限' then
//  begin
//   case cxTabControl1.TabIndex of
//   0:begin
//       ToolButton2.Visible:=true;
//       ToolButton4.Visible:=true;
//     end;
//   1:begin
//       ToolButton1.Visible:=true;
//     end;
//   end;
//  end;
end;

procedure TfrmProductOrderJdList.InitSub();
begin
  try
    ADOQuerySub.DisableControls;
    with ADOQuerySub do
    begin
      Close;
      sql.Clear;
      SQL.Add('select A.*');
       sql.add(' ,DK_PS=A.DR_PS-A.DC_PS ') ;
      sql.add(' ,DK_Qty= A.DR_Qty-A.DC_Qty ') ;
      sql.add(' ,DK_Len= A.DR_Len-A.DC_Len ') ;
      sql.add(' ,DK_Wt= A.DR_Wt-A.DC_Wt ') ;
      sql.add('  from jyorder_sub A') ;
      sql.add(' where MainId='+quotedstr(Trim(Order_Main.fieldbyname('mainid').AsString)));
      Open;
    end;
    SCreateCDS20(ADOQuerySub,CDS_Sub);
    SInitCDSData20(ADOQuerySub,CDS_Sub);
  finally
    ADOQuerySub.EnableControls;
  end;

end;


procedure TfrmProductOrderJdList.FormDestroy(Sender: TObject);
begin
  frmProductOrderJdList:=nil;
end;

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

procedure TfrmProductOrderJdList.FormCreate(Sender: TObject);
begin
  cxgrid1.Align:=alClient;
  DQdate:=SGetServerDate(ADOQueryTemp);
end;

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

procedure TfrmProductOrderJdList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.add(' select A.* ') ;
      sql.add(' ,HZDK_PS=A.HZDR_PS-A.HZDC_PS ') ;
      sql.add(' ,HZDK_Qty= A.HZDR_Qty-A.HZDC_Qty ') ;
      sql.add(' ,HZDK_Len= A.HZDR_Len-A.HZDC_Len ') ;
      sql.add(' ,HZDK_Wt= A.HZDR_Wt-A.HZDC_Wt ') ;
       sql.add(' ,HZWK_PS=A.HZWR_PS-A.HZWC_PS ') ;
      sql.add(' ,HZWK_Qty= A.HZWR_Qty-A.HZWC_Qty ') ;
      sql.add(' ,HZWK_Len= A.HZWR_Len-A.HZWC_Len ') ;
      sql.add(' ,HZWK_Wt= A.HZWR_Wt-A.HZWC_Wt ') ;
      sql.add(' from jyorder_main A') ;
      sql.add(' where OrdDate>'''+FormatDateTime('yyyy-MM-dd',BegDate.DateTime)+''' ');
      sql.add(' and OrdDate<='''+FormatDateTime('yyyy-MM-dd',enddate.DateTime+1)+''' ');
      case cxTabControl1.TabIndex  of
      0:begin
          sql.add('and status=''1'' ');
        end;
      1:begin
          sql.add('and status=''2'' ');
        end;
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;



procedure TfrmProductOrderJdList.InitForm();
begin
  ReadCxBandedGrid(self.Caption+tv1.Name,Tv1,'生产指示单管理');
  ReadCxBandedGrid(self.Caption+tv2.Name,Tv2,'生产指示单管理');
  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime:=EndDate.DateTime-15;
end;

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



procedure TfrmProductOrderJdList.TBExportClick(Sender: TObject);
begin
   TcxGridToExcel(Self.Caption,cxGrid1);
end;

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

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

procedure TfrmProductOrderJdList.FormShow(Sender: TObject);
begin
  canshu1:=trim(DParameters1);
  canshu2:=trim(DParameters2);
  InitForm();
  SetStatus();
end;

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

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

procedure TfrmProductOrderJdList.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();
  InitGrid();
end;

procedure TfrmProductOrderJdList.ToolButton1Click(Sender: TObject);
var
  Lctmainid:string;
begin
  Lctmainid:=   Trim(Order_Main.fieldbyname('mainid').AsString);
  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    SQL.Add('exec P_Update_Order_JD '+quotedstr(Lctmainid));
    ExecSQL;
  end;
  InitGrid();
  Order_Main.Locate('mainid',Lctmainid,[]);
end;

procedure TfrmProductOrderJdList.TV1FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
begin
InitSub();
end;

procedure TfrmProductOrderJdList.TV1DblClick(Sender: TObject);
begin
  try
    frmCkCrMxList:=TfrmCkCrMxList.Create(Application);
    with frmCkCrMxList do
    begin
      FMainId:=Order_Main.Fieldbyname('MainId').asstring;
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmCkCrMxList.Free;
  end;
end;

end.
