unit U_JYOrderHZList;

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, cxPC,
  cxContainer, cxTextEdit, cxMaskEdit, cxDropDownEdit, cxLookAndFeels,
  cxLookAndFeelPainters, dxCore, cxDateUtils, cxNavigator;

type
  TfrmJYOrderHZList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    ConNo: TEdit;
    TBExport: TToolButton;
    Label7: TLabel;
    C_Code: TEdit;
    v1Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    Label5: TLabel;
    C_CodeName: TEdit;
    v1Column22: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    RM2: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    ADOQueryPrint: TADOQuery;
    MovePanel2: TMovePanel;
    Label9: TLabel;
    v1Column28: TcxGridDBColumn;
    CDS_Print: TClientDataSet;
    v1Column33: TcxGridDBColumn;
    Panel4: TPanel;
    Label11: TLabel;
    Panel10: TPanel;
    Image2: TImage;
    RichEdit1: TRichEdit;
    Order_Main: TClientDataSet;
    ADOQueryMain: TADOQuery;
    Label30: TLabel;
    APBatchNo: TEdit;
    v1Column41: TcxGridDBColumn;
    BegDate: TcxDateEdit;
    EndDate: TcxDateEdit;
    btnFind: TToolButton;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    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 N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure btnFindClick(Sender: TObject);
    procedure ConNoChange(Sender: TObject);
  private
    DQdate: TDateTime;
    FLeft, FTop: Integer;
    procedure InitGrid();
    procedure InitForm();

 
    { Private declarations }
  public
    FFInt: Integer;
    { Public declarations }
  end;

var
  frmJYOrderHZList: TfrmJYOrderHZList;

implementation

uses
  U_DataLink, U_Fun, U_MJEdit,U_RTFun;   

{$R *.dfm}

procedure TfrmJYOrderHZList.FormDestroy(Sender: TObject);
begin
  frmJYOrderHZList := nil;
end;

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

procedure TfrmJYOrderHZList.FormCreate(Sender: TObject);
begin
  DQdate := SGetServerDate(ADOQueryTemp);
end;

procedure TfrmJYOrderHZList.TBCloseClick(Sender: TObject);
begin
  Close;
  if Trim(DName)='ADMIN' then
  begin
    WriteCxGridAll(trim(self.Caption), Tv1,ADOQueryCmd,ADOQueryTemp);
  end;


end;

procedure TfrmJYOrderHZList.InitGrid();
var
  fsj: string;
begin

  ConNo.SetFocus;
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add(' select  AA.*,ZMoney=AA.GYPrice*AA.MJMaoZ from (');
      sql.Add(' select  A.*,B.ConNo,C.C_Code,C.C_CodeName');
      sql.Add(',GYPrice=isnull(G.PBJGPrice,0)+isnull(C.JGTiaoJia,0)');
      sql.Add(',GYMoney=(isnull(G.PBJGPrice,0)+isnull(C.JGTiaoJia,0))*MJMaoZ');
      sql.Add(' from (  select  MainId,SubId,APBatchNo,SUM(MJMaoZ) MJMaoZ from WFB_MJJY_PB wb ');
      sql.Add(' where wb.Filltime>=''' + Trim(BegDate.Text) + '''');
      sql.Add(' and wb.FillTIme<''' + Trim(EndDate.Text) + '''');
      sql.Add(' GROUP BY MainId,SubId,APBatchNo ) A');
      sql.Add(' inner join Cloth_Main B on A.MainId=B.MainId    ');
      sql.Add(' inner join Cloth_Sub C on A.SubId=C.SubId');
      sql.Add(' left join CP_Info G on C.C_CodeName=G.SPName');
      sql.Add(') AA');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
  MovePanel2.Visible := False;
end;

procedure TfrmJYOrderHZList.InitForm();
var
  fsj: string;
begin
  ReadCxGridAll(trim(self.Caption), Tv1);
//  fsj := 'select distinct(Filler) name from WFB_MJJY_PB   ';
//  SInitComBoxBySql(ADOQueryCmd, Filler, False, fsj);
  EndDate.Text := FormatDateTime('yyyy-MM-dd', SGetServerDate10(ADOQueryTemp) + 1) + ' 08:00:00';
  BegDate.Text := FormatDateTime('yyyy-MM-dd', SGetServerDate10(ADOQueryTemp) - 1) + ' 08:00:00';
end;

procedure TfrmJYOrderHZList.TBExportClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  SelExportData(Tv1, ADOQueryMain, '¼ìÑé±¨¸æ');
end;

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

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

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

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

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

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

procedure TfrmJYOrderHZList.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main, False);
end;

procedure TfrmJYOrderHZList.btnFindClick(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 TfrmJYOrderHZList.ConNoChange(Sender: TObject);
begin
  btnFind.Click;
end;

end.

