unit U_OrderHCList;

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
  TfrmOrderHCList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    MLOrderNo: TEdit;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    MLConNo: TEdit;
    Label7: TLabel;
    Label2: TLabel;
    MLCodeName: TEdit;
    Panel4: TPanel;
    Label11: TLabel;
    Panel10: TPanel;
    Image2: TImage;
    RichEdit1: TRichEdit;
    v1MLOrderNo: TcxGridDBColumn;
    v1GangNo: TcxGridDBColumn;
    v1KHName: TcxGridDBColumn;
    v1JYType: TcxGridDBColumn;
    v1JYKG: TcxGridDBColumn;
    v1JYLen: TcxGridDBColumn;
    v1JYUnit: TcxGridDBColumn;
    Label4: TLabel;
    v1MLCodeName: TcxGridDBColumn;
    v1RKType: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    v1JYNo: TcxGridDBColumn;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    MovePanel2: TMovePanel;
    v1JYPZ: TcxGridDBColumn;
    v1JYJZ: TcxGridDBColumn;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    KHNameJC: TEdit;
    MLColor: TEdit;
    v1Column31: TcxGridDBColumn;
    v1MLConNo: TcxGridDBColumn;
    Label22: TLabel;
    ISHZ: TComboBox;
   // RMllPDFExport1: TRMllPDFExport;
    RMXLSExport1: TRMXLSExport;
    CDS_PRT: TClientDataSet;
    v1MLColorNo: TcxGridDBColumn;
    v1MLHX: TcxGridDBColumn;
    IsJYTime: TCheckBox;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    ToolButton1: TToolButton;
    Panel2: TPanel;
    Label12: TLabel;
    MDName: TBtnEditA;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Panel10MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure Image2Click(Sender: TObject);
    procedure Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    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 ToolButton1Click(Sender: TObject);
    procedure MDNameBtnClick(Sender: TObject);
  private
    DQdate: TDateTime;
    FLeft, FTop: Integer;
    CurrentPage, RecordsNumber: Integer;
    canshu1: string;
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    FFInt: Integer;
    { Public declarations }
  end;

var
  frmOrderHCList: TfrmOrderHCList;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp;

{$R *.dfm}


procedure TfrmOrderHCList.FormDestroy(Sender: TObject);
begin
  frmOrderHCList := nil;
end;

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

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

procedure TfrmOrderHCList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('订单核查表YX', Tv1, '检验管理');
end;

procedure TfrmOrderHCList.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 TfrmOrderHCList.InitForm();
var
  fsj: string;
begin
  ReadCxGrid('订单核查表YX', Tv1, '检验管理');
  BegDate.DateTime := SGetServerDate10(ADOQueryTemp) - 1;
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
end;

procedure TfrmOrderHCList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  SelExportData(Tv1, ADOQueryMain, '订单核查表');
end;

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

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

procedure TfrmOrderHCList.Panel10MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  TWinControl(Panel4).Perform(WM_SYSCOMMAND, $F012, 0);
end;

procedure TfrmOrderHCList.Image2Click(Sender: TObject);
begin
  Panel4.Visible := False;
end;

procedure TfrmOrderHCList.Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FLeft := X;
  FTop := Y;
end;

procedure TfrmOrderHCList.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  Panel4.Left := FLeft;
  Panel4.Top := FTop + 110;
  Panel4.Visible := True;
  Panel4.Refresh;
  Panel10.Caption := Trim(TV1.Controller.FocusedColumn.Caption);
  RichEdit1.Text := Order_Main.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString;
end;


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


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

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

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

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

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

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

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

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

procedure TfrmOrderHCList.ToolButton1Click(Sender: TObject);
var
  fPrintFile: string;
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.add('exec P_Print_CKMD5 ');
    sql.add('@mainID=' + quotedstr(Trim(Order_Main.fieldbyname('NewMLID').AsString)));
    sql.add(',@DName=' + quotedstr(Trim(DCode)));
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_PRT);
  SInitCDSData20(ADOQueryTemp, CDS_PRT);
  RMXLSExport1 := TRMXLSExport.Create(RMXLSExport1);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\'+Trim(MDName.Text)+'.rmf';
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\销售码单新.rmf'), '提示', 0);
  end;
end;

procedure TfrmOrderHCList.MDNameBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='MDName';
      flagname:='码单名称';
      if ShowModal=1 then
      begin
        Self.MDName.Text:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

end.


