调用类
using System;
using System.Collections.Generic;
using System.Text;
using SOACore2._0;
using SOACommon;
namespace SOAGroup
{
/// <summary>
/// 获取门户注册协议
/// </summary>
public class GetAgreement : SOACommandHandler
{
/// <summary>
/// 实现抽象方法Handle
/// </summary>
/// <param name="pc">协议参数集合</param>
public override string Handle(ParamentsCollection pc, ResHeader resheader)
{
try
{
if (!pc.ContainsKey("group"))
{
return resheader.ReSetResHeader(600, "缺少group参数:门户名称不能为空!");
}
if (!pc.ContainsKey("projecttype"))
{
return resheader.ReSetResHeader(600, "缺少projecttype参数:项目类型不能为空!");
}
if (!RHTools.RHUiti.RHCheckFormat.IsInt(pc["projecttype"]))
{
return resheader.ReSetResHeader(601, "projecttype参数:必须是数字!");
}
ZSMembership.Entities.Agreement agr=ZSMembership.Process.GetAgreement(RHTools.RHUiti.RHTypeParse.StrToInt(pc["projecttype"], 0),pc["group"]);
return this.OjbectToStrXml(agr);
}
catch (Exception exp)
{
RHTools.RHDebug.ThrowExcetpion(exp, "SetAgreement:设置门户注册协议失败!");
return resheader.ReSetResHeader(700, "服务业务操作失败!");
}
}
private string OjbectToStrXml(ZSMembership.Entities.Agreement agr)
{
StringBuilder strBuid = new StringBuilder();
strBuid.Append("<agreement>");
strBuid.Append("<title><![CDATA[");
strBuid.Append(agr.Title);
strBuid.Append("]]></title>");
strBuid.Append("<context><![CDATA[");
strBuid.Append(agr.Context);
strBuid.Append("]]></context>");
strBuid.Append("</agreement>");
return strBuid.ToString();
}
}
}
逻辑处理类
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Xml;
using RHTools.RHUiti;
using RHTools.RHData;
using ZSMembership.Entities;
namespace ZSMembership {
public class Process {
public static string BuildMemberRoleXml(List<Role> roles) {
string xml = null;
if (roles.Count > 0) {
StringBuilder sb = new StringBuilder();
sb.Append("<root>");
foreach (Role role in roles) {
sb.AppendFormat("<row roleid='{0}' expired='{1}'", role.RoleID, role.Expired.ToString("yyyy-MM-dd"));
if (role.RegDate > DateTime.MinValue)
sb.Append(" regdate='" + role.RegDate.ToString("yyyy-MM-dd") + "'");
sb.Append(" />");
}
sb.Append("</root>");
xml = sb.ToString();
}
return xml;
}
#region Club
/// <summary>
/// 添加门户
/// </summary>
/// <returns>-1 有重名, 0 未执行插入, >0 插入成功;</returns>
public static int ClubRegister(Club club) {
int clubId = 0;
if (!String.IsNullOrEmpty(club.ClubName))
clubId = DataProvider.ClubInsert(club.Project, club.ClubType, club.Expired, club.ClubName, club.Owner);
return clubId;
}
/// <summary>
/// 根据修改门户过期时间及户主
/// </summary>
/// <returns>失败=0, >0 成功 + RoleList</returns>
public static List<Role> ClubChange(Club club, out int result) {
result = 0;
List<Role> list = null;
DataSet ds = DataProvider.ClubChange(club.ClubID, club.Project, club.ClubName, club.ClubType, club.Expired, club.Owner);
if (RHDataCommon.DataSetIsNotNull(ds)) {
result = RHTypeParse.StrToInt(ds.Tables[0].Rows[0][0], 0);
if (ds.Tables.Count >= 2) {
list = new List<Role>();
foreach (DataRow row in ds.Tables[1].Rows) {
Role r = new Role();
r.RoleID = RHTypeParse.StrToInt(RHDataCommon.GetValueFromDataRow(row, "RoleID"), 0);
r.LinkID = RHTypeParse.StrToInt(RHDataCommon.GetValueFromDataRow(row, "LinkID"), 0);
r.RoleType = RHTypeParse.StrToInt(RHDataCommon.GetValueFromDataRow(row, "RoleType"), 0);
r.UserMark = RHTypeParse.StrToInt(RHDataCommon.GetValueFromDataRow(row, "UserMark"), 0);
r.RoleName = RHDataCommon.GetValueFromDataRow(row, "RoleName");
list.Add(r);
}
}
}
return list;
}
public static void ClubDelete(Club club) {
DataProvider.ClubDelete(club.ClubID, club.Project, club.ClubName);
}
/// <summary>
/// 根据project, club查询门户
/// </summary>
public static Club GetClub(Club club) {
DataSet ds = DataProvider.GetClub(club.Project, club.ClubName);
if (RHDataCommon.DataSetIsNotNull(ds))
club = Common.MakeClub(ds.Tables[0].Rows[0]);
return club;
}
/// <summary>
/// 根据project, club查询门户
/// </summary>
public static Club GetOwnerClub(int project, string owner) {
Club club = new Club();
DataSet ds = DataProvider.GetOwnerClub(project, owner);
if (RHDataCommon.DataSetIsNotNull(ds))
club = Common.MakeClub(ds.Tables[0].Rows[0]);
return club;
}
/// <summary>
/// 根据igid查询所属门户
/// </summary>
public static List<Club> GetClubList(string igid) {
return GetClubList(0, String.Empty, -1, igid);
}
/// <summary>
/// 根据igid查询所属门户
/// </summary>
public static List<Club> GetClubList(int project, string club, string igid) {
return GetClubList(project, club, -1, igid);
}
/// <summary>
/// 根据igid查询所属门户
/// </summary>
public static List<Club> GetClubList(int project, string clubname, int clubtype, string igid) {
DataSet ds = DataProvider.GetMemberClubs(project, clubname, clubtype, igid);
List<Club> list = new List<Club>();
if (RHDataCommon.DataSetIsNotNull(ds)) {
list = Common.MakeClubList(ds.Tables[0]);
if (ds.Tables.Count == 2) {
DataTable tabrole = ds.Tables[1];
foreach (Club club in list) {
Member member = new Member();
member.IGID = igid;
DataRow[] rows = tabrole.Select("ClubID=" + club.ClubID.ToString());
foreach (DataRow row in rows) {
// m.MemberID, m.ClubID, m.IGID, m.RoleType, m.RoleID, m.RegDate, m.Expired
Role role = new Role();
role.RoleID = RHTypeParse.StrToInt(row["RoleID"], 0);
role.RoleType = RHTypeParse.StrToInt(row["RoleType"], 0);
role.RegDate = RHTypeParse.StrToDateTime(row["RegDate"].ToString());
role.Expired = RHTypeParse.StrToDateTime(row["Expired"].ToString());
role.RoleName = row["RoleName"].ToString();
member.AddRole(role);
}
club.AddMember(member);
}
}
}
return list;
}
#endregion
#region ClubRole
/// <summary>
/// 添加门户角色
/// </summary>
public static int ClubRoleAdd(Club club, Role role) {
int roleId = DataProvider.ClubRoleInsert(club.ClubID, club.Project, club.ClubName, role.AuditType, role.LinkID, role.RoleType, role.UserMark, role.RoleName, role.AuditorsToString());
return roleId;
}
/// <summary>
/// 修改门户角色
/// </summary>
public static void ClubRoleSet(Role role) {
if (role.RoleID > 0)
DataProvider.ClubRoleModify(role.RoleID, role.AuditType, role.LinkID, role.RoleType, role.RoleName);
}
/// <summary>
/// 删除门户角色
/// </summary>
public static void ClubRoleDel(List<Role> roles) {
if (roles.Count > 0) {
List<string> list = new List<string>();
foreach (Role role in roles)
list.Add(role.RoleID.ToString());
string ids = String.Join(",", list.ToArray());
DataProvider.ClubRoleDelete(ids);
}
}
/// <summary>
/// 冻结、解冻门户角色
/// disable = 0 解冻
/// disable = 1 冻结
/// </summary>
public static void ClubRoleDisable(int disable, int[] roles) {
if (roles.Length > 0) {
DataProvider.ClubRoleDisable(disable, String.Join(",", Common.Int2StrArray(roles)));
}
}
/// <summary>
/// 根据roleid获取角色
/// </summary>
public static List<Role> GetRoles(int[] roles) {
string rolelist = String.Join(",", Common.Int2StrArray(roles));
List<Role> list = new List<Role>();
if (!String.IsNullOrEmpty(rolelist)) {
DataSet ds = DataProvider.GetRoles(rolelist);
if (RHDataCommon.DataSetIsNotNull(ds))
list = Common.MakeRoleList(ds.Tables[0]);
}
return list;
}
/// <summary>
/// 根据roleName获取角色
/// </summary>
public static List<Role> GetRoles(int project, string clubname, string rolename) {
List<Role> list = new List<Role>();
if (!String.IsNullOrEmpty(clubname) && !String.IsNullOrEmpty(rolename)) {
DataSet ds = DataProvider.GetRole(project, clubname, rolename);
if (RHDataCommon.DataSetIsNotNull(ds))
list = Common.MakeRoleList(ds.Tables[0]);
}
return list;
}
/// <summary>
/// 获取门户下所有角色
/// </summary>
public static List<Role> GetIGIDRoles(int project, string igid) {
DataSet ds = DataProvider.GetIGIDRoles(project, igid);
List<Role> list = new List<Role>();
if (RHDataCommon.DataSetIsNotNull(ds))
list = Common.MakeRoleList(ds.Tables[0]);
return list;
}
/// <summary>
/// 获取门户下所有角色
/// </summary>
public static List<Role> GetClubRoles(int project, string club) {
return GetClubRoles(project, club, -1);
}
/// <summary>
/// 获取门户某角色类型下所有角色
/// </summary>
public static List<Role> GetClubRoles(int project, string club, int roletype) {
DataSet ds = DataProvider.GetClubRoles(project, club, roletype);
List<Role> list = new List<Role>();
if (RHDataCommon.DataSetIsNotNull(ds))
list = Common.MakeRoleList(ds.Tables[0]);
return list;
}
#endregion
#region Member
/// <summary>
/// 判断是否为户主
/// </summary>
/// <returns>0=否,1=是</returns>
public static int CheckOwner(Member mem) {
return DataProvider.CheckOwner(mem.Project, mem.IGID);
}
/// <summary>
/// 插入用户
/// </summary>
/// <returns>-1 有重名, 0 未执行插入, >0 插入成功;</returns>
public static int MemberRegister(Member member) {
int memberId = 0;
if (!String.IsNullOrEmpty(member.ClubName) && !String.IsNullOrEmpty(member.IGID)) {
string rolexml = null;
if (member.RoleList.Count > 0)
rolexml = BuildMemberRoleXml(member.RoleList);
memberId = DataProvider.MemberInsert(member.Project, member.ClubName, 2, member.IGID, rolexml);
}
return memberId;
}
/// <summary>
/// 用户删除
/// </summary>
public static void MemberDel(int project, string club, string[] members) {
if (members.Length > 0) {
DataProvider.MemberDelete(project, club, String.Join(",", members));
}
}
/// <summary>
/// 查询用户所在门户MemberType
/// </summary>
/// <param name="project">项目类型</param>
/// <param name="club">门户词</param>
/// <param name="igid">igid</param>
/// <returns>0=不存在,1=户主,2=用户;</returns>
public static int MemberGetType(int project, string club, string igid) {
return DataProvider.MemberGetType(0, project, club, igid);
}
public static List<Member> GetMemberList(int project, string club, int pi, int ps, out int count) {
return GetMemberList(0, project, club, 0, -1, String.Empty, String.Empty, 0, pi, ps, out count);
}
public static List<Member> GetMemberList(int project, string club, short roletype, int pi, int ps, out int count) {
return GetMemberList(0, project, club, 0, roletype, String.Empty, String.Empty, 0, pi, ps, out count);
}
public static List<Member> GetMemberList(int project, string club, int roleid, int pi, int ps, out int count) {
return GetMemberList(0, project, club, roleid, -1, String.Empty, String.Empty, 0, pi, ps, out count);
}
/// <summary>
/// 获取门户club下会员igid的会员及其类型
/// </summary>
/// <param name="members">igid,igid</param>
public static List<Member> GetMemberList(int project, string club, string[] members) {
int pi = 0;
int ps = members.Length;
int count = 0;
return GetMemberList(0, project, club, 0, 0, String.Join(",", members), String.Empty, 0, pi, ps, out count);
}
/// <summary>
/// 查询用户及其角色
/// </summary>
public static List<Member> GetMemberList(int clubid, int project, string club, int roleid, short roletype, string members, string igid, int sorttype, int pi, int ps, out int count) {
count = 0;
DataSet ds = DataProvider.GetMembers(clubid, project, club, roleid, roletype, -1, members, igid, sorttype, pi, ps);
List<Member> list = new List<Member>();
if (RHDataCommon.DataSetIsNotNull(ds)) {
count = RHTypeParse.StrToInt(ds.Tables[ds.Tables.Count - 1].Rows[0][0], 0);
list = Common.MakeMemberList(ds.Tables[0]);
foreach (Member member in list) {
DataRow[] rows = ds.Tables[1].Select("MemberID=" + member.MemberID.ToString());
foreach (DataRow row in rows) {
//Role role = Common.MakeRole(row);
//m.MemberID, m.IGID, m.RoleType, m.RoleID, m.RegDate, m.Expired
Role role = new Role();
role.RoleID = RHTypeParse.StrToInt(row["RoleID"], 0);
role.RoleType = RHTypeParse.StrToInt(row["RoleType"], 0);
role.RegDate = RHTypeParse.StrToDateTime(row["RegDate"].ToString());
role.Expired = RHTypeParse.StrToDateTime(row["Expired"].ToString());
role.RoleName = row["RoleName"].ToString();
member.AddRole(role);
}
}
}
return list;
}
/// <summary>
/// B2B查询用户及其角色
/// </summary>
/// <param name="validity">是否有效, -1=全部,0=失效,1=有效</param>
public static List<Member> GetMemberList(int project, string club, int roleid, int validity, string igid, int sorttype, int pi, int ps, out int count) {
count = 0;
DataSet ds = DataProvider.GetMembers(0, project, club, roleid, -1, validity, String.Empty, igid, sorttype, pi, ps);
List<Member> list = new List<Member>();
if (RHDataCommon.DataSetIsNotNull(ds)) {
count = RHTypeParse.StrToInt(ds.Tables[ds.Tables.Count - 1].Rows[0][0], 0);
list = Common.MakeMemberList(ds.Tables[0]);
foreach (Member member in list) {
DataRow[] rows = ds.Tables[1].Select("MemberID=" + member.MemberID.ToString());
foreach (DataRow row in rows) {
//Role role = Common.MakeRole(row);
//m.MemberID, m.IGID, m.RoleType, m.RoleID, m.RegDate, m.Expired
Role role = new Role();
role.RoleID = RHTypeParse.StrToInt(row["RoleID"], 0);
role.RoleType = RHTypeParse.StrToInt(row["RoleType"], 0);
role.RegDate = RHTypeParse.StrToDateTime(row["RegDate"].ToString());
role.Expired = RHTypeParse.StrToDateTime(row["Expired"].ToString());
role.RoleName = row["RoleName"].ToString();
member.AddRole(role);
}
}
}
return list;
}
/// <summary>
/// 获取用户加入门户时间
/// </summary>
/// <param name="members">igid,igid</param>
public static DateTime GetClubMemberRegDate(int project, string club, string igid) {
DataSet dst = DataProvider.GetMemberRegDate(project, club, igid);
if (RHDataCommon.DataSetIsNotNull(dst)) {
return RHData.DataRowGetDateTime(dst.Tables[0].Rows[0], 0, DateTime.MinValue);
}
else {
return DateTime.MinValue;
}
}
/// <summary>
/// 获取门户会员数量
/// </summary>
/// <param name="members">igid,igid</param>
public static int GetClubMemberCount(int project, string club) {
DataSet dst = DataProvider.GetMemberCount(project, club);
if (RHDataCommon.DataSetIsNotNull(dst)) {
return RHData.DataRowGetInt32(dst.Tables[0].Rows[0], 0, 0);
}
else {
return 0;
}
}
/// <summary>
/// 获取门户会员数量
/// </summary>
public static List<Role> TotalClubRoleMembers(int project, string club) {
List<Role> list = new List<Role>();
DataSet ds = DataProvider.TotalClubRoleMembers(project, club);
if (RHDataCommon.DataSetIsNotNull(ds)) {
// r.ClubID, r.RoleID, r.RoleName, r.RoleType, ISNULL(m.MCount, 0) AS MCount
foreach (DataRow row in ds.Tables[0].Rows) {
Role role = new Role();
role.ClubID = RHTypeParse.StrToInt(row["ClubID"], 0);
role.RoleID = RHTypeParse.StrToInt(row["RoleID"], 0);
role.RoleType = RHTypeParse.StrToInt(row["RoleType"], 0);
role.RoleName = row["RoleName"].ToString();
role.MCount = RHTypeParse.StrToInt(row["MCount"], 0);
list.Add(role);
}
}
return list;
}
#endregion
#region Auditor
public static void AuditorSet(int roleid, string[] auditors) {
DataProvider.AuditorInsert(roleid, String.Join(",", auditors));
}
public static void AuditorDel(int roleid, string[] auditors) {
DataProvider.AuditorDelete(roleid, String.Join(",", auditors));
}
#endregion
#region MemberRole
/// <summary>
/// 用户角色申请
/// applyId = 1 成功;
/// applyId = 0 失败;
/// applyId = -1 已申请;
/// </summary>
public static int MemberApply(Apply apply) {
int applyId = 0;
applyId = DataProvider.RoleApply(apply.RoleID, apply.IGID, apply.Expired, apply.Info);
return applyId;
}
/// <summary>
/// 获取申请列表
/// </summary>
public static List<Applicant> GetApplicant(int project, string club, int pi, int ps, out int count) {
return GetApplicant(project, club, String.Empty, String.Empty, pi, ps, out count);
}
/// <summary>
/// 获取申请列表
/// </summary>
public static List<Applicant> GetApplicant(int project, string club, string igid, int pi, int ps, out int count) {
return GetApplicant(project, club, igid, String.Empty, pi, ps, out count);
}
/// <summary>
/// 获取申请列表
/// </summary>
public static List<Applicant> GetApplicant(int project, string club, int roleid, int pi, int ps, out int count) {
return GetApplicant(project, club, String.Empty, roleid.ToString(), pi, ps, out count);
}
/// <summary>
/// 获取申请列表
/// </summary>
public static List<Applicant> GetApplicant(int project, string club, string igid, string roles, int pi, int ps, out int count) {
List<Applicant> list = new List<Applicant>();
count = 0;
DataSet ds = DataProvider.GetApplicant(project, club, igid, roles, pi, ps);
if (RHDataCommon.DataSetIsNotNull(ds)) {
count = RHTypeParse.StrToInt(ds.Tables[ds.Tables.Count - 1].Rows[0][0], 0);
list = Common.MakeApplicantList(ds.Tables[0]);
foreach (Applicant applicant in list) {
DataRow[] rows = ds.Tables[1].Select("ApplyID=" + applicant.ApplyID.ToString());
foreach (DataRow row in rows) {
Auditor audit = Common.MakeAudit(row);
applicant.AddAudit(audit);
}
}
}
return list;
}
public static void MemberAudit(int state, string igid, string[] applylist, string info) {
DataProvider.RoleAudit(state, igid, String.Join(",", applylist), info);
}
public static void MemberRoleSet(Member member) {
if (member.RoleList.Count > 0) {
string rolexml = BuildMemberRoleXml(member.RoleList);
DataProvider.MemberRoleInsert(member.Project, member.ClubName, member.IGID, rolexml);
}
}
public static void MemberRoleChange(int project, string club, List<Member> delete, List<Member> insert) {
string delxml = String.Empty;
StringBuilder sb = null;
if (delete.Count > 0) {
sb = new StringBuilder();
foreach (Member mem in delete) {
foreach (Role role in mem.RoleList)
sb.AppendFormat("<row igid='{0}' roleid='{1}' />", mem.IGID, role.RoleID);
}
delxml = sb.ToString();
}
if (!String.IsNullOrEmpty(delxml))
delxml = "<root>" + delxml + "</root>";
string insxml = String.Empty;
if (insert.Count > 0) {
sb = new StringBuilder();
foreach (Member mem in insert) {
foreach (Role role in mem.RoleList) {
sb.AppendFormat("<row igid='{0}' roleid='{1}' roletype='{2}'", mem.IGID, role.RoleID, role.RoleType);
if (role.Expired > DateTime.MinValue)
sb.Append(" expired='" + role.Expired.ToString("yyyy-MM-dd") + "'");
if (role.RegDate > DateTime.MinValue)
sb.Append(" regdate='" + role.RegDate.ToString("yyyy-MM-dd") + "'");
sb.Append(" />");
}
}
insxml = sb.ToString();
}
if (!String.IsNullOrEmpty(insxml))
insxml = "<root>" + insxml + "</root>";
if (!String.IsNullOrEmpty(delxml) && !String.IsNullOrEmpty(insxml))
DataProvider.MemberRoleChange(project, club, delxml, insxml);
}
public static void MemberRoleDel(int project, string club, string igid, int[] roles) {
if (roles.Length > 0) {
string list = String.Join(",", Common.Int2StrArray(roles));
DataProvider.MemberRoleDelete(project, club, igid, list);
}
}
public static void MemberRoleReExpired(MemberRole role) {
DataProvider.MemberRoleReExpired(role.Project, role.ClubName, role.RoleID, role.IGID, role.Expired);
}
#endregion
#region Regest
public static int RegestInfoExSet(int project, string clubname, string igid, int roleid, List<RegestInfoEx> list) {
string xml = String.Empty;
int result = 0;
if (list.Count > 0) {
StringBuilder sb = new StringBuilder();
sb.Append("<root>");
foreach (RegestInfoEx ex in list) {
sb.AppendFormat("<row ename='{0}' etext='{1}' />", ex.EName, ex.EText);
}
sb.Append("</root>");
xml = sb.ToString();
result = DataProvider.RegestInfoExSet(project, 0, clubname, igid, roleid, xml);
}
return result;
}
public static void RegestInfoExDel(int exId) {
DataProvider.RegestInfoExDel(exId, 0, String.Empty, 0, String.Empty);
}
public static void RegestInfoExDel(int project, string clubname, int roleid, string igid) {
DataProvider.RegestInfoExDel(0, project, clubname, roleid, igid);
}
public static List<RegestInfoEx> GetRegestInfoExList(int project, string clubname, int roleid, string igid) {
List<RegestInfoEx> list = new List<RegestInfoEx>();
DataSet ds = DataProvider.RegestInfoExGet(project, clubname, roleid, igid);
if (RHDataCommon.DataSetIsNotNull(ds))
list = Common.MakeRegestInfoExList(ds.Tables[0]);
return list;
}
public static int RegestEntrySet(RegestEntry regest) {
return DataProvider.RegestEntrySet(regest.EntryID, regest.Project, regest.ClubID, regest.ClubName, regest.RoleID, regest.EntryText);
}
public static void RegestEntryDel(int entryId) {
DataProvider.RegestEntryDel(entryId, 0, String.Empty, 0);
}
public static void RegestEntryDel(int project, string clubname, int roleid) {
DataProvider.RegestEntryDel(0, project, clubname, roleid);
}
public static RegestEntry GetRegestEntry(int project, string clubname, int roleid) {
RegestEntry regest = new RegestEntry();
DataSet ds = DataProvider.RegestEntryGet(0, project, clubname, roleid);
if (RHDataCommon.DataSetIsNotNull(ds))
regest = Common.MakeRegestEntry(ds.Tables[0].Rows[0]);
return regest;
}
#endregion
#region Agreement 用户协议
public static void AgreementSet(Agreement agr) {
DataProvider.AgreementSet(agr.ClubID, agr.Project, agr.ClubName, agr.Title, agr.Context);
}
public static Agreement GetAgreement(int project, string clubname) {
Agreement agr = new Agreement();
DataSet ds = DataProvider.AgreementGet(0, project, clubname);
if (RHDataCommon.DataSetIsNotNull(ds)) {
DataRow row = ds.Tables[0].Rows[0];
agr.ClubID = RHTypeParse.StrToInt(row["ClubID"], 0);
agr.Title = row["Title"].ToString();
agr.Context = row["Context"].ToString();
}
return agr;
}
#endregion
#region SetMemPortalService
public static int MemPortalServiceSet(string igid, string enter) {
return DataProvider.MemPortalServiceSet(igid, enter);
}
#endregion
#region LoginLog
/// <summary>
/// 插入登录日志
/// </summary>
/// <param name="login">LoginLog对象</param>
/// <returns>-1=igid为空, 0=插入失败,>0成功;</returns>
public static int LoginLogSet(LoginLog login) {
if (!String.IsNullOrEmpty(login.IGID))
return DataProvider.LoginLogSet(login.Project, login.ClubName, login.Tag, login.IGID, login.IP);
else
return -1;
}
public static LoginLog LoginLogGetLast(string igid) {
return LoginLogGetLast(0, String.Empty, igid);
}
public static LoginLog LoginLogGetLast(int project, string club, string igid) {
LoginLog login = new LoginLog();
DataSet ds = DataProvider.LoginLogGetLast(project, club, igid);
if (RHDataCommon.DataSetIsNotNull(ds)) {
DataRow row = ds.Tables[0].Rows[0];
login.Project = project;
login.IGID = row["IGID"].ToString();
login.ClubName = row["ClubName"].ToString();
login.Times = RHTypeParse.StrToInt(row["LoginTimes"], 0);
login.LastLogin = RHTypeParse.StrToDateTime(row["LastLogin"].ToString());
}
return login;
}
/// <summary>
/// 根据igid查询登录日志
/// </summary>
public static List<LoginLog> LoginLogGetList(string igid, int pi, int ps, out int count) {
return LoginLogGetList(0, String.Empty, igid, pi, ps, out count);
}
/// <summary>
/// 查询登录日志
/// </summary>
public static List<LoginLog> LoginLogGetList(int project, string club, string igid, int pi, int ps, out int count) {
return LoginLogGetList(0, String.Empty, igid, DateTime.MinValue, DateTime.MinValue, pi, ps, out count);
}
/// <summary>
/// 查询登录日志
/// </summary>
public static List<LoginLog> LoginLogGetList(int project, string club, string igid, DateTime lowerTime, DateTime upperTime, int pi, int ps, out int count) {
count = 0;
List<LoginLog> list = new List<LoginLog>();
DataSet ds = DataProvider.LoginLogGetList(project, club, igid, lowerTime, upperTime, pi, ps);
if (RHDataCommon.DataTableIsNotNull(ds)) {
foreach (DataRow row in ds.Tables[0].Rows) {
LoginLog login = new LoginLog();
login.LogID = RHTypeParse.StrToInt(row["LogID"], 0);
login.Tag = RHTypeParse.StrToInt(row["Tag"], 0);
login.LoginTime = RHTypeParse.StrToDateTime(row["LoginTime"].ToString());
login.ClubID = RHTypeParse.StrToInt(row["ClubID"], 0);
login.Project = RHTypeParse.StrToInt(row["Project"], 0);
login.ClubName = row["ClubName"].ToString();
login.IGID = row["IGID"].ToString();
login.IP = row["IP"].ToString();
list.Add(login);
}
count = RHTypeParse.StrToInt(ds.Tables[1].Rows[0][0], 0);
}
return list;
}
#endregion
#region MemberReg 用户注册信息
/// <summary>
/// 设置用户最后修改密码时间
/// </summary>
/// <param name="igid"></param>
/// <returns>返回值>0表示成功</returns>
public static DateTime MemberRegSetPassTime(string igid) {
return DataProvider.MemberRegSetPassTime(igid);
}
/// <summary>
/// 获取用户最后修改密码时间
/// </summary>
/// <param name="igid"></param>
/// <returns>若返回时间=DateTime.MinValue,则表示空记录</returns>
public static DateTime MemberRegGetPassTime(string igid) {
return DataProvider.MemberRegGetPassTime(igid);
}
#endregion
}
}
数据处理类
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
using RHTools.RHUiti;
using MSSQLHelper;
using ZSMembership.Entities;
namespace ZSMembership {
public partial class DataProvider {
private static readonly string connectionString = ZSConfig.MssqlDBConfig.Instance.ZSMembership;
/// <summary>
/// 判断是否为户主
/// </summary>
/// <returns>0=否,1=是</returns>
public static int CheckOwner(int project, string igid) {
object obj = ProcHelper.ExecuteScalar("CheckOwner", connectionString, project, igid);
return RHTypeParse.StrToInt(obj, 0);
}
public static int ClubInsert(int project, int type, DateTime expired, string club, string owner) {
object date = DBNull.Value;
if (expired > new DateTime(1900, 1, 1))
date = expired;
object obj = ProcHelper.ExecuteScalar("ClubInsert", connectionString, project, type, date, club, owner);
return RHTypeParse.StrToInt(obj, 0);
}
public static DataSet ClubChange(int clubId, int project, string club, int clubtype, DateTime expired, string owner) {
SqlParameter[] parms = {
SqlHelper.MakeInParam("@ClubID", SqlDbType.Int, 0, clubId),
SqlHelper.MakeInParam("@Project", SqlDbType.Int, 0, project),
SqlHelper.MakeInParam("@ClubName", SqlDbType.NVarChar, 50, club),
SqlHelper.MakeInParam("@ClubType", SqlDbType.Int, 0, clubtype),
SqlHelper.MakeInParam("@Expired", SqlDbType.DateTime, 0, RHTypeParse.DateToMssqlValue(expired)),
SqlHelper.MakeInParam("@IGID", SqlDbType.NVarChar, 50, owner)
};
return SqlHelper.ExecuteDataset(connectionString, CommandType.StoredProcedure, "ClubChange", parms);
}
public static void ClubDelete(int clubid, int project, string club) {
ProcHelper.ExecuteNonQuery("ClubDelete", connectionString, clubid, project, club);
}
#region ClubRole
public static int ClubRoleInsert(int clubid, int project, string club, int audittype, int linkid, int roletype, int usermark, string rolename, string auditors) {
object obj = ProcHelper.ExecuteScalar("RoleInsert", connectionString, clubid, project, club, audittype, linkid, roletype, usermark, rolename, auditors);
int roleId = RHTypeParse.StrToInt(obj, 0);
return roleId;
}
public static void ClubRoleModify(int roleid, int audittype, int linkid, int roletype, string rolename) {
ProcHelper.ExecuteNonQuery("RoleUpdate", connectionString, roleid, audittype, linkid, roletype, rolename);
}
public static void ClubRoleDelete(string roles) {
ProcHelper.ExecuteNonQuery("RoleDelete", connectionString, roles);
}
public static void ClubRoleDisable(int disable, string roles) {
ProcHelper.ExecuteNonQuery("RoleDisable", connectionString, disable, roles);
}
#endregion
#region Member
public static int MemberInsert(int project, string club, int membertype, string igid, string rolexml) {
object obj = ProcHelper.ExecuteScalar("MemberInsert", connectionString, null, project, club, membertype, igid, rolexml);
return RHTypeParse.StrToInt(obj, 0);
}
public static void MemberDelete(int project, string club, string members) {
ProcHelper.ExecuteNonQuery("MemberDelete", connectionString, null, project, club, members);
}
public static int MemberGetType(int clubId, int project, string club, string igid) {
object obj = ProcHelper.ExecuteScalar("MemberGetType", connectionString, clubId, project, club, igid);
return RHTypeParse.StrToInt(obj, 0);
}
#endregion
#region MemberRole
public static void MemberRoleInsert(int project, string club, string igid, string rolexml) {
ProcHelper.ExecuteNonQuery("MemberRoleInsert", connectionString, null, project, club, null, igid, rolexml);
}
public static void MemberRoleDelete(int project, string club, string igid, string roles) {
ProcHelper.ExecuteNonQuery("MemberRoleDelete", connectionString, null, project, club, null, igid, roles);
}
public static void MemberRoleChange(int project, string club, string deletexml, string insertxml) {
ProcHelper.ExecuteNonQuery("MemberRoleChange", connectionString, project, club, deletexml, insertxml);
}
public static void MemberRoleReExpired(int project, string club, int roleid, string igid, DateTime expired) {
ProcHelper.ExecuteNonQuery("MemberRoleReExpired", connectionString, null, project, club, roleid, igid, expired);
}
#endregion
#region Auditor
public static void AuditorInsert(int roleid, string auditors) {
ProcHelper.ExecuteNonQuery("AuditorInsert", connectionString, roleid, auditors);
}
public static void AuditorDelete(int roleid, string auditors) {
ProcHelper.ExecuteNonQuery("AuditorDelete", connectionString, roleid, auditors);
}
#endregion
#region Apply
public static int RoleApply(int roleid, string igid, DateTime expired, string info) {
object obj = ProcHelper.ExecuteScalar("RoleApply", connectionString, roleid, igid, expired, info);
int applyId = RHTypeParse.StrToInt(obj, 0);
return applyId;
}
public static void RoleAudit(int state, string igid, string applylist, string info) {
ProcHelper.ExecuteNonQuery("RoleAudit", connectionString, state, igid, applylist, info);
}
#endregion
#region Regest
public static int RegestInfoExSet(int project, int clubid, string clubname, string igid, int roleid, string xml) {
object obj = ProcHelper.ExecuteScalar("SetRegestInfoEx", connectionString, project, clubid, clubname, roleid, igid, xml);
return RHTypeParse.StrToInt(obj, 0);
}
public static void RegestInfoExDel(int exId, int project, string clubname, int roleid, string igid) {
ProcHelper.ExecuteNonQuery("DelRegestInfoEx", connectionString, exId, project, clubname, roleid, igid);
}
public static DataSet RegestInfoExGet(int project, string clubname, int roleid, string igid) {
return ProcHelper.ExecuteDataset("GetRegestInfoEx", connectionString, project, clubname, roleid, igid);
}
public static int RegestEntrySet(int entryId, int project, int clubId, string clubname, int roleid, string entryText) {
object obj = ProcHelper.ExecuteScalar("SetRegestEntry", connectionString, entryId, project, clubId, clubname, roleid, entryText);
entryId = RHTypeParse.StrToInt(obj, 0);
return entryId;
}
public static void RegestEntryDel(int entryId, int project, string clubname, int roleid) {
ProcHelper.ExecuteNonQuery("DelRegestEntry", connectionString, entryId, project, clubname, roleid);
}
public static DataSet RegestEntryGet(int entryId, int project, string clubname, int roleid) {
return ProcHelper.ExecuteDataset("GetRegestEntry", connectionString, entryId, project, clubname, roleid);
}
#endregion
#region Agreement 用户协议
public static void AgreementSet(int clubId, int project, string clubname, string title, string context) {
ProcHelper.ExecuteNonQuery("SetAgreement", connectionString, clubId, project, clubname, title, context);
}
public static DataSet AgreementGet(int clubId, int project, string clubname) {
return ProcHelper.ExecuteDataset("GetAgreement", connectionString, clubId, project, clubname);
}
#endregion
#region SetMemPortalService
public static int MemPortalServiceSet(string igid, string enter) {
object obj = ProcHelper.ExecuteScalar("SetMemPortalService", connectionString, igid, enter);
return RHTypeParse.StrToInt(obj, 0);
}
#endregion
#region LoginLog 登录日志
public static int LoginLogSet(int project, string clubname, int tag, string igid, string ip) {
SqlParameter[] parms = {
SqlHelper.MakeInParam("@Project", SqlDbType.Int, 0, project),
SqlHelper.MakeInParam("@ClubName", SqlDbType.NVarChar, 50, clubname),
SqlHelper.MakeInParam("@Tag", SqlDbType.Int, 0, tag),
SqlHelper.MakeInParam("@IGID", SqlDbType.NVarChar, 50, igid),
SqlHelper.MakeInParam("@IP", SqlDbType.NVarChar, 128, ip)
};
object obj = SqlHelper.ExecuteScalar(connectionString, CommandType.StoredProcedure, "LoginLogSet", parms);
return RHTypeParse.StrToInt(obj, 0);
}
public static DataSet LoginLogGetLast(int project, string club, string igid) {
return ProcHelper.ExecuteDataset("LoginLogGetLast", connectionString, project, club, igid);
}
public static DataSet LoginLogGetList(int project, string club, string igid, DateTime lowerTime, DateTime upperTime, int pi, int ps) {
return ProcHelper.ExecuteDataset("LoginLogGetList", connectionString, project, club, igid, RHTypeParse.DateToMssqlValue(lowerTime), RHTypeParse.DateToMssqlValue(upperTime), pi, ps);
}
#endregion
#region MemberReg 用户注册信息
public static DateTime MemberRegSetPassTime(string igid) {
SqlParameter[] parms = {
SqlHelper.MakeInParam("@IGID", SqlDbType.NVarChar, 50, igid)
};
object obj = SqlHelper.ExecuteScalar(connectionString, CommandType.StoredProcedure, "MemberRegSetPassTime", parms);
return RHTypeParse.StrToDateTime(obj, DateTime.MinValue);
}
public static DateTime MemberRegGetPassTime(string igid) {
SqlParameter[] parms = {
SqlHelper.MakeInParam("@IGID", SqlDbType.NVarChar, 50, igid)
};
object obj = SqlHelper.ExecuteScalar(connectionString, CommandType.StoredProcedure, "MemberRegGetPassTime", parms);
return RHTypeParse.StrToDateTime(obj, DateTime.MinValue);
}
#endregion
}
}
数据处理类
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace MSSQLHelper
{
/// <summary>
/// StoredProcedure Helper Class
/// </summary>
public class ProcHelper
{
#region ExecuteNonQuery
/// <summary>
/// ExecuteNonQuery
/// </summary>
/// <param name="command">StoredProcedure Name</param>
/// <param name="connectionString">connection string</param>
/// <param name="parameters">parameters value</param>
/// <returns>ref count</returns>
public static int ExecuteNonQuery(string command, string connectionString, params object[] parameters)
{
int count = 0;
using (SqlConnection con = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = command;
cmd.CommandType = CommandType.StoredProcedure;
CommandBuilder.Instance.Build(cmd, parameters);
con.Open();
count = cmd.ExecuteNonQuery();
con.Close();
}
return count;
}
/// <summary>
/// ExecuteNonQuery command will be fill paraments
/// </summary>
/// <param name="command">StoredProcedure Name</param>
/// <param name="connectionString">connection string</param>
/// <param name="parameters">parameters value</param>
/// <returns>ref count</returns>
public static int ExecuteNonQuery(SqlCommand command, string connectionString, params object[] parameters)
{
int count = 0;
using (SqlConnection con = new SqlConnection(connectionString))
{
command.Connection = con;
CommandBuilder.Instance.Build(command, parameters);
con.Open();
command.Parameters.Add("getreturn", SqlDbType.Int);
command.Parameters["getreturn"].Direction = ParameterDirection.ReturnValue;
count = command.ExecuteNonQuery();
con.Close();
}
return count;
}
#endregion
#region ExecuteScalar
/// <summary>
/// ExecuteScalar
/// </summary>
/// <param name="command">StoredProcedure Name</param>
/// <param name="connectionString">connection string</param>
/// <param name="type">CommandType</param>
/// <param name="parameters">parameters value</param>
/// <returns>object</returns>
public static object ExecuteScalar(string command, string connectionString, params object[] parameters)
{
object res = null;
using (SqlConnection con = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = command;
cmd.CommandType = CommandType.StoredProcedure;
CommandBuilder.Instance.Build(cmd, parameters);
con.Open();
res = cmd.ExecuteScalar();
con.Close();
}
return res;
}
/// <summary>
/// ExecuteScalar command will be fill paraments
/// </summary>
/// <param name="command">StoredProcedure Name</param>
/// <param name="connectionString">connection string</param>
/// <param name="parameters">parameters value</param>
/// <returns>ref count</returns>
public static object ExecuteScalar(SqlCommand command, string connectionString, params object[] parameters)
{
object res = null;
using (SqlConnection con = new SqlConnection(connectionString))
{
command.Connection = con;
CommandBuilder.Instance.Build(command, parameters);
con.Open();
res = command.ExecuteScalar();
con.Close();
}
return res;
}
#endregion
#region ExecuteDataset
/// <summary>
/// ExecuteDataset
/// </summary>
/// <param name="command">StoredProcedure Name</param>
/// <param name="connectionString">connection string</param>
/// <param name="type">CommandType</param>
/// <param name="parameters">parameters value</param>
/// <returns>result as DataSet</returns>
public static DataSet ExecuteDataset(string command, string connectionString, params object[] parameters)
{
DataSet ds = new DataSet();
using (SqlConnection con = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = command;
cmd.CommandType = CommandType.StoredProcedure;
CommandBuilder.Instance.Build(cmd, parameters);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
}
return ds;
}
/// <summary>
/// ExecuteDataset command will be fill paraments
/// </summary>
/// <param name="command">StoredProcedure Name</param>
/// <param name="connectionString">connection string</param>
/// <param name="parameters">parameters value</param>
/// <returns>ref count</returns>
public static DataSet ExecuteDataset(SqlCommand command, string connectionString, params object[] parameters)
{
DataSet ds = new DataSet();
using (SqlConnection con = new SqlConnection(connectionString))
{
command.Connection = con;
CommandBuilder.Instance.Build(command, parameters);
SqlDataAdapter da = new SqlDataAdapter(command);
da.Fill(ds);
}
return ds;
}
#endregion
}
}
数据库支持类
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace MSSQLHelper
{
internal class CommandBuilder
{
#region SqlParameterCollection
private Dictionary<string, SqlParameterCollection> commandParametersDict = new Dictionary<string, SqlParameterCollection>();
private object lockHelperInstance = new object();
private SqlParameterCollection this[string commandName]
{
get
{
commandName = commandName.ToLower();
if (!commandParametersDict.ContainsKey(commandName))
{
return null ;
}
return commandParametersDict[commandName];
}
set
{
commandName = commandName.ToLower();
if (!commandParametersDict.ContainsKey(commandName))
{
lock (lockHelperInstance)
{
if (!commandParametersDict.ContainsKey(commandName))
{
commandParametersDict[commandName] = value;
}
}
}
}
}
#endregion
#region private function
private SqlParameterCollection GetSqlParameterCollection(SqlCommand cmd)
{
SqlParameterCollection spc = this[cmd.CommandText];
if (spc == null)
{
//clone cmd for builder
if (cmd.CommandType == CommandType.StoredProcedure)
{
using (SqlCommand builderCMD = (cmd as ICloneable).Clone() as SqlCommand)
{
//clone connection to protect cmd.connection
using (builderCMD.Connection = (cmd.Connection as ICloneable).Clone() as SqlConnection)
{
//builderParamters
builderCMD.Connection.Open();
SqlCommandBuilder.DeriveParameters(builderCMD);
builderCMD.Connection.Close();
}
spc = builderCMD.Parameters;
this[cmd.CommandText] = builderCMD.Parameters;
}
//builderCMD finish
}
}
return spc;
}
private void FillParameters(SqlCommand cmd, SqlParameterCollection spc)
{
//fill paramenters
if (spc == null)
{
return;
}
else
{
//Parameters[0] = @return value
for (int i = 1; i < spc.Count; i++)
{
//clone to protect commandParametersDict
cmd.Parameters.Add((spc[i] as ICloneable).Clone() as SqlParameter);
}
}
}
private void FillParametersValue(SqlCommand cmd, object[] parameters)
{
//fill paramenters value
if (parameters == null)
{
return;
}
//check parameters count
if (cmd.Parameters.Count > parameters.Length)
{
throw new ArgumentOutOfRangeException("sql command \"" + cmd.CommandText + "\" , Parameters.Count more than parameters.value.Count");
}
//set value
for (int i = 0; i < cmd.Parameters.Count; i++)
{
cmd.Parameters[i].Value = parameters[i];
}
}
#endregion
public void Build(SqlCommand cmd, object[] parameters)
{
//builder command
SqlParameterCollection spc = GetSqlParameterCollection(cmd);
//fill paramenters
FillParameters(cmd, spc);
//fill paramenters value
FillParametersValue(cmd, parameters);
}
#region Instance
private static volatile CommandBuilder instance = null;
private static object lockHelper = new object();
public static CommandBuilder Instance
{
get
{
if (instance == null)
{
lock (lockHelper)
{
if (instance == null)
{
instance = new CommandBuilder();
}
}
}
return instance;
}
}
#endregion
}
}