unit U_SHBase;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, ToolWin, ComCtrls,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGridLevel,
  cxClasses, cxControls, cxGridCustomView, cxGrid, DBClient, ADODB, ImgList,
  StdCtrls, ExtCtrls, cxTextEdit, cxGridCustomPopupMenu, cxGridPopupMenu,
  cxButtonEdit,jpeg,U_SLT,Math, Menus, cxCalendar;

type
  TfrmSHBase = class(TForm)
    ToolBar1: TToolBar;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DataSource1: TDataSource;
    ClientDataSet1: TClientDataSet;
    TBAdd: TToolButton;
    TBSave: TToolButton;
    TBDel: TToolButton;
    TBClose: TToolButton;
    ToolButton1: TToolButton;
    TBEdit: TToolButton;
    ADOConnection1: TADOConnection;
    Panel1: TPanel;
    Label1: TLabel;
    BPName: TEdit;
    ThreeImgList: TImageList;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label2: TLabel;
    BPCode: TEdit;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DataSource2: TDataSource;
    ML_GYS: TClientDataSet;
    Panel2: TPanel;
    ToolBar2: TToolBar;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    V2BPSeHao: TcxGridDBColumn;
    V2BPCol: TcxGridDBColumn;
    V2BPColEng: TcxGridDBColumn;
    V2BPNote: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    V2IFTP: TcxGridDBColumn;
    GroupBox1: TGroupBox;
    ScrollBox1: TScrollBox;
    adoqueryPicture: TADOQuery;
    Panel3: TPanel;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    V1BPCode: TcxGridDBColumn;
    V1BPName: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    GroupBox2: TGroupBox;
    ScrollBox2: TScrollBox;
    V1IFTP: TcxGridDBColumn;
    V1BPMiDu: TcxGridDBColumn;
    Label3: TLabel;
    BPMiDu: TEdit;
    V1Column1: TcxGridDBColumn;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBAddClick(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TV1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure V1NamePropertiesEditValueChanged(Sender: TObject);
    procedure V1NotePropertiesEditValueChanged(Sender: TObject);
    procedure V1Column1PropertiesEditValueChanged(Sender: TObject);
    procedure V1HelpTypePropertiesEditValueChanged(Sender: TObject);
    procedure v1note1PropertiesEditValueChanged(Sender: TObject);
    procedure V1BPCodePropertiesEditValueChanged(Sender: TObject);
    procedure V1BPNamePropertiesEditValueChanged(Sender: TObject);
    procedure V1BPUnitPropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure BPCodeChange(Sender: TObject);
    procedure BPNameChange(Sender: TObject);
    procedure TV2CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TV1FocusedRecordChanged(Sender: TcxCustomGridTableView;
      APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
    procedure V1IFTPPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure V2IFTPPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure TV1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private
    procedure InitGrid();
    procedure SaveData();
    procedure InitImage();
    procedure InitImage1();
    { Private declarations }
  public
    flag,flagname,snote,MainType,FInt:string;
    fnote,fnote1,forderno,fZdyFlag,ViewFlag,fHelpType:Boolean;
    PPSTE:integer;
    { Public declarations }
  end;
var
  frmSHBase: TfrmSHBase;
  Mach: array of TfrmSlt;

implementation
uses
  U_DataLink,U_Fun10,U_FileUp;

{$R *.dfm}
procedure TfrmSHBase.SaveData();
var maxno:string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    ClientDataSet1.DisableControls;
    with ClientDataSet1 do
    begin
      First;
      while not eof do
      begin
        if Trim(ClientDataSet1.FieldByName('BPID').AsString)='' then
        begin
          if GetLSNo(ADOQueryTemp,maxno,'BP','BP_ZDY',3,1)=False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            ClientDataSet1.EnableControls;
            Application.MessageBox('取最大编号失败！','提示',0);
            Exit;
          end;
        end
        else
        begin
          maxno:=Trim(ClientDataSet1.fieldbyname('BPID').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from BP_ZDY where BPID='''+Trim(maxno)+'''');
          Open;
        end;
        if ADOQueryCmd.IsEmpty then
        begin
          ADOQueryCmd.Append;
        end
        else
        begin
          ADOQueryCmd.edit;
        end;
        ADOQueryCmd.FieldByName('BPID').Value:=Trim(maxno);
        SSetSaveDataCDSNew(ADOQueryCmd,Tv1,ClientDataSet1,'BP_ZDY',3);
        ADOQueryCmd.FieldByName('BPType').Value:=flagName;
        ADOQueryCmd.FieldByName('BPFlag').Value:=flag;
        ADOQueryCmd.FieldByName('valid').Value:='Y';
        ADOQueryCmd.Post;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.add('select * from BP_ZDY where BPCode='''+Trim(ClientDataSet1.fieldbyname('BPCode').AsString)+'''');
          Open;
        end;
        if ADOQueryTemp.IsEmpty=False then
        begin
          if ADOQueryTemp.RecordCount>1 then
          begin
            with ADOQueryCmd do
            begin
              Close;
              sql.Clear;
              SQL.Add('delete BP_ZDY where BPID='''+Trim(ClientDataSet1.fieldbyname('BPID').AsString)+'''');
              ExecSQL;
            end;
            ADOQueryCmd.Connection.RollbackTrans;
            ClientDataSet1.EnableControls;
            Application.MessageBox('大类编号重复！','提示',0);
            Exit;
          end;
        end;
        ClientDataSet1.Edit;
        ClientDataSet1.FieldByName('BPID').Value:=Trim(maxno);
        //ClientDataSet1.Post;
        Next;
      end;
      ClientDataSet1.EnableControls;
    end;
    TV1.OptionsData.Editing:=false;
    TV1.OptionsSelection.CellSelect:=false;
    ADOQueryCmd.Connection.CommitTrans;
  except;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmSHBase.FormCreate(Sender: TObject);
begin
  try
    //cxGrid1.Align:=alClient;
    with ADOConnection1 do
    begin
      Connected:=false;
      ConnectionString:=DConString;
      //ConnectionString:='';
      Connected:=true;
    end;
  except;
    frmSHBase.Free;
  end;
end;

procedure TfrmSHBase.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  ToolBar1.SetFocus;
  if ClientDataSet1.IsEmpty then exit;
  if FInt<>'1' then
  SaveData();
  Action:=caFree;
end;

procedure TfrmSHBase.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.*');
      sql.Add(',IFTP=(case when isnull((select Top 1 B.CYID from XD_File B where B.CYID=A.BPID),'''')='''' then '''' else ''是'' end)');
      sql.add(' from BP_ZDY A where A.BPFlag='''+trim(flag)+'''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,ClientDataSet1);
    SInitCDSData20(ADOQueryMain,ClientDataSet1);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmSHBase.TBAddClick(Sender: TObject);
var
  i:Integer;
begin
  toolbar1.SetFocus;
  TV1.OptionsData.Editing:=True;
  TV1.OptionsSelection.CellSelect:=True;
  with ClientDataSet1 do
  begin
    Append;
    Post;
  end;
end;

procedure TfrmSHBase.TBSaveClick(Sender: TObject);
var
  maxno:string;
begin
  if ClientDataSet1.IsEmpty then Exit;
  Toolbar1.SetFocus;
  if ClientDataSet1.Locate('BPCode',null,[]) then
  begin
    Application.MessageBox('编号不能为空！','提示',0);
    Exit;
  end;
  if ClientDataSet1.Locate('BPCode','',[]) then
  begin
    Application.MessageBox('编号不能为空！','提示',0);
    Exit;
  end;
  if ClientDataSet1.Locate('BPName',null,[]) then
  begin
    Application.MessageBox('名称不能为空！','提示',0);
    Exit;
  end;
  if ClientDataSet1.Locate('BPName','',[]) then
  begin
    Application.MessageBox('名称不能为空！','提示',0);
    Exit;
  end;
  SaveData();
  Application.MessageBox('保存成功！','提示',0);
end;

procedure TfrmSHBase.TBDelClick(Sender: TObject);
begin
  ToolBar1.SetFocus;
  if ClientDataSet1.IsEmpty then Exit;
  if Trim(ClientDataSet1.FieldByName('BPID').AsString)<>'' then
  begin
    if application.MessageBox('确定要删除吗?','提示信息',1)=2 then exit;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete BP_ZDY where BPID='''+Trim(ClientDataSet1.fieldbyname('BPID').AsString)+'''');
      ExecSQL;
    end;
  end;
  ClientDataSet1.Delete;
end;

procedure TfrmSHBase.TBCloseClick(Sender: TObject);
begin
  ToolBar1.SetFocus;
  WriteCxGrid('自定义'+Trim(flag),TV1,'自定义数据');
  WriteCxGrid('自定义'+Trim(flag)+'1',TV2,'自定义数据');
  Close;
end;

procedure TfrmSHBase.FormShow(Sender: TObject);
begin
  InitGrid();
  ReadCxGrid('自定义'+Trim(flag),TV1,'自定义数据');
  ReadCxGrid('自定义'+Trim(flag)+'1',TV2,'自定义数据');
  frmSHBase.Caption:=Trim(flagname);
  if ViewFlag=True then
  begin
    TBAdd.Visible:=False;
    TBSave.Visible:=False;
    TBDel.Visible:=False;
    TBEdit.Visible:=False;
    ToolButton1.Visible:=true;
    ToolBar2.Visible:=false;
  end;
end;

procedure TfrmSHBase.ToolButton1Click(Sender: TObject);
begin
  ToolBar1.SetFocus;
  FInt:='1';
  ModalResult:=1;
end;

procedure TfrmSHBase.TBEditClick(Sender: TObject);
begin
  ToolBar1.SetFocus;
  TV1.OptionsData.Editing:=True;
  TV1.OptionsSelection.CellSelect:=True;
end;

procedure TfrmSHBase.TV1CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if ToolButton1.Visible=true then
  begin
    Fint:='1';
    ModalResult:=1;
  end;
end;

procedure TfrmSHBase.V1NamePropertiesEditValueChanged(Sender: TObject);
var
  maxno,mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPMF').Value:=Trim(mvalue);
    //Post;
  end;
end;

procedure TfrmSHBase.V1NotePropertiesEditValueChanged(Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPKZ').Value:=mvalue;
    //Post;
  end;
end;

procedure TfrmSHBase.V1Column1PropertiesEditValueChanged(Sender: TObject);
var
  mvalue:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  if Trim(mvalue)='' then
  begin
    mvalue:='0';
  end;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPJS').Value:=StrToInt(mvalue);
    //Post;
  end;
  {with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('Update KH_Zdy Set ZdyFlag='+Trim(mvalue));
    sql.Add(' where ZdyNo='''+Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString)+'''');
    ExecSQL;
  end; }
end;

procedure TfrmSHBase.V1HelpTypePropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPWS').Value:=mvalue;
    Post;
  end;
  {with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('Update KH_Zdy Set HelpType='''+Trim(mvalue)+'''');
    sql.Add(' where ZdyNo='''+Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString)+'''');
    ExecSQL;
  end;}
end;

procedure TfrmSHBase.v1note1PropertiesEditValueChanged(Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPMiDu').Value:=mvalue;
    Post;
  end;
end;

procedure TfrmSHBase.V1BPCodePropertiesEditValueChanged(Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPCode').Value:=mvalue;
  end;
  {with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('Update BP_ZDY Set BPCode='''+Trim(mvalue)+'''');
    sql.Add(' where BPID='''+Trim(ClientDataSet1.fieldbyname('BPID').AsString)+'''');
    ExecSQL;
  end;}
end;

procedure TfrmSHBase.V1BPNamePropertiesEditValueChanged(Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPName').Value:=mvalue;
  end;
end;

procedure TfrmSHBase.V1BPUnitPropertiesEditValueChanged(Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPUnit').Value:=mvalue;
    //Post;
  end;
  {with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('Update BP_ZDY Set BPUnit='+mvalue);
    sql.Add(' where BPID='''+Trim(ClientDataSet1.fieldbyname('BPID').AsString)+'''');
    ExecSQL;
  end; }
end;

procedure TfrmSHBase.ToolButton4Click(Sender: TObject);
begin
  ToolBar1.SetFocus;
  if ClientDataSet1.IsEmpty then exit;
  if ClientDataSet1.FieldByName('BPID').AsString='' then
  begin
    application.MessageBox('请保存主信息','提示');
    exit;
  end;
  with ML_GYS do
  begin
    Append;
    post;
  end;
end;

procedure TfrmSHBase.ToolButton5Click(Sender: TObject);
begin
  ToolBar1.SetFocus;
  if ML_GYS.IsEmpty then Exit;
  if Trim(ML_GYS.FieldByName('BPSubID').AsString)<>'' then
  begin
    if application.MessageBox('确定要删除吗?','提示信息',1)=2 then exit;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete BP_ZDY_Sub where BPSubID='''+Trim(ML_GYS.fieldbyname('BPSubID').AsString)+'''');
      ExecSQL;
    end;
  end;
  ML_GYS.Delete;
end;

procedure TfrmSHBase.ToolButton3Click(Sender: TObject);
  var maxno:string;
begin
  ToolBar1.SetFocus;
  try
    ADOQueryCmd.Connection.BeginTrans;
    ML_GYS.DisableControls;
    with ML_GYS do
    begin
      First;
      while not eof do
      begin
        if Trim(ML_GYS.FieldByName('BPSubID').AsString)='' then
        begin
          if GetLSNo(ADOQueryTemp,maxno,'BS','BP_ZDY_Sub',3,1)=False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            ML_GYS.EnableControls;
            Application.MessageBox('取最大编号失败！','提示',0);
            Exit;
          end;
        end
        else
        begin
          maxno:=Trim(ML_GYS.fieldbyname('BPSubID').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from BP_ZDY_Sub where BPSubID='''+Trim(maxno)+'''');
          Open;
        end;
        if ADOQueryCmd.IsEmpty then
        begin
          ADOQueryCmd.Append;
        end
        else
        begin
          ADOQueryCmd.edit;
        end;
        ADOQueryCmd.FieldByName('BPSubID').Value:=Trim(maxno);
        ADOQueryCmd.FieldByName('BPCode').Value:=Trim(ClientDataSet1.fieldbyname('BPCode').AsString);
        ADOQueryCmd.FieldByName('BPID').Value:=Trim(ClientDataSet1.fieldbyname('BPID').AsString);
        SSetSaveDataCDSNew(ADOQueryCmd,Tv2,ML_GYS,'BP_ZDY_Sub',1);
        ADOQueryCmd.FieldByName('BPType').Value:=flagName;
        ADOQueryCmd.FieldByName('BPFlag').Value:=flag;
        ADOQueryCmd.FieldByName('valid').Value:='Y';
        ADOQueryCmd.Post;
        ML_GYS.Edit;
        ML_GYS.FieldByName('BPSubID').Value:=Trim(maxno);
        Next;
      end;
      ML_GYS.EnableControls;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Application.MessageBox('保存成功！','提示',0);
  except;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmSHBase.BPCodeChange(Sender: TObject);
var
  fsj:String;
begin
  if Trim(BPCode.Text)<>'' then
  begin
    fsj:=' BPCode like '''+'%'+Trim(BPCode.Text)+'%'+'''';
  end;
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,fsj);
    SCreateCDS20(ADOQueryMain,ClientDataSet1);
    SInitCDSData20(ADOQueryMain,ClientDataSet1);
  end;
end;

procedure TfrmSHBase.BPNameChange(Sender: TObject);
var
  fsj:String;
begin
  if Trim(BPName.Text)<>'' then
  begin
    fsj:=' BPName like '''+'%'+Trim(BPName.Text)+'%'+'''';
  end;
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,fsj);
    SCreateCDS20(ADOQueryMain,ClientDataSet1);
    SInitCDSData20(ADOQueryMain,ClientDataSet1);
  end;
end;

procedure TfrmSHBase.InitImage1();
var
  i,j:integer;
  jpg:TJpegImage;
  myStream: TADOBlobStream;
begin
  j:=length(Mach);
  if j>0 then
  begin
    for i:=0 to j-1 do
    begin
      Mach[i].free;
    end;
  end; 
  SetLength(Mach, 0);
  try
    with adoqueryPicture do
    begin
      close;
      sql.Clear;
      sql.Add(' select A.TFID,A.WBID,A.FilesOther,B.FileName from TP_File A,XD_File B ');
      SQL.Add('where A.TFID=B.XFID and B.CYID='+quotedstr(trim(ClientDataSet1.fieldbyname('BPID').AsString)));
      //ShowMessage(SQL.Text);
      open;
    end;
    j:=adoqueryPicture.RecordCount;
    if j<1 then exit;
    adoqueryPicture.DisableControls;
    adoqueryPicture.First;
    SetLength(Mach, j);
    jpg:=TJpegImage.Create();
    for i:=0 to j-1 do
    begin
      if trim(adoqueryPicture.fieldbyname('FilesOther').AsString)<>'' then
      begin
        myStream:=tadoblobstream.Create(tblobfield(adoqueryPicture.fieldbyname('FilesOther')),bmread);
        jpg.LoadFromStream(myStream);
        Mach[i]:=TfrmSlt.Create(Self);
        Mach[i].Name:=trim(adoqueryPicture.fieldbyname('TFID').AsString);
        Mach[i].Parent := ScrollBox2;
        Mach[I].Left:=0+i*165;
        Mach[i].Init(adoqueryPicture.fieldbyname('TFID').AsString,adoqueryPicture.fieldbyname('FileName').AsString,jpg);
      end;
      adoqueryPicture.Next;
    end;
     adoqueryPicture.EnableControls;
  finally
    jpg.free;
    application.ProcessMessages;
  end;
end;

procedure TfrmSHBase.InitImage();
var
  i,j:integer;
  jpg:TJpegImage;
  myStream: TADOBlobStream;
begin
  j:=length(Mach);
  if j>0 then
  begin
    for i:=0 to j-1 do
    begin
      Mach[i].free;
    end;
  end;
  SetLength(Mach, 0);
  IF ML_GYS.IsEmpty then exit;
  try
    with adoqueryPicture do
    begin
      close;
      sql.Clear;
      sql.Add(' select A.TFID,A.WBID,A.FilesOther,B.FileName from TP_File A,XD_File B ');
      SQL.Add('where A.TFID=B.XFID and B.CYID='+quotedstr(trim(ML_GYS.fieldbyname('BPSubID').AsString)));
      //ShowMessage(SQL.Text);
      open;
    end;
    j:=adoqueryPicture.RecordCount;
    if j<1 then exit;
    adoqueryPicture.DisableControls;
    adoqueryPicture.First;
    SetLength(Mach, j);
    jpg:=TJpegImage.Create();
    for i:=0 to j-1 do
    begin
      if trim(adoqueryPicture.fieldbyname('FilesOther').AsString)<>'' then
      begin
        myStream:=tadoblobstream.Create(tblobfield(adoqueryPicture.fieldbyname('FilesOther')),bmread);
        jpg.LoadFromStream(myStream);
        Mach[i]:=TfrmSlt.Create(Self);
        Mach[i].Name:=trim(adoqueryPicture.fieldbyname('TFID').AsString);
        Mach[i].Parent := ScrollBox1;
        Mach[I].Left:=0+i*165;
        Mach[i].Init(adoqueryPicture.fieldbyname('TFID').AsString,adoqueryPicture.fieldbyname('FileName').AsString,jpg);
      end;
      adoqueryPicture.Next;
    end;
     adoqueryPicture.EnableControls;
  finally
    jpg.free;
    application.ProcessMessages;
  end;
end;

procedure TfrmSHBase.TV2CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  InitImage();
end;

procedure TfrmSHBase.TV1FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.* ');
    sql.Add(',IFTP=(case when isnull((select Top 1 B.CYID from XD_File B where B.CYID=A.BPSubID),'''')='''' then '''' else ''是'' end)');
    sql.Add(' from BP_ZDY_Sub A ');
    sql.Add('where A.BPID='''+trim(ClientDataSet1.fieldbyname('BPID').AsString)+'''');
    open;
  end;
  SCreateCDS20(ADOQueryCmd,ML_GYS);
  SInitCDSData20(ADOQueryCmd,ML_GYS);
  
end;

procedure TfrmSHBase.V1IFTPPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  if Self.ClientDataSet1.fieldbyname('BPID').AsString='' then
  begin
    Application.MessageBox('请保存信息','提示');
    exit;
  end;
  try
    frmFileUp:=TfrmFileUp.Create(Application);
    with frmFileUp do
    begin
      Code.Text:=Trim(Self.ClientDataSet1.fieldbyname('BPCode').AsString);
      CYID:=Trim(Self.ClientDataSet1.fieldbyname('BPID').AsString);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmFileUp.Free;
  end;
end;

procedure TfrmSHBase.V2IFTPPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  if Self.ML_GYS.fieldbyname('BPSubID').AsString='' then
  begin
    application.MessageBox('请保存明细信息','提示');
    exit;
  end;
  try
    frmFileUp:=TfrmFileUp.Create(Application);
    with frmFileUp do
    begin
      Code.Text:=Trim(Self.ML_GYS.fieldbyname('BPSeHao').AsString);
      CYID:=Trim(Self.ML_GYS.fieldbyname('BPSubID').AsString);
      if ShowModal=1 then
      begin
       
      end;
    end;
  finally
    frmFileUp.Free;
  end;
end;

procedure TfrmSHBase.TV1CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  //InitImage1();
end;

end.


