这里的多帐套的意思是指:程序可以连接到不同的具体数据库。
准备工作:
本文涉及到两个数据库MulDb1和MulDb2。
这两个数据库都是由平台自带数据库生成工具EAS.DbInitializer.exe生成。
下面开始编码:
建立一个MultipleAccountDemo工程
引用
EAS.Data.dll
EAS.Explorer.dll
EAS.MicroKernel.dll
EAS.Windows.dll
新建一个FrmLogin窗体,一个Resource.cs c#文件。
FrmLogin窗体实现EAS.Explorer.ILoginForm接口。
关键代码
try
{
//帐套登录
(EAS.Application.Instance as EAS.Windows.Application).Login(cboAccount.Text, txtUserName.Text,
txtPwd.Text);
_passed = 1;
MessageBox.Show("登录成功,帐套为:" + EAS.Application.Instance.Session.DataSet);
}
catch (System.Exception exc)
{
_passed = -1;
MessageBox.Show(exc.ToString());
}
Resource.cs实现EAS.Explorer.IResource接口。
关键代码
public ILoginForm GetLoginForm()
{
return new FrmLogin();
}
实现之后,编译成Dll。之后就是配置的问题了。
配置详解:
1.在服务端新增SAAS.config文件,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<MultiTenant>
<Items>
<Item DataSet="帐套一" Organization ="帐套一" Assembly="EAS.Data" Type="EAS.Data.Access.SqlClientProvider" Min="5" Max ="100">
<ConnectionString>Data Source=.;Initial Catalog=MulDb1;User ID=sa;Password=sa</ConnectionString>
</Item>
<Item DataSet="帐套二" Organization ="帐套二" Assembly="EAS.Data" Type="EAS.Data.Access.SqlClientProvider" Min="5" Max ="100">
<ConnectionString>Data Source=.;Initial Catalog=MulDb2;User ID=sa;Password=sa</ConnectionString>
</Item>
</Items>
</MultiTenant>
2.配置EAS.SOA.Server.exe.config
<!--数据访问器-->
<object name="DataAccessor" assembly="EAS.Data" type="EAS.Data.Access.DataAccessor" LifestyleType="Thread">
<property name="MultiTenant" type="object" value="MultiTenant"/>
<property name="Language" type="object" value="TSqlLanguage"/>
</object>
<!--XML多帐套-->
<object name="MultiTenant" assembly="EAS.Data" type="EAS.SAAS.XMLMultiTenant" LifestyleType="Singleton"/>
3.在客户端配置文件中加入资源配置
<!--资源-->
<object name="EAS.Explorer.Resource" assembly="MultipleAccountDemo" type="MultipleAccountDemo.Resources" LifestyleType="Singleton" />
运行即可。
http://download.csdn.net/detail/xueshaoyu/7957177点击打开链接