unit U_MLMange_ADDCX;

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, cxTextEdit,
  cxButtonEdit;

type
  TfrmMLMange_ADDCX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    DataSource1: TDataSource;
    ADOQueryTree: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Panel1: TPanel;
    Label2: TLabel;
    MLNo: TEdit;
    ToolButton2: TToolButton;
    Label1: TLabel;
    MLName: TEdit;
    DataSource2: TDataSource;
    ADOQueryMain: TADOQuery;
    CDS_Main: TClientDataSet;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    ODPat: TOpenDialog;
    IdFTP1: TIdFTP;
    SaveDialog1: TSaveDialog;
    TSsel: TToolButton;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1GSNo: TcxGridDBColumn;
    v1GYName: TcxGridDBColumn;
    v1MLNo: TcxGridDBColumn;
    v1MLName: TcxGridDBColumn;
    v1MLMF: TcxGridDBColumn;
    v1MLKZ: TcxGridDBColumn;
    v1MLType: TcxGridDBColumn;
    v1MLDLNo: TcxGridDBColumn;
    v1GYLX: TcxGridDBColumn;
    v1GYLXName: TcxGridDBColumn;
    v1DLHXK: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    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 MLNoChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure ToolButton9Click(Sender: TObject);
    procedure TFHClick(Sender: TObject);
    procedure ToZHADDClick(Sender: TObject);
    procedure TSselClick(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private
    { Private declarations }
    PState:Integer;
    FCPID,FTopID:String;
    procedure InitTree();
    procedure InitGrid();
    procedure ReadINIFile();

  public
    formid:string;
    { Public declarations }
  end;

var
  frmMLMange_ADDCX: TfrmMLMange_ADDCX;

implementation
uses
  U_DataLink,U_Fun,U_CPAdd,U_FileUp,U_MLManage_LR,U_BPZdy_LR,U_BPZdy_SH,U_MLManage_FHLR,U_MLManage_ZHLR;

{$R *.dfm}

procedure TfrmMLMange_ADDCX.InitTree();
begin
  
end;

procedure TfrmMLMange_ADDCX.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from ML_Manage ');
      if formid<>'1' then
      begin
        sql.Add(' where MLType=''单面料''');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmMLMange_ADDCX.FormDestroy(Sender: TObject);
begin
  frmMLMange_ADDCX:=nil;
end;

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

procedure TfrmMLMange_ADDCX.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 TfrmMLMange_ADDCX.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 ML_Manage where MLID='''+Trim(CDS_Main.fieldbyname('MLID').AsString)+'''');
    sql.Add('delete ML_Manage_PB where MLID='''+Trim(CDS_Main.fieldbyname('MLID').AsString)+'''');
    sql.Add('delete ML_Manage_GX where MLID='''+Trim(CDS_Main.fieldbyname('MLID').AsString)+'''');
    ExecSQL;
  end;
  CDS_Main.Delete;
end;

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

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

procedure TfrmMLMange_ADDCX.TBAddClick(Sender: TObject);
begin
  try
    frmMLManage_LR:=TfrmMLManage_LR.Create(Application);
    with frmMLManage_LR do
    begin
      FCYID:='';
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmMLManage_LR.Free;
  end;
end;

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

procedure TfrmMLMange_ADDCX.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('MLID').AsString);
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmMLManage_LR.Free;
  end;
end;

procedure TfrmMLMange_ADDCX.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 TfrmMLMange_ADDCX.MLNoChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

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

procedure TfrmMLMange_ADDCX.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 TfrmMLMange_ADDCX.ToolButton4Click(Sender: TObject);
begin
  frmBPZDY_LR:=TfrmBPZDY_LR.Create(self);
  with frmBPZDY_LR do
  begin
    flag:='PBName';
    flagName:='坯布';
    ToolBar2.Visible:=false;
    cxGrid2.Visible:=false;
    cxGrid3.Visible:=false;
    if ShowModal=1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmMLMange_ADDCX.ToolButton5Click(Sender: TObject);
begin
  frmBPZDY_LR:=TfrmBPZDY_LR.Create(self);
  with frmBPZDY_LR do
  begin
    flag:='GXName';
    flagName:='工序';
    V1BPMF1.Visible:=false;
    V1BPKZ.Visible:=false;
    V1BPJS.Visible:=false;
    //V1BPWS.Visible:=false;
    v1BPMiDu.Caption:='序号';
    ToolBar2.Visible:=false;
    cxGrid2.Visible:=false;
    if ShowModal=1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmMLMange_ADDCX.ToolButton6Click(Sender: TObject);
begin
  frmBPZDY_LR:=TfrmBPZDY_LR.Create(self);
  with frmBPZDY_LR do
  begin
    flag:='MHName';
    flagName:='棉花';
    V1BPJS.Visible:=false;
    //V1BPWS.Visible:=false;
    v1BPMiDu.Visible:=false;
    cxGrid3.Visible:=false;
    if ShowModal=1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmMLMange_ADDCX.ToolButton7Click(Sender: TObject);
begin
  frmBPZDY_LR:=TfrmBPZDY_LR.Create(self);
  with frmBPZDY_LR do
  begin
    flag:='XXName';
    flagName:='绣线';
    V1BPJS.Visible:=false;
    //V1BPWS.Visible:=false;
    v1BPMiDu.Caption:='颜色';
    V1BPMF1.Visible:=false;
    V1BPKZ.Visible:=false;
    ToolBar2.Visible:=false;
    cxGrid2.Visible:=false;
    cxGrid3.Visible:=false;
    if ShowModal=1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmMLMange_ADDCX.ToolButton8Click(Sender: TObject);
begin
  frmBPZDY_LR:=TfrmBPZDY_LR.Create(self);
  with frmBPZDY_LR do
  begin
    flag:='WFBDY';
    flagName:='无纺布';
    V1BPMF1.Visible:=false;
    V1BPKZ.Visible:=false;
    V1BPJS.Visible:=false;
    //V1BPWS.Visible:=false;
    v1BPMiDu.Visible:=false;
    cxGrid3.Visible:=false;
    if ShowModal=1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmMLMange_ADDCX.ToolButton9Click(Sender: TObject);
begin
  frmBPZDY_SH:=TfrmBPZDY_SH.Create(self);
  with frmBPZDY_SH do
  begin
    flag:='SHK';
    flagName:='色号库';
    if ShowModal=1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmMLMange_ADDCX.TFHClick(Sender: TObject);
begin
  try
    frmMLManage_FHLR:=TfrmMLManage_FHLR.Create(Application);
    with frmMLManage_FHLR do
    begin
      FCYID:='';
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmMLManage_FHLR.Free;
  end;
end;

procedure TfrmMLMange_ADDCX.ToZHADDClick(Sender: TObject);
begin
  frmMLManage_ZHLR:=TfrmMLManage_ZHLR.Create(self);
  with frmMLManage_ZHLR do
  begin
    if ShowModal=1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmMLMange_ADDCX.TSselClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then exit;
  ModalResult:=1;
end;

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

end.
