protected void Login1_LoggingIn(object sender, LoginCancelEventArgs e) { string passwordTemp = CommonSecurity.SHA1MD5MD5(Login1.Password); using (Entity entity = new Entity()) { User user = entity.User .Where(o => o.Tel == Login1.UserName && o.PassWord == passwordTemp && (o.Type & 8) > 0 && o.State == 1).FirstOrDefault(); if (user == null) { Server.Transfer("default.aspx?login=error"); } else { Session["userID"] = user.UserID; Server.Transfer("main.aspx"); } } }
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e) { try { var user = new User(); var file_url = (HtmlInputHidden)DetailsView1.FindControl("file_url"); if (!string.IsNullOrEmpty(file_url.Value)) { var img_url = (HtmlImage)DetailsView1.FindControl("img_url"); img_url.Src = ConfigurationManager.AppSettings["UploadUrl"] + file_url.Value; user.HeadPortrait = file_url.Value; } if (e.Values["Tel"] == null) { throw new Exception("用户电话不能为空"); } if (e.Values["PassWord"] == null) { throw new Exception("密码不能为空"); } user.Tel = (e.Values["Tel"]).ToString().Trim(); user.PassWord = CommonSecurity.SHA1MD5MD5((e.Values["PassWord"]).ToString().Trim()); string pattern = @"^(0|86|17951)?(1[234578])[0-9]{9}$"; Regex rgx = new Regex(pattern); if (!rgx.IsMatch(user.Tel)) { throw new Exception("电话号不正确"); } if (user.PassWord.Length < 6) { throw new Exception("密码长度不能小于6"); } if (e.Values["NickName"] == null) { user.NickName = "分享玩家"; } else { user.NickName = (e.Values["NickName"]).ToString().Trim(); } user.Gender = ((RadioButtonList)DetailsView1.FindControl("RadioButtonList_Gender")).SelectedValue; user.Married = ((RadioButtonList)DetailsView1.FindControl("RadioButtonList_Married")).SelectedValue; var CheckBoxList_Type = ((CheckBoxList)DetailsView1.FindControl("CheckBoxList_Type")); if (CheckBoxList_Type.Items[0].Selected) { user.Type = user.Type | 1; } if (CheckBoxList_Type.Items[1].Selected) { user.Type = user.Type | 2; } if (CheckBoxList_Type.Items[2].Selected) { user.Type = user.Type | 4; } if (CheckBoxList_Type.Items[3].Selected) { user.Type = user.Type | 8; } user.State = Convert.ToInt32(((RadioButtonList)DetailsView1.FindControl("RadioButtonList_State")).SelectedValue); user.CreatTime = DateTime.Now; user.UpdateTime = DateTime.Now; user.UserExtend = new UserExtend(); if (e.Values["UserExtend.ExperienceLevel"] != null) { int temp; if (!int.TryParse(e.Values["UserExtend.ExperienceLevel"].ToString(), out temp)) { throw new Exception("经验等级必须是整数"); } if (temp == 0) { temp = 1; } user.UserExtend.ExperienceLevel = temp; } using (Entity entity = new Entity()) { ExperienceLevel experienceLevel = entity.ExperienceLevel.Where(o => o.ExperienceLevelValue == user.UserExtend.ExperienceLevel).FirstOrDefault(); if (experienceLevel == null) { throw new Exception("经验等级和等级不对应"); } user.UserExtend.ExperienceValue = experienceLevel.ExperienceValueMin; if (user.Gender == "男") { user.UserExtend.ExperienceName = experienceLevel.NameMan; } else { user.UserExtend.ExperienceName = experienceLevel.NameWoman; } user.InitBeforeSave(); user.SetCounterfeit(); entity.User.Add(user); entity.SaveChanges(); } Response.Redirect("UserDetail.aspx?userID=" + user.UserID); } catch (Exception exception) { string error = exception.GetErrorMessage().Replace("'", "\\'").Replace("\"", "\\\"").Replace("\r\n", "\\r\\n"); ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", string.Format("<script>alert('{0}')</script>", error)); } }