Esempio n. 1
0
 //删除权限
 private void DeleteRightForId(long rightId)
 {
     if (rightId > 0)
     {
         T_Logs log = LogHelper.GetLog();
         try
         {
             if (rightBLL.Delete(rightId))
             {
                 JsAlert("操作成功!", successUrl);
                 log.LogContext = "删除权限操作成功! rightid" + rightId;
             }
             else
             {
                 JsAlert("操作失败!", successUrl);
                 log.LogContext = "删除权限操作失败! rightid" + rightId;
             }
             LogHelper.WriteOperationLog(log);
         }
         catch (Exception ex)
         {
             log.LogContext = "删除权限服务器异常!";
             LogHelper.WriteOperationLog(log);
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 根据主键删除 T_Logs 表数据
        /// </summary>
        /// <param name=id>主键</param>
        public bool Delete(System.Int64 id)
        {
            T_Logs info = new T_Logs();

            info.Logid = id;
            return(dal.Delete(info));
        }
Esempio n. 3
0
        /// <summary>
        /// 根据主键查询一个实体
        /// </summary>
        /// <param name=id>主键</param>
        public T_Logs SelectForID(System.Int64 id)
        {
            T_Logs info = new T_Logs();

            info.Logid = id;
            dal.SelectForID(info);
            return(info);
        }
Esempio n. 4
0
        /// <summary>
        /// 获取日志对象
        /// </summary>
        /// <returns></returns>
        public static T_Logs GetLog()
        {
            T_Logs log = new T_Logs();

            log.Ip       = Static.GetIPadress();
            log.UserName = Static.GetUserForCookie() == null ? "" : Static.GetUserForCookie().LoginName;
            log.LogTime  = DateTime.Now;
            return(log);
        }
Esempio n. 5
0
 /// <summary>
 /// 记录用户操作日志
 /// </summary>
 /// <param name="log"></param>
 public static void WriteOperationLog(T_Logs log)
 {
     try
     {
         logBLL.Insert(log);
     }
     catch (Exception ex)
     {
     }
 }
Esempio n. 6
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string Pwd(HttpContext context)
        {
            string resultText = "\"ok\":{0},\"msg\":\"{1}\"";
            string resultMsg  = string.Empty;

            string p1 = context.Request["p1"];
            string p2 = context.Request["p2"];
            string p3 = context.Request["p3"];

            if (string.IsNullOrEmpty(p1) || string.IsNullOrEmpty(p2) || string.IsNullOrEmpty(p3))
            {
                resultMsg = string.Format(resultText, -1, "参数不对!");
            }
            else
            {
                //获取当前用户
                T_User user = Static.GetUserForCookie();
                if (user != null)
                {
                    if (user.Pwd == Static.GetEncryptPwd(p1.ToLower(), user.RandKey))
                    {
                        T_User newUser = new T_User()
                        {
                            Id  = user.Id,
                            Pwd = Static.GetEncryptPwd(p2.ToLower(), user.RandKey)
                        };
                        if (userBLL.Update(newUser))
                        {
                            Static.DeleteUserToCookie();
                            resultMsg = string.Format(resultText, 0, "操作成功!");

                            T_Logs log = LogHelper.GetLog();
                            log.LogContext = user.LoginName + " 成功修改密码!";
                            LogHelper.WriteOperationLog(log);
                        }
                        else
                        {
                            resultMsg = string.Format(resultText, -2, "操作失败!");
                        }
                    }
                    else
                    {
                        resultMsg = string.Format(resultText, -3, "原密码不正确!");
                    }
                }
                else
                {
                    resultMsg = string.Format(resultText, -4, "请登录后再进行操作!");
                }
            }
            return("{" + resultMsg + "}");
        }
Esempio n. 7
0
 /// <summary>
 /// 记录用户操作日志
 /// </summary>
 /// <param name="log"></param>
 public static void WriteOperationLog(string title, string logContext, string userName, string ip)
 {
     try
     {
         T_Logs log = new T_Logs
         {
             LogName    = title,
             LogContext = logContext,
             UserName   = userName,
             Ip         = ip,
             LogTime    = DateTime.Now,
             LogType    = "用户操作日志"
         };
         logBLL.Insert(log);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 8
0
        //删除角色
        private void DeleteRoleForId(long rolesId)
        {
            T_Logs log = LogHelper.GetLog();

            try
            {
                //删除角色todo...
                if (rolesBLL.Delete(rolesId))
                {
                    log.LogContext = "删除角色,id为:" + rolesId;
                    LogHelper.WriteOperationLog(log);
                }
                JsAlert("操作成功!", "#");
            }
            catch (Exception ex)
            {
                log.LogContext = ex.Message + ex.StackTrace;
                LogHelper.WriteOperationLog(log);
                JsAlert("服务器异常!", "#");
            }
        }
Esempio n. 9
0
 /// <summary>
 /// 根据主键修改 T_Logs 表数据
 /// </summary>
 /// <param name=info>T_Logs 实体对象</param>
 public bool Update(T_Logs info)
 {
     return(dal.Update(info));
 }
Esempio n. 10
0
 /// <summary>
 /// 新增 T_Logs 表数据
 /// </summary>
 /// <param name=info>T_Logs 实体对象</param>
 public bool Insert(T_Logs info)
 {
     return(dal.Insert(info));
 }
Esempio n. 11
0
        //保存
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string UserId    = string.IsNullOrEmpty(txtUserId.Value) ? "0" : txtUserId.Value;
            string loginName = txtLoginName.Text;
            string randKey   = Static.GetRandom(6);
            string trueName  = txtTrueName.Text;
            string qq        = txtQQ.Text;
            string email     = txtEmail.Text;
            string phone     = txtPhone.Text;
            string intro     = txtIntro.Text;

            T_Logs log = LogHelper.GetLog();

            try
            {
                T_User user = new T_User();
                user.UTime = DateTime.Now;
                user.QQ    = qq;
                user.Email = email;
                user.Phone = phone;
                user.Intro = intro;
                List <long> listRolesIds = new List <long>();
                foreach (ListItem item in listRoles.Items)
                {
                    if (item.Selected)
                    {
                        listRolesIds.Add(Convert.ToInt64(item.Value));
                    }
                }

                string msg = string.Empty;

                if (UserId == "0")
                {
                    user.LoginName = loginName.ToLower();
                    user.RandKey   = randKey;
                    user.Pwd       = Static.GetEncryptPwd(Static.defaultPwd, randKey);;
                    user.CTime     = DateTime.Now;
                    user.TrueName  = trueName;
                    user.Contact   = trueName;
                    user.State     = 0;
                    user.UserType  = 0;
                    msg            = "新增用户";
                }
                else
                {
                    user.Id       = Convert.ToInt64(UserId);
                    user.TrueName = trueName;
                    msg           = "修改用户";
                }
                if (user.Id == 0)
                {
                    if (userBLL.ExistsUserName(user) != null)
                    {
                        JsAlert("登录名:" + user.LoginName + " 已经存在!", failUrl);
                        return;
                    }
                }
                if (userBLL.Edit(user, listRolesIds))
                {
                    log.LogContext = msg + ",成功!";
                }
                else
                {
                    log.LogContext = msg + ",失败!";
                }

                //记录操作日志
                LogHelper.WriteOperationLog(log);

                JsAlert(log.LogContext, successUrl);
            }
            catch (Exception ex)
            {
                log.LogContext = "编辑用户,服务器异常!" + ex.Message + ex.StackTrace;
                LogHelper.WriteOperationLog(log);
                JsAlert(ex.Message, failUrl);
            }
        }
Esempio n. 12
0
 //禁用,启用,删除用户
 private void Delete()
 {
     try
     {
         string action = Request["action"] ?? "";
         if (!string.IsNullOrEmpty(action))
         {
             T_User user = new T_User();
             user.Id = Convert.ToInt64(Request["userid"] ?? "0");
             user    = userBLL.SelectForID(user.Id);
             if (user == null)
             {
                 throw new Exception("该用户不存在!userid" + user.Id);
             }
             bool isTrue = false;
             if (action == "delete")//禁用,启用
             {
                 user.State = Convert.ToInt32(Request["isdelete"] ?? "0");
                 isTrue     = userBLL.Update(user);
             }
             if (action == "dodelete")//直接删除
             {
                 isTrue = userBLL.Delete(user.Id);
             }
             if (action == "resetpwd")//重置密码
             {
                 user.Pwd = Static.GetEncryptPwd(Static.defaultPwd, user.RandKey);
                 isTrue   = userBLL.Update(user);
             }
             if (isTrue)
             {
                 //登录用户
                 T_User curruser = Static.GetUserForCookie();
                 if (user != null)
                 {
                     T_Logs log = new T_Logs();
                     log.UserName = curruser.LoginName;
                     log.Ip       = Static.GetIPadress();
                     log.LogTime  = DateTime.Now;
                     //被操作用户
                     T_User opsuser = Static.GetUserForCookie();
                     if (action == "dodelete")
                     {
                         log.LogContext = " 删除账号 " + user.LoginName;
                     }
                     else if (action == "delete")
                     {
                         if (user.State == 0)
                         {
                             log.LogContext = "启用账号 " + user.LoginName;
                         }
                         else
                         {
                             log.LogContext = "禁用账号 " + user.LoginName;
                         }
                     }
                     else if (action == "resetpwd")
                     {
                         log.LogContext = user.LoginName + "账号密码重置";
                     }
                     else
                     {
                         log.LogContext = "恶意操作(禁用,启用,删除用户)";
                     }
                     LogHelper.WriteOperationLog(log);
                     JsAlert("操作成功!", successUrl);
                 }
                 else
                 {
                     JsAlert("操作失败!", successUrl);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         JsAlert("服务器异常!", successUrl);
     }
 }
Esempio n. 13
0
        //添加权限(菜单)
        protected void btn_AddRight_Click(object sender, EventArgs e)
        {
            string rightName     = txtRightName.Text;
            string url           = txtUrl.Text;
            int    isDisplayMenu = chkDisplay.Checked ? 0 : 1;
            long   parentId      = Convert.ToInt64(listRight.SelectedItem.Value.Split(',')[0]);
            int    level         = Convert.ToInt32(listRight.SelectedItem.Value.Split(',')[1]);
            long   rid           = Convert.ToInt64(txtRightId.Value);
            int    orderNum      = Convert.ToInt32(txtOrderNum.Text ?? "0");

            T_Logs log = LogHelper.GetLog();

            log.LogType = "系统权限编辑";

            try
            {
                //新增菜单
                T_Rights right = new T_Rights
                {
                    RName      = rightName,
                    Url        = url,
                    IsDisplay  = isDisplayMenu,
                    CreateDate = DateTime.Now,
                    OrderByNum = orderNum
                };
                if (rid > 0)
                {
                    right.NLevel = level;
                    right.Rid    = rid;
                }
                else
                {
                    right.ParentId = parentId;
                    right.NLevel   = level + 1;
                }
                //分配角色
                List <long> rolesIds = null;
                if (listRoles != null && listRoles.Items.Count > 0)
                {
                    rolesIds = new List <long>();
                    foreach (ListItem item in listRoles.Items)
                    {
                        if (item.Selected && !string.IsNullOrEmpty(item.Value))
                        {
                            rolesIds.Add(Convert.ToInt64(item.Value));
                        }
                    }
                }

                T_Rights resultRight = rightBll.AddRightToRoles(right, rolesIds);
                if (resultRight.Rid > 0)
                {
                    log.LogContext = rightName + "权限编辑成功!";
                    JsAlert(string.Format("权限名:{0} 保存成功!", rightName), successUrl);
                }
                else
                {
                    log.LogContext = rightName + "权限保存失败!";
                    JsAlert(string.Format("权限名:{0} 添加失败!", rightName), failUrl);
                }
                //记录日志
                LogHelper.WriteOperationLog(log);
            }
            catch (Exception ex)
            {
                log.LogContext = rightName + "权限编辑异常!," + ex.Message + ex.StackTrace;
                JsAlert("服务器异常!", "#");
                //JsAlert(ex.Message, failUrl);
            }
            LogHelper.WriteOperationLog(log);
        }
Esempio n. 14
0
        //添加角色,分配权限
        protected void btnAddRoles_Click(object sender, EventArgs e)
        {
            T_Logs log = LogHelper.GetLog();

            string rolesName = txtRoles.Text;

            if (!string.IsNullOrEmpty(rolesName))
            {
                try
                {
                    long rid = 0;
                    long.TryParse(txtRolesId.Value, out rid);

                    //新增判断角色名是否存在
                    if (rid == 0)
                    {
                        var roles = rolesBLL.SelectAll().FirstOrDefault(p => p.RoleName == rolesName);
                        if (roles != null)
                        {
                            JsAlertClose("角色名已经存在,请勿重复添加!");
                        }
                    }

                    //当前角色
                    var newRoles = new T_Roles
                    {
                        CreateDate = DateTime.Now,
                        RoleName   = rolesName
                    };

                    //修改需要指定主键id
                    if (rid > 0)
                    {
                        newRoles.RoleId = rid;
                    }

                    List <long> rightIds = null;
                    //选中的权限id
                    if (listRights != null && listRights.Items.Count > 0)
                    {
                        rightIds = new List <long>();
                        foreach (ListItem item in listRights.Items)
                        {
                            if (item.Selected && !string.IsNullOrEmpty(item.Value))
                            {
                                rightIds.Add(Convert.ToInt64(item.Value));
                            }
                        }
                    }
                    T_Roles resultRoles = rolesBLL.AddRolesForRights(newRoles, rightIds);
                    if (resultRoles.RoleId > 0)
                    {
                        JsAlert(string.Format("编辑【{0}】,保存成功!", rolesName), successUrl);
                        log.LogContext = string.Format("编辑角色名【{0}】保存成功!", rolesName);
                    }
                    else
                    {
                        JsAlert(string.Format("编辑【{0}】保存失败!", rolesName), failUrl);
                        log.LogContext = string.Format("编辑角色名 【{0}】保存失败!", rolesName);
                    }
                    LogHelper.WriteOperationLog(log);
                }
                catch (Exception ex)
                {
                    log.LogContext = string.Format("编辑角色名【{0}】,服务器异常", rolesName);
                    LogHelper.WriteOperationLog(log);
                    JsAlert(ex.Message, failUrl);
                }
            }
            else
            {
                JsAlert("请填写角色名", failUrl);
            }
        }