unit U_MLMangeRS_Sel2;

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, Menus, cxLookAndFeelPainters, cxButtons, cxImage;

type
  TfrmMLMangeRS_Sel2 = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    DataSource1: TDataSource;
    ADOQueryTree: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    DataSource2: TDataSource;
    ADOQueryMain: TADOQuery;
    CDS_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    ODPat: TOpenDialog;
    IdFTP1: TIdFTP;
    SaveDialog1: TSaveDialog;
    DataSource3: TDataSource;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Order_GX: TClientDataSet;
    DataSource4: TDataSource;
    cxGridPopupMenu3: TcxGridPopupMenu;
    ML_Col: TClientDataSet;
    DataSource5: TDataSource;
    cxGridPopupMenu4: TcxGridPopupMenu;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxGridPopupMenu5: TcxGridPopupMenu;
    DataSource6: TDataSource;
    ADOQuery1: TADOQuery;
    Panel5: TPanel;
    Label2: TLabel;
    MLNo: TEdit;
    Label1: TLabel;
    Label4: TLabel;
    MLName: TEdit;
    GYLXName: TEdit;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1MLNo: TcxGridDBColumn;
    v1MLName: TcxGridDBColumn;
    v1MLMF: TcxGridDBColumn;
    v1MLKZ: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1GYLXName: TcxGridDBColumn;
    v1SKID: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label3: TLabel;
    ToolButton3: TToolButton;
    v1ColNameKH: TcxGridDBColumn;
    v1ColNo: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cxDBTreeList1DblClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure MLNoChange(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure TCKClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
  private
    { Private declarations }
    PState:Integer;
    FCPID,FTopID:String;
    procedure InitTree();
    procedure InitGrid();
    procedure ReadINIFile();
    procedure ButtonColorCSH();
  public
    canshu1:string;
    Formid:string;
    { Public declarations }
  end;

var
  frmMLMangeRS_Sel2: TfrmMLMangeRS_Sel2;

implementation
uses
  U_DataLink,U_Fun,U_FileUp,U_MLManage_LRRS,U_MLManage_LRRSHT;

{$R *.dfm}

procedure TfrmMLMangeRS_Sel2.InitTree();
begin
  
end;

procedure TfrmMLMangeRS_Sel2.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select *,cast('''' as varchar(50)) ColNo,cast('''' as varchar(50)) ColNameKH,cast('''' as varchar(50)) GYSColNo ');
      sql.Add(',PTID=cast('''' as varchar(50))');
      sql.Add(',SKID=(select B.SKID from BP_ZDY B where B.BPID=A.MBPID)');
      sql.Add(',BPCode=(select B.BPCode from BP_ZDY B where B.BPID=A.MBPID)');
      sql.Add(' from ML_Manage A ');
      sql.Add(' where isnull(MLType,'''')=''染色面料'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
    ToolButton2.Click;
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmMLMangeRS_Sel2.FormDestroy(Sender: TObject);
begin
  frmMLMangeRS_Sel2:=nil;
end;

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

procedure TfrmMLMangeRS_Sel2.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('染色面料选择1',Tv1,'样品管理');
  Close;
end;
procedure TfrmMLMangeRS_Sel2.FormShow(Sender: TObject);
begin
  InitGrid();
  ReadCxGrid('染色面料选择1',Tv1,'样品管理');
end;

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

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

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

procedure TfrmMLMangeRS_Sel2.MLNoChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel5,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmMLMangeRS_Sel2.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 TfrmMLMangeRS_Sel2.Tv1DblClick(Sender: TObject);
begin
  if Formid='1' then
  begin
    ModalResult:=1;
  end
  else
  begin
    try
      frmMLManage_LRRS:=TfrmMLManage_LRRS.Create(Application);
      with frmMLManage_LRRS do
      begin
        FCYID:=Trim(Self.CDS_Main.fieldbyname('MLID').AsString);
        FGYName:='染色';
        viewFlag:=True;
        if ShowModal=1 then
        begin
          with CDS_Main do
          begin
            edit;
            FieldByName('ColNo').Value:=Trim(OrdBP_SH.fieldbyname('ColNo').AsString);
            FieldByName('ColNameKH').Value:=Trim(OrdBP_SH.fieldbyname('ColNameKH').AsString);
            FieldByName('GYSColNo').Value:=Trim(OrdBP_SH.fieldbyname('GYSColNo').AsString);
            FieldByName('PTID').Value:=Trim(OrdBP_SH.fieldbyname('PTID').AsString);
          end;
          ToolButton3.Click;
        end;
      end;
    finally
      frmMLManage_LRRS.Free;
    end;
  end;
end;

procedure TfrmMLMangeRS_Sel2.TCKClick(Sender: TObject);
begin
  if CDS_Main.FieldByName('GYType').AsString='染色' then
  begin
    try
      frmMLManage_LRRS:=TfrmMLManage_LRRS.Create(Application);
      with frmMLManage_LRRS do
      begin
        FCYID:=Trim(Self.CDS_Main.fieldbyname('MLID').AsString);
        FGYName:='染色';
        viewFlag:=True;
        if ShowModal=1 then
        begin
          Self.InitGrid();
        end;
      end;
    finally
      frmMLManage_LRRS.Free;
    end;
  end;
end;

procedure TfrmMLMangeRS_Sel2.ButtonColorCSH();
begin

end;

procedure TfrmMLMangeRS_Sel2.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
end;

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

procedure TfrmMLMangeRS_Sel2.N1Click(Sender: TObject);
begin
  try
    frmMLManage_LRRSHT:=TfrmMLManage_LRRSHT.Create(Application);
    with frmMLManage_LRRSHT do
    begin
      Button5.Visible:=false;
      FCYID:=Trim(Self.CDS_Main.fieldbyname('MLID').AsString);
      FGYName:='染色';
      FZ:='1';
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmMLManage_LRRSHT.Free;
  end;
end;

procedure TfrmMLMangeRS_Sel2.N2Click(Sender: TObject);
begin
  try
    frmMLManage_LRRSHT:=TfrmMLManage_LRRSHT.Create(Application);
    with frmMLManage_LRRSHT do
    begin
      TAdd.Visible:=false;
      ToolButton5.Visible:=false;
      FCYID:=Trim(Self.CDS_Main.fieldbyname('MLID').AsString);
      FGYName:='染色';
      FZ:='1';
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmMLManage_LRRSHT.Free;
  end;
end;

end.
