unit U_OrderMXSelist;

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,
  MovePanel, cxTextEdit, cxContainer, cxCurrencyEdit, BtnEdit, RM_e_main, RM_e_htm, RM_e_Graphic, RM_e_Jpeg, RM_e_txt, RM_e_csv, RM_E_llPDF, Math,
  cxPC, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmOrderMXSelist = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    MLOrderNo: TEdit;
    Order_Main: TClientDataSet;
    MLConNo: TEdit;
    Label7: TLabel;
    Label2: TLabel;
    MLCodeName: TEdit;
    v1MLOrderNo: TcxGridDBColumn;
    v1GangNo: TcxGridDBColumn;
    v1KHName: TcxGridDBColumn;
    v1JYType: TcxGridDBColumn;
    v1JYKG: TcxGridDBColumn;
    v1JYLen: TcxGridDBColumn;
    v1JYUnit: TcxGridDBColumn;
    Label4: TLabel;
    v1MLCodeName: TcxGridDBColumn;
    v1RKType: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    v1JYNo: TcxGridDBColumn;
    ADOQueryPrint: TADOQuery;
    MovePanel2: TMovePanel;
    v1JYPZ: TcxGridDBColumn;
    v1JYJZ: TcxGridDBColumn;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    KHNameJC: TEdit;
    MLColor: TEdit;
    v1Column31: TcxGridDBColumn;
    v1MLConNo: TcxGridDBColumn;
    Label22: TLabel;
    ISHZ: TComboBox;
    v1MLColorNo: TcxGridDBColumn;
    v1MLHX: TcxGridDBColumn;
    IsJYTime: TCheckBox;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    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 MLOrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure CheckBox2Click(Sender: TObject);
    procedure gangNOKeyPress(Sender: TObject; var Key: Char);
    procedure MLConNoKeyPress(Sender: TObject; var Key: Char);
    procedure TCBNORChange(Sender: TObject);
    procedure MLColorKeyPress(Sender: TObject; var Key: Char);
    procedure BegDateChange(Sender: TObject);
    procedure EndDateChange(Sender: TObject);
    procedure JYTypeChange(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private
    DQdate: TDateTime;
    FLeft, FTop: Integer;
    CurrentPage, RecordsNumber: Integer;
    canshu1: string;
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    FFInt: Integer;
    { Public declarations }
  end;

var
  frmOrderMXSelist: TfrmOrderMXSelist;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp;

{$R *.dfm}


procedure TfrmOrderMXSelist.FormDestroy(Sender: TObject);
begin
  frmOrderMXSelist := nil;
end;

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

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

procedure TfrmOrderMXSelist.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('订单明细表', Tv1, '检验管理');
end;

procedure TfrmOrderMXSelist.InitGrid();
var
  fwhere, Pwhere: string;
begin
  MovePanel2.Left := (self.Width - MovePanel2.Width) div 2;
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  Pwhere := SGetFilters(Panel1, 1, 2);

  if trim(Pwhere) <> '' then
    fwhere := fwhere + ' and ' + trim(Pwhere);

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      SQL.Add('select ');
      sql.Add(' B.MLOrderNo,B.MLConNo,B.MLCodeName,B.KHName,KM.KHNameJC,C.* ');
      sql.Add(',KHConNo=(select TOP 1 X.KHConNo from ML_ConMain X where X.MLConID=B.ConMainId)');
      sql.Add('from ML_OrderMainNew B');
      sql.Add('inner join ML_OrderSubidNew C on B.NewMLid=C.NewMLid ');
      sql.Add('inner join KH_Main KM on B.KHNO=KM.KHNO ');
      sql.Add(' where 1=1');
      if IsJYTime.Checked then
      begin
        sql.Add('and B.FillTime>=''' + trim(FormatDateTime('yyyy-MM-dd', BegDate.Date)) + '''');
        sql.add(' and B.Filltime<''' + trim(FormatDateTime('yyyy-MM-dd', enddate.Date + 1)) + '''');
      end;
      sql.Add(fwhere);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
    MovePanel2.Visible := false;
  finally
    ADOQueryMain.EnableControls;
    MovePanel2.Visible := false;
  end;
end;

procedure TfrmOrderMXSelist.InitForm();
var
  fsj: string;
begin
  ReadCxGrid('订单核查表YX', Tv1, '检验管理');
  BegDate.DateTime := SGetServerDate10(ADOQueryTemp) - 1;
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
end;

procedure TfrmOrderMXSelist.TBRafreshClick(Sender: TObject);
begin
  toolbar1.SetFocus;
  InitGrid();
end;

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

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


procedure TfrmOrderMXSelist.CheckBox2Click(Sender: TObject);
begin
  SelOKNo(Order_Main, CheckBox2.Checked);
end;

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

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

procedure TfrmOrderMXSelist.TCBNORChange(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmOrderMXSelist.MLColorKeyPress(Sender: TObject; var Key: Char);
begin
  InitGrid();
end;

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

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

procedure TfrmOrderMXSelist.JYTypeChange(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmOrderMXSelist.Tv1CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if Order_Main.IsEmpty then exit;
  ModalResult:=1;
end;

end.


