unit U_SLT_TP;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,U_SLT,
  cxControls, cxContainer, cxEdit, cxImage, ExtCtrls, Dialogs,jpeg,ShellAPI,ADODB,
  IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdFTP, DB,
  StdCtrls;

type
  TfrmSLT_TP = class(TFrame)
    IdFTP1: TIdFTP;
    ODPat: TOpenDialog;
    SaveDialog1: TSaveDialog;
    adoqueryPicture: TADOQuery;
    Panelq: TPanel;
    Panel0: TPanel;
    Label1: TLabel;
    WBID: TEdit;
    Label6: TLabel;
    Label7: TLabel;
    Label10: TLabel;
    SKName: TEdit;
    SKWZ: TEdit;
    SKCode: TEdit;
    Label2: TLabel;
    SKNote: TMemo;
    Button2: TButton;
    ADOQuery1: TADOQuery;
    ADOQuery2: TADOQuery;
    Label3: TLabel;
    SKCodeOld: TEdit;
    Panel2: TPanel;
    cxImage1: TcxImage;
    Label4: TLabel;
    Panel3: TPanel;
    SKID: TEdit;
    Button4: TButton;
    CPID: TEdit;
    Panel4: TPanel;
    Label5: TLabel;
    Button1: TButton;
    Button3: TButton;
    ADOQuery3: TADOQuery;
    ScrollBox2: TScrollBox;
    Button5: TButton;
    procedure cxImage1DblClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
  private
    CYID,FileName:string;
    procedure initImage1();
  //   procedure Sharpen(SrcBmp:TBitmap);
    { Private declarations }
  public
    FMXCPID:string;
    procedure Init(fCYID:string;fFileName:string;fPicture:TJpegImage);
    { Public declarations }
  end;
var
    Mach: array of TfrmSlt;

implementation
uses
  U_DataLink, U_FileUp_TPSH,U_Fun,U_FileUp_TP;
{$R *.dfm}


procedure TfrmSLT_TP.Init(fCYID:string;fFileName:string;fPicture:TJpegImage);
begin
  CYID:=trim(fCYID);
  FileName:=trim(fFileName);
  //Panel1.Caption:=FileName;
  cxImage1.Picture.Assign(fPicture);
end;
procedure TfrmSLT_TP.cxImage1DblClick(Sender: TObject);
var
  IdFTP1: TIdFTP;
  FPath,FFName:string;
  FInt:integer;
begin
  try
    IdFTP1:=TIdFTP.Create(self);
    IdFTP1.Host :=PicSvr;
    IdFTP1.Username := 'three';
    IdFTP1.Password := '641010';
    IdFTP1.Connect();
  except
    IdFTP1.Quit;
    IdFTP1.Free;
    Application.MessageBox('无法连接到文件服务器，请检查！', '提示', MB_ICONWARNING);
    Exit;
  end;
  FPath:='D:\Right1209\';
  if not DirectoryExists(ExtractFileDir(FPath)) then
    CreateDir(ExtractFileDir(FPath));
  FFName:=Trim(FileName);
  FFName:=FPath+FFName;
  deleteFile(FFName);
 { if FileExists(FFName) then
  begin
    FInt:=1;
  end;
  if FInt<>1 then }
  IdFTP1.Get(UserDataFlag+'YP\'+FileName,FFName);
  if IdFTP1.Connected then
  begin
    IdFTP1.Quit;
    IdFTP1.Free;
  end;
  try

    ShellExecute(Handle, 'open',PChar(FFName),'', '', SW_SHOWNORMAL);
  except
  end;

end;

procedure TfrmSLT_TP.initImage1();
begin

end;

procedure TfrmSLT_TP.Button1Click(Sender: TObject);
begin
  panel0.SetFocus;
  try
    frmFileUp_TPSH:=TfrmFileUp_TPSH.Create(Application);
    with frmFileUp_TPSH do
    begin
      Code.Text:=Trim(Self.Name);   //色卡的SKID
      CYID:=Trim(Self.Name);
      if ShowModal=1 then
      begin
        
      end;
    end;
  finally
    frmFileUp_TPSH.Free;
  end;
end;

procedure TfrmSLT_TP.Button2Click(Sender: TObject);
var maxno:string;
begin
  if SKCode.Text='' then
  begin
    application.MessageBox('色卡编号不能为空','提示');
    exit;
  end;
  with ADOQuery1 do
  begin
    close;
    sql.Clear;
    sql.Add('select * from SK_Base where WBID='''+trim(WBID.Text)+'''');
    open;
  end;
  with ADOQuery1 do
  begin
    if IsEmpty then
    begin
      if GetLSNo(ADOQuery2,MaxNo,'SK','SK_Base',4,1)=False then
      begin
        Application.MessageBox('取图片最大号失败！','提示',0);
        Exit;
      end;
      Append;
      FieldByName('SKID').Value:=Trim(MaxNo);
      FieldByName('filler').Value:=Trim(DName);
      FieldByName('Valid').Value:='Y';
    end
    else
    begin
      edit;
      FieldByName('editer').Value:=Trim(DName);
      FieldByName('Edittime').Value:=now;
    end;
    RTSetsavedata(ADOQuery1,'SK_Base',Self.Panel0,2);
    post;
  end;
  Application.MessageBox('保存成功','提示');
end;

procedure TfrmSLT_TP.Button4Click(Sender: TObject);
var
  max:string;
begin
  try
    frmFileUp_TP:=TfrmFileUp_TP.Create(Application);
    with frmFileUp_TP do
    begin
      if GetLSNo(ADOQuery3,max,'YP','XD_File_TP',4,1)=False then
      begin
        Application.MessageBox('取图片最大号失败！','提示',0);
        Exit;
      end;
      Code.Text:=Trim(Self.CPID.Text);
      CYID:=Trim(max);
      FSKID:=Trim(self.SKID.Text);
      if ShowModal=1 then
      begin
        Self.WBID.Text:=Trim(CYID);
        with ADOQuery1 do
        begin
          close;
          sql.Clear;
          sql.Add('update SK_Base set WBID='''+trim(CYID)+''' ');
          sql.Add('where SKID='''+trim(SKID.Text)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally;
    frmFileUp_TP.Free;
  end;
end;

procedure TfrmSLT_TP.Button3Click(Sender: TObject);
var
  maxno:string;
  j,i:Integer;
begin
  with ScrollBox2 do
  begin
    for i:=0 to ScrollBox2.ControlCount-1 do
    begin
      if Controls[i] is TfrmSLT then
      begin
        with TfrmSLT(Controls[i]).Panel1 do
        begin
          for j:=0 to ControlCount-1 do
          begin
            if Controls[j] is TButton then
            begin
              TButton(Controls[j]).Click;
            end;
          end;
        end;
      end;
    end;
  end;
  Application.MessageBox('保存成功','提示');
  {j:=length(Mach1);
  IF j>0 then
  begin
    for i:=0 to 98 do
    begin
      for j:=0 to 98 do
      begin
        with Mach1[i,j] do
        begin
          if ColorNo.Text='' then
          begin
            application.MessageBox('色号不能为空','提示');
            exit;
          end;
          with ADOQuery1 do
          begin
            close;
            sql.Clear;
            sql.Add('select * from SH_Base where WBID='''+trim(WBID.Text)+'''');
            open;
          end;
          with ADOQuery1 do
          begin
            if IsEmpty then
            begin
              if GetLSNo(ADOQuery2,MaxNo,'SH','SH_Base',4,1)=False then
              begin
                Application.MessageBox('取图片最大号失败！','提示',0);
                Exit;
              end;
              Append;
              FieldByName('SHID').Value:=Trim(MaxNo);
              FieldByName('SKID').Value:=Trim(SKID);
              FieldByName('filler').Value:=Trim(DName);
              FieldByName('Valid').Value:='Y';
            end
            else
            begin
              edit;
              FieldByName('editer').Value:=Trim(DName);
              FieldByName('Edittime').Value:=now;
            end;
            RTSetsavedata(ADOQuery1,'SH_Base',Self.Panel1,2);
            post;
          end;
        end;
      end;
    end;
  end;
  Application.MessageBox('保存成功','提示'); }
end;

procedure TfrmSLT_TP.Button5Click(Sender: TObject);
begin
  with ADOQuery1 do
  begin
    close;
    sql.Clear;
    sql.Add('delete from SK_Base where SKID='''+trim(self.Name)+'''');
    sql.Add('delete from SH_Base where SKID='''+trim(self.Name)+'''');
    sql.Add('delete from XD_File where CYNO='''+trim(self.Name)+'''');
    sql.Add('delete from XD_File_TP where CYID='''+trim(self.WBID.Text)+'''');
    //sql.Add('delete from TP_File where WBID='''+trim(WBID.Text)+'''');
    sql.Add('delete from TP_File_TP where WBID='''+trim(self.WBID.Text)+'''');
    ExecSQL;
  end;
  Self.Visible:=false;
end;

end.
