unit U_ClothSYarnCListSel;

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, cxCalendar, cxButtonEdit, cxSplitter, RM_Common, RM_Class,
  RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, cxTextEdit, cxCheckBox,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmClothSYarnCListSel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label2: TLabel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    ConNo: TEdit;
    Label5: TLabel;
    MPRTCodeName: TEdit;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMXLSExport1: TRMXLSExport;
    Label10: TLabel;
    MPRTCode: TEdit;
    btnOK: TToolButton;
    OrderNo: TEdit;
    Label6: TLabel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    v1ConNo: TcxGridDBColumn;
    v1KHConNO: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1OrdDefStr1: TcxGridDBColumn;
    v1DeliveryDate: TcxGridDBColumn;
    v1MPRTCodeName: TcxGridDBColumn;
    v1MPRTSpec: TcxGridDBColumn;
    v1MPRTMF: TcxGridDBColumn;
    v1MPRTKZ: TcxGridDBColumn;
    v1PRTColor: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Tv1Column1: TcxGridDBColumn;
    CheckBox1: TCheckBox;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnOKClick(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
//    procedure Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
  private
    FInt, PFInt: Integer;
    canshu1: string;
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    ftype: string;
    { Public declarations }
  end;

var
  frmClothSYarnCListSel: TfrmClothSYarnCListSel;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp;

{$R *.dfm}

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

procedure TfrmClothSYarnCListSel.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid(trim(self.Caption), Tv1, '坯布生产管理22');
end;

procedure TfrmClothSYarnCListSel.InitGrid();
var
  WSql: string;
begin
  WSql := SGetFilters(Panel1, 1, 2);
  if WSql <> '' then
    WSql := ' and ' + WSql
  else
    CheckBox1.Checked := True;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select  A.*');
      sql.add('from V_Ord_MS A where 1=1 ');

      if CheckBox1.Checked then
      begin
        sql.Add(' and FILLTIME>=''' + formatdateTime('yyyy-MM-dd', begdate.Date) + ''' ');
        sql.Add(' and  FILLTIME<''' + formatdateTime('yyyy-MM-dd', enddate.Date + 1) + ''' ');

      end;
      sql.Add(WSql);
//       ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmClothSYarnCListSel.InitForm();
begin
  ReadCxGrid(trim(self.Caption), Tv1, '坯布生产管理22');

  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime - 30;
  InitGrid();
end;

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

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

procedure TfrmClothSYarnCListSel.FormCreate(Sender: TObject);
begin
  canshu1 := Trim(DParameters1);
end;

procedure TfrmClothSYarnCListSel.btnOKClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  ModalResult := 1;
end;

procedure TfrmClothSYarnCListSel.Tv1DblClick(Sender: TObject);
begin
  btnOK.Click;
end;

procedure TfrmClothSYarnCListSel.ConNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CheckBox1.Checked := False;
    InitGrid();
  end;

end;

end.

