unit U_DyePlanCardSel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, cxMemo,
  cxRichEdit, ComCtrls, cxContainer, cxTextEdit, cxMaskEdit, cxButtonEdit,
  StdCtrls, ToolWin, DBClient, ADODB, ExtCtrls, BtnEdit, cxCalendar, StrUtils,
  cxCurrencyEdit, cxImage, cxDBEdit, Menus, RM_Common, RM_Class, RM_e_Xls,
  RM_Dataset, RM_System, RM_GridReport, cxGridCustomPopupMenu, cxGridPopupMenu,
  cxPC, cxSplitter, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdFTP, ShellAPI, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
    dxDateRanges, dxBarBuiltInMenu,
  U_BaseHelp, System.ImageList, Vcl.ImgList, cxCheckBox, 
   dxScrollbarAnnotations, FrameDateSel;

type
  TfrmDyePlanCardSel = class(TfrmBaseHelp)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    GPM_1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    ADOConnection1: TADOConnection;
    ToolButton1: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column14: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1CustomerNoName: TcxGridDBColumn;
    Tv1Column16: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1MPRTCodeName: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    v1MPRTSpec: TcxGridDBColumn;
    v1MPRTMF: TcxGridDBColumn;
    v1MPRTKZ: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    Tv1Column19: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    Tv1Column18: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column13: TcxGridDBColumn;
    Tv1Column14: TcxGridDBColumn;
    Tv1Column15: TcxGridDBColumn;
    Tv1Column17: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    Tv1Column12: TcxGridDBColumn;
    Tv1Column20: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label3: TLabel;
    Label4: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label2: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    OrderNo: TcxTextEdit;
    CustName: TcxTextEdit;
    C_Name: TcxTextEdit;
    ConNo: TcxTextEdit;
    C_Spec: TcxTextEdit;
    PCID: TcxTextEdit;
    C_ColorNo: TcxTextEdit;
    C_Color: TcxTextEdit;
    ToolButton2: TToolButton;
    frmFrameDateSel1: TfrmFrameDateSel;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private
    DQdate: TDateTime;
    procedure InitGrid();
    { Private declarations }
  public
    FFInt, FCloth: Integer;
    fsyrName: string;
    canshu1, canshu2: string;
    fFlileFlag: string;
    { Public declarations }
  end;

var
  frmDyePlanCardSel: TfrmDyePlanCardSel;

implementation

uses
  U_DataLink, U_RTFun;
{$R *.dfm}

procedure TfrmDyePlanCardSel.FormDestroy(Sender: TObject);
begin
  inherited;
  frmDyePlanCardSel := nil;
end;

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

procedure TfrmDyePlanCardSel.FormCreate(Sender: TObject);
begin
  inherited;
  try
    with ADOConnection1 do
    begin
      Connected := false;
      ConnectionString := DConString;
      Connected := true;
    end;
    ADOQueryBaseCmd.Connection := ADOConnection1;
    ADOQueryBaseTemp.Connection := ADOConnection1;
  except
    application.MessageBox('网络连接失败！', '提示信息');
  end;
end;

procedure TfrmDyePlanCardSel.TBCloseClick(Sender: TObject);
begin

  Close;
end;

procedure TfrmDyePlanCardSel.InitGrid();
var
  strwhere: string;
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin

      Close;
      Filtered := False;
      sql.Clear;
      sql.Add('select  A.* ');
      SQL.Add(',LabVolume=(SELECT TOP 1 LabVolume FROM DYE_Cloth_Inspect_Rule E WHERE E.RULEID=A.PCID)');
      SQL.Add(',ADDWET=(SELECT TOP 1 ADDWET FROM DYE_Cloth_Inspect_Rule E WHERE E.RULEID=A.PCID)');

//      sql.Add(',GlideList=[dbo].[F_Dye_Card_GlideList](A.PCID) ');
      sql.Add('from Dye_Plan_Card A ');
      sql.Add('where A.PCTime>=''' + formatdateTime('yyyy-MM-dd', frmFrameDateSel1.BegDate.Date) + ''' ');
      sql.Add('and A.PCTime<''' + formatdateTime('yyyy-MM-dd', frmFrameDateSel1.BegDate.Date + 1) + ''' ');
      sql.Add('and not exists(  SELECT *   FROM Dye_Formula_Large_Main A CROSS APPLY [dbo].[F_Tool_SplitString]( GGCARNO, '','' ) AS SplitMembers WHERE  b.pcid=RTVALUE)');
      sql.Add('  and  PSC_StkPiece<>0');
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  finally
    ADOQueryMain.EnableControls;
    TBFind.Click;
  end;
end;

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

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

procedure TfrmDyePlanCardSel.ToolButton1Click(Sender: TObject);
begin
  WriteCxGrid(self.Caption + 'TV1', Tv1, '生产指示单管理');

end;

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

procedure TfrmDyePlanCardSel.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(self.Caption + 'TV1', Tv1, '生产指示单管理');
  frmFrameDateSel1.BegDate.Date := SGetServerDate(ADOQueryTemp) - 90;
  frmFrameDateSel1.EndDate.Date := SGetServerDate(ADOQueryTemp);
  InitGrid();
end;

procedure TfrmDyePlanCardSel.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmDyePlanCardSel.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmDyePlanCardSel.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmDyePlanCardSel.Tv1DblClick(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  ModalResult := 1;
end;

end.

