public int UpdateGZHInfo(Tab_GongZhongHao m) { if (m.F_Logo == null && m.F_About == null) { return(1); } var sql = new StringBuilder(); sql.Append("UPDATE [Tab_GongZhongHao]"); if (m.F_About != null) { sql.Append(" SET [F_About] = @F_About"); } if (m.F_Logo != null) { if (m.F_About != null) { sql.Append(",[F_Logo] = @F_Logo"); } else { sql.Append(" SET [F_Logo] = @F_Logo"); } } sql.Append(" WHERE [F_Id] = @F_Id"); using (SqlConnection conn = new SqlConnection(MHConncetionString)) { return(conn.Execute(sql.ToString(), new { F_Id = m.F_Id, F_About = m.F_About, F_Logo = m.F_Logo })); } }
public Tab_GongZhongHao GetGZH(int uid) { var sql = @"SELECT c.F_Id, c.F_GZHName, c.F_Logo, c.F_About FROM Tab_User a JOIN Tab_User_GZH_Relation b ON b.F_UserId = a.F_Id JOIN Tab_GongZhongHao c ON c.F_Id = b.F_GZHId WHERE a.F_Id = @F_Id"; using (SqlConnection conn = new SqlConnection(MHConncetionString)) { var list = conn.Query <Tab_GongZhongHao>(sql, new { F_Id = uid }).ToList(); if (list != null && list.Count > 0) { Tab_GongZhongHao g = new Tab_GongZhongHao(); g.F_Id = list[0].F_Id; g.F_GZHName = list[0].F_GZHName; g.F_About = list[0].F_About; g.F_Logo = list[0].F_Logo; return(g); } } return(null); }
public int AddGZH(Tab_GongZhongHao m) { var sql = @"INSERT INTO [Tab_GongZhongHao] ([F_GZHName] ,[F_WXName] ,[F_CreateDate]) VALUES (@F_GZHName ,@F_WXName ,@F_CreateDate)"; var sql1 = "SELECT COUNT(*) FROM[Tab_GongZhongHao] WHERE[F_GZHName] = @F_GZHName"; var sql2 = "SELECT COUNT(*) FROM[Tab_GongZhongHao] WHERE[F_WXName] = @F_WXName"; using (SqlConnection conn = new SqlConnection(MHConncetionString)) { conn.Open(); using (SqlTransaction tran = conn.BeginTransaction(IsolationLevel.RepeatableRead)) { var a = conn.ExecuteScalar(sql1, new { F_GZHName = m.F_GZHName }, tran); var b = conn.ExecuteScalar(sql2, new { F_WXName = m.F_WXName }, tran); if (0 == Convert.ToInt32(a) && 0 == Convert.ToInt32(b)) { int r = conn.Execute(sql, new { F_GZHName = m.F_GZHName, F_WXName = m.F_WXName, F_CreateDate = DateTime.Now, }, tran); if (r == 1) { tran.Commit(); return(1); } } if (Convert.ToInt32(a) > 0) { tran.Rollback(); return(2); } if (Convert.ToInt32(b) > 0) { tran.Rollback(); return(3); } } } return(0); }
public ActionResult Add() { var name = Request.Form["name"]; var wxin = Request.Form["wxin"]; if (name == null || name.Length < 1 || name.Length > 200) { return(Json(new DWZJson() { statusCode = (int)DWZStatusCode.ERROR, message = "长度必须大于1个字符小于200字符" })); } if (wxin == null || wxin.Length < 1 || wxin.Length > 200) { return(Json(new DWZJson() { statusCode = (int)DWZStatusCode.ERROR, message = "长度必须大于1个字符小于200字符" })); } Tab_GongZhongHao m = new Tab_GongZhongHao(); m.F_GZHName = name; m.F_WXName = wxin; int i = _gzhs.AddGZH(m); // 0:没执行;1:执行成功;2:公号名称重复;3:关联微信号重复; 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 if (i == 3) { return(Json(new DWZJson { statusCode = (int)DWZStatusCode.ERROR, message = "关联微信号重复" })); } else { return(Json(new DWZJson { statusCode = (int)DWZStatusCode.ERROR, message = "失败" })); } }
public int UpdateGZH(Tab_GongZhongHao m) { var sql = @"UPDATE [Tab_GongZhongHao] SET [F_GZHName] = @F_GZHName ,[F_WXName] = @F_WXName WHERE [F_Id] = @F_Id"; var sql1 = "SELECT COUNT(*) FROM[Tab_GongZhongHao] WHERE[F_GZHName] = @F_GZHName"; var sql2 = "SELECT COUNT(*) FROM[Tab_GongZhongHao] WHERE[F_WXName] = @F_WXName"; using (SqlConnection conn = new SqlConnection(MHConncetionString)) { conn.Open(); using (SqlTransaction tran = conn.BeginTransaction(IsolationLevel.RepeatableRead)) { var a = conn.ExecuteScalar(sql1, new { F_GZHName = m.F_GZHName }, tran); var b = conn.ExecuteScalar(sql2, new { F_WXName = m.F_WXName }, tran); if (0 == Convert.ToInt32(a) && 0 == Convert.ToInt32(b)) { int r = conn.Execute(sql, new { F_GZHName = m.F_GZHName, F_WXName = m.F_WXName, F_Id = m.F_Id, }, tran); if (r == 1) { tran.Commit(); return(1); } } if (Convert.ToInt32(a) > 0) { tran.Rollback(); return(2); } if (Convert.ToInt32(b) > 0) { tran.Rollback(); return(3); } } } return(0); }
public Tab_GongZhongHao GetGZH(int gid) { var sql = "SELECT F_Id, F_GZHName, F_WXName, F_About, F_Logo FROM dbo.Tab_GongZhongHao WHERE F_Id = @F_Id"; using (SqlConnection conn = new SqlConnection(MHConncetionString)) { var list = conn.Query <Tab_GongZhongHao>(sql, new { F_Id = gid }).ToList(); if (list != null && list.Count > 0) { Tab_GongZhongHao g = new Tab_GongZhongHao(); g.F_Id = list[0].F_Id; g.F_GZHName = list[0].F_GZHName; g.F_WXName = list[0].F_WXName; g.F_About = list[0].F_About; g.F_Logo = list[0].F_Logo; return(g); } } return(null); }
public ActionResult InfoEdit() { var id = Request.Form["id"]; var about = Request.Form["about"]; var gid = 0; if (!int.TryParse(id, out gid) || gid == 0) { // IE浏览器对非ajax请求Content-Type:是json的不友好所以使用View而非Json return(View(new DWZJson() { statusCode = (int)DWZStatusCode.ERROR, message = "公号不存在" })); } 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 = "失败" })); } }
public ActionResult Edit() { var name = Request.Form["name"]; var wxin = Request.Form["wxin"]; var id = Request.Form["id"]; var gid = 0; if (!int.TryParse(id, out gid) || gid == 0) { return(Json(new DWZJson() { statusCode = (int)DWZStatusCode.ERROR, message = "公众号不存在" })); } if (name == null || name.Length < 1 || name.Length > 200) { return(Json(new DWZJson() { statusCode = (int)DWZStatusCode.ERROR, message = "长度必须大于1个字符小于200字符" })); } if (wxin == null || wxin.Length < 1 || wxin.Length > 200) { return(Json(new DWZJson() { statusCode = (int)DWZStatusCode.ERROR, message = "长度必须大于1个字符小于200字符" })); } Tab_GongZhongHao m = new Tab_GongZhongHao(); m.F_GZHName = name; m.F_WXName = wxin; m.F_Id = gid; int i = _gzhs.UpdateGZH(m); // 0:没执行;1:执行成功;2:公号名称重复;3:关联微信号重复; 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 if (i == 3) { return(Json(new DWZJson { statusCode = (int)DWZStatusCode.ERROR, message = "关联微信号重复" })); } else { return(Json(new DWZJson { statusCode = (int)DWZStatusCode.ERROR, message = "失败" })); } }
public int UpdateGZHInfo(Tab_GongZhongHao m) { return(gzhr.UpdateGZHInfo(m)); }
/// <summary> /// 0:没执行;1:执行成功;2:公号名称重复;3:关联微信号重复; /// </summary> public int AddGZH(Tab_GongZhongHao m) { return(gzhr.AddGZH(m)); }
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 = "失败" })); } }