⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filecreatefrm.pas

📁 一个基于局域网的公司公文管理系统
💻 PAS
字号:
unit FileCreateFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,GlobalUnit,adodb,shellapi;

type
  TFileCreateForm = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    Label4: TLabel;
    Label3: TLabel;
    Memo1: TMemo;
    Label5: TLabel;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    OpenDialog1: TOpenDialog;
//    pathFilepath:string;
    procedure ComboBox1Change(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FileCreateForm: TFileCreateForm;
  Filepath:string;


function GetIndexFromTable(strTableName:string):integer;

implementation

{$R *.dfm}

procedure TFileCreateForm.ComboBox1Change(Sender: TObject);
begin
//showmessage(inttostr(ComboBox1.ItemIndex));
   if ComboBox1.ItemIndex=2 then
   begin
      OpenDialog1.Execute;
      if OpenDialog1.FileName<>'' then
          showmessage('文档成功导入!')
      else
      begin
           showmessage('您取消导入文档,请选择其它电子文档类型!');
           ComboBox1.SetFocus;
      end;

   end;

end;

procedure TFileCreateForm.Button1Click(Sender: TObject);
var
nNow:TdateTime;
bcopyed:boolean;
i,itemindex:integer;
qrTemp:TAdoQuery;
memo,strSQL:string;
strFileTitle:string;
begin
   nNow:=Now;
   Filepath:=g_user_id+FormatDateTime('_yyyymmddhhnnss',nNow);
   case ComboBox1.ItemIndex of
   0:
      begin
       Filepath:=Filepath+'.doc';
       bcopyed:=CopyFile(PChar('\\'+ServerName+'\filetest\wordmodel.doc'), PChar('\\'+ServerName+'\filetest\'+Filepath), false);
       end;
   1:
      begin
       Filepath:= Filepath+'.xls';
       bcopyed:=CopyFile(PChar('\\'+ServerName+'\filetest\excelmodel.xls'),PChar('\\'+ServerName+'\filetest\'+Filepath), false);
      end;
   2:
      begin
         if OpenDialog1.FileName<>'' then
         begin  
            Filepath:=Filepath+'.'+GetFileExt(OpenDialog1.FileName,strFileTitle);
            bcopyed:=CopyFile(PChar(OpenDialog1.FileName),PChar('\\'+ServerName+'\filetest\'+Filepath), false);
         end
         else//导入文件时选择取消
         begin
            showmessage('操作取消,因为您已经没有导入扫描文档!');
            exit;
          end;
      end;
   end;
   itemindex:= GetIndexFromTable('ent_file');
   for i:=0 to Memo1.Lines.Count-1 do
   memo:=memo+Memo1.Lines.Strings[i];
   
   qrTemp:=TAdoQuery.Create(nil);
   qrTemp.Connection :=G_ADOConnection;
   qrTemp.SQL.Clear;
   strSQL:='insert into ent_file(unit_id,iindex,title,path,creater,time,iclass,memo) values('+inttostr(g_unit_id)+','+inttostr(itemindex)+','''+Edit1.text+''','''+Filepath+''','''+g_user_id+''','''+datetimetostr(Now)+''','+inttostr(ComboBox2.ItemIndex)+','''+memo+''')';
//   showmessage(strSQL);
    qrTemp.SQL.Text:=strSQL;
    try
        qrTemp.ExecSQL;
    except
        showMessage('用户操作不成功!');
        exit;
    end;
    if bcopyed then
          ShellExecute(Application.Handle,  nil,  PChar('\\'+ServerName+'\filetest\'+Filepath),  nil,  nil,  SW_SHOWNORMAL)
    else
         showmessage(SysErrorMessage(GetLastError));
end;

function GetIndexFromTable(strTableName:string):integer;
var
    qrTemp:TAdoQuery;
    imin,imax:integer;
    index:integer;
begin
    qrTemp:=TAdoQuery.Create(nil);
    qrTemp.Connection :=G_ADOConnection;
    qrTemp.SQL.Text:='select min([iindex]) as minindex,max([iindex]) as maxindex from ent_file ';
    qrTemp.Open;
    qrTemp.First;
    imin:=qrTemp.FieldByName('minindex').AsInteger-1;
    imax :=qrTemp.FieldByName('maxindex').AsInteger +1;
    if imin>0 then
        Result:=imin
    else
        Result:= imax;
    qrTemp.Close;
    qrTemp.Free;
end;



end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -