unit U_MLMangeTJ;

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, BtnEdit,
  jpeg, cxContainer;

type
  TfrmMLMangeTJ = 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;
    ToolButton1: TToolButton;
    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;
    CDS_Sub: TClientDataSet;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    DataSource6: TDataSource;
    Ord_HX: TClientDataSet;
    ADOQuery1: TADOQuery;
    TCK: TToolButton;
    ToolButton11: TToolButton;
    Panel5: TPanel;
    Label2: TLabel;
    TJML: TEdit;
    Label1: TLabel;
    Label4: TLabel;
    MLPinYin: TEdit;
    TJGYName: TEdit;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1TJML: TcxGridDBColumn;
    v1MLName: TcxGridDBColumn;
    v1MLMF: TcxGridDBColumn;
    v1MLKZ: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1TJGYName: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label3: TLabel;
    v1MLXXGYName: TcxGridDBColumn;
    v1HXType: TcxGridDBColumn;
    v1MLXXNO: TcxGridDBColumn;
    v1ColGS: TcxGridDBColumn;
    Label5: TLabel;
    MLXXNO: TEdit;
    Label6: TLabel;
    MLKZ: TEdit;
    Label7: TLabel;
    Button1: TButton;
    HXType: TEdit;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N4: TMenuItem;
    Panel2: TPanel;
    cxButton1: TcxButton;
    cxButton2: TcxButton;
    cxButton3: TcxButton;
    Label8: TLabel;
    RM2: TRMGridReport;
    Image1: TImage;
    N5: TMenuItem;
    Label9: TLabel;
    SMRK: TEdit;
    N3: TMenuItem;
    Panel3: TPanel;
    Image11: TImage;
    Image22: TImage;
    TJHX: TLabel;
    TJHXType: TLabel;
    TJMLNo: TLabel;
    cxImage1: TcxImage;
    Image2: TImage;
    Panel16: TPanel;
    cxButton4: TcxButton;
    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 ToolButton1Click(Sender: TObject);
    procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure ToolButton10Click(Sender: TObject);
    procedure TV4CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Tv1DblClick(Sender: TObject);
    procedure TCKClick(Sender: TObject);
    procedure ToolButton11Click(Sender: TObject);
    procedure TPrintClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure HXTypeChange(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure cxButton1Click(Sender: TObject);
    procedure Image1Click(Sender: TObject);
    procedure cxButton2Click(Sender: TObject);
    procedure cxButton3Click(Sender: TObject);
    procedure N5Click(Sender: TObject);
    procedure SMRKKeyPress(Sender: TObject; var Key: Char);
    procedure Image2Click(Sender: TObject);
    procedure cxImage1DblClick(Sender: TObject);
    procedure cxButton4Click(Sender: TObject);
  private
    { Private declarations }
    PState:Integer;
    FCPID,FTopID,FileName:String;
    procedure InitGrid();
    procedure ReadINIFile();
  public
    canshu1:string;
    { Public declarations }
  end;

var
  frmMLMangeTJ: TfrmMLMangeTJ;

implementation
uses
  U_DataLink,U_Fun,U_CPAdd,U_FileUp,U_MLManage_LR,U_BPZdy_LR,U_BPZdy_SH,U_MLManage_LRRS,U_HXKTJ,
  U_MLManage_FHLR,U_MLManage_ZHLR,U_BPZdy_HXK,U_MLMange_CX,U_BPZdy_LRPB,U_BPZdy_LRGX,U_BPZdy_ColTJ,
  U_CPManage_TP,U_BPZdy_LRSHK, U_BPZdy_PanelCX,U_BPZdy_Panel,U_MLManage_LRTJ,U_MLManage_LRTJ_Ceshi1,
  U_SCPerson,U_MLManage_LRTJDY,U_HXKTJ_CX;

{$R *.dfm}

procedure TfrmMLMangeTJ.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select *,MLDLNo SKID,MLPinYin=dbo.getPinYin(A.MLName) ');
      sql.Add(',ColGS=(select count(B.TJML) from Image_Info B where B.TJML=A.TJML)');
      sql.Add(' from ML_Manage A ');
      sql.Add(' where isnull(A.MLType,'''')=''烫金面料'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmMLMangeTJ.FormDestroy(Sender: TObject);
begin
  frmMLMangeTJ:=nil;
end;

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

procedure TfrmMLMangeTJ.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('烫金面料1',Tv1,'样品管理');
  Close;
end;
procedure TfrmMLMangeTJ.FormShow(Sender: TObject);
begin
  {if canshu1='高权限' then
  begin
    toolbutton11.Visible:=True;
    ToolButton3.Visible:=true;
    TBDel.Visible:=true;
  end
  else
  begin
    if canshu1='查询' then
    begin
      toolbutton11.Visible:=false;
      ToolButton3.Visible:=false;
      TBDel.Visible:=false;
    end
    else
    begin
      toolbutton11.Visible:=false;
      ToolButton3.Visible:=false;
      TBDel.Visible:=false;
    end;
  end;}
  InitGrid();
  ReadCxGrid('烫金面料1',Tv1,'样品管理');
end;

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

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

procedure TfrmMLMangeTJ.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 TfrmMLMangeTJ.ToolButton1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  TcxGridToExcel('客户拿样',cxGrid1);
end;

procedure TfrmMLMangeTJ.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 TfrmMLMangeTJ.Tv1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select A.*,isnull(B.BPCode,C.MLNo) BPCode,isnull(B.BPName,C.MLName) BPName');
    sql.Add(' ,isnull(B.BPMF,C.MLMF) BPMF,isnull(B.BPKZ,C.MLKZ) BPKZ');
    sql.Add(',B.BPJS,B.BPWS,B.BPMiDu,B.BPUnit,C.MLDLNo,C.DLHXK');
    SQL.Add(' from ML_Manage_PB A left join BP_ZDY B on B.BPID=A.BPID ');
    sql.Add(' left join ML_Manage C on C.MLID=A.BPID');
    sql.Add(' where A.MLID='''+Trim(CDS_Main.fieldbyname('MLID').AsString)+'''');
    //ShowMessage(sql.Text);
    Open;
  end;
  SCreateCDS20(ADOQueryCmd,CDS_Sub);
  SInitCDSData20(ADOQueryCmd,CDS_Sub);
  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select A.*,B.*,C.* from ML_Manage_GX A inner join BP_ZDY B on B.BPID=A.BPID ');
    sql.Add('inner join BP_ZDY_Sub C on C.BPSubID=A.BPSubID');
    sql.Add(' where A.MLID='''+Trim(CDS_Main.fieldbyname('MLID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryCmd,Order_GX);
  SInitCDSData20(ADOQueryCmd,Order_GX);
  //if CDS_Main.FieldByName('MLType').AsString<>'复合' then
  begin
    //if CDS_Main.FieldByName('MLType').AsString<>'组合' then
    begin
      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        sql.Add('select * from BP_ZDY_Sub ');
        sql.Add('where BPCode='''+Trim(CDS_Main.fieldbyname('MLDLNo').AsString)+''' and BPflag=''SHK''');
        Open;
      end;
      SCreateCDS20(ADOQueryCmd,ML_Col);
      SInitCDSData20(ADOQueryCmd,ML_Col);
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select A.*,B.* from BP_ZDY_Sub A ');
      Sql.Add('inner join KH_Zdy_Attachment B on A.HXATID=B.ATID and B.Type=''CPHX''');
      sql.Add(' where A.BPCode='''+trim(CDS_Main.fieldbyname('DLHXK').AsString)+'''');
      open;
    end;
    SCreateCDS20(ADOQueryCmd,Ord_HX);
    SInitCDSData20(ADOQueryCmd,Ord_HX);
  end;
end;

procedure TfrmMLMangeTJ.ToolButton10Click(Sender: TObject);
begin
  {if RadioGroup1.ItemIndex=-1 then
  begin
    application.MessageBox('请选择工序','提示');
    exit;
  end;}
  
end;

procedure TfrmMLMangeTJ.TV4CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  //if CDS_Main.FieldByName('MLType').AsString='复合' then
  begin
    with ADOQuery1 do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from BP_ZDY_Sub ');
      sql.Add('where BPCode='''+Trim(CDS_Sub.Fieldbyname('MLDLNo').AsString)+''' and BPflag=''SHK''');
      Open;
    end;
    SCreateCDS20(ADOQuery1,ML_Col);
    SInitCDSData20(ADOQuery1,ML_Col);
    with ADOQuery1 do
    begin
      Close;
      SQL.Clear;
      sql.Add('select A.*,B.* from BP_ZDY_Sub A ');
      Sql.Add('inner join KH_Zdy_Attachment B on A.HXATID=B.ATID and B.Type=''CPHX''');
      sql.Add(' where A.BPCode='''+trim(CDS_Sub.Fieldbyname('DLHXK').AsString)+'''');
      open;
    end;
    SCreateCDS20(ADOQuery1,Ord_HX);
    SInitCDSData20(ADOQuery1,Ord_HX);
  end;
end;

procedure TfrmMLMangeTJ.Tv1DblClick(Sender: TObject);
begin
  TCK.Click;
end;

procedure TfrmMLMangeTJ.TCKClick(Sender: TObject);
begin
  try
    frmMLManage_LRTJ:=TfrmMLManage_LRTJ.Create(Application);
    with frmMLManage_LRTJ do
    begin
      FCYID:=Trim(Self.CDS_Main.fieldbyname('MLID').AsString);
      FGYName:='烫金';
      formid:='1';
      //viewFlag:=True;
      TSave.Visible:=false;
      Button2.Visible:=false;
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmMLManage_LRTJ.Free;
  end;
end;

procedure TfrmMLMangeTJ.ToolButton11Click(Sender: TObject);
begin
  try
    frmMLManage_LRTJ:=TfrmMLManage_LRTJ.Create(Application);
    with frmMLManage_LRTJ do
    begin
      FCYID:='';
      FGYName:='烫金';
      if ShowModal=1 then
      begin
        Self.InitGrid();
        CDS_Main.Locate('MLID',FCYID,[]);
      end;
    end;
  finally
    frmMLManage_LRTJ.Free;
  end;
end;

procedure TfrmMLMangeTJ.TPrintClick(Sender: TObject);
begin
  frmHXKTJ:=TfrmHXKTJ.create(self);
  with frmHXKTJ do
  begin
    TJHX.Text:=Trim(CDS_Main.fieldbyname('TJML').AsString);
    if ShowModal=1 then
    begin

    end;
    free;
  end;
end;

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

procedure TfrmMLMangeTJ.N1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  try
    frmMLManage_LRTJ:=TfrmMLManage_LRTJ.Create(Application);
    with frmMLManage_LRTJ do
    begin
      FCYID:=Trim(Self.CDS_Main.fieldbyname('MLID').AsString);
      FGYName:='烫金';
      Panel7.Visible:=false;
      Button2.Visible:=false;
      Button3.Visible:=false;
      Panel10.Visible:=false;
      TJGYName.Enabled:=false;
      TJGYName.Color:=clScrollBar;
      if ShowModal=1 then
      begin
        Self.InitGrid();
        CDS_Main.Locate('MLID',FCYID,[]);
      end;
    end;
  finally
    frmMLManage_LRTJ.Free;
  end;
end;

procedure TfrmMLMangeTJ.N2Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    SQL.Add('select * from ML_Manage A ');
    sql.Add(' where isnull(A.MLType,'''')=''烫金面料''');
    sql.Add(' and TJML='''+trim(CDS_Main.fieldbyname('TJML').AsString)+'''');
    Open;
  end;
  if ADOQueryCmd.RecordCount=1 then
  begin
    Application.MessageBox('烫金编号只有一条,不能删除','提示');
    exit;
  end;
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    SQL.Add('select * from BP_DY ');
    sql.Add('where MLID='''+trim(CDS_Main.fieldbyname('MLID').AsString)+'''');
    Open;
  end;
  if ADOQueryCmd.IsEmpty=false then
  begin
    if Application.MessageBox('数据已打印确定要删除吗?','提示',32+4)<>IDYES then Exit;
    //exit;
  end
  else
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  end;
  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)+'''');
    sql.Add('delete Image_Info where TJML='''+Trim(CDS_Main.fieldbyname('TJML').AsString)+'''');
    sql.Add(' and TJGYName='''+Trim(CDS_Main.fieldbyname('TJGYName').AsString)+'''');
    ExecSQL;
  end;
  CDS_Main.Delete;
end;

procedure TfrmMLMangeTJ.N3Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  try
    frmMLManage_LRTJ:=TfrmMLManage_LRTJ.Create(Application);
    with frmMLManage_LRTJ do
    begin
      FCYID:=Trim(Self.CDS_Main.fieldbyname('MLID').AsString);
      FGYName:='烫金';
      formid:='3';
      if ShowModal=1 then
      begin
        Self.InitGrid();
        CDS_Main.Locate('MLID',FCYID,[]);
      end;
    end;
  finally
    frmMLManage_LRTJ.Free;
  end;
end;

procedure TfrmMLMangeTJ.Button1Click(Sender: TObject);
begin
  frmSCPerson:=TfrmSCPerson.Create(Application);
  with frmSCPerson do
  begin
    FlagStr:='HXZDYType';
    if ShowModal=1 then
    begin
      HXType.Text:=Trim(FSDPerson);
    end;
    free;
  end;
end;

procedure TfrmMLMangeTJ.HXTypeChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmMLMangeTJ.N4Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  try
    frmMLManage_LRTJ:=TfrmMLManage_LRTJ.Create(Application);
    with frmMLManage_LRTJ do
    begin
      FCYID:=Trim(Self.CDS_Main.fieldbyname('MLID').AsString);
      FGYName:='烫金';
      FOrmid:='2';
      if ShowModal=1 then
      begin
        Self.InitGrid();
        CDS_Main.Locate('MLID',FCYID,[]);
      end;
    end;
  finally
    frmMLManage_LRTJ.Free;
  end;
end;

procedure TfrmMLMangeTJ.cxButton1Click(Sender: TObject);
var
   fPrintFile,Txt,fImagePath,maxno:string;
   i,j:Integer;
   Moudle: THandle;
   Makebar:TMakebar;
   Mixtext:TMixtext;
begin
  if CDS_Main.IsEmpty then Exit;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\烫金面料标签.rmf';
  if FileExists(fPrintFile)=False then
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\烫金面料标签.rmf'),'提示',0);
    exit;
  end;
  CDS_Main.DisableControls;
  with CDS_Main do
  begin
    //First;
    //while Locate('SSel',True,[]) do
    begin
      try
        ADOQueryCmd.Connection.BeginTrans;
        if GetLSNo(ADOQueryCmd,maxno,'TGML','BP_DY',4,1,)=False then
        begin
          ADOQueryCmd.Connection.RollbackTrans;
          Application.MessageBox('取样品打印最大号失败!','提示',0);
          Exit;
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          SQL.Add('select * from BP_DY where DYId='''+Trim(maxno)+'''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          Append;
          FieldByName('MLID').Value:=Trim(CDS_Main.fieldbyname('MLID').AsString);
          FieldByName('TFID').Value:=Trim(CDS_Main.fieldbyname('PTID').AsString);
          FieldByName('DYId').Value:=Trim(maxno);
          FieldByName('Filler').Value:=Trim(DName);
          FieldByName('FillerCode').Value:=Trim(DCode);
          FieldByName('Valid').Value:='Y';
          Post;
        end;
        ADOQueryCmd.Connection.CommitTrans;
      except
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('保存打印流水号异常！','提示',0);
        Exit;
      end;
      try
        Moudle:=LoadLibrary('MakeQRBarcode.dll');
        @Makebar:=GetProcAddress(Moudle,'Make');
        @Mixtext:=GetProcAddress(Moudle,'MixText');
        Txt:=Trim(maxno);
        fImagePath:=ExtractFilePath(Application.ExeName)+'image\temp.bmp';
        if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName)+'image')) then
          CreateDirectory(pchar(ExtractFilePath(Application.ExeName)+'image'),nil);
        if FileExists(fImagePath) then DeleteFile(fImagePath);
        Makebar(pchar(Txt),Length(Txt),3,3,0,PChar(fImagePath),3);
      except
        application.MessageBox('二维码生成失败！','提示信息',MB_ICONERROR);
        exit;
      end;
      RMVariables['QRBARCODE']:=fImagePath;
      RMVariables['DYID']:=maxno;
      RM1.LoadFromFile(fPrintFile);
     // RM1.ShowReport;
      RM1.PrintReport;
    end;
  end;
  CDS_Main.EnableControls;
  panel2.Visible:=false;
end;

procedure TfrmMLMangeTJ.Image1Click(Sender: TObject);
begin
  panel2.Visible:=False;
end;

procedure TfrmMLMangeTJ.cxButton2Click(Sender: TObject);
begin
  frmMLManage_LRTJDY:=TfrmMLManage_LRTJDY.Create(self);
  with frmMLManage_LRTJDY do
  begin
    FCYID:=Trim(Self.CDS_Main.fieldbyname('MLID').AsString);
    FGYName:='烫金';
    formid:='1';
    if ShowModal=1 then
    begin

    end;
    free;
  end;
  panel2.Visible:=false;
end;

procedure TfrmMLMangeTJ.cxButton3Click(Sender: TObject);
begin
  frmMLManage_LRTJDY:=TfrmMLManage_LRTJDY.Create(self);
  with frmMLManage_LRTJDY do
  begin
    formid:='2';
    FCYID:=Trim(Self.CDS_Main.fieldbyname('MLID').AsString);
    FGYName:='烫金';
    if ShowModal=1 then
    begin

    end;
    free;
  end;
  panel2.Visible:=false;
end;

procedure TfrmMLMangeTJ.N5Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then exit;
  Panel2.Visible:=true;
end;

procedure TfrmMLMangeTJ.SMRKKeyPress(Sender: TObject; var Key: Char);
var
  jpg:TJpegImage;
  myStream: TADOBlobStream;
begin
  if Key=#13 then
  begin
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select Top 1 A.*,B.*,E.*,MLDLNo SKID,MLPinYin=dbo.getPinYin(A.MLName) ');
      sql.Add(',ColGS=(select count(B.TJML) from Image_Info B where B.TJML=A.TJML)');
      sql.Add(' from ML_Manage A ');
      sql.Add(' left join Image_Info B on B.TJML=A.TJML ');
      sql.Add(' left join Image_File E on B.IMID=E.IMID ');
      sql.Add(' left join BP_DY C on C.TFID=B.IMID and C.MLID=A.MLID');
      sql.Add(' left join BP_DY D on D.TFID=A.PTID and D.MLID=A.MLID');
      sql.Add(' where isnull(A.MLType,'''')=''烫金面料'' and isnull(C.DYID,D.DYID)='''+trim(SMRK.Text)+'''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
    Panel3.Visible:=true;
    if ADOQueryMain.IsEmpty=False then
    begin
      FileName:=Trim(CDS_Main.fieldbyname('ImagePath').AsString);
      jpg:=TJpegImage.Create();
      myStream:=tadoblobstream.Create(tblobfield(ADOQueryMain.fieldbyname('ImageFile')),bmread);
      jpg.LoadFromStream(myStream);
      cxImage1.Picture.Assign(jpg);
      TJHX.Caption:=trim(CDS_Main.fieldbyname('TJHX').AsString);
      TJHXType.Caption:=trim(CDS_Main.fieldbyname('TJHXType').AsString);
      TJMLNo.Caption:=trim(CDS_Main.fieldbyname('TJMLNo').AsString);
    end;
    SMRK.Text:='';
  end;
end;

procedure TfrmMLMangeTJ.Image2Click(Sender: TObject);
begin
  panel3.Visible:=false;
end;

procedure TfrmMLMangeTJ.cxImage1DblClick(Sender: TObject);
var
  IdFTP1: TIdFTP;
  FPath,FFName:string;
  FInt:integer;
  maxno:string;
  j,i:Integer;
  fPrintFile:string;
begin
  if Application.MessageBox('原图下载需要等待时间，确定要查看原图吗？','提示',32+4)<>IDYES then Exit;
  try
    ReadINIFile();
    server:=ReadINIFileStr('SYSTEMSET.INI','SERVER','服务器地址','127.0.0.1');
    IdFTP1:=TIdFTP.Create(self);
    IdFTP1.Host :=server;
    IdFTP1.Username := 'three';
    IdFTP1.Password := '641010';
    IdFTP1.Connect();
  except
    IdFTP1.Quit;
    IdFTP1.Free;
    Application.MessageBox('无法连接到文件服务器，请检查！', '提示', MB_ICONWARNING);
    Exit;
  end;
  Panel16.Visible:=true;
  Panel16.Refresh;
  fPrintFile:= ExtractFilePath(Application.ExeName)+'Photo\';
  if not DirectoryExists(ExtractFileDir(FPrintFile)) then
    CreateDir(ExtractFileDir(fPrintFile));
  FFName:=Trim(FileName);
  FFName:=fPrintFile+FFName+'.jpg';
  if not FileExists(FFName) then
  begin
    IdFTP1.Get('TJ\'+FileName,FFName);
  end;
  if IdFTP1.Connected then
  begin
    IdFTP1.Quit;
    IdFTP1.Free;
  end;
  Panel16.Visible:=false;
  ShellExecute(Handle, 'open',PChar(FFName),'', '', SW_SHOWNORMAL);
end;

procedure TfrmMLMangeTJ.cxButton4Click(Sender: TObject);
begin
  frmMLManage_LRTJDY:=TfrmMLManage_LRTJDY.Create(self);
  with frmMLManage_LRTJDY do
  begin
    FCYID:=Trim(Self.CDS_Main.fieldbyname('MLID').AsString);
    FGYName:='烫金';
    formid:='3';
    if ShowModal=1 then
    begin

    end;
    free;
  end;
  panel2.Visible:=false;
end;

end.


