/// <summary> /// 上传用户头像 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btn_up_head_Click(object sender, EventArgs e) { if (FileUpload1.HasFile && Path.GetExtension(FileUpload1.FileName).ToLower() == ".jpg") { Travel.Model.Tab_user tab_user = new Travel.Model.Tab_user(); tab_user.U_emaile = Travel.BLL.UserBusiness.GetUserByEmaile(Session["u_emaile"].ToString()).U_emaile; tab_user.U_head = "head\\" + Guid.NewGuid().ToString() + ".jpg"; //再上传到服务器 FileUpload1.SaveAs(Server.MapPath(tab_user.U_head)); if (Travel.BLL.UserBusiness.ChangeUserHead(tab_user.U_emaile, tab_user.U_head)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('修改头像成功!')</script>"); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('修改失败,请重试')</script>"); } } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('请先选择jpg文件')</script>"); } }
/// <summary> /// 我的评论删除 /// </summary> /// <param name="source"></param> /// <param name="e"></param> protected void DataList4_ItemCommand(object source, DataListCommandEventArgs e) { if (e.CommandName == "delete") { string u_id = e.CommandArgument.ToString(); Session["u_id"] = u_id; Travel.Model.Tab_user tab_user = new Travel.Model.Tab_user(); Travel.Model.Tab_discuss tab_discuss = new Travel.Model.Tab_discuss(); //通过Session获取用户emaile tab_user.U_emaile = Travel.BLL.UserBusiness.GetUserByEmaile(Session["u_emaile"].ToString()).U_emaile; //通过Session获取用户的 u_discuss //tab_discuss.U_discuss = Travel.BLL.DiscussBusiness.GetDiscussByEmaileB(Session["u_emaile"].ToString()).U_discuss; tab_discuss.U_discuss = Travel.BLL.DiscussBusiness.GetDiscussById(Convert.ToInt32(Session["u_id"])).U_discuss; //调用数据库里的删除评论的存储过程 if (Travel.BLL.DiscussBusiness.DeleteDiscuss(tab_user.U_emaile, tab_discuss.U_discuss)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('删除评论成功!')</script>"); Response.AddHeader("Refresh", "0"); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('删除评论失败!')</script>"); } this.MultiView1.ActiveViewIndex = 3; } }
/// <summary> /// 我的收藏删除 /// </summary> /// <param name="source"></param> /// <param name="e"></param> protected void DataList3_ItemCommand(object source, DataListCommandEventArgs e) { if (e.CommandName == "delete") { string u_id = e.CommandArgument.ToString(); Session["u_id"] = u_id; Travel.Model.Tab_user tab_user = new Travel.Model.Tab_user(); Travel.Model.Tab_collect tab_collect = new Travel.Model.Tab_collect(); ////通过Session获取用户的 u_collect tab_collect.U_collect = Travel.BLL.CollectBusiness.GetCollectById(Convert.ToInt32(Session["u_id"])).U_emaile; //通过Session获取用户emaile tab_user.U_emaile = Travel.BLL.UserBusiness.GetUserByEmaile(Session["u_emaile"].ToString()).U_emaile; //Travel.Model.Tab_collect tc = Travel.BLL.CollectBusiness.GetCollectByEmaile(Session["u_emaile"].ToString()); //tab_collect.U_collect = tc.U_emaile; //调用数据库里的删除收藏的存储过程 if (Travel.BLL.CollectBusiness.DeleteCollect(tab_user.U_emaile, tab_collect.U_collect)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('删除收藏成功!')</script>"); Response.AddHeader("Refresh", "0"); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('删除收藏失败!')</script>"); } } }
/// <summary> /// 我的游记修改和删除 /// </summary> /// <param name="source"></param> /// <param name="e"></param> protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e) { if (e.CommandName == "delete") { string u_id = e.CommandArgument.ToString(); Session["u_id"] = u_id; Travel.Model.Tab_user tab_user = new Travel.Model.Tab_user(); Travel.Model.Tab_article tab_article = new Travel.Model.Tab_article(); //通过Session获取游记title tab_article.T_title = Travel.BLL.ArticleBusiness.GetArticleById(Convert.ToInt32(Session["u_id"])).T_title; //通过Session获取用户emaile tab_user.U_emaile = Travel.BLL.UserBusiness.GetUserByEmaile(Session["u_emaile"].ToString()).U_emaile; //调用数据库里的删除游记的存储过程 if (Travel.BLL.ArticleBusiness.DeleteArticle(tab_user.U_emaile, tab_article.T_title)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('删除游记成功!')</script>"); Response.AddHeader("Refresh", "0"); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('删除游记失败!')</script>"); } } if (e.CommandName == "change") { //通过commandArgument传参数过来 string u_id = Convert.ToString(e.CommandArgument); Session["u_id"] = u_id; Response.Redirect("ChangeArticle.aspx?u_id=" + Session["u_id"]); } }
/// <summary> /// 修改用户密码 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btn_change_password_Click(object sender, EventArgs e) { string password = txt_password.Text.Trim(); string newpassword = txt_newpassword.Text.Trim(); Travel.Model.Tab_user tab_user = new Travel.Model.Tab_user(); //通过Session获取用户emaile tab_user.U_emaile = Travel.BLL.UserBusiness.GetUserByEmaile(Session["u_emaile"].ToString()).U_emaile; if (string.IsNullOrEmpty(newpassword)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('新密码不能为空')</script>"); } else { if (password == newpassword) { Page.ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('两次密码相同SB')</script>"); } else { if (Travel.BLL.UserBusiness.ChangePassword(tab_user.U_emaile, password, newpassword)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('修改密码成功!请记住新密码')</script>"); Response.AddHeader("Refresh", "0"); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('修改失败,请重新尝试!')</script>"); } } } }
protected void btn_sure_Click(object sender, EventArgs e) { string title = tx_title.Text.Trim(); //旅行名字 string depart = tx_depart.Text.Trim(); //获取出发地 string destination = tx_destination.Text.Trim(); //从地图上获取目的地 string sumtime = tx_sumTime.Text.Trim(); //获取旅行的天数 string starttime = tx_startTime.Text.Trim(); //获取开始旅行的时间 Travel.Model.Tab_user tab_user = new Travel.Model.Tab_user(); Travel.Model.Tab_travel tab_travel = new Travel.Model.Tab_travel(); //通过Session将emaile和ID交给tab_travel对象 tab_travel.U_emaile = Travel.BLL.UserBusiness.GetUserByEmaile(Session["u_emaile"].ToString()).U_emaile;//获取用户emaile if (string.IsNullOrEmpty(tab_travel.U_emaile)) { Page.ClientScript.RegisterStartupScript(GetType(), "info", "<script>alert('请先登录!')</script>"); //跳转到指定界面 Response.Redirect("Login.aspx"); } else { if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(depart) || string.IsNullOrEmpty(destination) || string.IsNullOrEmpty(sumtime) || string.IsNullOrEmpty(starttime)) { Page.ClientScript.RegisterStartupScript(GetType(), "info", "<script>alert('请先填写完整数据!')</script>"); } else { int sumTime = Convert.ToInt32(sumtime); DateTime startTime = Convert.ToDateTime(starttime); tab_travel.T_title = title; tab_travel.T_depart = depart;//将其交给它 tab_travel.T_destination = destination; tab_travel.T_sumTime = sumTime; tab_travel.T_startTime = startTime; tab_travel.UploadTime = Convert.ToDateTime(DateTime.Now.ToString()); if (Travel.BLL.TravelBusiness.TravelIsExist(destination)) { Page.ClientScript.RegisterStartupScript(GetType(), "info", "<script>alert('您已经有该行程!')</script>"); } else { if (Travel.BLL.TravelBusiness.AddTravel(tab_travel)) { Page.ClientScript.RegisterStartupScript(GetType(), "info", "<script>alert('添加行程成功!')</script>"); } else { Page.ClientScript.RegisterStartupScript(GetType(), "info", "<script>alert('添加行程失败!')</script>"); } } } } }
protected void btn_zhuce_Click(object sender, EventArgs e) { //string u_emaile = txt_emaile.Text.Trim(); string u_emaile = txt_emaile.Value.Trim(); string u_password = txt_password.Text.Trim(); string u_name = txt_name.Text.Trim(); string u_re_password = re_password.Text.Trim(); DateTime lastLoginTime = DateTime.Now; Travel.Model.Tab_user tab_user = new Travel.Model.Tab_user(); tab_user.U_emaile = u_emaile; tab_user.U_name = u_name; tab_user.U_password = u_password; tab_user.LastLoginTime = lastLoginTime; if (string.IsNullOrEmpty(u_emaile) || string.IsNullOrEmpty(u_password)) { Page.ClientScript.RegisterStartupScript(GetType(), "info", "<script>alert('账户和密码不能为空!')</script>"); } else { if (u_password != u_re_password) { Page.ClientScript.RegisterStartupScript(GetType(), "info", "<script>alert('两次密码不想同!')</script>"); } else { if (Travel.BLL.UserBusiness.UserIsExist(u_emaile)) { Page.ClientScript.RegisterStartupScript(GetType(), "info", "<script>alert('该用户已存在!')</script>"); } else { if (Travel.BLL.UserBusiness.AddUser(tab_user)) { Page.ClientScript.RegisterStartupScript(GetType(), "info", "<script>alert('注册成功!')</script>"); //将用户放进Session里 Session["u_emaile"] = u_emaile; //给用户颁发一个身分凭证 FormsAuthentication.RedirectFromLoginPage(u_emaile, false); Response.Redirect("Personal_Detail.aspx"); } else { Page.ClientScript.RegisterStartupScript(GetType(), "info", "<script>alert('用户注册失败!')</script>"); } } } } }
/// <summary> /// 修改用户昵称 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btn_chenge_name_Click(object sender, EventArgs e) { string nameNew = u_nameNew.Text.Trim(); Travel.Model.Tab_user tab_user = new Travel.Model.Tab_user(); //通过Session获取用户emaile tab_user.U_emaile = Travel.BLL.UserBusiness.GetUserByEmaile(Session["u_emaile"].ToString()).U_emaile; if (string.IsNullOrEmpty(nameNew)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('请输入新昵称!')</script>"); } else { if (Travel.BLL.UserBusiness.ChangeUserName(tab_user.U_emaile, nameNew)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('修改昵称成功!')</script>"); Response.AddHeader("Refresh", "0"); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('修改失败,请重新尝试!')</script>"); } } }