示例#1
0
        public UserM GetUser(string userID)
        {
            UserDA  userDA = null;
            DataRow dr;
            var     u = new UserM {
            };

            try
            {
                userDA = new UserDA();

                dr = userDA.GetUsers(userID).Rows[0];

                u = new UserM
                {
                    UserID    = dr["UserID"].ToString(),
                    UserName  = dr["UserName"].ToString(),
                    Active    = CommUtil.ConvertObjectToBool(dr["Active"]),
                    IsDeleted = Convert.ToByte(dr["IsDeleted"]),
                };
            }
            finally
            {
                if (userDA != null)
                {
                    userDA.CloseConnection();
                }
            }

            return(u);
        }
示例#2
0
        public IEnumerable <MenuModel> GetMenu()
        {
            List <string> moduleList = new List <string>();

            List <MenuModel> menuList = new List <MenuModel>();
            ModuleDA         moduleDA = null;
            DataTable        dt       = new DataTable();

            try
            {
                moduleDA = new ModuleDA();
                dt       = moduleDA.GetMenuByUserID(UserUID, Operation);


                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];

                    if ("".Equals(CommUtil.ConvertObjectToString(dr["ModuleCode"])) || moduleList.Contains(CommUtil.ConvertObjectToString(dr["ModuleCode"])))
                    {
                        continue;
                    }
                    else
                    {
                        moduleList.Add(CommUtil.ConvertObjectToString(dr["ModuleCode"]));
                    }

                    MenuModel mm = new MenuModel();
                    mm.ModuleCode       = CommUtil.ConvertObjectToString(dr["ModuleCode"]);
                    mm.ModuleName       = CommUtil.ConvertObjectToString(dr["ModuleName"]);
                    mm.ModuleController = CommUtil.ConvertObjectToString(dr["ModuleController"]);
                    mm.ModuleAction     = CommUtil.ConvertObjectToString(dr["ModuleAction"]);
                    mm.IsFatherNode     = CommUtil.ConvertObjectToBool(dr["IsFatherNode"]);
                    bool isSelect = false;
                    if (mm.IsFatherNode)
                    {
                        mm.SubMenu = GetSubMenu(mm.ModuleCode, 1, out isSelect);
                    }
                    else
                    {
                        isSelect = CheckMenuSelected(mm.ModuleController, mm.ModuleAction);
                    }

                    mm.IsSelect = isSelect;
                    menuList.Add(mm);
                }
            }
            finally
            {
                if (moduleDA != null)
                {
                    moduleDA.CloseConnection();
                }
            }

            return(menuList);
        }
示例#3
0
        public ResultModel Login(LoginViewModel model)
        {
            ResultModel result = new ResultModel();

            UserDA    userDA = null;
            DataTable dt     = new DataTable();

            try
            {
                userDA = new UserDA();
                dt     = userDA.GetUsers(model.UserID.Trim());

                if (dt == null)
                {
                    result.IsSuccess = false;
                    result.Exception = string.Format("User does not exist!");
                    return(result);
                }

                DataRow dr = dt.Rows[0];

                if (!string.Equals(dr["password"], GetSHA512Encrypt(model.Password)))
                {
                    result.IsSuccess = false;
                    result.Exception = string.Format("The Password is incorrect");
                    return(result);
                }

                if (!CommUtil.ConvertObjectToBool(dr["active"]))
                {
                    result.IsSuccess = false;
                    result.Exception = string.Format("User blocked, please contact your administrator!");
                    return(result);
                }

                // TODO: Add web service logic here

                UserName = dr["UserName"].ToString();
                UserID   = dr["UserID"].ToString();
                UserUID  = dr["UID"].ToString();
                //Operation = "EEGHK";//在未完成Operation模块时作为测试数据
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Exception = ex.Message;
            }
            finally
            {
                if (userDA != null)
                {
                    userDA.CloseConnection();
                }
            }

            return(result);
        }
示例#4
0
        /// <summary>
        /// Get all module accessright
        /// </summary>
        /// <param name="allowAccessActionList"></param>
        /// <returns></returns>
        private List <ModuleRightModel> GetAllModule(List <string> allowAccessActionList)
        {
            ModuleDA      moduleDA      = null;
            AccessRightDA accessRightDA = null;

            List <ModuleRightModel> moduleRightList = new List <ModuleRightModel>();
            DataTable dtAllModule = new DataTable();

            try
            {
                moduleDA      = new ModuleDA();
                accessRightDA = new AccessRightDA();
                dtAllModule   = moduleDA.GetAllLevel1Module();
                for (int i = 0; i < dtAllModule.Rows.Count; i++)
                {
                    DataRow dr = dtAllModule.Rows[i];
                    if (dr["code"] != null)
                    {
                        ModuleRightModel mrModel = FillModuleRightModel(dr, allowAccessActionList, accessRightDA);

                        if (CommUtil.ConvertObjectToBool(dr["IsFatherNode"]))
                        {
                            mrModel.SubModule = GetSubModule(moduleDA, accessRightDA, allowAccessActionList, mrModel.ModuleCode, 1);
                        }
                        moduleRightList.Add(mrModel);
                    }
                }
            }
            finally
            {
                if (accessRightDA != null)
                {
                    accessRightDA.CloseConnection();
                }
                if (moduleDA != null)
                {
                    moduleDA.CloseConnection();
                }
            }
            return(moduleRightList);
        }
示例#5
0
        /// <summary>
        /// get sub module accessright
        /// </summary>
        /// <param name="allowAccessActionList"></param>
        /// <param name="moduleCode"></param>
        /// <param name="deep"></param>
        /// <returns></returns>
        private List <ModuleRightModel> GetSubModule(ModuleDA moduleDA, AccessRightDA accessRightDA, List <string> allowAccessActionList, string moduleCode, int deep)
        {
            List <ModuleRightModel> moduleRightList = new List <ModuleRightModel>();

            DataTable dtAllModule = moduleDA.GetModuleByFatherCode(moduleCode);

            for (int i = 0; i < dtAllModule.Rows.Count; i++)
            {
                DataRow dr = dtAllModule.Rows[i];
                if (dr["code"] != null)
                {
                    ModuleRightModel mrModel = FillModuleRightModel(dr, allowAccessActionList, accessRightDA);

                    if (CommUtil.ConvertObjectToBool(dr["IsFatherNode"]) && deep <= 5)
                    {
                        mrModel.SubModule = GetSubModule(moduleDA, accessRightDA, allowAccessActionList, mrModel.ModuleCode, deep);
                    }
                    moduleRightList.Add(mrModel);
                }
            }
            return(moduleRightList);
        }
示例#6
0
        private List <MenuModel> GetSubMenu(string code, int deep, out bool isSelect)
        {
            bool temp = false;

            isSelect = false;
            List <string>    moduleList = new List <string>();
            List <MenuModel> menuList   = new List <MenuModel>();
            ModuleDA         moduleDA   = null;
            DataTable        dt         = new DataTable();

            try
            {
                moduleDA = new ModuleDA();
                dt       = moduleDA.GetMenuByCodeAndUserID(code, UserUID, Operation);


                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];

                    if ("".Equals(CommUtil.ConvertObjectToString(dr["ModuleCode"])) || moduleList.Contains(CommUtil.ConvertObjectToString(dr["ModuleCode"])))
                    {
                        continue;
                    }
                    else
                    {
                        moduleList.Add(CommUtil.ConvertObjectToString(dr["ModuleCode"]));
                    }

                    MenuModel mm = new MenuModel();
                    mm.ModuleCode       = CommUtil.ConvertObjectToString(dr["ModuleCode"]);
                    mm.ModuleName       = CommUtil.ConvertObjectToString(dr["ModuleName"]);
                    mm.ModuleController = CommUtil.ConvertObjectToString(dr["ModuleController"]);
                    mm.ModuleAction     = CommUtil.ConvertObjectToString(dr["ModuleAction"]);
                    mm.IsFatherNode     = CommUtil.ConvertObjectToBool(dr["IsFatherNode"]);

                    if (mm.IsFatherNode && deep <= 5)
                    {
                        mm.SubMenu = GetSubMenu(mm.ModuleCode, deep + 1, out isSelect);
                    }
                    else
                    {
                        isSelect = CheckMenuSelected(mm.ModuleController, mm.ModuleAction);
                    }

                    mm.IsSelect = isSelect;

                    //subMenu is selected
                    if (isSelect)
                    {
                        temp = true;
                    }

                    menuList.Add(mm);
                }

                //if submenu is selectd father menu is selected
                if (temp)
                {
                    isSelect = true;
                }
            }
            finally
            {
                if (moduleDA != null)
                {
                    moduleDA.CloseConnection();
                }
            }

            return(menuList);
        }