unit U_SeHaoKu;

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;

type
  TfrmSeHaoKu = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBAdd: TToolButton;
    TBDel: TToolButton;
    TBClose: TToolButton;
    DataSource1: TDataSource;
    ADOQueryTree: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    Panel1: TPanel;
    Label2: TLabel;
    CYNo: TEdit;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    Label1: TLabel;
    CYName: TEdit;
    v1MLNo: TcxGridDBColumn;
    v1MLName: TcxGridDBColumn;
    v1MLMF: TcxGridDBColumn;
    v1MLKZ: TcxGridDBColumn;
    v1MLDLNo: TcxGridDBColumn;
    DataSource2: TDataSource;
    ADOQueryMain: TADOQuery;
    CDS_Main: TClientDataSet;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    ODPat: TOpenDialog;
    IdFTP1: TIdFTP;
    SaveDialog1: TSaveDialog;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cxDBTreeList1DblClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure CYNoKeyPress(Sender: TObject; var Key: Char);
    procedure CYNoChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
  private
    { Private declarations }
    PState:Integer;
    FCPID,FTopID:String;
    procedure InitTree();
    procedure InitGrid();
    procedure ReadINIFile();

  public
    { Public declarations }
  end;

var
  frmSeHaoKu: TfrmSeHaoKu;

implementation
uses
  U_DataLink,U_Fun,U_CPAdd,U_FileUp,U_MLManage_LR,U_ZDYHelp,U_BPZdy_LR;

{$R *.dfm}

procedure TfrmSeHaoKu.InitTree();
var
  i:Integer;
begin
  {with ADOQueryTree do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from CP_Type order by CPlevel,CPName');
    Open;
  end;
  cxDBTreeList1.Items[0].Expand(false);  }
  //cxDBTreeList1.Items[1].Expand(False);
end;

procedure TfrmSeHaoKu.InitGrid();
begin
  
end;

procedure TfrmSeHaoKu.FormDestroy(Sender: TObject);
begin
  frmSeHaoKu:=nil;
end;

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

procedure TfrmSeHaoKu.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('客户拿样',Tv1,'样品管理');
  if  DirectoryExists(ExtractFileDir('E:\Right1209')) then
    winexec('cmd /c rd /s /q D:\Right1209',sw_hide);
  Close;
end;
procedure TfrmSeHaoKu.TBDelClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('delete CP_YDang_KHGet where CKID='''+Trim(CDS_Main.fieldbyname('CKID').AsString)+'''');
    ExecSQL;
  end;
  CDS_Main.Delete;
end;

procedure TfrmSeHaoKu.FormShow(Sender: TObject);
begin
  //InitTree();
  ReadCxGrid('样品列表',Tv1,'样品管理');
end;

procedure TfrmSeHaoKu.cxDBTreeList1DblClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmSeHaoKu.TBAddClick(Sender: TObject);
begin
  try
    frmMLManage_LR:=TfrmMLManage_LR.Create(Application);
    with frmMLManage_LR do
    begin
      FCYID:='';
      //FCPID:=Trim(Self.ADOQueryTree.fieldbyname('CPID').AsString);
      //FCPNo:=Trim(Self.ADOQueryTree.fieldbyname('CPNo').AsString);
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmMLManage_LR.Free;
  end;
end;

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

procedure TfrmSeHaoKu.ToolButton3Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  try
    frmMLManage_LR:=TfrmMLManage_LR.Create(Application);
    with frmMLManage_LR do
    begin
      FCYID:=Trim(Self.CDS_Main.fieldbyname('CKID').AsString);
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmMLManage_LR.Free;
  end;
end;

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

procedure TfrmSeHaoKu.CYNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CP_YDang where CYID='''+Trim(CYNo.Text)+'''');
      Open;
      CYNo.Text:=Trim(fieldbyname('CYNo').AsString);
    end;
  end;
end;

procedure TfrmSeHaoKu.CYNoChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmSeHaoKu.ToolButton1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  TcxGridToExcel('客户拿样',cxGrid1);
end;

procedure TfrmSeHaoKu.ReadINIFile();
var
  programIni:Tinifile;  //配置文件名
  FileName:string;
begin
  FileName:=ExtractFilePath(Paramstr(0))+'SYSTEMSET.INI';
  programIni:=Tinifile.create(FileName);
  server:=programIni.ReadString('SERVER','服务器地址','127.0.0.1');
  programIni.Free;
end;

procedure TfrmSeHaoKu.Tv1CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
 // ToolButton6.Click;
end;

procedure TfrmSeHaoKu.ToolButton6Click(Sender: TObject);
begin
  frmBPZDY_LR:=TfrmBPZDY_LR.Create(self);
  with frmBPZDY_LR do
  begin
    flag:='MHName';
    flagName:='棉花';
    if ShowModal=1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmSeHaoKu.ToolButton7Click(Sender: TObject);
begin
  frmBPZDY_LR:=TfrmBPZDY_LR.Create(self);
  with frmBPZDY_LR do
  begin
    flag:='XXName';
    flagName:='绣线';
    if ShowModal=1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmSeHaoKu.ToolButton8Click(Sender: TObject);
begin
  frmBPZDY_LR:=TfrmBPZDY_LR.Create(self);
  with frmBPZDY_LR do
  begin
    flag:='WFBDY';
    flagName:='无纺布';
    if ShowModal=1 then
    begin

    end;
    free;
  end;
end;

end.
