unit U_DCDList_Sel;

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;

type
  TfrmDCDList_Sel = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    Panel1: TPanel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    ToolButton3: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column14: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1ConNo: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    v1OrdPerson1: TcxGridDBColumn;
    v1CustomerNoName: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1FKPayment: TcxGridDBColumn;
    v1YJDCDate: TcxGridDBColumn;
    v1YJSHDate: TcxGridDBColumn;
    v1EditNote: TcxGridDBColumn;
    v1EditSQTime: TcxGridDBColumn;
    v1LCChuanQ: TcxGridDBColumn;
    v1YiDuanZ: TcxGridDBColumn;
    v1LCQty: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label1: TLabel;
    Label4: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label5: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    zorderno: TEdit;
    DCNO: TEdit;
    TOPlace: TEdit;
    KHName: TEdit;
    ToolButton1: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton1Click(Sender: TObject);
    procedure DCNOChange(Sender: TObject);
    procedure DCNOKeyPress(Sender: TObject; var Key: Char);
  private
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    FFInt, FCloth: Integer;

    { Public declarations }
  end;

var
  frmDCDList_Sel: TfrmDCDList_Sel;

implementation

uses
  U_DataLink, U_Fun;

{$R *.dfm}

procedure TfrmDCDList_Sel.FormDestroy(Sender: TObject);
begin
  frmDCDList_Sel := nil;
end;

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

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

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

procedure TfrmDCDList_Sel.InitGrid();
begin
//  if Length(Trim(self.ConNO.Text)) < 3 then
//    Exit;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select   ');
      sql.Add('A.*');
      SQL.Add(',GSNAME=''振永纺织''');
      SQL.Add(',ZORDERNO=CAST((SELECT  STUFF(( SELECT  '','' +convert(VARCHAR, FROMORDERNO) FROM JYOrderCon_TT_Sub B WHERE A.TTID=B.TTId FOR XML PATH('''')), 1, 1, '''') )AS VARCHAR)');
      SQL.Add(',ZQTY=(SELECT SUM(PRTORDERQTY) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
      SQL.Add(',ZMONEY=(SELECT SUM(MONEY) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
      SQL.Add(',ZMAOZHONG=(SELECT SUM(MAOZHONG) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
      SQL.Add(',ZJINGZHONG=(SELECT SUM(JINGZHONG) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
      SQL.Add(',ZTIJI=(SELECT SUM(tiji) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
      SQL.Add(',ZBZJS=(SELECT SUM(BZJS) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
      sql.Add(' from JYOrderCon_TT A ');
      SQL.Add('where ((FILLTIME>=''' + FormatDateTime('yyyy-MM-dd', BegDate.DateTime) + '''');
      SQL.Add('and  FILLTIME<''' + FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1) + ''') or ChkStatus=''审核不通过'') ');

      if DCNO.Text <> '' then
      begin
        SQL.Add('AND dcno like' + quotedstr('%' + trim(DCNO.text) + '%'));
      end;
      if KHName.Text <> '' then
      begin
        SQL.Add('AND KHName like' + quotedstr('%' + trim(KHName.text) + '%'));
      end;
      if zorderno.Text <> '' then
      begin
        SQL.Add('AND CAST((SELECT  STUFF(( SELECT  '','' +convert(VARCHAR, FROMORDERNO) FROM JYOrderCon_TT_Sub B WHERE A.TTID=B.TTId FOR XML PATH('''')), 1, 1, '''') )AS VARCHAR) like' + quotedstr('%' + trim(zorderno.text) + '%'));
      end;
      if TOPlace.Text <> '' then
      begin
        SQL.Add('AND TOPlace like' + quotedstr('%' + trim(TOPlace.text) + '%'));
      end;
//      else if cxTabControl1.TabIndex = 1 then
//      begin
//        SQL.Add('AND ISNULL(SChkFlag,0)=1 AND  ISNULL(ChkStatus,0)=0 ');
//      end
//      else if cxTabControl1.TabIndex = 2 then
//      begin
//        SQL.Add(' AND  ChkStatus=1 ');
//      end;
//ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

procedure TfrmDCDList_Sel.ToolButton3Click(Sender: TObject);
begin
  ModalResult := 1;
end;

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

procedure TfrmDCDList_Sel.ToolButton1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmDCDList_Sel.DCNOChange(Sender: TObject);
begin

//  InitGrid();
//  if ADOQueryMain.Active then
//  begin
//    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
//    SCreateCDS20(ADOQueryMain, Order_Main);
//    SInitCDSData20(ADOQueryMain, Order_Main);
//  end;
end;

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

end.

