unit u_info_rules; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, ADODB, dxExEdtr, bsSkinCtrls, ExtCtrls, dxDBTLCl, dxGrClms, dxDBCtrl, dxDBGrid, dxTL, dxCntner, StdCtrls, ComCtrls, DBCtrls,shellapi, wwdbdatetimepicker, bsdbctrls, Mask, Grids, DBGridEh, Menus; type Tfrm_info_rules = class(TForm) bsSkinPanel1: TbsSkinPanel; bsSkinPanel2: TbsSkinPanel; Label1: TLabel; DBEdit1: TDBEdit; DBRichEdit1: TDBRichEdit; dxDBGrid1: TdxDBGrid; Panel1: TPanel; bsSkinButton7: TbsSkinButton; bsSkinButton6: TbsSkinButton; bsSkinButton1: TbsSkinButton; bsSkinButton4: TbsSkinButton; bsSkinButton3: TbsSkinButton; bsSkinButton5: TbsSkinButton; bsSkinButton8: TbsSkinButton; t_info_rules: TADOQuery; t_info_rules1: TDataSource; dxDBGrid1Column1: TdxDBGridMaskColumn; dxDBGrid1Column2: TdxDBGridMaskColumn; dxDBGrid1Column3: TdxDBGridDateColumn; bsSkinPanel3: TbsSkinPanel; Splitter1: TSplitter; bsSkinButton2: TbsSkinButton; bsSkinButton9: TbsSkinButton; bsSkinButton11: TbsSkinButton; dxDBGrid2: TdxDBGrid; dsrFuJian: TDataSource; SaveDialog1: TSaveDialog; OpenDialog1: TOpenDialog; t_info_file: TADOQuery; dxDBGrid2fid: TdxDBGridMaskColumn; dxDBGrid2rl_id: TdxDBGridMaskColumn; dxDBGrid2Column3: TdxDBGridColumn; dxDBGrid2Column5: TdxDBGridColumn; dxDBGrid2Column6: TdxDBGridDateColumn; dxDBGrid2Column7: TdxDBGridColumn; dxDBGrid2Column8: TdxDBGridColumn; dxDBGrid2Column4: TdxDBGridColumn; ProgressBar1: TProgressBar; bsSkinButton10: TbsSkinButton; qrytmp: TADOQuery; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormShow(Sender: TObject); procedure bsSkinButton5Click(Sender: TObject); procedure bsSkinButton7Click(Sender: TObject); procedure bsSkinButton6Click(Sender: TObject); procedure bsSkinButton8Click(Sender: TObject); procedure bsSkinButton4Click(Sender: TObject); procedure bsSkinButton3Click(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); procedure t_info_rulesAfterInsert(DataSet: TDataSet); procedure t_info_rulesBeforePost(DataSet: TDataSet); procedure t_info_rulesBeforeEdit(DataSet: TDataSet); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure FormResize(Sender: TObject); procedure DBEdit1KeyPress(Sender: TObject; var Key: Char); procedure dxDBGrid1ColumnSorting(Sender: TObject; Column: TdxDBTreeListColumn; var Allow: Boolean); procedure bsSkinButton2Click(Sender: TObject); procedure bsSkinButton9Click(Sender: TObject); procedure bsSkinButton11Click(Sender: TObject); procedure bsSkinButton10Click(Sender: TObject); procedure t_info_fileBeforeEdit(DataSet: TDataSet); procedure dxDBGrid2Exit(Sender: TObject); private { Private declarations } procedure UpLoadPro(fname:string); //fname包含完整路径、文件名 procedure DownLoadPro(fname:string); //从数据库的表中下载 public { Public declarations } end; var frm_info_rules: Tfrm_info_rules; implementation uses u_main, my_sys_function; {$R *.dfm} procedure Tfrm_info_rules.FormClose(Sender: TObject; var Action: TCloseAction); begin frm_info_rules.Hide; frm_info_rules.ManualFloat(frm_info_rules.BoundsRect ); frm_main.freeTabs('frm_info_rules'); action:=cafree; frm_info_rules:=nil; end; procedure Tfrm_info_rules.FormShow(Sender: TObject); begin with t_info_rules,sql do begin close ;clear ; add('select * from t_info_rules '); add('where 录入人='+''''+employee+''' or ') ; add(open_data('9003','录入人','no','no','no','no')) ; Open; end ; t_info_file.Open ; ProgressBar1.SendToBack ; ProgressBar1.Visible:=false ; end; procedure Tfrm_info_rules.bsSkinButton5Click(Sender: TObject); begin close; end; procedure Tfrm_info_rules.bsSkinButton7Click(Sender: TObject); begin table_Prior(t_info_rules); end; procedure Tfrm_info_rules.bsSkinButton6Click(Sender: TObject); begin table_next(t_info_rules); end; procedure Tfrm_info_rules.bsSkinButton8Click(Sender: TObject); begin table_post(t_info_rules); if t_info_file.State in [dsedit,dsinsert] then t_info_file.post ; end; procedure Tfrm_info_rules.bsSkinButton4Click(Sender: TObject); begin if t_info_rules.isempty then exit; if not if_open('241') then begin showmessage('对不起你没有此模块的操作权限!'); exit; end; if do_data('9003',t_info_rules.fieldbyname('录入人').asstring,'','','','','')=false then begin showmessage('对不起你无权删除此数据!!'); abort; end; if application.MessageBox('您确定要删除数据吗?','警告:',MB_OKCANCEL)=IDOK then begin with qrytmp,sql do //删除从表 begin close ; clear ; add('delete from t_info_rulls_file where rl_id=:rlid'); parameters.ParamByName('rlid').Value:=t_info_rules.fieldbyname('rl_id').value ; execsql ; end ; t_info_rules.delete; end ; // table_delete(t_info_rules); end; procedure Tfrm_info_rules.bsSkinButton3Click(Sender: TObject); begin table_cancel(t_info_rules); end; procedure Tfrm_info_rules.bsSkinButton1Click(Sender: TObject); begin if not if_open('239') then begin showmessage('对不起你没有此模块的操作权限!'); exit; end; t_info_rules.insert; end; procedure Tfrm_info_rules.t_info_rulesAfterInsert(DataSet: TDataSet); begin t_info_rules['录入日期']:=date; t_info_rules['录入人']:=employee; DBEdit1.SetFocus; end; procedure Tfrm_info_rules.t_info_rulesBeforePost(DataSet: TDataSet); begin table_before_post(t_info_rules,'规章制度'); table_before_post(t_info_rules,'内容'); end; procedure Tfrm_info_rules.t_info_rulesBeforeEdit(DataSet: TDataSet); begin if do_data('9003',t_info_rules.fieldbyname('录入人').asstring,'','','','','')=false then begin showmessage('对不起,你无权修改!!'); abort; end; end; procedure Tfrm_info_rules.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin CanClose:=close_query(t_info_rules); end; procedure Tfrm_info_rules.FormResize(Sender: TObject); var i:integer; begin i:=round(panel1.Width/7); bsSkinButton7.Width:=i; bsSkinButton8.Width:=i; bsSkinButton6.Width:=i; bsSkinButton1.Width:=i; bsSkinButton4.Width:=i; bsSkinButton3.Width:=i; DBEdit1.Width:=bsSkinPanel2.Width-DBEdit1.Left-6; end; procedure Tfrm_info_rules.DBEdit1KeyPress(Sender: TObject; var Key: Char); begin if key=#13 then begin key:=#0; DBRichEdit1.SetFocus; end; end; procedure Tfrm_info_rules.dxDBGrid1ColumnSorting(Sender: TObject; Column: TdxDBTreeListColumn; var Allow: Boolean); begin Column_sort(Column,t_info_rules,'规章制度'); end; procedure Tfrm_info_rules.UpLoadPro(fname:string); const BufSize=$F000; var Counter, N: Integer; Buffer: PAnsiChar; FieldStrm: TStream; ExeFileStream:TFileStream; size_tmp: Double; filename,fileExt:string ; begin ProgressBar1.BringToFront ; ProgressBar1.Visible:=true ; filename:=ExtractFileName(fname) ; fileExt:=ExtractFileExt(filename) ; with t_info_file do begin Open; append; try ExeFileStream:=TFileStream.Create(fname,fmopenRead); //打开文件 FieldStrm := CreateBlobStream(FieldByName('内容'),bmWrite); GetMem(Buffer,BufSize); try Counter := ExeFileStream.Size; size_tmp :=ExeFileStream.Size; ProgressBar1.Position := 0; ProgressBar1.Max := Counter div BufSize; //每次上传文件流为61440 byte=$F000 while Counter<>0 do begin if Counter>BufSize then N :=BufSize else N:=Counter; ExeFileStream.ReadBuffer(Buffer^,N); FieldStrm.WriteBuffer(Buffer^, N); Dec(Counter, N); ProgressBar1.Position :=ProgressBar1.Position+1; // Application.ProcessMessages; end; finally FreeMem(Buffer,BufSize); FieldStrm.Free; end; FieldByName('名称').AsString:=filename; FieldByName('大小').AsFloat:=size_tmp; FieldByName('上传日期').AsDateTime:=now(); FieldByName('所有者').Asstring:=employee; FieldByName('类型').Asstring:=fileExt; Post; ProgressBar1.SendToBack ; ProgressBar1.Visible:=false ; Application.MessageBox('程序上传至服务器成功!','提示',MB_OK+MB_IconInformation); finally ProgressBar1.Position:=ProgressBar1.Max; ExeFileStream.Free; end; end; end ; procedure Tfrm_info_rules.DownLoadPro(fname:string) ; //从数据库的表中下载 const MaxBufSize=$F000; var myfilename:string;//保存文件的路径和文件名 myfileStream,exeBlobStream:TStream; Count,BufSize,N: Integer; Buffer:PChar; begin ProgressBar1.BringToFront ; ProgressBar1.Visible:=true ; myfilename:=FName ; with t_info_file do begin myfilename:=myfilename ; //+fieldbyname('类型').asstring ; myfileStream :=TFileStream.Create(myfilename,fmCreate);//创建文件 try //SaveToStream(Stream); ExeBlobStream:=CreateBlobStream(FieldByName('内容'),bmRead); //从数据库中取得记录 Count:=0; try if Count=0 then begin ExeBlobStream.Position:=0; Count:=ExeBlobStream.Size;//showmessage(inttostr(count)); end; if Count>MaxBufSize then BufSize:=MaxBufSize else BufSize:=Count; GetMem(Buffer,BufSize); ProgressBar1.Position:=0; ProgressBar1.Max:=count div bufsize;//每次写入文件的数据流大小为bufsize,所以max为count 除以 bufsize try while Count<>0 do begin if Count>BufSize then N:=BufSize else N:=Count; ExeBlobStream.ReadBuffer(Buffer^,N);//从数据库表中取数据流 MyFileStream.WriteBuffer(Buffer^,N);//将数据流写入文件 Dec(Count,N); ProgressBar1.Position:=ProgressBar1.Position+1; end; finally FreeMem(Buffer,BufSize); end; finally ExeBlobStream.Free; end; finally myfileStream.Free; end; end; ProgressBar1.Visible:=false ; ProgressBar1.SendToBack ; // MessageBox(Handle,pchar('下载成功'),'信息',MB_ICONINFORMATION); end; procedure Tfrm_info_rules.bsSkinButton2Click(Sender: TObject); begin if not if_open('239') then begin showmessage('对不起你没有此模块的操作权限!'); exit; end; if t_info_rules.State in [dsedit,dsinsert] then t_info_rules.Post ; if OpenDialog1.Execute then UpLoadPro(Opendialog1.FileName) else exit ; end; procedure Tfrm_info_rules.bsSkinButton9Click(Sender: TObject); begin if SaveDialog1.Execute then DownLoadPro(Savedialog1.FileName+t_info_file.fieldbyname('类型').asstring) else exit ; end; procedure Tfrm_info_rules.bsSkinButton11Click(Sender: TObject); var arr: array[0..MAX_PATH] of Char; num: DWORD; tmpfile:string ; begin try GetTempPath(MAX_PATH, arr); tmpfile:=arr+t_info_file.fieldbyname('名称').asstring ; DownLoadPro(tmpfile) ; ShellExecute(Handle, nil, pchar(tmpfile), nil, nil, SW_NORMAL); if ProgressBar1.Visible then begin ProgressBar1.Visible:=false ; ProgressBar1.SendToBack ; end ; except showmessage('不能打开文件,请检查网络连接等错误!'); end ; end; procedure Tfrm_info_rules.bsSkinButton10Click(Sender: TObject); begin if not if_open('241') then begin showmessage('对不起你没有此模块的操作权限!'); exit; end; if do_data('9003',t_info_file.fieldbyname('所有者').asstring,'','','','','')=false then begin showmessage('对不起你无权删除此数据!!'); abort; end; if t_info_rules.State in [dsedit,dsinsert] then t_info_rules.post ; if application.MessageBox('您确定要删除附件吗?','警告:',MB_OKCANCEL)=IDOK then t_info_file.delete ; end; procedure Tfrm_info_rules.t_info_fileBeforeEdit(DataSet: TDataSet); begin if t_info_file.FieldByName('所有者').asstring<>employee then begin showmessage('对不起,您不是所有者,无权修改!'); abort ; end ; end; procedure Tfrm_info_rules.dxDBGrid2Exit(Sender: TObject); begin if t_info_file.state in [dsedit,dsinsert] then t_info_file.post ; end; end.