unit U_SXRKSel;

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, cxDropDownEdit, cxButtonEdit,
  cxContainer, cxMaskEdit, FrameDateSel, FrameDateTimeSel;

type
  TfrmSXRKSel = class(TfrmBaseHelp)
    ToolBar1: TToolBar;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ToolButton1: TToolButton;
    ADOConnection1: TADOConnection;
    GPM_1: TcxGridPopupMenu;
    ImageList1: TImageList;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column6: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    Tv1Column15: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column12: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    Tv1Column13: TcxGridDBColumn;
    Tv1Column14: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Panel1: TPanel;
    Label3: TLabel;
    Label4: TLabel;
    Label8: TLabel;
    Label12: TLabel;
    Label10: TLabel;
    Label6: TLabel;
    Label5: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label7: TLabel;
    Label9: TLabel;
    Y_Name: TcxTextEdit;
    FromCoName: TcxTextEdit;
    BCPH: TcxTextEdit;
    BYIOID: TcxTextEdit;
    StkCoName: TcxTextEdit;
    IOType: TcxComboBox;
    GYSPH: TcxTextEdit;
    JGPH: TcxTextEdit;
    Y_Spec: TcxComboBox;
    Y_Code: TcxTextEdit;
    Yarn_Name: TcxTextEdit;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    Frame11: TfrmFrameDateSel;
    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);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure BYIOIDPropertiesChange(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    FCoType, FAuthority: string;
    { Public declarations }
  end;

var
  frmSXRKSel: TfrmSXRKSel;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmSXRKSel.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;

  Frame11.EndDate.Date := SGetServerDate(ADOQueryTemp);
  Frame11.BegDate.Date := Frame11.EndDate.Date - 30;
end;

procedure TfrmSXRKSel.FormDestroy(Sender: TObject);
begin
  inherited;
  frmSXRKSel := nil;
end;

procedure TfrmSXRKSel.BYIOIDPropertiesChange(Sender: TObject);
begin
  ToolButton3.Click;
end;

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

procedure TfrmSXRKSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      sql.Add(' from BS_Yarn_IO A');
      sql.add(' where A.IOTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', Frame11.BegDate.Date)) + '''');
      sql.Add(' and A.IOTime<''' + Trim(FormatDateTime('yyyy-MM-dd', Frame11.enddate.Date + 1)) + '''');
      sql.Add(' and isnull(StkName,'''')=''' + Trim('纱线') + '''');
      SQL.Add(' and IOFlag=''入库''  ');
      SQL.Add(' order by IOTime desc');
      Open;
    end;
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmSXRKSel.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 TfrmSXRKSel.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid('纱线入库' + Trim(FCoType), TV1, '自定义数据');
  InitGrid();
end;

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

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

end;

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

procedure TfrmSXRKSel.ToolButton2Click(Sender: TObject);
begin
  ToolBar1.SetFocus;
  InitGrid();
end;

procedure TfrmSXRKSel.ToolButton3Click(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 TfrmSXRKSel.Tv1DblClick(Sender: TObject);
begin
  ModalResult := 1;
end;

end.

