unit U_ZSDXZ;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
  cxStyles, dxSkinsCore,    
   dxSkinDarkRoom,  
     
     
     
    
    
    
   dxSkinOffice2013White,  
    dxSkinSharpPlus, 
  dxSkinSpringTime,   
  dxSkinsDefaultPainters,   
   dxSkinscxPCPainter, cxCustomData, cxFilter, cxData,
  cxDataStorage, cxEdit, cxNavigator, DB, cxDBData, cxCheckBox, cxCalendar,
  cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxClasses, cxGridCustomView, cxGrid, ADODB, DBClient, StdCtrls, ComCtrls,
  ExtCtrls, ToolWin;

type
  Tfrmzsdxz = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label9: TLabel;
    Label12: TLabel;
    Label5: TLabel;
    Label7: TLabel;
    Label6: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    MLOrderNo: TEdit;
    MLConNo: TEdit;
    MPRTKZ: TEdit;
    MLCodeName: TEdit;
    status: TComboBox;
    NewMLID: TEdit;
    HX: TEdit;
    KHNameJC: TComboBox;
    filler: TComboBox;
    Order_Main: TClientDataSet;
    DataSource1: TDataSource;
    ADOQueryMain: TADOQuery;
    Cxgrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Ssel: TcxGridDBColumn;
    v1OrdDate: TcxGridDBColumn;
    v1MLOrderNo: TcxGridDBColumn;
    v1MLConNo: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1MLCodeName: TcxGridDBColumn;
    v1KHName: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Cxgrid1Level1: TcxGridLevel;
    ToolButton1: TToolButton;
    ADOQueryTemp: TADOQuery;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmzsdxz: Tfrmzsdxz;

implementation

uses
  U_DataLink, U_RTFun, U_Fun, U_ZDYHelp;

{$R *.dfm}
procedure Tfrmzsdxz.InitGrid();
var
  fwhere, Pwhere: string;
begin
  ToolBar1.SetFocus;
  Pwhere := SGetFilters(Panel1, 1, 2);
//  if canshu1 <> '高权限' then
//  begin
//    if Pwhere <> '' then
//      Pwhere := Pwhere + ' and filler=''' + trim(DName) + ''''
//    else
//      Pwhere := '  filler=''' + trim(DName) + '''';
//  end;

  fwhere := ' where OrdDate>=' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime));
  fwhere := fwhere + ' and OrdDate<=' + quotedstr(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1));
  if trim(Pwhere) <> '' then
    fwhere := fwhere + ' and ' + trim(Pwhere);

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;                       
      sql.Add('SELECT AA.* FROM(');
      sql.add('select A.*,B.NewSubid,B.MLColorNoKH,B.MLColorNo,B.kuanhao,B.MLColorEng,B.MLColor,KM.KHNameJC,KHNameHZ=isnull(A.KHNO,'''')+isnull(KM.KHName,'''')+isnull(KM.KHNameJC,'''')');
      sql.Add('+dbo.getpinyin(isnull(KM.KHName,''''))+dbo.getpinyin(isnull(KM.KHNameJC,''''))');
      SQL.Add(',ZQty=(select Sum(B.Qty) from ML_OrderSubidNew B where B.NewMLID=A.NewMLID) ');
      sql.Add(',HX=(select top 1 MLHX from ML_OrderSubidNew B where B.NewMLID=A.NewMLID)');
      sql.Add(',KHConNo=(select TOP 1 X.KHConNo from ML_ConMain X where X.MLConID=A.ConMainId)');
      sql.Add(' from ML_OrderMainNew A ');
      sql.Add(' left join ML_OrderSubidNew B on B.NewMLID=A.NewMLID ');
      sql.Add(' left join KH_Main KM on KM.KHNO=A.KHNO ');
      sql.Add(')AA');
      sql.Add(fwhere);
     // ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure Tfrmzsdxz.InitForm();
begin
//  Panel3.Visible := False;
  ReadCxGrid('生产指示单选择', Tv1, '生产指示单选择');

  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime - 15;
//  ConEndDate.DateTime := EndDate.DateTime;
//  ConBegDate.DateTime := EndDate.DateTime - 15;
//  if trim(DdataBase) = '查询' then
//  begin
//    TBadd.Visible := false;
//    tbedit.Visible := false;
//    ToolButton2.Visible := false;
//    tbdel.Visible := false;
//  end;
  //SetStatus();
  InitGrid();

end;

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

procedure Tfrmzsdxz.FormDestroy(Sender: TObject);
begin
  frmzsdxz := nil;
end;

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

procedure Tfrmzsdxz.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('生产指示单选择', Tv1, '生产指示单选择');
end;

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

procedure Tfrmzsdxz.ToolButton1Click(Sender: TObject);
begin
  ModalResult := 1;
end;

end.

