?? ufrmserver.pas
字號:
unit UfrmServer;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, DB, ADODB, Buttons,Share;
type
TFrm_Server = class(TForm)
Panel1: TPanel;
Image1: TImage;
Notebook1: TNotebook;
Panel2: TPanel;
ConSetup: TADOConnection;
BitBtn2: TBitBtn;
qySetup: TADOQuery;
BitBtn3: TBitBtn;
BitBtn1: TBitBtn;
GroupBox1: TGroupBox;
Label4: TLabel;
Label5: TLabel;
Edit3: TEdit;
Edit2: TEdit;
Label2: TLabel;
RadioGroup1: TRadioGroup;
Edit1: TEdit;
Edit4: TEdit;
Btn_v: TSpeedButton;
Qy_V: TADOQuery;
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure BitBtn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject);
procedure Btn_vClick(Sender: TObject);
private
{ Private declarations }
public
sName:string;
{ Public declarations }
end;
const
RegPath='\Software\NewsumSoft\PowerManager\';
var
Frm_Server: TFrm_Server;
myShare:TShare;
bWriteReg:Boolean;
implementation
{$R *.dfm}
procedure TFrm_Server.BitBtn2Click(Sender: TObject);
var
ConStr:String;
begin
if Edit3.Text='' then
begin
MessageBox(Application.Handle,'請輸入數據庫實例名','提示',48);
Edit3.SetFocus;
Exit;
end;
ConStr:='Provider=SQLOLEDB.1;Persist Security Info=False;'
+'User ID=sa;Password="'+Edit2.Text+'";'
+'Initial Catalog=master;Data Source='+edit3.Text;
ConSetup.Connected:=False;
ConSetup.ConnectionString:=ConStr;
try
ConSetup.Connected:=True;
application.MessageBox('數據庫連接正確','系統提示',48);
RadioGroup1.Enabled:=true;
Btn_v.Enabled:=true;
BitBtn3.Enabled:=True;
Edit2.ReadOnly:=True;
edit3.ReadOnly:=true;
BitBtn2.Enabled:=False;
except
application.MessageBox('數據庫連接不正確,密碼是否正確','系統提示',48);
exit;
end;
end;
procedure TFrm_Server.BitBtn3Click(Sender: TObject);
var
S_Name:string;
begin
if RadioGroup1.ItemIndex=-1 then
showmessage('請先選擇所安裝的 SQL Server 的版本!');
case RadioGroup1.ItemIndex of
0: //SQL Server 7.0
begin
if Edit1.Text='' then
begin
Application.MessageBox('數據庫庫名不能為空!',' 系統提示',MB_ICONINFORMATION);
Edit1.SetFocus;
exit;
end;
//showmessage(ExtractFilePath(Application.Exename)+'DataBase\SQL_7.0\SSMS_7.0_Data.MDF');
// showmessage(ExtractFilePath(Application.Exename)+'DataBase\SQL_7.0\'+trim(Edit1.Text)+'_log.LDF');
if not FileExists(ExtractFilePath(Application.Exename)+'DataBase\SQL_7.0\SSMS_7.0_Data.MDF') then
begin
Application.MessageBox('數據庫文件不存在,請重新安裝!',' 系統提示',MB_ICONINFORMATION);
Exit;
end;
if FileExists(ExtractFilePath(Application.Exename)+'DataBase\SQL_7.0\'+trim(Edit1.Text)+'_log.LDF') then
begin
S_Name:= '【'+Edit1.text+'】'+' 數據庫已被安裝!';
Application.MessageBox(pchar(S_Name),' 系統提示',MB_ICONINFORMATION);
Exit;
end;
qySetup.Close;
qySetup.SQL.Text:='sp_attach_db @dbname =N'+''''+Edit1.Text+''''+' , @filename1 =N'
+''''+ExtractFilePath(Application.Exename)+'DataBase\SQL_7.0\SSMS_7.0_Data.MDF'+'''';
try
qySetup.ExecSQL;
except
end;
qysetup.Close;
qysetup.SQL.Text:=' use '+'"'+edit1.Text+'"';
try
qysetup.ExecSQL;
Application.MessageBox('數據庫已創建!',' 系統提示',MB_ICONINFORMATION);
BitBtn3.Enabled:=False;
except
Application.MessageBox('數據庫新建失敗,請退出后重新創建!',' 系統提示',MB_ICONINFORMATION);
exit;
end;
myShare:=TShare.Create;
if (myShare.WriteRegistryValue(RegPath,'sSource',edit3.Text)) and
(myShare.WriteRegistryValue(RegPath,'sCataLog',Edit1.Text)) and
(myShare.WriteRegistryValue(RegPath,'sPass',Edit2.Text))
then
bWriteReg:=True
else
begin
Application.MessageBox('注冊表寫入失敗!',' 系統提示',MB_ICONINFORMATION);
myShare.Free;
Exit;
end;
myShare.Free;
Close;
end;
1: //SQL Server 2000
begin
if Edit4.Text='' then
begin
Application.MessageBox('數據庫庫名不能為空!',' 系統提示',MB_ICONINFORMATION);
Edit4.SetFocus;
exit;
end;
if not FileExists(ExtractFilePath(Application.Exename)+'DataBase\SQL_2000\SSMS_Data.MDF') then
begin
Application.MessageBox('數據庫文件不存在,請重新安裝!',' 系統提示',MB_ICONINFORMATION);
Exit;
end;
if FileExists(ExtractFilePath(Application.Exename)+'DataBase\SQL_2000\'+trim(Edit4.Text)+'_log.LDF') then
begin
S_Name:= '【'+Edit4.text+'】'+'數據庫已被安裝!';
Application.MessageBox(Pchar(S_Name),' 系統提示',MB_ICONINFORMATION);
Exit;
end;
qySetup.Close;
qySetup.SQL.Text:='sp_attach_db @dbname =N'+''''+Edit4.Text+''''+' , @filename1 =N'
+''''+ExtractFilePath(Application.Exename)+'DataBase\SQL_2000\SSMS_Data.MDF'+'''';
try
qySetup.ExecSQL;
except
end;
qysetup.Close;
qysetup.SQL.Text:=' use '+'"'+edit4.Text+'"';
try
qysetup.ExecSQL;
Application.MessageBox('數據庫已創建!',' 系統提示',MB_ICONINFORMATION);
BitBtn3.Enabled:=False;
except
Application.MessageBox('數據庫新建失敗!',' 系統提示',MB_ICONINFORMATION);
exit;
end;
myShare:=TShare.Create;
if (myShare.WriteRegistryValue(RegPath,'sSource',edit3.Text)) and
(myShare.WriteRegistryValue(RegPath,'sCataLog',Edit4.Text)) and
(myShare.WriteRegistryValue(RegPath,'sPass',Edit2.Text))
then
bWriteReg:=True
else
begin
Application.MessageBox('注冊表寫入失敗!',' 系統提示',MB_ICONINFORMATION);
myShare.Free;
Exit;
end;
myShare.Free;
Close;
end;
end;
end;
procedure TFrm_Server.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
if (bitBtn3.Enabled) or (not bWriteReg) then
begin
if (application.MessageBox('你確認退出服務器注冊程序嗎,您可以在安裝目錄來運行注冊程序!','詢問',36)=ID_YES) then
else
begin
CanClose:=False;
Exit;
end;
end;
CanClose:=True;
end;
procedure TFrm_Server.BitBtn1Click(Sender: TObject);
begin
Close;
end;
procedure TFrm_Server.FormCreate(Sender: TObject);
begin
bWriteReg:=False;
end;
procedure TFrm_Server.RadioGroup1Click(Sender: TObject);
begin
case RadioGroup1.ItemIndex of
0:
begin
Edit1.Enabled:=true;
Edit4.Enabled:=false;
Edit4.Text:='';
Edit1.SetFocus;
end;
1:
begin
Edit4.Enabled:=true;
Edit1.Enabled:=false;
Edit1.Text:='';
Edit4.SetFocus;
end;
end;
end;
procedure TFrm_Server.Btn_vClick(Sender: TObject);
var
ConStr:string;
begin
ConStr:='Provider=SQLOLEDB.1;Persist Security Info=False;'
+'User ID=sa;Password="'+Edit2.Text+'";'
+'Initial Catalog=master;Data Source='+edit3.Text;
ConSetup.Connected:=False;
ConSetup.ConnectionString:=ConStr;
ConSetup.Connected:=true;
Qy_V.Connection:=ConSetup;
Qy_V.Prepared;
Qy_V.Open;
ShowMessage(Qy_V.fieldbyname('V').AsString);
if Copy(Qy_V.FieldByName('V').AsString,23,1)='2' then
begin
RadioGroup1.ItemIndex:=1;
Edit4.Text:='SSMS';
RadioGroup1.Controls[0].Enabled := False;
end
else
begin
RadioGroup1.ItemIndex:=0;
Edit1.Text:='SSMS';
RadioGroup1.Controls[1].Enabled := False;
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -