Пример #1
2
        private void AddData(HttpContext context)
        {
            var stuModel = new Models.Student();
            stuModel.StudentId = Guid.NewGuid();
            SetModelValue(stuModel, context);
            stuModel.CreateTime = DateTime.Now;
            stuModel.LastModifyTime = DateTime.Now;
            var stuBll = new BLL.Student();
            var result = false;
            var msg = "";
            try
            {
                var sysUserMo = new Models.SysUser();
                var sysuserbll = new BLL.SysUser();
                sysUserMo.UserRole = (int) EnumUserRole.Student;
                sysUserMo.UserName = stuModel.StuName;
                sysUserMo.UserId = stuModel.StudentId;
                sysUserMo.UserPassWord = stuBll.GetPwd();
                sysUserMo.UserAccount = stuBll.GetStuAccount();

                sysuserbll.Add(sysUserMo);
                result = stuBll.Add(stuModel);

                if (!result)
                {
                    msg = "保存失败!";
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLogofExceptioin(ex);
                result = false;
                msg = ex.Message;

            }

            //  var str = JsonConvert.SerializeObject(new { success = result, errorMsg = msg});
            context.Response.Write(msg);
        }
Пример #2
0
 public JsonResult Login(SysChain.Model.VM_SysLogin model)
 {
     Helper.ResultInfo <bool> rs = new Helper.ResultInfo <bool>();
     if (ModelState.IsValid)
     {
         BLL.SysUser            Operation = new BLL.SysUser();
         SysChain.Model.SysUser user      = Operation.GetEntity(model);
         if (user != null)
         {
             if (user.State != true)
             {
                 rs.Data   = false;
                 rs.Msg    = "账号已冻结,请联系管理员.";
                 rs.Result = false;
                 rs.Url    = "";
             }
             else
             {
                 Session["UserInfo"] = user;
                 rs.Data             = true;
                 rs.Msg    = "登录成功,正在进入系统";
                 rs.Result = true;
                 rs.Url    = Url.Action("Index", "Home", new { area = "Admin" });
             }
         }
         else
         {
             rs.Data   = false;
             rs.Msg    = "账号或密码错误.";
             rs.Result = false;
             rs.Url    = "";
         }
         JsonResult jr = new JsonResult();
         jr.Data = rs;
         return(jr);
     }
     else
     {
         System.Text.StringBuilder sbErrors = new System.Text.StringBuilder();
         foreach (var item in ModelState.Values)
         {
             if (item.Errors.Count > 0)
             {
                 for (int i = item.Errors.Count - 1; i >= 0; i--)
                 {
                     sbErrors.Append(item.Errors[i].ErrorMessage);
                     sbErrors.Append("<br/>");
                 }
             }
         }
         rs.Data   = false;
         rs.Msg    = sbErrors.ToString();
         rs.Result = false;
         rs.Url    = "";
         JsonResult jr = new JsonResult();
         jr.Data = rs;
         return(jr);
     }
 }
Пример #3
0
        private void AddData(HttpContext context)
        {
            var sysUserModel = new Models.SysUser();
            sysUserModel.UserId = Guid.NewGuid();
            SetModelValue(sysUserModel, context);
            sysUserModel.CreateTime = DateTime.Now;

            var sysUserBll = new BLL.SysUser();
            var result = false;
            var msg = "";
            try
            {
                if (sysUserBll.GetAccountExsist(sysUserModel.UserAccount, sysUserModel.UserId))
                {
                    msg = "该账号已存在,请修改!";
                }
                else
                {
                    result = sysUserBll.Add(sysUserModel);

                    if (!result)
                    {
                        msg = "保存失败!";
                    }
                }

            }
            catch (Exception ex)
            {
                LogHelper.WriteLogofExceptioin(ex);
                result = false;
                msg = ex.Message;

            }

            //  var str = JsonConvert.SerializeObject(new { success = result, errorMsg = msg});
            context.Response.Write(msg);
        }
Пример #4
0
        private string GetUser(string userId)
        {
            try
            {
                var result = new StringBuilder("");
                var userBll = new BLL.SysUser();
                var userInfo = userBll.GetModel(new Guid(userId));

                var stuBll = new BLL.Student();
                var stuInfo = stuBll.GetModel(new Guid(userId));

                if (userInfo != null)
                {
                    result.Append("UserName:"******",UserAccount:" + userInfo.UserAccount);
                    result.Append(",UserPassWord:"******",UserRole:" + userInfo.UserRole);

                }
                if (stuInfo != null)
                {
                    // result.Append(",UserName:"******",Gender:" + stuInfo.Gender);
                    result.Append(",IdentityNo:" + stuInfo.IdentityNo);
                    result.Append(",School:" + stuInfo.School);
                    result.Append(",TelNo:" + stuInfo.TelNo);
                    result.Append(",Title:" + stuInfo.JobTitle);
                }
                result.Append("");
                return result.ToString();
            }
            catch (Exception ex)
            {
                LogHelper.WriteLogofExceptioin(ex);
                return string.Empty;
            }
        }
Пример #5
0
        private string ModifyUser(HttpContext context)
        {
            try
            {
                var result = "";
                var userId = new Guid(context.Request["uid"]);
                var userBll = new BLL.SysUser();

                if (userBll.GetAccountExsist(context.Request["UserAccount"], userId))  //登录账户不能重复
                {
                    return "该账号已存在!";
                }

                var userModel = userBll.GetModel(userId);

                if (userModel.UserRole == (int) EnumUserRole.Student)
                {
                    var stubll = new BLL.Student();
                    var stuModel = stubll.GetModel(userModel.UserId);

                    if (!string.IsNullOrEmpty(context.Request["Gender"]))
                    {
                        stuModel.Gender = Convert.ToInt32(context.Request["Gender"]);
                    }
                    stuModel.TelNo = context.Request["TelNo"];
                    stuModel.JobTitle = context.Request["Title"];
                    stuModel.StuName = context.Request["UserName"];
                    stuModel.School = context.Request["School"];
                    stuModel.LastModifyTime = DateTime.Now;
                    stuModel.IdentityNo = context.Request["IdentityNo"];
                    stubll.Update(stuModel);

                    userModel.UserAccount = context.Request["UserAccount"];
                    userModel.UserName = context.Request["UserName"];
                    userModel.UserPassWord = context.Request["UserPassWord"];
                    userModel.CreateTime = DateTime.Now;
                    userBll.Update(userModel);
                }
                else
                {
                    userModel.UserAccount = context.Request["UserAccount"];
                    userModel.UserName = context.Request["UserName"];
                    userModel.UserPassWord = context.Request["UserPassWord"];
                    userModel.CreateTime = DateTime.Now;
                    userBll.Update(userModel);
                }
                return result;
            }
            catch (Exception ex)
            {
                 LogHelper.WriteLogofExceptioin(ex);
                return ex.Message;
            }
        }
Пример #6
0
        private void DelData(string id,HttpContext context)
        {
            var stuBll = new BLL.Student();
            var result = false;
            var msg = "";
            try
            {
                result= stuBll.Delete(new Guid(id));
                var sysuserbll = new BLL.SysUser();
                sysuserbll.Delete(new Guid(id));

                if (!result)
                {
                    msg = "保存失败!";
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLogofExceptioin(ex);
                result = false;
                msg = ex.Message;

            }
            //  var str = JsonConvert.SerializeObject(new { success = result, errorMsg = msg});
            context.Response.Write(msg);
        }
Пример #7
0
        private void Query(HttpContext context)
        {
            var stuName = context.Request["name"];
            var school = context.Request["sch"];
            var ds = new DataSet();
            var sysUserBll = new BLL.SysUser();
            var strWhere = "";
            if (!string.IsNullOrEmpty(stuName))
            {
                strWhere = string.Format(" UserName like '%" + stuName + "%' ");
            }
            if (!string.IsNullOrEmpty(school))
            {
                if (!string.IsNullOrEmpty(strWhere))
                {
                    strWhere += string.Format(" and  UserRole=" + school + " ");
                }
                else
                {
                    strWhere = string.Format(" UserRole=" + school + " ");
                }
            }
              //  ds = sysUserBll.GetList(strWhere);

            var page = Convert.ToInt32(context.Request["page"]);
            var rows = Convert.ToInt32(context.Request["rows"]);
            var startIndex = (page - 1) * rows + 1;
            var endIndex = startIndex + rows - 1;
            var sort = string.IsNullOrEmpty(context.Request["sort"]) ? "UserName" : context.Request["sort"];
            var order = string.IsNullOrEmpty(context.Request["order"]) ? "asc" : context.Request["order"];

            if (sort == "UserRoleName")
            {
                sort = "UserRole";
            }

            var num = sysUserBll.GetRecordCount(strWhere);
            ds = sysUserBll.GetListByPage(strWhere, sort, startIndex, endIndex,order);

            var str = JsonConvert.SerializeObject(new { total = num, rows = ds.Tables[0] });
            context.Response.Write(str);
        }
Пример #8
0
        private string GetData(HttpContext context)
        {
            var ds = new DataSet();
            var sysUserBll = new BLL.SysUser();

            var page = Convert.ToInt32(context.Request["page"]);
            var rows = Convert.ToInt32(context.Request["rows"]);
            var sort = string.IsNullOrEmpty(context.Request["sort"]) ? "UserName" : context.Request["sort"];
            var order = string.IsNullOrEmpty(context.Request["order"]) ? "asc" : context.Request["order"];

            if (sort == "UserRoleName")
            {
                sort = "UserRole";
            }

            var startIndex = (page - 1) * rows + 1;
            var endIndex = startIndex + rows - 1;

            var num = sysUserBll.GetRecordCount("");
            ds = sysUserBll.GetListByPage("", sort, startIndex, endIndex,order);

            var str = JsonConvert.SerializeObject(new { total =  num, rows = ds.Tables[0] });
            return str;
        }
Пример #9
0
        /// <summary>
        /// 根据用户Id获取用户信息,登录测试页面用。
        /// </summary>
        /// <param name="userAccount"></param>
        /// <param name="pwd"></param>
        public static bool Load(string userAccount,string pwd)
        {
            try
            {
                if ((!string.IsNullOrEmpty(userAccount))&&(!string.IsNullOrEmpty(pwd)))
                {
                    var sysUserBll = new BLL.SysUser();
                    var sysUser = sysUserBll.GetSysUserByAccount(userAccount,pwd);
                    if (sysUser != null)
                    {

                        HttpContext.Current.Session.Add(SESSION_NAME, sysUser);
                     //   HttpContext.Current.Session[SESSION_NAME] = sysUser;
                        return true;
                    }
                    else // 该用户在本系统中不存在
                    {
                        throw new Exception("不存在该用户信息,请核对!");
                    }
                }

                return false;
            }
            catch (Exception ex)
            {
                LogHelper.WriteLogofExceptioin(ex);
                return false;
            }
        }