コード例 #1
0
        public string AddUser(string loginIdentifer, string userJSONString)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("Message", "");
            LoginUser loginUser = GlobalAppModule.GetLoginUser(loginIdentifer);

            if (loginUser == null)
            {
                obj2["Message"] = "未登录";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            if (loginUser.LoginTimeout)
            {
                obj2["Message"] = "登录超时";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            loginUser.LastOperateTime = DateTime.Now;
            try
            {
                JavaScriptObject obj3 = (JavaScriptObject)JavaScriptConvert.DeserializeObject(userJSONString);
                if (obj3 == null)
                {
                    obj2["Message"] = "参数格式错误";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }
                if (SysUserModule.GetUserId(obj3["用户名"].ToString()) > 0)
                {
                    obj2["Message"] = "此用户已经存在!";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }
                try
                {
                    SysUser user = new SysUser();
                    user.UserName   = obj3["用户名"].ToString();
                    user.Password   = "******";
                    user.RegDate    = DateTime.Now;
                    user.LogonDate  = DateTime.Parse("2000-1-1");
                    user.IsAllow    = 1;
                    user.RoleId     = long.Parse(obj3["角色ID"].ToString());
                    user.DistrictId = long.Parse(obj3["管理ID"].ToString());
                    user.TrueName   = obj3["用户名"].ToString();
                    user.Sex        = "";
                    user.Mobile     = "";
                    user.Address    = "";
                    user.Remark     = "";

                    string str = SysUserModule.AddUser(user);
                    if (str.Contains("添加成功"))
                    {
                        obj2["Result"] = true;
                    }
                    obj2["Message"] = str;

                    try
                    {
                        SysLog log = new SysLog();
                        log.LogUserId   = loginUser.UserId;
                        log.LogUserName = loginUser.LoginName;
                        log.LogAddress  = ToolsWeb.GetIP(context.Request);
                        log.LogTime     = DateTime.Now;
                        log.LogType     = "添加用户";
                        log.LogContent  = str + "|" + ModelHandler <SysUser> .ToString(user);

                        SysLogModule.Add(log);
                    }
                    catch { }
                }
                catch (Exception exception)
                {
                    obj2["Message"] = exception.Message;
                }
            }
            catch (Exception exception2)
            {
                obj2["Message"] = exception2.Message;
            }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
コード例 #2
0
        public string ModifyUser(string loginIdentifer, string userJSONString)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("Message", "");
            LoginUser loginUser = GlobalAppModule.GetLoginUser(loginIdentifer);

            if (loginUser == null)
            {
                obj2["Message"] = "未登录";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            if (loginUser.LoginTimeout)
            {
                obj2["Message"] = "登录超时";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            loginUser.LastOperateTime = DateTime.Now;
            try
            {
                JavaScriptObject obj3 = (JavaScriptObject)JavaScriptConvert.DeserializeObject(userJSONString);
                if (obj3 == null)
                {
                    obj2["Message"] = "参数格式错误";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }

                try
                {
                    SysUser user = SysUserModule.GetUser(long.Parse(obj3["ID"].ToString()));
                    user.UserName   = obj3["用户名"].ToString();
                    user.RoleId     = long.Parse(obj3["角色ID"].ToString());
                    user.DistrictId = long.Parse(obj3["管理ID"].ToString());
                    user.TrueName   = obj3["用户名"].ToString();

                    long existsId = SysUserModule.GetUserId(user.UserName);
                    if (existsId > 0 && existsId != user.ID)
                    {
                        obj2["Message"] = "此用户已经存在!";
                        return(JavaScriptConvert.SerializeObject(obj2));
                    }

                    string str = SysUserModule.ModifyUser(user);
                    if (str.Contains("修改成功"))
                    {
                        obj2["Result"] = true;
                    }
                    obj2["Message"] = str;
                }
                catch (Exception exception)
                {
                    obj2["Message"] = exception.Message;
                }
            }
            catch (Exception exception2)
            {
                obj2["Message"] = exception2.Message;
            }

            try
            {
                SysLog log = new SysLog();
                log.LogUserId   = loginUser.UserId;
                log.LogUserName = loginUser.LoginName;
                log.LogAddress  = ToolsWeb.GetIP(context.Request);
                log.LogTime     = DateTime.Now;
                log.LogType     = "修改用户";
                log.LogContent  = obj2["Message"].ToString() + "|" + userJSONString;
                SysLogModule.Add(log);
            }
            catch { }
            return(JavaScriptConvert.SerializeObject(obj2));
        }