unit U_TatYarnSel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, ToolWin, ComCtrls, U_BaseHelp, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGrid, DBClient, ADODB, ImgList, StdCtrls, ExtCtrls,
  cxTextEdit, cxGridCustomPopupMenu, cxGridPopupMenu, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxDateRanges, dxBarBuiltInMenu,
  System.ImageList, U_BaseInput, cxCheckBox, cxCalendar, dxScrollbarAnnotations,
  dxSkinsCore, dxSkinsDefaultPainters;

type
  TfrmTatYarnSel = class(TfrmBaseHelp)
    ToolBar1: TToolBar;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ToolButton1: TToolButton;
    ADOConnection1: TADOConnection;
    Panel1: TPanel;
    GPM_1: TcxGridPopupMenu;
    ImageList1: TImageList;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column7: TcxGridDBColumn;
    v1OrderNo: TcxGridDBColumn;
    v1ConNo: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    v1OrdDefStr1: TcxGridDBColumn;
    v1MPRTCodeName: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label3: TLabel;
    Label8: TLabel;
    OrderNo: TEdit;
    ConNo: TEdit;
    Label1: TLabel;
    CustName: TEdit;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Label2: TLabel;
    C_Name: TEdit;
    Label4: TLabel;
    Y_Code: TEdit;
    Label5: TLabel;
    Yarn_Name: TEdit;
    Tv1Column9: TcxGridDBColumn;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    FCoType, FAuthority: string;
    { Public declarations }
  end;

var
  frmTatYarnSel: TfrmTatYarnSel;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmTatYarnSel.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 TfrmTatYarnSel.FormDestroy(Sender: TObject);
begin
  inherited;
  frmTatYarnSel := nil;
end;

procedure TfrmTatYarnSel.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := cahide;
end;

procedure TfrmTatYarnSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add(' select Y_Spec=(select Y_Spec from Bs_Yarn_Info X where X.Y_Code =C.Y_Code),C.*,A.*,B.*');
      sql.Add(' from Tat_Plan_Main A  ');
      sql.Add(' inner join Tat_Plan_Sub B on A.MainId=B.MainId ');
      sql.Add(' INNER JOIN Tat_Plan_Yarn C on A.MainId =C.MainId ');
      sql.Add(' where isnull(C.Y_Code,'''') <> '''' ');
      sql.Add(' and  isnull(A.status,''0'') in (''0'',''9'') ');
//      ShowMessage(sql.Text);
      Open;
    end;
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

procedure TfrmTatYarnSel.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid('纱线选择' + Trim(FCoType), TV1, '自定义数据');
  InitGrid();
end;

procedure TfrmTatYarnSel.TBCloseClick(Sender: TObject);
begin
  inherited;
  Close;
end;

procedure TfrmTatYarnSel.TBSaveClick(Sender: TObject);
begin
  WriteCxGrid('纱线选择' + Trim(FCoType), TV1, '自定义数据');

end;

procedure TfrmTatYarnSel.ToolButton1Click(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmTatYarnSel.Tv1DblClick(Sender: TObject);
begin
  ModalResult := 1;
end;

end.

