N
nfsong
Unregistered / Unconfirmed
GUEST, unregistred user!
unit w_dlcs;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, ExtCtrls, DB, DBTables,IniFiles, Grids, DBGrids;<br><br>type<br> Tw_dlfrm = class(TForm)<br> Panel1: TPanel;<br> Image1: TImage;<br> Label1: TLabel;<br> Label2: TLabel;<br> E_user: TEdit;<br> E_pwd: TEdit;<br> B_yes: TButton;<br> B_quit: TButton;<br> dlfrm_dbg: TDBGrid;<br> procedure FormCreate(Sender: TObject);<br> procedure B_quitClick(Sender: TObject);<br> procedure B_yesClick(Sender: TObject);<br> procedure E_userDblClick(Sender: TObject);<br> procedure E_userKeyDown(Sender: TObject; var Key: Word;<br> Shift: TShiftState);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> procedure db_link; //数据库连接,公用<br> end;<br><br>var<br> w_dlfrm: Tw_dlfrm;<br><br>implementation<br><br>{$R *.dfm}<br>uses w_log,M_datahz;<br><br>procedure Tw_dlfrm.FormCreate(Sender: TObject);<br>var dl_times:integer;<br> Dbini:TiniFile;<br> filebm:string;<br> a_alias:string;<br> BDEalias:TstringList;<br> Bdesession:Tsession;<br>begin<br> dlfrm_dbg.Hide;<br> dl_times:=0;<br> filebm:=ExtractFilePath(paramstr(0))+'mydb.ini';<br> Dbini:=TiniFile.Create(filebm);<br> a_alias:=Dbini.ReadString('数据库登录','AliasName','');<br> BDEAlias:=TstringList.Create;<br> Bdesession:=Tsession.Create(self);<br> Bdesession.AutoSessionName:=true;<br> Bdesession.GetAliasNames(BdeAlias);<br> //如果BDE中不存在mdb.ini中的别名设置,就显示设置参数窗体<br> if (BDEAlias.IndexOf(a_alias)=-1) or (a_alias='') then<br> begin<br> MessageDlg('数据库参数设置错误,请检查设置!',Mterror,[mbok],0);<br> try<br> w_csfrm:=TW_csfrm.Create(self);<br> w_csfrm.c_alias.Text:=trim(Dbini.ReadString('数据库登录','AliasName',''));<br> w_csfrm.c_dbmc.Text:=trim(Dbini.ReadString('数据库登录','Database',''));<br> w_csfrm.c_server.Text:=trim(Dbini.ReadString('数据库登录','ServerName',''));<br> w_csfrm.c_dlmc.Text:=trim(Dbini.ReadString('数据库登录','LogId',''));<br> w_csfrm.c_mm.Text:=trim(Dbini.ReadString('数据库登录','Logpassword',''));<br> w_csfrm.ShowModal;<br> finally<br> W_csfrm.Free;<br> Bdesession.AutoSessionName:=false;<br> Bdesession.Free;<br> end;<br> end;<br>end;<br><br><br>procedure Tw_dlfrm.B_quitClick(Sender: TObject);<br>begin<br> close;<br>end;<br><br>procedure Tw_dlfrm.db_link;<br>var Dbini:TiniFile;<br> filebm:string;<br>begin<br> filebm:=ExtractFilePath(paramstr(0))+'mydb.ini';<br> Dbini:=TiniFile.Create(filebm);<br> M_mxhz:=TM_mxhz.Create(self);<br> with M_mxhz do<br> try<br> dlfrm_DB.AliasName:=dbini.ReadString('数据库登录','AliasName','');<br> dlfrm_DB.DatabaseName:=dbini.ReadString('数据库登录','Database','');<br> dlfrm_DB.Params.Add('Server Name='+dbini.ReadString('数据库登录','ServerName',''));<br> dlfrm_DB.Params.Add('User Name='+dbini.ReadString('数据库登录','LogId',''));<br> dlfrm_DB.Params.Add('PassWord='+dbini.ReadString('数据库登录','LogPassword',''));<br> dlfrm_DB.LoginPrompt:=false;<br> dlfrm_DB.DriverName:='MSSQL';<br> dlfrm_Qry.DatabaseName:=dlfrm_DB.DatabaseName;<br> dlfrm_DB.Connected:=true;<br> except<br> raise;<br> dlfrm_DB.Free;<br> dlfrm_qry.Free;<br> end;<br>end;<br><br>procedure Tw_dlfrm.B_yesClick(Sender: TObject);<br>begin<br> close;<br>end;<br><br>procedure Tw_dlfrm.E_userDblClick(Sender: TObject);<br>begin<br> db_link;<br> with M_mxhz do<br> try<br> dlfrm_qry.Close;<br> dlfrm_Qry.SQL.Clear;<br> dlfrm_Qry.SQL.Add('select dzycode,dzyname from zhiydoc');<br> dlfrm_Qry.Prepare;<br> dlfrm_Qry.open;<br> except<br> raise;<br> dlfrm_qry.Free;<br> end;<br> dlfrm_dbg.Show;<br>end;<br><br>procedure Tw_dlfrm.E_userKeyDown(Sender: TObject; var Key: Word;<br> Shift: TShiftState);<br>begin<br> Db_link;<br> if E_user.Text<>'' then<br> M_mxhz:=TM_mxhz.Create(self);<br> with M_mxhz do<br> try<br> dlfrm_qry.Close;<br> dlfrm_qry.SQL.Clear;<br> dlfrm_qry.SQL.Add('select dzycode,dzyname from zhiydoc');<br> dlfrm_qry.SQL.Add('where (dzycode like :A or dzyname like :B or zjm like :C)');<br> dlfrm_qry.ParamByName('A').AsString:=trim(E_user.Text)+'%';<br> dlfrm_qry.ParamByName('B').AsString:='%'+trim(E_user.Text)+'%';<br> dlfrm_qry.ParamByName('C').AsString:='%'+trim(E_user.Text)+'%';<br> dlfrm_qry.Active:=true;<br> dlfrm_qry.Prepare;<br> dlfrm_qry.Open;<br> except<br> dlfrm_qry.Free;<br> raise;<br> end;<br> dlfrm_dbg.Show;<br>end;<br><br>end.<br><br>初学delphi,请大家多多指教!