unit U_ProductOrderRGBCX;

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, cxButtonEdit, cxDropDownEdit, cxTextEdit, RM_e_Graphic, RM_e_Jpeg,
  BtnEdit;

type
  TfrmProductOrderRGBCX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBDataSet1: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    ToolButton1: TToolButton;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    PopupMenu2: TPopupMenu;
    N11: TMenuItem;
    N21: TMenuItem;
    N31: TMenuItem;
    Panel1: TPanel;
    Label1: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Chk: TClientDataSet;
    DS_Chk: TDataSource;
    cxGridPopupMenu2: TcxGridPopupMenu;
    cxGridPopupMenu3: TcxGridPopupMenu;
    CDS_Sub: TClientDataSet;
    DS_Sub: TDataSource;
    CDS_Chker: TClientDataSet;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    CustomerNoName: TEdit;
    MPRTCodeName: TEdit;
    MPRTSpec: TEdit;
    ConNo: TEdit;
    MPRTKZ: TEdit;
    Label8: TLabel;
    Panel4: TPanel;
    Label3: TLabel;
    Label7: TLabel;
    Panel5: TPanel;
    Image1: TImage;
    RadioGroup2: TRadioGroup;
    TSure: TButton;
    TaiTou: TBtnEditA;
    ETaiTou: TEdit;
    IFYJ: TCheckBox;
    IFAdd: TCheckBox;
    IFGZ: TCheckBox;
    ADOQuery2: TADOQuery;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn26: TcxGridDBColumn;
    cxGridDBColumn28: TcxGridDBColumn;
    cxGridDBColumn30: TcxGridDBColumn;
    v5Column7: TcxGridDBColumn;
    v5Column8: TcxGridDBColumn;
    cxGridDBColumn31: TcxGridDBColumn;
    cxGridDBColumn68: TcxGridDBColumn;
    cxGridDBColumn69: TcxGridDBColumn;
    cxGridDBColumn70: TcxGridDBColumn;
    cxGridDBColumn71: TcxGridDBColumn;
    cxGridDBColumn72: TcxGridDBColumn;
    cxGridDBColumn73: TcxGridDBColumn;
    cxGridDBColumn74: TcxGridDBColumn;
    cxGridDBColumn75: TcxGridDBColumn;
    cxGridDBColumn76: TcxGridDBColumn;
    cxGridDBColumn77: TcxGridDBColumn;
    cxGridDBColumn78: TcxGridDBColumn;
    cxGridDBColumn79: TcxGridDBColumn;
    cxGridDBColumn80: TcxGridDBColumn;
    cxGridDBColumn81: TcxGridDBColumn;
    cxGridDBColumn82: TcxGridDBColumn;
    cxGridDBColumn83: TcxGridDBColumn;
    cxGridDBColumn84: TcxGridDBColumn;
    cxGridDBColumn85: TcxGridDBColumn;
    cxGridDBColumn86: TcxGridDBColumn;
    cxGridDBColumn87: TcxGridDBColumn;
    cxGridDBColumn88: TcxGridDBColumn;
    cxGridDBColumn89: TcxGridDBColumn;
    v5SJJQDate: TcxGridDBColumn;
    v5Column1: TcxGridDBColumn;
    v5Column2: TcxGridDBColumn;
    v5Column5: TcxGridDBColumn;
    v5Column6: TcxGridDBColumn;
    cxGridDBColumn90: TcxGridDBColumn;
    cxGridDBColumn91: TcxGridDBColumn;
    cxGridDBColumn92: TcxGridDBColumn;
    cxGridDBColumn93: TcxGridDBColumn;
    cxGridDBColumn94: TcxGridDBColumn;
    v5Column3: TcxGridDBColumn;
    cxGridDBColumn95: TcxGridDBColumn;
    cxGridDBColumn96: TcxGridDBColumn;
    v5Column4: TcxGridDBColumn;
    cxGridDBColumn97: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    MPRTMF: TEdit;
    N1: TMenuItem;
    TSsel: TToolButton;
    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 FormShow(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure TSselClick(Sender: TObject);
  private
    canshu1,canshu3:String;
    DQdate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    procedure InitGridFH();
    { Private declarations }
  public
    FFInt,FCloth:Integer;
    Ftype,canshu2:string;
    { Public declarations }
  end;

var
  frmProductOrderRGBCX: TfrmProductOrderRGBCX;

implementation
uses
  U_DataLink,U_ConInPut,U_Fun,U_ZDYHelp, U_ConInPutNew,U_ZDYHelpSel;

{$R *.dfm}

procedure TfrmProductOrderRGBCX.FormDestroy(Sender: TObject);
begin
  frmContractList_SHTGCX:=nil;
end;

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

procedure TfrmProductOrderRGBCX.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
  cxgrid1.Align:=alClient;
  DQdate:=SGetServerDate(ADOQueryTemp);
end;

procedure TfrmProductOrderRGBCX.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('入柜表查询',Tv1,'正排表管理');
end;

procedure TfrmProductOrderRGBCX.InitGrid();
var
  fsj:string;
begin
  fsj:='select distinct(PinZhiNote) Name,Cast(Null as varchar(20)) Code from JYOrderCon_Sub where isnull(PinZhiNote,'''')<>'''' ';
  SInitCxGridComboBoxBySql(ADOQueryTemp,cxGridDBColumn133,fsj,0,False,'');
  fsj:='select distinct(GenDanPerson) Name,Cast(Null as varchar(20)) Code from JYOrderCon_Sub where isnull(GenDanPerson,'''')<>'''' ';
  SInitCxGridComboBoxBySql(ADOQueryTemp,cxGridDBColumn139,fsj,0,False,'');
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.add(' select CustomerNoName=C.CustomerNo,MPRTCodeName=B.PRTCodeName,MPRTSpec=B.PRTSpec,MPRTMF=B.PRTMF,MPRTKZ=B.PRTKZ,C.DlyDate ') ;
      sql.Add(' ,OrdPerson2=C.YWY,OrdPerson3=C.YWYZhuLi,C.ConNo,C.OrdDate,C.ChkTime,B.SubId SubIdHT');
      sql.Add(',DBFlag=(select top 1 Cast(1 as bit) from JYOrderCon_TT TT ');
      sql.Add('         where TT.TTType=''DB'' and TT.ChkStatus=''审核通过'' and TT.ConNo=C.ConNo)');
      sql.Add(',LCDate=(select top 1 SKDate from JYOrderCon_TT TT ');
      sql.Add('         where TT.TTType=''LC'' and TT.ChkStatus=''审核通过'' and TT.ConNo=C.ConNo)');
      sql.Add(',DJDate=(select top 1 SKDate from JYOrderCon_TT TT ');
      sql.Add('         where TT.TTType=''TT'' and TT.ChkStatus=''审核通过'' and TT.ConNo=C.ConNo)');
      sql.Add(',OrderDate=(select ORDDate from JYOrder_Main JM where JM.OrderNo=CR.OrderNo)');
      sql.Add(' ,OrderNoXHStr=dbo.GetOrderNoNum(CR.OrderNo)');
      sql.Add(' ,SpecNote=isnull(CR.SpecNote,B.SpecNote),Pin=isnull(CR.Pin,B.Pin),Zheng=isnull(CR.Zheng,B.Zheng)');
      sql.Add(' ,SeKaDate=isnull(CR.SeKaDate,B.SeKaDate),SeKaComeDate=isnull(CR.SeKaComeDate,B.SeKaComeDate)');
      sql.Add(' ,PinZhiNote=isnull(CR.PinZhiNote,B.PinZhiNote)');
      sql.Add(' ,GenDanPerson=isnull(CR.GenDanPerson,B.GenDanPerson),ShengChanNote=isnull(CR.ShengChanNote,B.ShengChanNote)');
      sql.Add(',CR.JCID,CR.JCName,CR.CRCiShu,CR.CRID,CR.OrdQty,CR.OrdQtyUnit,CR.YuJiCangDate,CR.YuYanHuoDate,CR.OrderNo');
      sql.Add(',CR.ConSubId,CR.SeKaOKDate,CR.BaoZhuang,CR.ChuanYangFlag,CR.GongChangOKFlag,CR.CangKuOKFlag,CR.LastEditTime');
      sql.Add(',CR.ChuanDate,CR.Qty,CR.QtyJian,CR.CRTime,CR.KCQty,CR.KCQtyJian,CGQty=Cast(Null as decimal(18,2))');
      sql.Add(',CGQtyJian=Cast(Null as decimal(18,2))');
      sql.Add(',B.PRTOrderQty,B.OrderUnit,B.SJJQDate ');
      sql.Add(' from JYOrderCon_Sub B ');
      sql.Add(' inner join JYOrderCon_Main C on B.Mainid=C.MainId');
      sql.Add(' left join JYOrder_CR CR on B.SubId=CR.ConSubId and isnull(CR.CRFlag,'''')=''入库'' ');
      sql.Add(' where C.OrdDate>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
      sql.Add(' and C.OrdDate<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
      SQL.Add(' and  ( exists(select top 1 Cast(1 as bit) from JYOrderCon_TT TT where TT.TTType=''TT''  ');
      sql.Add('                 and TT.ChkStatus=''审核通过'' and TT.ConNo=C.ConNo ) ');
      SQL.Add(' or   exists(select top 1 Cast(1 as bit) from JYOrderCon_TT TT where TT.TTType=''DB'' ');
      sql.Add('                and TT.ChkStatus=''审核通过'' and TT.ConNo=C.ConNo ) ');
      SQL.Add(' or   exists(select top 1 Cast(1 as bit) from JYOrderCon_TT TT where TT.TTType=''LC'' ');
      sql.Add('                and TT.ChkStatus=''审核通过'' and TT.ConNo=C.ConNo ) ');
      sql.Add(')');
      sql.Add(' and isnull(C.ChkStatus,'''')=''审核通过'' ');
      sql.Add(' and C.ZuoFeiFlag=0');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmProductOrderRGBCX.InitForm();
begin
  ReadCxGrid('入柜表查询',Tv1,'正排表管理');
  BegDate.DateTime:=SGetServerDate10(ADOQueryTemp)-7;
  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
  initgrid();
end;

procedure TfrmProductOrderRGBCX.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 TfrmProductOrderRGBCX.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  SelExportData(Tv1,ADOQueryMain,'正排表');
end;

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

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

procedure TfrmProductOrderRGBCX.CustomerNoNameChange(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 TfrmProductOrderRGBCX.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main,True);
end;

procedure TfrmProductOrderRGBCX.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main,False);
end;

procedure TfrmProductOrderRGBCX.TSselClick(Sender: TObject);
begin
  if Order_Main.Locate('Ssel',true,[])=False then
  begin
    application.MessageBox('没有选择数据','提示');
    exit;
  end;
  ModalResult:=1;
end;

end.
