⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usergroups.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
字号:
namespace PowerEasy.SqlServerDal.UserManage
{
    using Microsoft.Practices.EnterpriseLibrary.Data;
    using PowerEasy.Enumerations;
    using PowerEasy.IDal.UserManage;
    using PowerEasy.Model.UserManage;
    using PowerEasy.SqlServerDal;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;

    public class UserGroups : IUserGroups
    {
        private int m_NumUserGroups;

        public bool Add(UserGroupsInfo userGroupsInfo)
        {
            userGroupsInfo.GroupId = GetNewGroupId();
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand command = GetProcdbComm(db, "PR_UserManage_UserGroups_Add", userGroupsInfo);
            bool flag = false;
            try
            {
                if (db.ExecuteNonQuery(command) > 0)
                {
                    flag = true;
                }
            }
            catch
            {
                flag = false;
            }
            return flag;
        }

        public bool Delete(int id)
        {
            Parameters cmdParams = new Parameters();
            cmdParams.AddInParameter("@GroupId", DbType.Int32, id);
            string strSql = "DELETE FROM PE_UserGroups WHERE GroupID =@GroupId";
            return DBHelper.ExecuteSql(strSql, cmdParams);
        }

        private static IList<UserGroupsInfo> GetGroupInfoList(Database db, DbCommand dbComm)
        {
            IList<UserGroupsInfo> list = new List<UserGroupsInfo>();
            using (NullableDataReader reader = new NullableDataReader(db.ExecuteReader(dbComm)))
            {
                while (reader.Read())
                {
                    UserGroupsInfo userGroupsInfo = new UserGroupsInfo();
                    UserGroupsFromrdr(userGroupsInfo, reader);
                    list.Add(userGroupsInfo);
                }
            }
            return list;
        }

        public int GetMaxId()
        {
            return DBHelper.GetMaxId("PE_UserGroups", "GroupID");
        }

        private static int GetNewGroupId()
        {
            return (DBHelper.GetMaxId("PE_UserGroups", "GroupID") + 1);
        }

        public int GetNumberUserGroups()
        {
            return this.m_NumUserGroups;
        }

        private static DbCommand GetProcdbComm(Database db, string proName, UserGroupsInfo userGroupsInfo)
        {
            DbCommand storedProcCommand = db.GetStoredProcCommand(proName);
            db.AddInParameter(storedProcCommand, "@GroupID", DbType.Int32, userGroupsInfo.GroupId);
            db.AddInParameter(storedProcCommand, "@GroupName", DbType.String, userGroupsInfo.GroupName);
            db.AddInParameter(storedProcCommand, "@Description", DbType.String, userGroupsInfo.Description);
            db.AddInParameter(storedProcCommand, "@Settings", DbType.String, userGroupsInfo.Settings);
            db.AddInParameter(storedProcCommand, "@GroupType", DbType.Int32, userGroupsInfo.GroupType);
            db.AddInParameter(storedProcCommand, "@GroupSetting", DbType.String, userGroupsInfo.GroupSetting);
            return storedProcCommand;
        }

        public UserGroupsInfo GetUserGroupById(int id)
        {
            Database database = DatabaseFactory.CreateDatabase();
            database = DatabaseFactory.CreateDatabase();
            DbCommand sqlStringCommand = database.GetSqlStringCommand("SELECT * FROM PE_UserGroups WHERE GroupID=@GroupID");
            database.AddInParameter(sqlStringCommand, "@GroupID", DbType.Int32, id);
            using (NullableDataReader reader = new NullableDataReader(database.ExecuteReader(sqlStringCommand)))
            {
                if (reader.Read())
                {
                    UserGroupsInfo userGroupsInfo = new UserGroupsInfo();
                    UserGroupsFromrdr(userGroupsInfo, reader);
                    return userGroupsInfo;
                }
                return new UserGroupsInfo(true);
            }
        }

        public IList<UserGroupsInfo> GetUserGroupList(GroupType groupType)
        {
            string query = "SELECT * FROM PE_UserGroups WHERE GroupType=@GroupType Order By GroupID ASC";
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand sqlStringCommand = db.GetSqlStringCommand(query);
            db.AddInParameter(sqlStringCommand, "@GroupType", DbType.Int32, groupType);
            return GetGroupInfoList(db, sqlStringCommand);
        }

        public IList<UserGroupsInfo> GetUserGroupList(int startRowIndexId, int maxNumberRows)
        {
            string filter = string.Empty;
            return this.GetUserGroupsList(filter, startRowIndexId, maxNumberRows);
        }

        private IList<UserGroupsInfo> GetUserGroupsList(string filter, int startRowIndexId, int maxNumberRows)
        {
            IList<UserGroupsInfo> list = new List<UserGroupsInfo>();
            Database database = DatabaseFactory.CreateDatabase();
            DbCommand storedProcCommand = database.GetStoredProcCommand("PR_Common_GetList");
            database.AddInParameter(storedProcCommand, "@StartRows", DbType.Int32, startRowIndexId);
            database.AddInParameter(storedProcCommand, "@PageSize", DbType.Int32, maxNumberRows);
            database.AddInParameter(storedProcCommand, "@SortColumn", DbType.String, "GroupID");
            database.AddInParameter(storedProcCommand, "@StrColumn", DbType.String, "*");
            database.AddInParameter(storedProcCommand, "@Sorts", DbType.String, "ASC");
            database.AddInParameter(storedProcCommand, "@Filter", DbType.String, filter);
            database.AddInParameter(storedProcCommand, "@TableName", DbType.String, "PE_UserGroups");
            database.AddOutParameter(storedProcCommand, "@Total", DbType.Int32, maxNumberRows);
            using (NullableDataReader reader = new NullableDataReader(database.ExecuteReader(storedProcCommand)))
            {
                while (reader.Read())
                {
                    UserGroupsInfo userGroupsInfo = new UserGroupsInfo();
                    UserGroupsFromrdr(userGroupsInfo, reader);
                    list.Add(userGroupsInfo);
                }
            }
            this.m_NumUserGroups = (int) database.GetParameterValue(storedProcCommand, "@Total");
            return list;
        }

        public int GetUserInGroupNumber(int groupId)
        {
            Database database = DatabaseFactory.CreateDatabase();
            DbCommand sqlStringCommand = database.GetSqlStringCommand("SELECT Count(*) FROM PE_Users WHERE groupId=@groupId");
            database.AddInParameter(sqlStringCommand, "@groupId", DbType.String, groupId);
            object obj2 = database.ExecuteScalar(sqlStringCommand);
            if (obj2 == null)
            {
                return 0;
            }
            return Convert.ToInt32(obj2);
        }

        public bool Update(UserGroupsInfo userGroupsInfo)
        {
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand command = GetProcdbComm(db, "PR_UserManage_UserGroups_Update", userGroupsInfo);
            bool flag = false;
            if (db.ExecuteNonQuery(command) > 0)
            {
                flag = true;
            }
            return flag;
        }

        public bool UserGroupIsExist(string groupName)
        {
            Database database = DatabaseFactory.CreateDatabase();
            DbCommand sqlStringCommand = database.GetSqlStringCommand("SELECT COUNT(*) FROM PE_UserGroups WHERE GroupName=@GroupName");
            database.AddInParameter(sqlStringCommand, "@GroupName", DbType.String, groupName);
            bool flag = false;
            if (((int) database.ExecuteScalar(sqlStringCommand)) > 0)
            {
                flag = true;
            }
            return flag;
        }

        private static void UserGroupsFromrdr(UserGroupsInfo userGroupsInfo, NullableDataReader rdr)
        {
            userGroupsInfo.GroupId = rdr.GetInt32("GroupID");
            userGroupsInfo.GroupName = rdr.GetString("GroupName");
            userGroupsInfo.Description = rdr.GetString("Description");
            userGroupsInfo.Settings = rdr.GetString("Settings");
            userGroupsInfo.GroupType = (GroupType) rdr.GetInt32("GroupType");
            userGroupsInfo.GroupSetting = rdr.GetString("GroupSetting");
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -