LoginPromt =false;
通过以上方法,Server端和Client端(中间层)都建立起来了,并且可以运行了。
链接示例:
例1:对部门的数据进行操作,数据库略。
在SererDataModule中建立TADODataSet组件,属性如下:
Name :=DeptADS;
Connection:=ADOConnection1
CommandText: = “select * from tblDept”;
再放置TdataSetProvider组件,并设置其属性如下:
Name:=DeptDSP;
DataSet:=DeptADS;
在ClientDataModule中放置TclientDataSet组件,并设置其属性如下:
Name:= DeptCDS;
RemoveServer:=DCOMConnection1;
ProViderName:= DeptDSP;
这样,整个中间层已建立起来了
3.建立表示层业务
选择MulitSys为活动项目,在刚才建立起的Mainfrm上放置菜单,根据需要设置菜单项,略。
建立Dept 的表示层,并进行简单数据操作。
File
à
New
à
Form
对Form命名,放置DBGrid组件到Form上,并放置SpeedButton按钮到Form上,分别命名为AddBtn,UpdateBtn,DelBtn,SearchBtn,SaveBtn,CancelBtn,PrintBtn,ExitBtn,等。
再从File
à
Use Unit 中,选择ClientDataModule,将它use到deptfrm中。
再放置一TdataSource组件到Form上,设置DataSet的属性如下:
在选择DataSource的DataSet属性前需要选打开ClientData,否则DataSource的DataSet下拉框中无值。
选择,DeptCDS为DataSet属性值。
再将DBGrid1的DataSource值为DataSource1。前面那些数据库的操作按钮见下面代码。
unit pu_Dept;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, Grids, DBGrids, ExtCtrls, Buttons, StdCtrls, Mask, DBCtrls,
ComCtrls;
type
TDeptfrm = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
DBGrid1: TDBGrid;
Panel3: TPanel;
DataSource1: TDataSource;
BackBtn: TSpeedButton;
NextBtn: TSpeedButton;
FindBtn: TSpeedButton;
PrintBtn: TSpeedButton;
AddBtn: TSpeedButton;
EditBtn: TSpeedButton;
DeleteBtn: TSpeedButton;
SaveBtn: TSpeedButton;
CancelBtn: TSpeedButton;
ExitBtn: TSpeedButton;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
Label1: TLabel;
Label2: TLabel;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure Btn;
procedure UnBtn;
procedure BackBtnClick(Sender: TObject);
procedure NextBtnClick(Sender: TObject);
procedure AddBtnClick(Sender: TObject);
procedure EditBtnClick(Sender: TObject);
procedure DeleteBtnClick(Sender: TObject);
procedure SaveBtnClick(Sender: TObject);
procedure CancelBtnClick(Sender: TObject);
procedure ExitBtnClick(Sender: TObject);
private
{ Private declarations }
procedure OnMouseWheel(Var Msg :TMsg;var Handled:Boolean);
public
{ Public declarations }
end;
var
Deptfrm: TDeptfrm;
implementation
uses pu_ClientData, pf_pubfunction;
{$R *.dfm}
//正常
procedure TDeptfrm.Btn;
begin
SaveBtn.Enabled:=false;
CancelBtn.Enabled:=false;
panel3.Visible:=false;
BackBtn.Enabled:=true;
NextBtn.Enabled:=true;
FindBtn.Enabled:=true;
PrintBtn.Enabled:=true;
{AddBtn.Enabled:=pf_pubfunction.p_checkgrouppower(tform(panel1.Owner).Name,'AddBit');
EditBtn.Enabled:=pf_pubfunction.p_checkgrouppower(tform(panel1.Owner).Name,'EditBit');
DeleteBtn.Enabled:=pf_pubfunction.p_checkgrouppower(tform(panel1.Owner).Name,'DelBit');
}
AddBtn.Enabled:=true;
EditBtn.Enabled:=true;
DeleteBtn.Enabled:=true;
ExitBtn.Enabled:=true;
end;
//解锁
procedure TDeptfrm.UnBtn;
begin
SaveBtn.Enabled:=true;
CancelBtn.Enabled:=true;
Panel3.Visible:=true;
BackBtn.Enabled:=false;
NextBtn.Enabled:=false;
FindBtn.Enabled:=false;
PrintBtn.Enabled:=false;
AddBtn.Enabled:=false;
EditBtn.Enabled:=false;
DeleteBtn.Enabled:=false;
ExitBtn.Enabled:=false;
end;
Procedure TDeptfrm.OnMouseWheel(Var Msg :TMsg;var Handled:Boolean);
begin
if Msg.message = WM_MouseWheel then
begin
if Msg.wParam > 0 then
begin
if DBGrid1.Focused then
SendMessage(DBGrid1.Handle,WM_VSCROLL,SB_PAGEUP,0);
end
else
begin
if DBGrid1.Focused then
SendMessage(DBGrid1.Handle,WM_VSCROLL,SB_PAGEDOWN,0);
end;
Handled:= True;
end;
end;
procedure TDeptfrm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree;
end;
procedure TDeptfrm.FormCreate(Sender: TObject);
begin
ClientData.DeptCDS.Active:=true;
Btn;
Application.OnMessage:=OnMouseWheel;
end;
procedure TDeptfrm.BackBtnClick(Sender: TObject);
begin
ClientData.DeptCDS.Prior;
end;
procedure TDeptfrm.NextBtnClick(Sender: TObject);
begin
ClientData.DeptCDS.Next;
end;
procedure TDeptfrm.AddBtnClick(Sender: TObject);
begin
UnBtn;
ClientData.DeptCDS.Insert;
ClientData.DeptCDS.FieldValues['DeptNO']:=pf_pubfunction.p_getmaxno('tblDept','DeptNO',3);
DBEdit2.SetFocus;
end;
procedure TDeptfrm.EditBtnClick(Sender: TObject);
begin
UnBtn;
ClientData.DeptCDS.Edit;
end;
procedure TDeptfrm.DeleteBtnClick(Sender: TObject);
begin
//if MessageDlg('确实要删除吗?',mtConfirmation,[mbYes, mbNo],0)=mrYes then
if MessageDlg('Are you confirm Delete?',mtConfirmation,[mbYes,mbNo],0)=mrYes then
begin
ClientData.DeptCDS.Delete;
ClientData.DeptCDS.ApplyUpdates(-1);
end;
end;
procedure TDeptfrm.SaveBtnClick(Sender: TObject);
begin
Btn;
ClientData.DeptCDS.ApplyUpdates(0);
end;
procedure TDeptfrm.CancelBtnClick(Sender: TObject);
begin
Btn;
ClientData.DeptCDS.Cancel;
end;
procedure TDeptfrm.ExitBtnClick(Sender: TObject);
begin
close;
end;
end.
通过以上步聚,基本上建立起一个完整的三层架构体系了。至于程序的发布,那是另外要再讲的了。以上步聚你都成功了吗?