unit u_update; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, bsSkinData, BusinessSkinForm, bsSkinCtrls, DB, ADODB,inifiles, VCLUnZip, VCLZip, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP; type Tfrmsoftupdate = class(TForm) Label1: TLabel; Edit1: TEdit; bsBusinessSkinForm1: TbsBusinessSkinForm; bsSkinData1: TbsSkinData; bsStoredSkin1: TbsStoredSkin; bsSkinButton1: TbsSkinButton; Edit2: TEdit; Label2: TLabel; Label3: TLabel; Edit3: TEdit; VCLZip1: TVCLZip; bsBusinessSkinForm2: TbsBusinessSkinForm; bsSkinData2: TbsSkinData; bsStoredSkin2: TbsStoredSkin; Label4: TLabel; Edit4: TEdit; bsSkinButton2: TbsSkinButton; t_sys_soft_update: TADOQuery; p_update: TADOStoredProc; db_update: TADOConnection; t_sql: TADOQuery; t_readme: TADOQuery; db: TADOConnection; Label5: TLabel; Edit5: TEdit; GroupBox1: TGroupBox; Memo1: TMemo; bsSkinCheckRadioBox1: TbsSkinCheckRadioBox; bsSkinButton3: TbsSkinButton; t_update: TADOQuery; t_view_update: TADOQuery; t_sys_soft_do: TADOQuery; t_sys_soft_doDSDesigner: TStringField; t_sys_soft_doDSDesigner2: TBlobField; t_sys_soft_doDSDesigner1: TStringField; t_sys_soft_doDSDesigner22: TStringField; t_sys_soft_doDSDesigner3: TStringField; Label6: TLabel; Edit8: TEdit; t_max_sql: TADOQuery; Button1: TButton; IdHTTP1: TIdHTTP; procedure bsSkinButton1Click(Sender: TObject); procedure bsSkinButton2Click(Sender: TObject); procedure db_updateBeforeConnect(Sender: TObject); procedure dbBeforeConnect(Sender: TObject); procedure bsSkinButton3Click(Sender: TObject); procedure FormShow(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } function GetFileVersion(FileName: string): string; end; var frmsoftupdate: Tfrmsoftupdate; implementation uses update_sql_readme; {$R *.dfm} procedure Tfrmsoftupdate.bsSkinButton1Click(Sender: TObject); var table:Tadoquery; inifile1:Tinifile; str:string; j,i:integer; if_add:boolean; TempStr,Stemp:TStringlist; begin Memo1.Lines.Clear; Memo1.Lines.Add('开始升级'+DateTimeToStr(NOW)); try db.Connected:=true; except showmessage('服务器连接失败!!'); Memo1.Lines.Add('服务器连接失败!!'); end; TempStr:=TStringList.Create; Stemp:=TStringList.Create; try table:=Tadoquery.Create(application); table.Connection:=db; table.SQL.text:='select top 1 版本号 from t_sys_soft order by 版本号 desc '; table.open; t_max_sql.Open; Memo1.Lines.Add('当前程序版本号:'+table.fieldbyname('版本号').asstring); Memo1.Lines.Add('升级版本号:'+t_max_sql.fieldbyname('版本号').AsString); if bsSkinCheckRadioBox1.Checked then begin str:=table.fieldbyname('版本号').AsString; str:=StringReplace(str,'.','',[rfReplaceAll]); t_sql.close; t_sql.Parameters.ParamByName('版本号').value:=str; t_sql.open; if t_sql.IsEmpty then begin showmessage('当前版本已经是最新版本,不需升级!!'); Memo1.Lines.Add('当前版本已经是最新版本,不需升级!!'); table.free; exit; end; t_sql.first; while not t_sql.eof do begin TempStr.Text:=t_sql.fieldbyname('执行').asstring; try Memo1.Lines.Add('执行版本号'+t_sql.FieldByName('版本号').AsString+'顺序'+t_sql.FieldByName('顺序').AsString+'。'); for i:=0 to TempStr.Count-1 do begin if (TRIM(UpperCase(TempStr[i]))<>'GO') then stemp.add(TempStr[i]) else begin if (Stemp.Text)<>'' then begin frmsoftupdate.p_update.close; frmsoftupdate.p_update.Parameters.ParamByName('@sSQL').value:=Stemp.Text; frmsoftupdate.p_update.Parameters.ParamByName('@pi_Result').value:=0; frmsoftupdate.p_update.Parameters.ParamByName('@ps_Message').value:=''; frmsoftupdate.p_update.ExecProc; stemp.Clear; end; end; end; if (Stemp.Text)<>'' then begin frmsoftupdate.p_update.close; frmsoftupdate.p_update.Parameters.ParamByName('@sSQL').value:=Stemp.Text; frmsoftupdate.p_update.Parameters.ParamByName('@pi_Result').value:=0; frmsoftupdate.p_update.Parameters.ParamByName('@ps_Message').value:=''; frmsoftupdate.p_update.ExecProc; stemp.Clear; end; except on e:Exception do begin Memo1.Lines.Add('执行版本号'+t_sql.FieldByName('版本号').AsString+'顺序'+t_sql.FieldByName('顺序').AsString+'时出错。'); Memo1.Lines.Add(e.Message); Abort; end; end; t_sql.next; end; end; table.close; table.open; table.free; showmessage('升级完毕!'); Memo1.Lines.Add('升级完毕,时间'+DateTimeToStr(Now)); FreeAndNil(TempStr); FreeAndNil(Stemp); // close; except showmessage('升级失败!'); Memo1.Lines.Add('升级失败,时间'+DateTimeToStr(Now)); FreeAndNil(TempStr); FreeAndNil(Stemp); end; Memo1.Lines.SaveToFile(ExtractFilePath(Application.ExeName)+FormatDateTime('YYYYMMDDHHNNSS',NOW)+'.txt'); end; procedure Tfrmsoftupdate.bsSkinButton2Click(Sender: TObject); begin close; end; procedure Tfrmsoftupdate.db_updateBeforeConnect(Sender: TObject); begin db_update.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=' +ExtractFilePath(Application.ExeName)+'update.mdb;' +'Mode=Share Deny None;Extended Properties="";' +'Jet OLEDB:System database="";Jet OLEDB:Registry Path="";' +'Jet OLEDB:Database Password="";Jet OLEDB:Engine Type=5;' +'Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;' +'Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";' +'Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;' +'Jet OLEDB:Don'+''''+'t Copy Locale on Compact=False;' +'Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False'; end; procedure Tfrmsoftupdate.dbBeforeConnect(Sender: TObject); var str:string; begin str:=''; str:='Provider=SQLOLEDB.1;'; str:=str+'Password='+Edit3.text+';'; str:=str+'Persist Security Info=False;'; str:=str+'User ID='+Edit2.text+';'; str:=str+'Initial Catalog='+Edit4.text+';'; str:=str+'Data Source='+Edit1.text+';'; db.ConnectionString:=str; end; procedure Tfrmsoftupdate.bsSkinButton3Click(Sender: TObject); begin try db.Connected:=true; except showmessage('服务器连接失败!!'); Memo1.Lines.Add('服务器连接失败!!'); exit; end; if not t_sys_soft_do.Active then t_sys_soft_do.open; frmsoftupdate.Caption:=frmsoftupdate.Caption+' '+t_sys_soft_do.fieldbyname('版本1').asstring+t_sys_soft_do.fieldbyname('版本2').asstring+t_sys_soft_do.fieldbyname('版本3').asstring; frmupdatesql:=Tfrmupdatesql.Create(Self); try frmupdatesql.ShowModal; finally FreeAndNil(frmupdatesql); end; end; procedure Tfrmsoftupdate.FormShow(Sender: TObject); var inifile1:Tinifile; str,s_ver,s,s3,s4:string; table:Tadoquery; begin inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini'); str:=inifile1.ReadString('database','Password',''); Edit3.Text:=copy(str,1,length(str)-1); str:=inifile1.ReadString('database','User ID',''); Edit2.text:=copy(str,1,length(str)-1); str:=inifile1.ReadString('database','Initial Catalog',''); Edit4.Text:=copy(str,1,length(str)-1); str:=inifile1.ReadString('database','Data Source',''); edit1.text:=copy(str,1,length(str)-1); inifile1.free; try db.Connected:=true; except showmessage('服务器连接失败!!'); Memo1.Lines.Add('服务器连接失败!!'); end; try table:=Tadoquery.Create(application); table.Connection:=db; table.SQL.text:='select top 1 版本号 from t_sys_soft order by 版本号 desc'; table.open; str:=table.fieldbyname('版本号').AsString; str:=StringReplace(str,'.','',[rfReplaceAll]); Edit8.Text:=str; finally table.Free; end; t_max_sql.Close; t_max_sql.open; Edit5.Text:=t_max_sql.fieldbyname('版本号').asstring; end; function Tfrmsoftupdate.GetFileVersion(FileName: string): string; type PVerInfo = ^TVS_FIXEDFILEINFO; TVS_FIXEDFILEINFO = record dwSignature: longint; dwStrucVersion: longint; dwFileVersionMS: longint; dwFileVersionLS: longint; dwFileFlagsMask: longint; dwFileFlags: longint; dwFileOS: longint; dwFileType: longint; dwFileSubtype: longint; dwFileDateMS: longint; dwFileDateLS: longint; end; var ExeNames: array[0..255] of char; zKeyPath: array[0..255] of Char; VerInfo: PVerInfo; Buf: pointer; Sz: word; L, Len: Cardinal; begin StrPCopy(ExeNames, FileName); Sz := GetFileVersionInfoSize(ExeNames, L); if Sz=0 then begin Result:=''; Exit; end; try GetMem(Buf, Sz); try GetFileVersionInfo(ExeNames, 0, Sz, Buf); if VerQueryValue(Buf, '\', Pointer(VerInfo), Len) then begin Result := IntToStr(HIWORD(VerInfo.dwFileVersionMS)) + '.' + IntToStr(LOWORD(VerInfo.dwFileVersionMS)) + '.' + IntToStr(HIWORD(VerInfo.dwFileVersionLS)) + '.' + IntToStr(LOWORD(VerInfo.dwFileVersionLS)); end; finally FreeMem(Buf); end; except Result := '-1'; end; end; procedure Tfrmsoftupdate.Button1Click(Sender: TObject); var DownLoadFile:TFileStream; begin DownLoadFile:=TFileStream.Create('c:\aa.rar',fmCreate); IdHTTP1.Get('http://123.57.17.72:8008/tools/setup.rar',DownLoadFile); DownLoadFile.Free; end; end.