我有一个DNN应用程序,我设法放置一个自定义模块。该模块基本上是递增和递减标签中的值。并且还有一个名为submit的按钮,该按钮仅在标签中显示正值,该值也是递增和递减的值。其目的仅仅是计算应用程序中用户的下载量。
现在这是我的减量代码: public void doDecrement(string propertyKey,UserInfo userInformation,int portalID) { int newDownloadCount = GetProfilePropertyValueAsInt(propertyKey,userInformation); ; int result = 0; result = newDownloadCount - 1; userInformation.Profile.SetProfileProperty(propertyKey,result.ToString()); UserController.UpdateUser(portalID,userInformation); }
这是我的增量代码:
public void doIncrement(string propertyKey, UserInfo userInformation, int portalID)
{
int newDownloadCount = GetProfilePropertyValueAsInt(propertyKey, userInformation);
int result = 0; //initialize to zero
result = newDownloadCount + 1; //assign new value
//set the profile property to RAM... no need to test because Get will default to zero
userInformation.Profile.SetProfileProperty(propertyKey, result.ToString());
//call update user to write the changes to disk
UserController.UpdateUser(portalID, userInformation);
}
这是我的提交代码,因此我可以更新值:
public void UpdatePropertyValue(string propertyKey, UserInfo userInformation, int portalID, string txtNewVale)
{
int newDownloadCount = 0;
int resultValue = 0;
int.TryParse(txtNewVale, out newDownloadCount);
if (String.IsNullOrEmpty(txtNewVale))
{
newDownloadCount = resultValue;
}
userInformation.Profile.SetProfileProperty(propertyKey, newDownloadCount.ToString());
UserController.UpdateUser(portalID, userInformation);
}
我现在的问题是,我遇到了路障。我想使用postgres将增量值保存在数据库中。我希望每当值递增或递减或更新时,它都将保存到数据库中。
我真的很感激任何有帮助的人。提前谢谢。
答案 0 :(得分:1)
您可能知道,DNN的数据访问层是为MS SQL Server编写的。对Postgres或mySQL等开源数据库没有官方支持。但是,您可以编写将连接到外部数据库的代码。这更难,但可以做到。
由于您已经在用户配置文件(存储在DNN SQL数据库中)中更新了增量值,因此您需要编写另一个获取用户配置文件值并更新外部数据库的方法。
首先下载.NET Postgres data driver。在DNN web.config中添加连接字符串作为应用程序密钥。
<appSettings>
...
<add key="PostgresDBConn" value="Server=my-postgres-svr;Port=9090;User Id=dbuser;Password=abc123;Database=dnnExternalTables;" />
...
</appSettings>
然后使用以下命令检索模块代码中的连接字符串:
string connstring = DotNetNuke.Common.Utilities.Config.GetSetting("PostgresDBConn");
NpgsqlConnection conn = new NpgsqlConnection(connstring);
conn.Open();