unit U_DyePlanForCardSel;

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, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu, cxPC, dxSkinsCore,
  dxSkinsDefaultPainters, dxDateRanges, dxScrollbarAnnotations;

type
  TfrmProductOrderListSel = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    Panel1: TPanel;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    OrderNo: TEdit;
    Tv1OrderNo: TcxGridDBColumn;
    Tv1F_Name: TcxGridDBColumn;
    Order_Main: TClientDataSet;
    Tv1C_CodeName: TcxGridDBColumn;
    Tv1QtyOrder: TcxGridDBColumn;
    ToolButton3: TToolButton;
    v1Column4: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    Tv1DlyDate: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Tv1OrdDate: TcxGridDBColumn;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label1: TLabel;
    Label2: TLabel;
    cxTabControl1: TcxTabControl;
    Tv1C_PlanQty: TcxGridDBColumn;
    Tv1Column16: TcxGridDBColumn;
    ToolButton1: TToolButton;
    Label4: TLabel;
    C_Name: TEdit;
    Tv1F_description: TcxGridDBColumn;
    Tv1finishDescription: TcxGridDBColumn;
    Tv1C_description: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
//    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure Tv1DblClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
  private
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    FFInt, FCloth: Integer;
    fWorkshop: string;
    { Public declarations }
  end;

var
  frmProductOrderListSel: TfrmProductOrderListSel;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmProductOrderListSel.FormDestroy(Sender: TObject);
begin
  frmProductOrderListSel := nil;
end;

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

procedure TfrmProductOrderListSel.TBCloseClick(Sender: TObject);
begin
  Close;

end;

procedure TfrmProductOrderListSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      Filtered := False;
      sql.Clear;
      sql.Add('select A.*   ');
      sql.add('from Dye_Plan_Main A');
//      sql.Add('inner join  Dye_Plan_Main B on B.mainID=A.mainID ');
      sql.Add('where A.OrdDate>=''' + formatdateTime('yyyy-MM-dd', begdate.Date) + ''' ');
      sql.Add('and A.OrdDate<''' + formatdateTime('yyyy-MM-dd', enddate.Date + 1) + ''' ');
//      sql.Add('and B.Workshop=' + quotedstr(fWorkshop));

//      sql.Add('and  isnull(B.status,''0'')=''9''');
      if OrderNo.Text <> '' then
      begin
        SQL.Add('AND A.OrderNo like ''' + '%' + Trim(OrderNo.Text) + '%' + '''');
      end;
      if C_Name.Text <> '' then
      begin
        SQL.Add('AND A.C_Name like ''' + '%' + Trim(C_Name.Text) + '%' + '''');
      end;

      if cxTabControl1.TabIndex = 0 then
        sql.Add('and not exists(select PCID from Dye_Plan_Card X where   X.MainID=A.MainID)');
      if cxTabControl1.TabIndex = 1 then
        sql.Add('and exists(select PCID from Dye_Plan_Card X where  X.MainID=A.MainID)');
//        ShowMessage(sql.text);
      Open;
    end;
    SCreateCDS(ADOQueryMain, Order_Main);
    SInitCDSData(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
    Tbfind.Click;
  end;
end;

procedure TfrmProductOrderListSel.InitForm();
begin
  ReadCxGrid('指示单列表选择', Tv1, '生产指示单管理');
  BegDate.DateTime := SGetServerDate(ADOQueryTemp);
  EndDate.DateTime := SGetServerDate(ADOQueryTemp);
  InitGrid();
end;

procedure TfrmProductOrderListSel.FormShow(Sender: TObject);
begin

  InitForm();
  if FFInt = 1 then
  begin
    v1Column4.Visible := False;
    v1Column4.Hidden := True;
  end;
  InitGrid();
end;

procedure TfrmProductOrderListSel.ToolButton1Click(Sender: TObject);
begin
  WriteCxGrid('指示单列表选择', Tv1, '生产指示单管理');
end;

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

//procedure TfrmProductOrderListSel.OrderNoKeyPress(Sender: TObject; var Key: Char);
//begin
//  if Key = #13 then
//  begin
//    if Length(Trim(OrderNo.Text)) < 3 then
//      Exit;
//    try
//      ADOQueryMain.DisableControls;
//      with ADOQueryMain do
//      begin
//
//        Close;
//        Filtered := False;
//        sql.Clear;
//        sql.Add('select B.*,A.*,A.OrderNo orderNoM  ');
//        sql.add('from Dye_Plan_sub A');
//        sql.Add('inner join  Dye_Plan_Main B on B.mainID=A.mainID ');
//   //   sql.Add('left  join Dye_PlanCon_Main C on C.conNO=B.conNO ');
//        SQL.Add('where B.OrderNo like ''' + '%' + Trim(OrderNo.Text) + '%' + '''');
//        Open;
//      end;
//      SCreateCDS(ADOQueryMain, Order_Main);
//      SInitCDSData(ADOQueryMain, Order_Main);
//    finally
//      ADOQueryMain.EnableControls;
//    end;
//  end;
//end;

procedure TfrmProductOrderListSel.Tv1DblClick(Sender: TObject);
begin
  ToolButton3.Click;
end;

procedure TfrmProductOrderListSel.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main, True);
end;

procedure TfrmProductOrderListSel.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main, false);
end;

procedure TfrmProductOrderListSel.OrderNoKeyPress(Sender: TObject;
  var Key: Char);
begin
  InitGrid();
end;

procedure TfrmProductOrderListSel.TBRafreshClick(Sender: TObject);
begin
  initgrid();
end;

procedure TfrmProductOrderListSel.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, Order_Main);
  SInitCDSData(ADOQueryMain, Order_Main);
end;

procedure TfrmProductOrderListSel.cxTabControl1Change(Sender: TObject);
begin
  TBRafresh.Click;
end;

end.

