Ejemplo n.º 1
0
        private void edit(HttpContext context)
        {
            bool   state    = false;
            string userid   = context.Request["userid"];
            string username = context.Request["username"];
            //string password = context.Request["password"];
            string name           = context.Request["name"];
            string Icon           = context.Request["Icon"];
            string job            = context.Request["job"];
            string phone          = context.Request["phone"];
            string organizationid = context.Request["organizationid"];
            string roleid         = (context.Request["roleid"]);
            //string[] roleids = (context.Request["roleid"]).Split(',');
            string json = "{IsSuccess:'false',Message:'保存失败!'}";

            TBL_USER user = new TBL_USER();

            user.userid   = userid;
            user.username = username;
            //user.password = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5");
            user.name           = name;
            user.job            = job;
            user.organizationid = organizationid;
            user.phone          = phone;
            user.Icon           = System.Text.Encoding.Default.GetBytes(Icon);
            user.roleid         = roleid;
            //List<TBL_USERAUTHORIZATION> tuaList = new List<TBL_USERAUTHORIZATION>();

            //foreach (string roleid in roleids)
            //{
            //    TBL_USERAUTHORIZATION tua = new TBL_USERAUTHORIZATION();
            //    tua.userid = userid;
            //    tua.roleid = roleid;
            //    tuaList.Add(tua);
            //}



            try
            {
                List <TBL_USER> list = userBLL.GetList(string.Format(" and A.username='******' AND A.userid !='{1}'", username, userid)).ToList <TBL_USER>();
                if (list.Count > 0)
                {
                    json = "{IsSuccess:'false',Message:'该登录名已存在,请重新输入!'}";
                }
                else
                {
                    if (userBLL.Update(user))
                    {
                        //useraBLL.Delete(" userid='" + userid + "'");
                        //foreach (TBL_USERAUTHORIZATION tua in tuaList)
                        //{
                        //    useraBLL.Insert(tua);
                        //}
                        //if (!string.IsNullOrEmpty(password))
                        //{
                        //    userBLL.UpdatePwd(user);
                        //}


                        TBL_USERAUTHORIZATION tua = new TBL_USERAUTHORIZATION();
                        tua.userid = userid;
                        tua.roleid = roleid;
                        useraBLL.Update(tua);
                        state = true;
                    }

                    if (state)
                    {
                        json = "{IsSuccess:'true',Message:'保存成功!'}";
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                json = "{IsSuccess:'false',Message:'保存失败!'}";
                //json = JsonConvert.SerializeObject("{IsSuccess:'false',Message:'保存失败!'}");
            }
            json = JsonConvert.SerializeObject(json);
            context.Response.ContentType = "application/json";
            //返回JSON结果
            context.Response.Write(json);
            context.Response.End();
        }
Ejemplo n.º 2
0
        private void add(HttpContext context)
        {
            //string mids = context.Request["mids"];
            bool   state    = false;
            string username = context.Request["username"];
            //string password = context.Request["password"];
            string name           = context.Request["name"];
            string Icon           = context.Request["Icon"];
            string job            = context.Request["job"];
            string phone          = context.Request["phone"];
            string organizationid = context.Request["organizationid"];
            string roleid         = context.Request["roleid"];

            //byte[] byteArray = System.Text.Encoding.Default.GetBytes ( str );
            //string str = System.Text.Encoding.Default.GetString ( byteArray );

            string   json   = "{IsSuccess:'false',Message:'保存失败!'}";
            string   userid = System.Guid.NewGuid().ToString().ToUpper();
            TBL_USER user   = new TBL_USER();

            user.userid         = userid;
            user.username       = username;
            user.password       = FormsAuthentication.HashPasswordForStoringInConfigFile("88888888", "MD5");
            user.name           = name;
            user.job            = job;
            user.organizationid = organizationid;
            user.phone          = phone;
            user.Icon           = System.Text.Encoding.Default.GetBytes(Icon);
            List <TBL_USERAUTHORIZATION> tuaList = new List <TBL_USERAUTHORIZATION>();

            //foreach (string roleid in roleids)
            //{
            //    TBL_USERAUTHORIZATION tua = new TBL_USERAUTHORIZATION();
            //    tua.userid = userid;
            //    tua.roleid = roleid;
            //    tuaList.Add(tua);
            //}

            if (username == "admin" || name == "admin")
            {
                json = "{IsSuccess:'false',Message:'登录名或用户名不能为关键字,请重新输入!'}";
            }
            else
            {
                try
                {
                    List <TBL_USER> list = userBLL.GetList(string.Format(" and A.username='******' ", username)).ToList <TBL_USER>();
                    if (list.Count > 0)
                    {
                        json = "{IsSuccess:'false',Message:'该登录名已存在,请重新输入!'}";
                    }
                    else
                    {
                        if (userBLL.Insert(user))
                        {
                            TBL_USERAUTHORIZATION tua = new TBL_USERAUTHORIZATION();
                            tua.userid = userid;
                            tua.roleid = roleid;
                            useraBLL.Insert(tua);
                            state = true;
                        }
                    }

                    if (state)
                    {
                        json = "{IsSuccess:'true',Message:'保存成功,初始密码88888888!',id:'" + user.userid + "'}";
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    json = "{IsSuccess:'false',Message:'保存失败!'}";
                }
            }

            json = JsonConvert.SerializeObject(json);
            context.Response.ContentType = "application/json";
            //返回JSON结果
            context.Response.Write(json);
            context.Response.End();
        }