public ActionResult UpdateBodyData() { if (Session["userName"] == null) { return(RedirectToAction("LoginRemind", "Topic")); } string UserName = Session["userName"].ToString(); string SkinColor = Request["SkinColor"]; float Weight = float.Parse(Request["Weight"]); float XiongWei = float.Parse(Request["XiongWei"]); float YaoWei = float.Parse(Request["YaoWei"]); float TunWei = float.Parse(Request["TunWei"]); float Height = float.Parse(Request["Height"]); float LegLength = float.Parse(Request["LegLength"]); float ThighGirth = float.Parse(Request["ThighGirth"]); float ArmGirth = float.Parse(Request["ArmGirth"]); float CalfGirth = float.Parse(Request["CalfGirth"]); People_bll user = new People_bll(); if (user.UpdateBodyData(UserName, SkinColor, Weight, XiongWei, YaoWei, TunWei, Height, LegLength, ThighGirth, ArmGirth, CalfGirth) == 1) { return(RedirectToAction("Change_Data")); } else { return(RedirectToAction("Change_Data")); } }
/// <summary> /// 退出登录状态,退出成功返回1,失败返回0 /// login /// </summary> /// <returns></returns> public ActionResult AjaxMakeUnLogin() { Session["userName"] = null; Session["rank"] = null; return(Content("1")); People_bll people = new People_bll(); string username = Request["username"]; string password = Request["password"]; bool login = false; //true代表账号密码都正确 try { login = people.LoginYes(username, password); } catch (Exception e) { //数据库异常处理,数据库里存在大于两条用户名一样的数据 ErrorMessage_bll errorMessage_bll = new ErrorMessage_bll(); errorMessage_bll.InsertErrorMessage("数据库出错", "数据库里tb_User表存在大于2条用户名一样的数据,用户名为:" + username); return(Content("2")); } if (login) { //登录成功之后,保存用户的用户名,权限等资料到session Session["userName"] = username; Session["rank"] = "rank"; return(Content("1")); } else { return(Content("0")); } }
/// <summary> /// 保存个人信息 /// </summary> /// <returns></returns> public ActionResult UpdateInformation() { if (Session["userName"] == null) { return(RedirectToAction("LoginRemind", "Topic")); } string userName = Session["userName"].ToString(); string realName = Request["realName"]; string BirthDate = Request["BirthDate"]; string Profession = Request["Profession"]; string PhoneNumber = Request["PhoneNumber"]; string EducationalBackground = Request["EducationalBackground"]; string Interest = Request["Interest"]; if (realName == null) { realName = null; } if (BirthDate == null) { BirthDate = null; } if (Profession == null) { Profession = null; } if (PhoneNumber == null) { PhoneNumber = null; } if (EducationalBackground == null) { EducationalBackground = null; } if (Interest == null) { Interest = null; } People_bll user = new People_bll(); if (user.UpdateInformation(userName, realName, BirthDate, Profession, PhoneNumber, EducationalBackground, Interest) == 1) { ViewData["finshSave"] = 1; return(RedirectToAction("Change_Data")); } else { ViewData["finshSave"] = -1; return(RedirectToAction("Change_Data")); } }
/// <summary> /// 根据用户名判断账号名是否存在,存在返回1,不存在返回0,数据库出错返回2 /// 用于Login页面、Register页面 /// </summary> /// <returns></returns> public ActionResult ajaxUserName() { string userName = Request["userName"].ToString(); People_bll people = new People_bll(); //数据库出错处理,数据库里存在大于两条用户名一样的数据 if (people.HavingUserName(userName) >= 2) { ErrorMessage_bll errorMessage_bll = new ErrorMessage_bll(); errorMessage_bll.InsertErrorMessage("数据库出错", "数据库存在2条用户名一样的数据,用户名为:" + userName); //return View("PeopleHomePage"); //throw new Exception("数据库出错,存在两条用户名一样的数据。"); } return(Content(people.HavingUserName(userName).ToString())); }
/// <summary> /// 配置用户登录状态 /// 如果已登录,返回true,并且设置登录状态:设置ViewData["LoginYes"] = 1;并且从数据库里取出用户头像的链接:ViewData["TouXiangUrl"] =...; /// 未登录返回false,并且设置ViewData["LoginYes"] = 0 /// </summary> public bool LoginStatusConfig() { if (Session["userName"] == null) {//未登录 ViewData["LoginYes"] = 0; return(false); } //已登录 ViewData["LoginYes"] = 1; ViewData["userName"] = Session["userName"].ToString(); ViewData["signature"] = Session["signature"].ToString(); People_bll peopleBll = new People_bll(); ViewData["TouXiangUrl"] = peopleBll.GetImgUrlTouXiang(Session["userName"].ToString());//从数据库里获取头像url return(true); }
/// <summary> /// 实现注册功能,把数据保存到数据库 /// </summary> /// <returns></returns> public ActionResult makeRegister() { People_bll people = new People_bll(); string username = Request["username"]; string password = Request["password"]; string phoneNumberOrEmail = Request["phoneNumberOrEmail"]; string quanShenZhaoUrl = "/Images/people-index-defaultQuanShenZhao.png"; string touXiangUrl = "/Images/people-geRenTouXiang.png"; if (people.Register(username, password, "普通用户", phoneNumberOrEmail, quanShenZhaoUrl, touXiangUrl) == 0) { return(RedirectToAction("Login", new { finshRegister = 1 })); } else { return(View()); } }
/// <summary> /// 判断登录是否成功,登录成功返回1,登录失败返回0,数据库异常返回2,用户类型不一致返回3 /// login /// </summary> /// <returns></returns> public ActionResult ajaxMakeLogin() { People_bll people = new People_bll(); string username = Request["username"].ToString(); string password = Request["password"].ToString(); string rankName = Request["rankName"].ToString(); bool login = false; //true代表账号密码都正确 try { login = people.LoginYes(username, password); } catch (Exception e) { //数据库异常处理,数据库里存在大于两条用户名一样的数据 ErrorMessage_bll errorMessage_bll = new ErrorMessage_bll(); errorMessage_bll.InsertErrorMessage("数据库出错", "数据库里tb_User表存在大于2条用户名一样的数据,用户名为:" + username); return(Content("2")); } if (login) { ////登录成功后,判断用户类型是否与用户填写的一致 Rank_bll rank_bll = new Rank_bll(); string rankNameDB = rank_bll.GetRankName(username); //该用户数据库里的等级名 rankNameDB = rankNameDB.Trim(); //去除空格 if (rankName != rankNameDB) { return(Content("3")); } //,保存用户的用户名,权限等资料到session Session["userName"] = username; Session["rank"] = rankName; User_bll user_bll = new User_bll(); Session["signature"] = user_bll.GetSignature(username); return(Content("1")); } else { return(Content("0")); } }
public ActionResult UploadQuanShenZhao() { //判断是否登录,未登录返回0 if (Session["userName"] == null) { return(Content("0")); } string userName = Session["userName"].ToString(); byte[] imgBase64Byte = Convert.FromBase64String(Request["data1"]);//将图片数据转化为base64的格式 System.IO.MemoryStream ms = new System.IO.MemoryStream(imgBase64Byte); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(ms); //接下来将图片保存在本地 bitmap.Save(Server.MapPath("~/Images/UserImages/QuanShenZhao/" + userName + ".png"), System.Drawing.Imaging.ImageFormat.Png); People_bll people = new People_bll(); //将图片的路径保存到数据库 people.InsertUrlQuanShenZhao(userName, ".png"); return(Content("1")); }
/// <summary> /// 本函数实现专家注册功能,把数据保存到数据库 /// 实现密码注册功能 /// </summary> /// <returns></returns> public ActionResult makeExpertRegister() { People_bll people1 = new People_bll(); string userName = Request["username"]; string realName = Request["realname"]; string Email = Request["email"]; string phoneNumber = Request["phonenumber"]; string profession = Request["profession"]; string introduction = Request["SelfIntroduction"]; string password = Request["password"]; string quanShenZhaoUrl = "/Images/people-index-defaultQuanShenZhao.png"; string touXiangUrl = "/Images/people-geRenTouXiang.png"; if (people1.ExpertRegister(userName, realName, "专家", Email, phoneNumber, profession, introduction, password, quanShenZhaoUrl, touXiangUrl) == 0) { return(RedirectToAction("Login", new { finshRegister = 1 })); } else { return(View()); } }
public ActionResult postData() { ////先把前端传回来的content内容保存为静态页面 byte[] byteData = new byte[Request.InputStream.Length]; //定义一个字节数组保存前端传回来的Post数据全部数据 Request.InputStream.Read(byteData, 0, byteData.Length); //将流读取到byteData,InputStream读取到的是http头里的主体数据 //string postData = System.Text.Encoding.Default.GetString(byteData);//系统的默认编码为gb2312,不适用这种 string postData = System.Text.Encoding.UTF8.GetString(byteData); postData = Server.UrlDecode(postData); //对数据进行url解码 string[] datas = postData.Split('&'); //对postData数据进行分割,提取出发帖内容里的html数据 string contentData = datas[1].ToString(); //data[1]为变量名为content的内容 contentData = contentData.Substring(contentData.IndexOf('=') + 1); //去除变量名,如content=aaa,只取出aaa DateTime datetime = DateTime.Now; string fileName = datetime.ToString("yyyyMMddHHmmss_ffff") + ".html"; //定义文件名fileName string fileNamePath = Server.MapPath("~/StaticHtml/TieZiHtml/") + fileName; //物理路径 while (System.IO.File.Exists(fileNamePath)) //先判断文件是否存在,若存在:更换文件名 { datetime = DateTime.Now; fileName = datetime.ToString("yyyyMMddHHmmss_ffff") + ".html"; fileNamePath = Server.MapPath("~/StaticHtml/TieZiHtml/") + fileName; } System.IO.FileStream fs = new System.IO.FileStream(fileNamePath, System.IO.FileMode.Create); byte[] contentBytes = System.Text.Encoding.UTF8.GetBytes(contentData); //byte[] contentBytes = System.Text.Encoding.Default.GetBytes(contentData); fs.Write(contentBytes, 0, contentBytes.Length); fs.Close();//保存静态html成功 ///////将帖子数据保存到数据库 Post_bll Post = new Post_bll(); Theme_bll themeName = new Theme_bll(); People_bll User = new People_bll(); string caption = Request["question"].ToString(); string userName = Session["userName"].ToString(); int userId = User.GainUserId(userName); string theme = Request["theme"].ToString(); int themeId = themeName.CollocateThemeId(theme); string staticHtmlPath = "/StaticHtml/TieZiHtml/" + fileName; //相对路径 string editorContent = datas[3].ToString(); //data[3]的为前端传回来的发帖内容的纯文本 editorContent = editorContent.Substring(editorContent.IndexOf('=') + 1); System.Text.RegularExpressions.Regex regexImg = new System.Text.RegularExpressions.Regex(@"<img[^>]+>"); editorContent = regexImg.Replace(editorContent, "");//过滤掉editorContent里图片 int len = editorContent.Length; if (len > 200)//如果editorContent的长度超过200,取editorContent里的前两百个字符,将用于保存到数据库 { len = 200; } string content200 = editorContent.Substring(0, len); if (Post.finshInsert(caption, content200, userId, themeId, staticHtmlPath, datetime) != 1) { return(Content("保存帖子信息时数据库出错")); }//将帖子数据保存到数据库---------成功 //////获取所有图片里的图片路径,并且将图片路径保存到数据库里 System.Text.RegularExpressions.Regex regImg2 = new System.Text.RegularExpressions.Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);// 定义正则表达式用来匹配 img 标签 System.Text.RegularExpressions.MatchCollection matches = regImg2.Matches(contentData); int i = 0; string[] strUrlList = new string[matches.Count]; foreach (System.Text.RegularExpressions.Match match in matches) { strUrlList[i++] = match.Groups["imgUrl"].Value;// 取得匹配项列表 } if (strUrlList.Length >= 1) { int postId = Post.GetPostId(caption); //根据帖子的标题查询数据库,得到该贴子的postId PostPhoto_bll postPhoto_bll = new PostPhoto_bll(); if (postPhoto_bll.InsertPhotoUrl(postId, strUrlList, 1) < 0) { return(Content("保存图片路径时数据库出错")); } } return(Content("成功")); }
public ActionResult Index() { if (Session["userName"] == null) { return(RedirectToAction("LoginRemind", "Topic")); } LoginStatusConfig();//配置登录状态 People_bll user = new People_bll(); string userName = Session["userName"].ToString(); //检测姓名是否为空 if (user.CheckRealName(userName) == null) { ViewData["realName"] = "请输入您的真实姓名"; } else { ViewData["realName"] = user.CheckRealName(userName); } // 检测出生年月是否为空 if (user.CheckBirthDate(userName) == null) { ViewData["BirthDate"] = "请输入您的出生年月"; } else { ViewData["BirthDate"] = user.CheckBirthDate(userName); } //检测职业是否为空 if (user.CheckProfession(userName) == null) { ViewData["Profession"] = "请输入您的职业"; } else { ViewData["Profession"] = user.CheckProfession(userName); } // 检测手机号是否为空 if (user.CheckPhoneNumber(userName) == null) { ViewData["PhoneNumber"] = "请输入您的手机号"; } else { ViewData["PhoneNumber"] = user.CheckPhoneNumber(userName); } //检测学历是否为空 if (user.CheckEducationalBackground(userName) == null) { ViewData["CheckEducationalBackground"] = "请输入您的手机号"; } else { ViewData["CheckEducationalBackground"] = user.CheckEducationalBackground(userName); } //检测爱好是否为空 if (user.CheckInterest(userName) == null) { ViewData["Interest"] = "请输入您的兴趣"; } else { ViewData["Interest"] = user.CheckInterest(userName); } //检测肤色是否为空 if (user.GetSkinColor(userName) == null) { ViewData["SkinColor"] = "请输入您的肤色"; } else { ViewData["SkinColor"] = user.GetSkinColor(userName); } //检测体重是否为空 if (user.GetWeight(userName) == -1) { ViewData["Weight"] = "请输入您的体重"; } else { ViewData["Weight"] = user.GetWeight(userName); } //检测臀围是否为空 if (user.GetTunWei(userName) == -1) { ViewData["TunWei"] = "请输入您的臀围"; } else { ViewData["TunWei"] = user.GetTunWei(userName); } //检测胸围是否为空 if (user.GetXiongWei(userName) == -1) { ViewData["XiongWei"] = "请输入您的胸围"; } else { ViewData["XiongWei"] = user.GetXiongWei(userName); } //检测腰围是否为空 if (user.GetYaoWei(userName) == -1) { ViewData["YaoWei"] = "请输入您的腰围"; } else { ViewData["YaoWei"] = user.GetYaoWei(userName); } //检测身高是否为空 if (user.GetHeight(userName) == -1) { ViewData["Height"] = "请输入您的身高"; } else { ViewData["Height"] = user.GetHeight(userName); } //检测腿长是否为空 if (user.GetThighGirth(userName) == -1) { ViewData["LegLength"] = "请输入您的腿长"; } else { ViewData["LegLength"] = user.GetLegLength(userName); } //检测大腿围是否为空 if (user.GetThighGirth(userName) == -1) { ViewData["ThighGirth"] = "请输入您的大腿围"; } else { ViewData["ThighGirth"] = user.GetThighGirth(userName); } //检测小腿围是否为空 if (user.GetCalfGirth(userName) == -1) { ViewData["CalfGirth"] = "请输入您的小腿围"; } else { ViewData["CalfGirth"] = user.GetCalfGirth(userName); } //检测手臂围是否为空 if (user.GetArmGirth(userName) == -1) { ViewData["ArmGirth"] = "请输入您的手臂围"; } else { ViewData["ArmGirth"] = user.GetArmGirth(userName); } //检测手臂围是否为空 if (user.GetQuanShenZhao(userName) == "1") { ViewData["QuanShenZhao"] = "请输入您的手臂围"; } else { ViewData["QuanShenZhao"] = user.GetQuanShenZhao(userName); } //获取用户的CountUser_model 数据:点赞数 关注数 粉丝数 收藏数 提问数 回帖数 特定咨询数 等 User_bll user_bll = new User_bll(); int userId = user_bll.GetUserId(userName); CountUser_model countUser_model = user_bll.GetCountUser(userId); ViewData["countUser_model"] = countUser_model; return(View()); }