unit u_info_shareDoc; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, dxExEdtr, DB, ADODB, StdCtrls, ComCtrls, DBCtrls, Mask,shellapi, dxDBGrid, ExtCtrls, bsSkinCtrls, dxDBTLCl, dxGrClms, dxTL, dxDBCtrl, dxCntner, ImgList, ToolWin, ActnList; type Tfrm_info_shareDoc = class(TForm) Panel1: TPanel; bsSkinButton7: TbsSkinButton; bsSkinButton6: TbsSkinButton; bsSkinButton1: TbsSkinButton; bsSkinButton4: TbsSkinButton; bsSkinButton3: TbsSkinButton; bsSkinButton5: TbsSkinButton; bsSkinButton8: TbsSkinButton; bsSkinPanel1: TbsSkinPanel; Splitter1: TSplitter; dxDBGrid2: TdxDBGrid; dxDBGrid2fid: TdxDBGridMaskColumn; dxDBGrid2rl_id: TdxDBGridMaskColumn; dxDBGrid2Column3: TdxDBGridColumn; dxDBGrid2Column4: TdxDBGridColumn; dxDBGrid2Column5: TdxDBGridColumn; dxDBGrid2Column6: TdxDBGridDateColumn; dxDBGrid2Column7: TdxDBGridColumn; dxDBGrid2Column8: TdxDBGridColumn; bsSkinPanel2: TbsSkinPanel; Label1: TLabel; DBEdit1: TDBEdit; Editor: TDBRichEdit; bsSkinPanel3: TbsSkinPanel; bsSkinButton2: TbsSkinButton; bsSkinButton9: TbsSkinButton; bsSkinButton11: TbsSkinButton; bsSkinButton10: TbsSkinButton; t_info_sharedoc: TADOQuery; t_info_sharedoc1: TDataSource; qrytmp: TADOQuery; t_info_file: TADOQuery; dsrFuJian: TDataSource; OpenDialog1: TOpenDialog; SaveDialog1: TSaveDialog; DBEdit2: TDBEdit; Label2: TLabel; bsSkinPanel4: TbsSkinPanel; dxDBGrid1: TdxDBGrid; dxDBGrid1sc_id: TdxDBGridMaskColumn; dxDBGrid1Column6: TdxDBGridColumn; dxDBGrid1Column2: TdxDBGridColumn; dxDBGrid1Column4: TdxDBGridColumn; dxDBGrid1Column5: TdxDBGridColumn; bsSkinPanel5: TbsSkinPanel; Edit1: TEdit; Label3: TLabel; bsSkinButton12: TbsSkinButton; bsSkinPanel6: TbsSkinPanel; ToolbarImages: TImageList; ActionList1: TActionList; ActionList2: TActionList; EditUndoCmd: TAction; EditCutCmd: TAction; EditCopyCmd: TAction; EditPasteCmd: TAction; EditFontCmd: TAction; OpenDialog: TOpenDialog; FontDialog1: TFontDialog; SaveDialog: TSaveDialog; bsSkinSpeedButton1: TbsSkinSpeedButton; FontName: TComboBox; FontSize: TEdit; UpDown1: TUpDown; bsSkinSpeedButton2: TbsSkinSpeedButton; bsSkinSpeedButton3: TbsSkinSpeedButton; LeftAlign: TbsSkinSpeedButton; CenterAlign: TbsSkinSpeedButton; RightAlign: TbsSkinSpeedButton; 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_sharedocAfterInsert(DataSet: TDataSet); procedure t_info_sharedocBeforePost(DataSet: TDataSet); procedure t_info_sharedocBeforeEdit(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); procedure bsSkinButton12Click(Sender: TObject); procedure Edit1KeyPress(Sender: TObject; var Key: Char); procedure FileNewCmdExecute(Sender: TObject); procedure bsSkinSpeedButton1Click(Sender: TObject); procedure bsSkinSpeedButton2Click(Sender: TObject); procedure bsSkinSpeedButton3Click(Sender: TObject); procedure FontNameChange(Sender: TObject); procedure FontSizeChange(Sender: TObject); procedure LeftAlignClick(Sender: TObject); procedure EditorSelectionChange(Sender: TObject); private FUpdating:boolean; { Private declarations } procedure UpLoadPro(fname:string); //fname包含完整路径、文件名 procedure DownLoadPro(fname:string); //从数据库的表中下载 function CurrText: TTextAttributes; procedure GetFontNames; public { Public declarations } end; var frm_info_shareDoc: Tfrm_info_shareDoc; implementation {$R *.dfm} uses u_main, my_sys_function,u_sys_progress; function EnumFontsProc(var LogFont: TLogFont; var TextMetric: TTextMetric; FontType: Integer; Data: Pointer): Integer; stdcall; begin TStrings(Data).Add(LogFont.lfFaceName); Result := 1; end; procedure Tfrm_info_shareDoc.GetFontNames; var DC: HDC; begin DC := GetDC(0); EnumFonts(DC, nil, @EnumFontsProc, Pointer(FontName.Items)); ReleaseDC(0, DC); FontName.Sorted := True; end; procedure Tfrm_info_shareDoc.FormClose(Sender: TObject; var Action: TCloseAction); begin frm_info_shareDoc.Hide; frm_info_shareDoc.ManualFloat(frm_info_shareDoc.BoundsRect ); frm_main.freeTabs('frm_info_shareDoc'); action:=cafree; frm_info_shareDoc:=nil; end; procedure Tfrm_info_shareDoc.FormShow(Sender: TObject); begin with t_info_shareDoc,sql do begin close ;clear ; add('select * from t_info_sharedoc '); add('where 录入人='+''''+employee+''' or ') ; add(open_data('9005','录入人','no','no','no','no')) ; add(' order by 录入日期 '); Open; end ; t_info_file.Open ; GetFontNames; end; procedure Tfrm_info_shareDoc.bsSkinButton5Click(Sender: TObject); begin close; end; procedure Tfrm_info_shareDoc.bsSkinButton7Click(Sender: TObject); begin table_Prior(t_info_shareDoc); end; procedure Tfrm_info_shareDoc.bsSkinButton6Click(Sender: TObject); begin table_next(t_info_shareDoc); end; procedure Tfrm_info_shareDoc.bsSkinButton8Click(Sender: TObject); begin table_post(t_info_shareDoc); if t_info_file.State in [dsedit,dsinsert] then t_info_file.post ; end; procedure Tfrm_info_shareDoc.bsSkinButton4Click(Sender: TObject); begin if not if_open('247') then begin showmessage('对不起你没有此模块的操作权限!'); exit; end; if do_data('9005',t_info_sharedoc.fieldbyname('录入人').asstring,'','','','','')=false then begin showmessage('对不起你无权删除此数据!!'); abort; end; if t_info_shareDoc.isempty then exit; if application.MessageBox('您确定要删除数据吗?','警告:',MB_OKCANCEL)=IDOK then begin with qrytmp,sql do //删除从表 begin close ; clear ; add('delete from t_info_sharedoc_file where sc_id=:scid'); parameters.ParamByName('scid').Value:=t_info_sharedoc.fieldbyname('sc_id').value ; execsql ; end ; t_info_sharedoc.delete; end ; end; procedure Tfrm_info_shareDoc.bsSkinButton3Click(Sender: TObject); begin table_cancel(t_info_sharedoc); end; procedure Tfrm_info_shareDoc.bsSkinButton1Click(Sender: TObject); begin if not if_open('245') then begin showmessage('对不起你没有此模块的操作权限!'); exit; end; t_info_sharedoc.insert; end; procedure Tfrm_info_shareDoc.t_info_sharedocAfterInsert(DataSet: TDataSet); begin t_info_sharedoc['录入日期']:=date; t_info_sharedoc['录入人']:=employee; DBEdit1.SetFocus; end; procedure Tfrm_info_shareDoc.t_info_sharedocBeforePost(DataSet: TDataSet); begin table_before_post(t_info_sharedoc,'文档名称'); table_before_post(t_info_sharedoc,'内容'); end; procedure Tfrm_info_shareDoc.t_info_sharedocBeforeEdit(DataSet: TDataSet); begin if do_data('9005',t_info_sharedoc.fieldbyname('录入人').asstring,'','','','','')=false then begin showmessage('对不起,你无权修改!!'); abort; end; end; procedure Tfrm_info_shareDoc.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin CanClose:=close_query(t_info_sharedoc); end; procedure Tfrm_info_shareDoc.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_shareDoc.DBEdit1KeyPress(Sender: TObject; var Key: Char); begin if key=#13 then begin key:=#0; Editor.SetFocus; end; end; procedure Tfrm_info_shareDoc.dxDBGrid1ColumnSorting(Sender: TObject; Column: TdxDBTreeListColumn; var Allow: Boolean); begin Column_sort(Column,t_info_sharedoc,'录入日期'); end; procedure Tfrm_info_shareDoc.DownLoadPro(fname: string); const MaxBufSize=$F000; var myfilename:string;//保存文件的路径和文件名 myfileStream,exeBlobStream:TStream; Count,BufSize,N: Integer; Buffer:PChar; begin if not ASSIGNED(frm_sys_progress) then frm_sys_progress:=tfrm_sys_progress.Create(self); frm_sys_progress.bsSkinGauge1.ProgressText:='加载数据请等候。。。'; frm_sys_progress.Show; frm_sys_progress.Update; 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); frm_sys_progress.bsSkinGauge1.MaxValue:=(Count div BufSize)+2; frm_sys_progress.bsSkinGauge1.MinValue:=0; frm_sys_progress.bsSkinGauge1.Value:=0; 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); frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; end; finally FreeMem(Buffer,BufSize); end; finally ExeBlobStream.Free; end; finally myfileStream.Free; end; end; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; frm_sys_progress.close; frm_sys_progress:=nil; end; procedure Tfrm_info_shareDoc.UpLoadPro(fname: string); const BufSize=$F000; var Counter, N: Integer; Buffer: PAnsiChar; FieldStrm: TStream; ExeFileStream:TFileStream; size_tmp: Double; filename,fileExt:string ; begin if not ASSIGNED(frm_sys_progress) then frm_sys_progress:=tfrm_sys_progress.Create(self); frm_sys_progress.bsSkinGauge1.ProgressText:='加载数据请等候。。。'; frm_sys_progress.Show; frm_sys_progress.Update; 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; frm_sys_progress.bsSkinGauge1.MaxValue:=(Counter div BufSize)+2; frm_sys_progress.bsSkinGauge1.MinValue:=0; frm_sys_progress.bsSkinGauge1.Value:=0; 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); frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+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; Application.MessageBox('程序上传至服务器成功!','提示',MB_OK+MB_IconInformation); finally frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; frm_sys_progress.close; frm_sys_progress:=nil; ExeFileStream.Free; end; end; end; procedure Tfrm_info_shareDoc.bsSkinButton2Click(Sender: TObject); begin if not if_open('245') then begin showmessage('对不起你没有此模块的操作权限!'); exit; end; if t_info_sharedoc.State in [dsedit,dsinsert] then t_info_sharedoc.Post ; if t_info_sharedoc.FieldByName('文档名称').asstring='' then begin showmessage('必须添加文档名称!'); exit ; end ; if OpenDialog1.Execute then UpLoadPro(Opendialog1.FileName) else exit ; end; procedure Tfrm_info_shareDoc.bsSkinButton9Click(Sender: TObject); begin if SaveDialog1.Execute then DownLoadPro(Savedialog1.FileName+t_info_file.fieldbyname('类型').asstring) else exit ; end; procedure Tfrm_info_shareDoc.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); except showmessage('不能打开文件,请检查网络连接等错误!'); end ; end; procedure Tfrm_info_shareDoc.bsSkinButton10Click(Sender: TObject); begin if not if_open('247') then begin showmessage('对不起你没有此模块的操作权限!'); exit; end; if do_data('9005',t_info_file.fieldbyname('所有者').asstring,'','','','','')=false then begin showmessage('对不起你无权删除此数据!!'); abort; end; if t_info_sharedoc.State in [dsedit,dsinsert] then t_info_sharedoc.post ; if application.MessageBox('您确定要删除附件吗?','警告:',MB_OKCANCEL)=IDOK then t_info_file.delete ; end; procedure Tfrm_info_shareDoc.t_info_fileBeforeEdit(DataSet: TDataSet); begin if t_info_file.FieldByName('所有者').asstring<>employee then begin showmessage('对不起,您不是所有者,无权修改!'); abort ; end ; end; procedure Tfrm_info_shareDoc.dxDBGrid2Exit(Sender: TObject); begin if t_info_file.state in [dsedit,dsinsert] then t_info_file.post ; end; procedure Tfrm_info_shareDoc.bsSkinButton12Click(Sender: TObject); begin with t_info_shareDoc,sql do begin close ;clear ; add('select * from t_info_sharedoc '); add('where 1=1 and ') ; if trim(edit1.text)<>'' then begin add(' 文档名称 like ''%'+edit1.text+'%''and ') ; end; add(open_data('9005','录入人','no','no','no','no')) ; add(' order by 录入日期 '); Open; end ; t_info_file.Open ; end; procedure Tfrm_info_shareDoc.Edit1KeyPress(Sender: TObject; var Key: Char); begin if Key=#13 then bsSkinButton12.OnClick(Sender); end; function Tfrm_info_shareDoc.CurrText: TTextAttributes; begin if Editor.SelLength > 0 then Result := Editor.SelAttributes else Result := Editor.DefAttributes; end; procedure Tfrm_info_shareDoc.FileNewCmdExecute(Sender: TObject); begin Editor.Lines.Clear; end; procedure Tfrm_info_shareDoc.bsSkinSpeedButton1Click(Sender: TObject); begin if fsBold in Editor.SelAttributes.Style then CurrText.Style := CurrText.Style - [fsBold] else CurrText.Style := CurrText.Style + [fsBold]; end; procedure Tfrm_info_shareDoc.bsSkinSpeedButton2Click(Sender: TObject); begin if fsItalic in Editor.SelAttributes.Style then CurrText.Style := CurrText.Style - [fsItalic] else CurrText.Style := CurrText.Style + [fsItalic]; end; procedure Tfrm_info_shareDoc.bsSkinSpeedButton3Click(Sender: TObject); begin if fsUnderline in Editor.SelAttributes.Style then CurrText.Style := CurrText.Style - [fsUnderline] else CurrText.Style := CurrText.Style + [fsUnderline]; end; procedure Tfrm_info_shareDoc.FontNameChange(Sender: TObject); begin if FUpdating then Exit; CurrText.Name := FontName.Items[FontName.ItemIndex]; end; procedure Tfrm_info_shareDoc.FontSizeChange(Sender: TObject); begin if FUpdating then Exit; CurrText.Size := StrToInt(FontSize.Text); end; procedure Tfrm_info_shareDoc.LeftAlignClick(Sender: TObject); begin Editor.Paragraph.Alignment := TAlignment(TControl(Sender).Tag); end; procedure Tfrm_info_shareDoc.EditorSelectionChange(Sender: TObject); begin with Editor.Paragraph do try FUpdating := True; FontSize.Text := IntToStr(Editor.SelAttributes.Size); FontName.Text := Editor.SelAttributes.Name; case Ord(Alignment) of 0: LeftAlign.Down := True; 1: RightAlign.Down := True; 2: CenterAlign.Down := True; end; finally FUpdating := False; end; end; end.