unit U_ProductOrder_CX;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, StdCtrls, ExtCtrls, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData,
  cxCalendar, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid,
  cxCheckBox, ADODB, DBClient;

type
  TFrmProductOrder_CX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    ToolButton1: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    Label3: TLabel;
    Label5: TLabel;
    Label4: TLabel;
    Label6: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    ConNo: TEdit;
    MPRTCodeName: TEdit;
    MPRTSpec: TEdit;
    PRTColor: TEdit;
    Label2: TLabel;
    Filler: TEdit;
    Label7: TLabel;
    orderNO: TEdit;
    Label8: TLabel;
    MPRTKZ: TEdit;
    Label9: TLabel;
    MPRTMF: TEdit;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    v1ConNo: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1OrdDate: TcxGridDBColumn;
    v1DeliveryDate: TcxGridDBColumn;
    v1CustomerNoName: TcxGridDBColumn;
    v1MPRTCodeName: TcxGridDBColumn;
    v1MPRTSpec: TcxGridDBColumn;
    v1MPRTMF: TcxGridDBColumn;
    v1MPRTKZ: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1PRTColor: TcxGridDBColumn;
    v1PRTHX: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1Ssel: TcxGridDBColumn;
    DataSource1: TDataSource;
    Order_Main: TClientDataSet;
    ADOQueryTmp: TADOQuery;
    v1SYRName: TcxGridDBColumn;
    v1MPRTBZNote: TcxGridDBColumn;
    v1SOrddefstr1: TcxGridDBColumn;
    ADOQueryCMD: TADOQuery;
    CheckBox1: TCheckBox;
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure ConNoChange(Sender: TObject);
    procedure orderNOKeyPress(Sender: TObject; var Key: Char);
  private
    procedure initGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmProductOrder_CX: TFrmProductOrder_CX;

implementation

uses U_DataLink,U_ZDYHelp,U_Fun;
{$R *.dfm}
procedure TFrmProductOrder_CX.initGrid();
begin
  with ADOQueryTmp do
  begin
    close;
    sql.clear;
    sql.Add('select A.*,B.*,C.SYRName from JYOrder_Main A ');
    SQL.Add('inner join JYOrder_Sub B on B.Mainid=A.Mainid ');
    sql.add('left join JYOrderCon_Main C on C.Mainid=A.Mainid ');
    sql.add('where A.OrdDate>='''+trim(formatdatetime('yyyy-MM-dd',begdate.datetime))+'''');
    sql.add('and A.OrdDate<'''+trim(formatdatetime('yyyy-MM-dd',enddate.datetime+1))+'''');
    open;
  end;
  SCreateCDS20(ADOQueryTmp,Order_Main);
  SInitCDSData20(ADOQueryTmp,Order_Main);
end;

procedure TFrmProductOrder_CX.TBRafreshClick(Sender: TObject);
begin
   initGrid();
end;

procedure TFrmProductOrder_CX.ToolButton1Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  ModalResult:=1;
end;

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

procedure TFrmProductOrder_CX.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid(self.Caption+tv1.Name,Tv1,'生产指示管理');
end;

procedure TFrmProductOrder_CX.FormCreate(Sender: TObject);
begin
  cxgrid1.Align:=alClient;
end;

procedure TFrmProductOrder_CX.FormShow(Sender: TObject);
begin
  ReadCxGrid(self.Caption+tv1.Name,Tv1,'生产指示管理');
  BegDate.DateTime:=SGetServerDate10(ADOQueryCMD)-7;
  EndDate.DateTime:=SGetServerDate10(ADOQueryCMD);
  initGrid();
end;

procedure TFrmProductOrder_CX.Tv1CellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  ToolButton1.Click;
end;

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

procedure TFrmProductOrder_CX.FormDestroy(Sender: TObject);
begin
  FrmProductOrder_CX:=nil;
end;

procedure TFrmProductOrder_CX.CheckBox1Click(Sender: TObject);
begin
  with Order_Main do
  begin
    DisableControls;
    first;
    while not eof do
    begin
      edit;
      Order_Main.FieldByName('Ssel').AsBoolean:=CheckBox1.Checked;
      post;
      next;
    end;
    EnableControls;
  end;
end;

procedure TFrmProductOrder_CX.ConNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TFrmProductOrder_CX.orderNOKeyPress(Sender: TObject;
  var Key: Char);
begin
  IF key=#13 then
  begin
    IF length(orderNO.Text)<4 then exit;
    with ADOQueryTmp do
    begin
    close;
    sql.clear;
    sql.Add('select A.*,B.*,C.SYRName from JYOrder_Main A ');
    SQL.Add('inner join JYOrder_Sub B on B.Mainid=A.Mainid ');
    sql.add('left join JYOrderCon_Main C on C.Mainid=A.Mainid ');
    sql.add('where A.orderNo like '+quotedstr('%'+trim(orderNo.Text)+'%'));
    open;
    end;
    SCreateCDS20(ADOQueryTmp,Order_Main);
    SInitCDSData20(ADOQueryTmp,Order_Main);
  end;
end;

end.
