コード例 #1
0
        public ActionResult Create(Tab_User Sql)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // TODO: Add insert logic here
                    var db       = new DB();
                    var tab_user = new Tab_User
                    {
                        user_num        = Sql.user_num,
                        user_name       = Sql.user_name,
                        user_password   = md5.MD5Encrypt(Sql.user_password),
                        user_permission = Sql.user_permission,
                        phone           = Sql.phone,
                        address         = Sql.address
                    };

                    db.Tab_User.InsertOnSubmit(tab_user);
                    db.SubmitChanges();
                    return(RedirectToAction("Index"));
                }
                catch
                {
                    return(View(Sql));
                }
            }
            else
            {
                return(View(Sql));
            }
        }
コード例 #2
0
        public ActionResult IndexView()
        {
            Tab_User   u          = null;
            HttpCookie authCookie = Request.Cookies["a"]; // 获取cookie

            if (authCookie != null)
            {
                try
                {
                    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value); // 解密
                    var user = SerializeHelper.FromJson <Tab_User>(ticket.UserData);
                    u = _us.GetUser(user.F_Name, user.F_Password);
                    if (u != null)
                    {
                    }
                    else
                    {
                        return(RedirectToAction("SignOut", "Home"));
                    }
                }
                catch (Exception ex)
                {
                    return(RedirectToAction("SignOut", "Home"));
                }
            }

            var gzh = _gzhs.GetGZH(u.F_Id);

            ViewBag.gzh = gzh;
            ViewBag.msg = gzh == null ? "账号没有关联公众号" : "";

            return(View());
        }
コード例 #3
0
ファイル: UserController.cs プロジェクト: xtaje25/ManHua
        public ActionResult Add()
        {
            var id   = Request.Form["gid"];
            var name = Request.Form["name"];

            if (name == null || name.Length < 1 || name.Length > 50)
            {
                return(Json(new DWZJson()
                {
                    statusCode = (int)DWZStatusCode.ERROR, message = "长度必须大于1个字符小于50字符"
                }));
            }

            var gid = 0;

            if (!int.TryParse(id, out gid) || gid == 0)
            {
                return(Json(new DWZJson()
                {
                    statusCode = (int)DWZStatusCode.ERROR, message = "公众号ID不存在"
                }));
            }

            Tab_User m = new Tab_User();

            m.F_Name     = name;
            m.F_Password = Tools.MD5Encrypt32("123456");
            m.GZHId      = gid;
            m.RoleId     = 2; // 公众号管理员

            var i = _us.AddUser(m);

            if (i == 1)
            {
                return(Json(new DWZJson {
                    statusCode = (int)DWZStatusCode.OK, message = "成功"
                }));
            }
            else if (i == 2)
            {
                return(Json(new DWZJson {
                    statusCode = (int)DWZStatusCode.ERROR, message = "登录名已存在"
                }));
            }
            else
            {
                return(Json(new DWZJson {
                    statusCode = (int)DWZStatusCode.ERROR, message = "失败"
                }));
            }
        }
コード例 #4
0
        public Tab_User GetUser(int uid)
        {
            var sql = "SELECT [F_Id], [F_Name], [F_Password], [F_CreateDate] FROM [Tab_User] WHERE F_Id = @F_Id";

            using (SqlConnection conn = new SqlConnection(MHConncetionString))
            {
                var list = conn.Query <Tab_User>(sql, new { F_Id = uid }).ToList();

                if (list != null && list.Count > 0)
                {
                    Tab_User u = new Tab_User();
                    u.F_Id       = list[0].F_Id;
                    u.F_Name     = list[0].F_Name;
                    u.F_Password = list[0].F_Password;

                    return(u);
                }
                else
                {
                    return(null);
                }
            }
        }
コード例 #5
0
ファイル: MHController.cs プロジェクト: xtaje25/GH
        public ActionResult DirView()
        {
            var option = new int[] { 20, 50, 100, 200 };

            var pageNum    = Request.Form["pageNum"];
            var numPerPage = Request.Form["numPerPage"];
            var id         = Request["id"];

            var pageIndex   = 0;
            var pageSize    = 0;
            var totalPage   = 0;
            var totalRecord = 0;
            var mhid        = 0;

            int.TryParse(pageNum, out pageIndex);
            int.TryParse(numPerPage, out pageSize);
            int.TryParse(id, out mhid);

            pageIndex = pageIndex == 0 ? 1 : pageIndex;
            pageSize  = pageSize == 0 ? 50 : pageSize;

            Tab_User   u          = null;
            HttpCookie authCookie = Request.Cookies["a"]; // 获取cookie

            if (authCookie != null)
            {
                try
                {
                    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value); // 解密
                    var user = SerializeHelper.FromJson <Tab_User>(ticket.UserData);
                    u = _us.GetUser(user.F_Name, user.F_Password);
                    if (u != null)
                    {
                    }
                    else
                    {
                        return(RedirectToAction("SignOut", "Home"));
                    }
                }
                catch (Exception ex)
                {
                    return(RedirectToAction("SignOut", "Home"));
                }
            }
            var gzh = _gzhs.GetGZH(u.F_Id);

            ViewBag.gzh = gzh;

            var list = _mhs.GetMHImgList(mhid, pageIndex, pageSize, out totalPage, out totalRecord);

            VM_Page <Tab_MHImg> vm = new VM_Page <Tab_MHImg>();

            vm.pageNum    = pageIndex;
            vm.numPerPage = pageSize;
            vm.totalcount = totalRecord;
            vm.option     = option;
            vm.list       = list;
            ViewBag.ca    = vm;

            var mh = _ms.GetMH(mhid);

            ViewBag.mh = mh;

            ViewBag.ul = _us.GetUserLis();

            return(View());
        }
コード例 #6
0
ファイル: MHController.cs プロジェクト: xtaje25/GH
        public ActionResult Add()
        {
            var id   = Request.Form["mhid"];
            var sort = Request.Form["sort"]; // 章节ID
            var name = Request.Form["name"];

            var        gid        = 0;
            Tab_User   u          = null;
            HttpCookie authCookie = Request.Cookies["a"]; // 获取cookie

            if (authCookie != null)
            {
                try
                {
                    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value); // 解密
                    var user = SerializeHelper.FromJson <Tab_User>(ticket.UserData);
                    u = _us.GetUser(user.F_Name, user.F_Password);
                    if (u != null)
                    {
                    }
                    else
                    {
                        return(RedirectToAction("SignOut", "Home"));
                    }
                }
                catch (Exception ex)
                {
                    return(RedirectToAction("SignOut", "Home"));
                }
            }
            var gzh = _gzhs.GetGZH(u.F_Id);

            if (gzh != null)
            {
                gid = gzh.F_Id;
            }

            if (gid == 0)
            {
                // IE浏览器对非ajax请求Content-Type:是json的不友好所以使用View而非Json
                return(View(new DWZJson()
                {
                    statusCode = (int)DWZStatusCode.ERROR, message = "账号没有关联公众号"
                }));
            }

            int mhid = 0;

            if (id == null || !int.TryParse(id, out mhid) || mhid == 0)
            {
                return(View(new DWZJson()
                {
                    statusCode = (int)DWZStatusCode.ERROR, message = "漫画ID无效"
                }));
            }

            int zjid = 0;

            if (sort == null || !int.TryParse(sort, out zjid) || zjid == 0)
            {
                return(View(new DWZJson()
                {
                    statusCode = (int)DWZStatusCode.ERROR, message = "章节ID无效"
                }));
            }

            if (name == null || name.Length > 50)
            {
                return(View(new DWZJson()
                {
                    statusCode = (int)DWZStatusCode.ERROR, message = "章节名称长度必须小于50字符"
                }));
            }

            var img = "";

            if (Request.Files.Count > 0 &&
                Request.Files[0].ContentLength > 0 &&
                new string[] { ".gif", ".jpeg", ".jpg", ".png" }.Contains(System.IO.Path.GetExtension(Request.Files[0].FileName.ToLower())))
            {
                var key   = QN.MHimg(gid, mhid);
                var token = QN.GetUploadToken(QN.BUCKET, key);

                FormUploader fu     = new FormUploader();
                HttpResult   result = fu.UploadStream(Request.Files[0].InputStream, key, token);
                if (result.Code == 200)
                {
                    img = key;
                }
            }
            else
            {
                return(View(new DWZJson()
                {
                    statusCode = (int)DWZStatusCode.ERROR, message = "请为章节内容添加图片"
                }));
            }

            Tab_MHImg m = new Tab_MHImg();

            m.F_Name   = name;
            m.F_Img    = img != "" ? img : null;
            m.F_MHId   = mhid;
            m.F_Sort   = zjid;
            m.F_UserId = u.F_Id;

            var i = _mhs.AddImg(m);

            if (i == 1)
            {
                return(View(new DWZJson()
                {
                    statusCode = (int)DWZStatusCode.OK, message = "成功"
                }));
            }
            else if (i == 2)
            {
                return(View(new DWZJson()
                {
                    statusCode = (int)DWZStatusCode.ERROR, message = "章节重复"
                }));
            }
            else
            {
                return(View(new DWZJson()
                {
                    statusCode = (int)DWZStatusCode.ERROR, message = "失败"
                }));
            }
        }
コード例 #7
0
        public int AddUser(Tab_User m)
        {
            var sql = @"INSERT INTO [Tab_User]
                                   ([F_Name]
                                   ,[F_Password]
                                   ,[F_CreateDate])
                             VALUES
                                   (@F_Name
                                   ,@F_Password
                                   ,@F_CreateDate);
                             SELECT SCOPE_IDENTITY();";

            var sql1 = @"INSERT INTO [Tab_User_GZH_Relation]
                                    ([F_UserId]
                                    ,[F_GZHId])
                              VALUES
                                    (@F_UserId
                                    ,@F_GZHId)";

            var sql2 = @"INSERT INTO [Tab_User_Role_Relation]
                                    ([F_UserId]
                                    ,[F_RoleId])
                              VALUES
                                    (@F_UserId
                                    ,@F_RoleId)";

            var sql3 = "SELECT COUNT(*) FROM Tab_User WHERE F_Name = @F_Name;";

            using (SqlConnection conn = new SqlConnection(MHConncetionString))
            {
                conn.Open();
                using (SqlTransaction tran = conn.BeginTransaction(IsolationLevel.RepeatableRead))
                {
                    var n = conn.ExecuteScalar(sql3, new { F_Name = m.F_Name }, tran);

                    if (Convert.ToInt32(n) > 0)
                    {
                        tran.Rollback();
                        return(2);
                    }

                    var r = conn.ExecuteScalar(sql, new { F_Name = m.F_Name, F_Password = m.F_Password, F_CreateDate = DateTime.Now }, tran);

                    int uid = 0;
                    if (r != null && int.TryParse(r.ToString(), out uid) && uid > 0)
                    {
                        var a = conn.Execute(sql1, new { F_UserId = uid, F_GZHId = m.GZHId }, tran);

                        var b = conn.Execute(sql2, new { F_UserId = uid, F_RoleId = m.RoleId }, tran);

                        if (a == 1 && b == 1)
                        {
                            tran.Commit();
                            return(1);
                        }
                        else
                        {
                            tran.Rollback();
                            return(3);
                        }
                    }
                    else
                    {
                        tran.Rollback();
                        return(3);
                    }
                }
            }
        }
コード例 #8
0
ファイル: UserController.cs プロジェクト: xtaje25/GH
        public ActionResult Add()
        {
            var name = Request.Form["name"];
            var id   = Request.Form["rid"];


            if (name == null || name.Length > 50)
            {
                return(Json(new DWZJson()
                {
                    statusCode = (int)DWZStatusCode.ERROR, message = "用户名必须小于50个字符"
                }));
            }

            int rid = 0;

            if (id == null || !int.TryParse(id, out rid) || !new int[] { 2, 3, 4 }.Contains(rid))
            {
                return(Json(new DWZJson()
                {
                    statusCode = (int)DWZStatusCode.ERROR, message = "章节ID无效"
                }));
            }

            Tab_User   u          = null;
            HttpCookie authCookie = Request.Cookies["a"]; // 获取cookie

            if (authCookie != null)
            {
                try
                {
                    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value); // 解密
                    var user = SerializeHelper.FromJson <Tab_User>(ticket.UserData);
                    u = _us.GetUser(user.F_Name, user.F_Password);
                    if (u != null)
                    {
                    }
                    else
                    {
                        return(RedirectToAction("SignOut", "Home"));
                    }
                }
                catch (Exception ex)
                {
                    return(RedirectToAction("SignOut", "Home"));
                }
            }
            var gzh = _gzhs.GetGZH(u.F_Id);
            var gid = 0;

            if (gzh != null)
            {
                gid = gzh.F_Id;
            }
            else
            {
                return(Json(new DWZJson()
                {
                    statusCode = (int)DWZStatusCode.ERROR, message = "你没有关联公众号不能添加账号"
                }));
            }

            Tab_User uu = new Tab_User();

            uu.F_Name     = name;
            uu.F_Password = Tools.MD5Encrypt32("123456");
            uu.GZHId      = gid;
            uu.RoleId     = rid;

            var i = _us.AddUser(uu);

            if (i == 1)
            {
                return(Json(new DWZJson {
                    statusCode = (int)DWZStatusCode.OK, message = "成功"
                }));
            }
            else if (i == 2)
            {
                return(Json(new DWZJson {
                    statusCode = (int)DWZStatusCode.ERROR, message = "登录名已存在"
                }));
            }
            else
            {
                return(Json(new DWZJson {
                    statusCode = (int)DWZStatusCode.ERROR, message = "失败"
                }));
            }
        }
コード例 #9
0
 public int AddUser(Tab_User m)
 {
     return(ur.AddUser(m));
 }
コード例 #10
0
        public ActionResult Edit()
        {
            var name  = Request.Form["name"];
            var about = Request.Form["about"];

            var        gid        = 0;
            Tab_User   u          = null;
            HttpCookie authCookie = Request.Cookies["a"]; // 获取cookie

            if (authCookie != null)
            {
                try
                {
                    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value); // 解密
                    var user = SerializeHelper.FromJson <Tab_User>(ticket.UserData);
                    u = _us.GetUser(user.F_Name, user.F_Password);
                    if (u != null)
                    {
                    }
                    else
                    {
                        return(RedirectToAction("SignOut", "Home"));
                    }
                }
                catch (Exception ex)
                {
                    return(RedirectToAction("SignOut", "Home"));
                }
            }
            var gzh = _gzhs.GetGZH(u.F_Id);

            if (gzh != null)
            {
                gid = gzh.F_Id;
            }

            if (gid == 0)
            {
                // IE浏览器对非ajax请求Content-Type:是json的不友好所以使用View而非Json
                return(View(new DWZJson()
                {
                    statusCode = (int)DWZStatusCode.ERROR, message = "账号没有关联公众号"
                }));
            }

            if (name != null && name.Length > 200)
            {
                return(View(new DWZJson()
                {
                    statusCode = (int)DWZStatusCode.ERROR, message = "公号名称长度必须小于200字符"
                }));
            }

            if (about != null && about.Length > 4000)
            {
                return(View(new DWZJson()
                {
                    statusCode = (int)DWZStatusCode.ERROR, message = "公号简介长度必须小于4000字符"
                }));
            }

            var logo = "";

            if (Request.Files.Count > 0 &&
                Request.Files[0].ContentLength > 0 &&
                new string[] { ".gif", ".jpeg", ".jpg", ".png" }.Contains(System.IO.Path.GetExtension(Request.Files[0].FileName.ToLower())))
            {
                var key   = QN.GZHLogo(gid);
                var token = QN.GetUploadToken(QN.BUCKET, key);

                FormUploader fu     = new FormUploader();
                HttpResult   result = fu.UploadStream(Request.Files[0].InputStream, key, token);
                if (result.Code == 200)
                {
                    logo = key;
                }
            }

            Tab_GongZhongHao g = new Tab_GongZhongHao();

            g.F_About = (about != null && about.Length > 0) ? about : null;
            g.F_Logo  = logo != "" ? logo : null;
            g.F_Id    = gid;

            var i = _gzhs.UpdateGZHInfo(g);

            if (i == 1)
            {
                return(View(new DWZJson()
                {
                    statusCode = (int)DWZStatusCode.OK, message = "成功"
                }));
            }
            else
            {
                return(View(new DWZJson()
                {
                    statusCode = (int)DWZStatusCode.ERROR, message = "失败"
                }));
            }
        }