增加了Groups的相关功能
This commit is contained in:
parent
c1b5dd0fa0
commit
56c4b26258
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
<cacheManager>
|
<cacheManager>
|
||||||
<add key="TerminalData-CodeTerminalHelper" interval="600" desc="输入口信息缓存" />
|
<add key="TerminalData-CodeTerminalHelper" interval="600" desc="输入口信息缓存" />
|
||||||
|
<add key="GroupData-CodeGroupHelper" interval="600" desc="群组信息缓存" />
|
||||||
</cacheManager>
|
</cacheManager>
|
||||||
|
|
||||||
<cacheManagerList>
|
<cacheManagerList>
|
||||||
|
|
|
@ -57,6 +57,8 @@
|
||||||
<Link>bldver.cs</Link>
|
<Link>bldver.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="DBAccessManager.cs" />
|
<Compile Include="DBAccessManager.cs" />
|
||||||
|
<Compile Include="Group.cs" />
|
||||||
|
<Compile Include="GroupHelper.cs" />
|
||||||
<Compile Include="Menu.cs" />
|
<Compile Include="Menu.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Terminal.cs" />
|
<Compile Include="Terminal.cs" />
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// author:liuchun
|
||||||
|
/// date:2016.10.22
|
||||||
|
/// </summary>
|
||||||
|
public class Group
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获得/设置 群组主键ID
|
||||||
|
/// </summary>
|
||||||
|
public int ID { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获得/设置 群组名称
|
||||||
|
/// </summary>
|
||||||
|
public string GroupName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获得/设置 群组描述
|
||||||
|
/// </summary>
|
||||||
|
public string Description { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,113 @@
|
||||||
|
using Longbow.Caching;
|
||||||
|
using Longbow.Caching.Configuration;
|
||||||
|
using Longbow.ExceptionManagement;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// author:liuchun
|
||||||
|
/// date:2016.10.22
|
||||||
|
/// </summary>
|
||||||
|
///
|
||||||
|
public static class GroupHelper
|
||||||
|
{
|
||||||
|
private const string GroupDataKey = "GroupData-CodeGroupHelper";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有群组信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<Group> RetrieveGroups(string tId = null)
|
||||||
|
{
|
||||||
|
string sql = "select t.* from Groups t";
|
||||||
|
var ret = CacheManager.GetOrAdd(GroupDataKey, CacheSection.RetrieveIntervalByKey(GroupDataKey), key =>
|
||||||
|
{
|
||||||
|
List<Group> Groups = new List<Group>();
|
||||||
|
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
Groups.Add(new Group()
|
||||||
|
{
|
||||||
|
ID = (int)reader[0],
|
||||||
|
GroupName = (string)reader[1],
|
||||||
|
Description = (string)reader[2]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||||
|
return Groups;
|
||||||
|
}, CacheSection.RetrieveDescByKey(GroupDataKey));
|
||||||
|
return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.ID.ToString(), StringComparison.OrdinalIgnoreCase));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除群组信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ids"></param>
|
||||||
|
public static void DeleteGroup(string ids)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(ids) || ids.Contains("'")) return;
|
||||||
|
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Groups where ID in ({0})", ids);
|
||||||
|
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||||
|
ClearCache();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 保存新建/更新的群组信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool SaveGroup(Group p)
|
||||||
|
{
|
||||||
|
if (p == null) throw new ArgumentNullException("p");
|
||||||
|
bool ret = false;
|
||||||
|
if (p.GroupName.Length > 50) p.GroupName.Substring(0, 50);
|
||||||
|
if (p.Description.Length > 500) p.Description.Substring(0, 500);
|
||||||
|
string sql = p.ID == 0 ?
|
||||||
|
"Insert Into Groups (GroupName, Description) Values (@GroupName, @Description)" :
|
||||||
|
"Update Groups set GroupName = @GroupName, Description = @Description where ID = @ID";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.ID, ParameterDirection.Input));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupName", p.GroupName, ParameterDirection.Input));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", p.Description, ParameterDirection.Input));
|
||||||
|
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||||
|
}
|
||||||
|
ret = true;
|
||||||
|
ClearCache();
|
||||||
|
}
|
||||||
|
catch (DbException ex)
|
||||||
|
{
|
||||||
|
ExceptionManager.Publish(ex);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新缓存
|
||||||
|
private static void ClearCache()
|
||||||
|
{
|
||||||
|
CacheManager.Clear(key => key.Contains("GroupData-"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue