unit U_ProductFileSel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin, StdCtrls,
  cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, ShellAPI, IniFiles, cxCheckBox, cxCalendar, cxButtonEdit,
  cxTextEdit;

type
  TfrmProductFileSel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    Label3: TLabel;
    SPName: TEdit;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    SPSpec: TEdit;
    Label4: TLabel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2Column6: TcxGridDBColumn;
    v2Column11: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    ToolButton1: TToolButton;
    v2Column2: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    B1del: TToolButton;
    TBedit: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure SPNameChange(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure B1delClick(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
  public
    FYFGSType, fDEFstr5: string;
  end;

var
  frmProductFileSel: TfrmProductFileSel;

implementation

uses
  U_DataLink, U_RTFun, U_ProductFileLR;

{$R *.dfm}

procedure TfrmProductFileSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add(' select * from CP_Info where DataType=''CW'' and ZFFlag=0 ');
      if FYFGSType <> '' then
        sql.Add(' and SPType= ' + QUOTEDSTR(Trim(FYFGSType)));
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
  ToolButton2.Click;
end;

procedure TfrmProductFileSel.FormDestroy(Sender: TObject);
begin
  frmProductFileSel := nil;
end;

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

procedure TfrmProductFileSel.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('原料信息管理', Tv2, '客户自定义');
  Close;
end;

procedure TfrmProductFileSel.FormShow(Sender: TObject);
begin
  ReadCxGrid('原料信息管理', Tv2, '客户自定义');
  InitGrid();
end;

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

procedure TfrmProductFileSel.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  end;
end;

procedure TfrmProductFileSel.SPNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmProductFileSel.Tv2CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  if CDS_HZ.IsEmpty then
    Exit;
  ModalResult := 1;
end;

procedure TfrmProductFileSel.ToolButton1Click(Sender: TObject);
begin
  try
    frmProductFileLR := TfrmProductFileLR.Create(Application);
    with frmProductFileLR do
    begin
      FCYID := '';
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmProductFileLR.Free;
  end;
end;

procedure TfrmProductFileSel.ToolButton3Click(Sender: TObject);
begin
  try
    frmProductFileLR := TfrmProductFileLR.Create(Application);
    with frmProductFileLR do
    begin
      FCYID := Trim(Self.CDS_HZ.fieldbyname('CPID').AsString);
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmProductFileLR.Free;
  end;
end;

procedure TfrmProductFileSel.B1delClick(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    Exit;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  if Trim(CDS_HZ.fieldbyname('CPID').AsString) <> '' then
  begin
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' UPdate CP_Info Set ZFFlag=1,ZFTime=Getdate(),ZFPerson=''' + Trim(DName) + '''');
      sql.Add(' where CPID=''' + Trim(CDS_HZ.fieldbyname('CPID').AsString) + '''');
      ExecSQL;
    end;
  end;
  CDS_HZ.Delete;
end;

end.

