ljszs.pas
资源名称:挡案管理系统.rar [点击查看]
上传用户:szruida
上传日期:2007-06-01
资源大小:6518k
文件大小:9k
源码类别:
Delphi控件源码
开发平台:
Delphi
- unit ljszs;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- Buttons, StdCtrls, ComCtrls, ImgList, ExtCtrls, Registry, Spin, Db,
- DBClient, variants, MConnect, SConnect, TFlatHintUnit, AppEvnts, ObjBrkr;
- type
- TLjsz = class(TForm)
- Panel1: TPanel;
- StatusBar1: TStatusBar;
- Panel2: TPanel;
- Label1: TLabel;
- edtAppHost: TEdit;
- Label2: TLabel;
- edtAppIP: TEdit;
- btnAppName: TBitBtn;
- Label3: TLabel;
- edtPort: TEdit;
- btnOK: TSpeedButton;
- btnCancel: TSpeedButton;
- Socket1: TSocketConnection;
- Socket2: TSocketConnection;
- Socket3: TSocketConnection;
- ApplicationEvents1: TApplicationEvents;
- Socket4: TSocketConnection;
- Socket5: TSocketConnection;
- Socket6: TSocketConnection;
- Socket7: TSocketConnection;
- procedure btnOKClick(Sender: TObject);
- procedure edtAppHostExit(Sender: TObject);
- procedure edtAppIPExit(Sender: TObject);
- procedure btnCancelClick(Sender: TObject);
- procedure btnAppNameClick(Sender: TObject);
- procedure edtAppHostKeyPress(Sender: TObject; var Key: Char);
- procedure edtAppIPKeyPress(Sender: TObject; var Key: Char);
- procedure edtPortKeyPress(Sender: TObject; var Key: Char);
- procedure FormCreate(Sender: TObject);
- procedure Socket1AfterDisconnect(Sender: TObject);
- procedure Socket1BeforeDisconnect(Sender: TObject);
- procedure ApplicationEvents1Exception(Sender: TObject; E: Exception);
- procedure FormKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure ApplicationEvents1ActionExecute(Action: TBasicAction;
- var Handled: Boolean);
- private
- //向注册表写入应用配置信息
- procedure WriteToReg(const bAppHost, bAppIP, aPort: string);
- { Private declarations }
- public
- { Public declarations }
- host,ip:string;
- dir:string;
- end;
- //打开配置窗口,并测试是否连接成功
- function LjszExecute(aFormClass: TFormClass): boolean;
- var
- Ljsz: TLjsz;
- Connected: boolean= false; //代表是否连接成功 。
- implementation
- uses mainfrms,frmnets, logins,u_Public;
- {$R *.DFM}
- //打开配置窗口,并测试是否连接成功
- function LjszExecute(aFormClass: TFormClass): boolean;
- begin
- with aFormClass.Create(Application) do
- begin
- Connected := False;
- try
- showModal;
- finally
- free;
- end;
- result := Connected;
- end;
- end;
- //向注册表里写入应用服务器的配置信息
- procedure TLjsz.WriteToReg(const bAppHost, bAppIP, aPort: string);
- var
- Reg: Tregistry;
- begin
- reg := Tregistry.create;
- Reg.RootKey := HKEY_LOCAL_MACHINE;
- if not Reg.OpenKey('Software档案管理', False) then
- begin
- reg.createkey('Software档案管理');
- Reg.OpenKey('Software档案管理', False);
- end;
- Reg.WriteString('Host', bAppHost);
- Reg.WriteString('Address', bAppIP);
- Reg.WriteString('Port', aPort);
- reg.free;
- end;
- procedure TLjsz.btnOKClick(Sender: TObject);
- begin
- if ((edtAppHost.text = null) or (edtAppHost.text = '')) and ((edtAppIP.text = null) or (edtAPPIP.text = '')) then
- begin
- Application.MessageBox('请输入应用服务器名字或IP!', '输入错误..', mb_iconinformation + mb_defbutton1);
- exit;
- end;
- try
- strtoint(edtPort.text);
- except
- Application.MessageBox('请输入正确的端口号', '输入错误..', mb_iconinformation + mb_defbutton1);
- exit;
- end;
- if trim(edtAppHost.text)<>'' then Socket1.Host := edtAppHost.text else Socket1.Address := edtAppIP.text;
- Socket1.ServerName:='MMServer.MnData'; Socket1.Connected := true;
- if trim(edtAppHost.text)<>'' then Socket2.Host := edtAppHost.text else Socket2.Address := edtAppIP.text;
- Socket2.ServerName:='MMServer.MnData'; Socket2.Connected := true;
- if trim(edtAppHost.text)<>'' then Socket3.Host := edtAppHost.text else Socket3.Address := edtAppIP.text;
- Socket3.ServerName:='MMServer.MnData'; Socket3.Connected := true;
- if trim(edtAppHost.text)<>'' then Socket4.Host := edtAppHost.text else Socket4.Address := edtAppIP.text;
- Socket4.ServerName:='MMServer.MnData'; Socket4.Connected := true;
- if trim(edtAppHost.text)<>'' then Socket5.Host := edtAppHost.text else Socket5.Address := edtAppIP.text;
- Socket5.ServerName:='MMServer.MnData'; Socket5.Connected := true;
- if trim(edtAppHost.text)<>'' then Socket6.Host := edtAppHost.text else Socket6.Address := edtAppIP.text;
- Socket6.ServerName:='MMServer.MnData'; Socket6.Connected := true;
- if trim(edtAppHost.text)<>'' then Socket7.Host := edtAppHost.text else Socket7.Address := edtAppIP.text;
- Socket7.ServerName:='MMServer.MnData'; Socket7.Connected := true;
- if trim(edtAppHost.text)<>'' then mainfrm.Socket1.Host := edtAppHost.text else mainfrm.Socket1.Address := edtAppIP.text;
- mainfrm.Socket1.ServerName:='MMServer.MnData'; mainfrm.Socket1.Connected := true;
- //-------------------------------------------------- 将客户端与中间层建立连接
- ip:=trim(edtappip.Text);//主机ip
- host:=trim(edtapphost.Text);//主机名
- if IP<>'' then
- Computer_Ip:=Ip //主机ip
- else if host<>'' then
- Computer_Ip:=Host;//主机名
- statusbar1.panels[0].text := '正在连接应用程序服务器,请稍候..';
- statusbar1.refresh;
- Screen.cursor := crHourGlass;
- //---------连接socketconnection1
- application.MessageBox('连接成功', '档案管理管理系统', mb_iconinformation + mb_defbutton1);
- hide;
- login:=tlogin.Create(application);
- login.show;
- //-----
- screen.cursor := crdefault;
- statusbar1.refresh;
- exit;
- //连接成功向注册表里写入应用服务器配置信息
- WriteToReg(edtAppHost.Text, edtAppIP.Text, edtPort.Text);
- ljsz.Hide;
- //close;;
- end;
- //关闭窗口
- procedure TLjsz.btnCancelClick(Sender: TObject);
- begin
- if trim(edtAppHost.text)<>'' then mainfrm.Socket1.Host := edtAppHost.text else mainfrm.Socket1.Address := edtAppIP.text;
- mainfrm.Socket1.ServerName:='MMServer.MnData'; mainfrm.Socket1.Connected := true;
- application.Terminate;
- end;
- //利用可视化窗体来选择计算机
- procedure TLjsz.btnAppNameClick(Sender: TObject);
- begin
- edtAppIP.clear;
- //NetExecute方法打开TfrmNet窗口,返回选定的计算机名
- edtAppHost.text := NetExecute(TFrmNet);
- end;
- //当应用服务器名输入后,自动将应用服务器IP地址输入框置空
- procedure TLjsz.edtAppHostExit(Sender: TObject);
- begin
- if edtAppHost.Text <> '' then
- edtAppIP.Text := '';
- end;
- //当应用服务器IP地址输入后,自动将应用服务器名输入框置空
- procedure TLjsz.edtAppIPExit(Sender: TObject);
- begin
- if edtAppIP.Text <> '' then
- edtAppHost.Text := '';
- end;
- //应用服务器名输入框按键事件,当按下“回车”键后,将输入焦点转移到输入端口号输入框
- procedure TLjsz.edtAppHostKeyPress(Sender: TObject; var Key: Char);
- begin
- edtAppIP.clear;
- if key = #13 then
- edtPort.SetFocus;
- end;
- //应用服务器IP地址输入框按键事件,当按下“回车”键后,将输入焦点转移到输入端口号输入框
- procedure TLjsz.edtAppIPKeyPress(Sender: TObject; var Key: Char);
- begin
- edtAppHost.clear;
- if key = #13 then
- edtPort.SetFocus;
- end;
- //端口号输入框按键事件,当按下“回车”键后,调用“确定”按钮的Click方法
- procedure TLjsz.edtPortKeyPress(Sender: TObject; var Key: Char);
- begin
- if key = #13 then
- btnOK.click;
- end;
- procedure TLjsz.FormCreate(Sender: TObject);
- begin
- getdir(0,dir);
- end;
- procedure TLjsz.Socket1AfterDisconnect(Sender: TObject);
- begin
- //application.MessageBox('程序与服务器断开连接!','提示',mb_iconinformation+mb_defbutton1);
- end;
- procedure TLjsz.Socket1BeforeDisconnect(Sender: TObject);
- begin
- //application.MessageBox('程序与服务器断开连接!','提示',mb_iconinformation+mb_defbutton1);
- end;
- procedure TLjsz.ApplicationEvents1Exception(Sender: TObject; E: Exception);
- var
- str: string;
- begin
- str := e.Message;
- if pos('RPC服务器不可用', str)>0 then
- application.MessageBox(pchar(str),'提示'mb_ok+mb_iconinformation);
- end;
- procedure TLjsz.FormKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- begin
- if key=VK_F1 then//确定
- btnOkClick(Sender);
- if key=VK_F3 then//取消
- BtnCancelClick(Sender);
- end;
- procedure TLjsz.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- Socket1.Connected:=false;
- Socket2.Connected:=false;
- Socket3.Connected:=false;
- Socket4.Connected:=false;
- Socket5.Connected:=false;
- Socket6.Connected:=false;
- Socket7.Connected:=false;
- mainfrm.Socket1.Connected:=false;
- end;
- procedure TLjsz.ApplicationEvents1ActionExecute(Action: TBasicAction;
- var Handled: Boolean);
- var str:string;
- begin
- {str:=e.Message;
- if (pos('datetime',str)>0) then
- application.MessageBox('数据类型不符合要求!','提示',mb_iconExclaMation);
- if (pos('Calendar',str)>0) then
- application.MessageBox('数据范围有误!','提示',mb_iconExclaMation);
- if (Pos('Reference 约束',str)>0) then}
- end;
- end.