unit U_OrderSel;

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;

type
  TfrmOrderSel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label1: TLabel;
    Tv1: TcxGridDBTableView;
    Cxgrid1Level1: TcxGridLevel;
    Cxgrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    MLOrderNo: TEdit;
    v1MLOrderNo: TcxGridDBColumn;
    v1OrdDate: TcxGridDBColumn;
    v1MLConNo: TcxGridDBColumn;
    Order_Main: TClientDataSet;
    v1KHName: TcxGridDBColumn;
    Label4: TLabel;
    KHNameHZ: TEdit;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    ToolButton1: TToolButton;
    Label9: TLabel;
    MLConNo: TEdit;
    Label12: TLabel;
    MPRTKZ: TEdit;
    v1Column2: TcxGridDBColumn;
    cxSplitter1: TcxSplitter;
    ADOQuerySub: TADOQuery;
    DataSource2: TDataSource;
    MLCodeName: TEdit;
    Label5: TLabel;
    N1: TMenuItem;
    v1Ssel: TcxGridDBColumn;
    Panel2: TPanel;
    Label7: TLabel;
    status: TComboBox;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v1XHNo: TcxGridDBColumn;
    v1MLColor: TcxGridDBColumn;
    v1MLColorNo: TcxGridDBColumn;
    v1MLHX: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1QtyUnit: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    v1MLCodeName: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    ToolButton2: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure BegDateChange(Sender: TObject);
    procedure EndDateChange(Sender: TObject);
    procedure MLCodeNameKeyPress(Sender: TObject; var Key: Char);
    procedure MLConNoKeyPress(Sender: TObject; var Key: Char);
    procedure MLOrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure KHNameHZChange(Sender: TObject);
  private
    DQdate: TDateTime;
    procedure InitGrid();

    procedure InitForm();

    procedure InitSub();

    { Private declarations }
  public
    FFInt, FCloth: Integer;
    canshu1, canshu2, canshu3: string;
    fFlileFlag: string;
    { Public declarations }
  end;

var
  frmOrderSel: TfrmOrderSel;

implementation

uses
  U_DataLink, U_Fun, U_FjList_RZ ; //U_OrderInPut_New ,U_MLOrderMXSel  ,U_KHList_CX
{$R *.dfm}





procedure TfrmOrderSel.InitSub();
begin
  if Order_Main.IsEmpty then
    exit;
  with ADOQuerySub do
  begin
    close;
    sql.Clear;
    sql.Add('select * from ML_OrderSubidNew ');
    sql.Add('where NewMLID =' + quotedstr((Order_Main.fieldbyname('NewMLID').AsString)));
    open;
  end;
 
end;

procedure TfrmOrderSel.FormDestroy(Sender: TObject);
begin
  frmOrderSel := nil;
end;

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

procedure TfrmOrderSel.FormCreate(Sender: TObject);
begin
  cxgrid1.Align := alClient;
  DQdate := SGetServerDate(ADOQueryTemp);
  canshu1 := trim(DParameters1);
  canshu2 := trim(DdataBase);
end;

procedure TfrmOrderSel.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('生产指示单新Sel', Tv1, '生产指示单管理');
end;

procedure TfrmOrderSel.InitGrid();
var
  fwhere, Pwhere: string;
begin
  Pwhere := SGetFilters(Panel1, 1, 2);
 { if canshu1 <> '高权限' then
  begin
    if Pwhere <> '' then
      Pwhere := Pwhere + ' and A.filler=''' + trim(DName) + ''''
    else
      Pwhere := '  A.filler=''' + trim(DName) + '''';
  end; }

  fwhere := ' where A.OrdDate>' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime));
  fwhere := fwhere + ' and A.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 A.*,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(' from ML_OrderMainNew A ');
      sql.Add(' left join KH_Main KM on KM.KHNO=A.KHNO ');
      sql.Add(fwhere);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmOrderSel.InitForm();
begin
  ReadCxGrid('生产指示单新Sel', Tv1, '生产指示单管理');
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime - 15;
  InitGrid();
end;

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

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

procedure TfrmOrderSel.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

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

procedure TfrmOrderSel.Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  InitSub();
end;

procedure TfrmOrderSel.BegDateChange(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmOrderSel.EndDateChange(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmOrderSel.MLCodeNameKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    InitGrid();
end;

procedure TfrmOrderSel.MLConNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    InitGrid();
end;

procedure TfrmOrderSel.MLOrderNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    InitGrid();
end;

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

end.

