protected void Page_Load(object sender, EventArgs e) { MasterPage.RequiredPermission = 5000; MasterPage.IsSecure = true; if (Session["Curr_Patron"] == null) { Response.Redirect("Default.aspx"); } if (!IsPostBack) { SetPageRibbon(StandardModuleRibbons.NotificationsRibbon()); PatronsRibbon.GetByAppContext(this); var patron = (Patron)Session["Curr_Patron"]; MasterPage.PageTitle = string.Format("{0} - {1} {2} ({3})", "Patron Notification", patron.FirstName, patron.LastName, patron.Username); } if (!IsPostBack) { lblPK.Text = Request["PK"]; if (lblPK.Text.Length == 0) { dv.ChangeMode(DetailsViewMode.Insert); Session["Curr_Notification_ID"] = lblPK.Text; } else { dv.ChangeMode(DetailsViewMode.Edit); } Page.DataBind(); } }
protected void rptr_ItemCommand(object source, RepeaterCommandEventArgs e) { var masterPage = (IControlRoomMaster)((BaseControlRoomPage)Page).Master; if (e.CommandName.ToLower() == "back") { Response.Redirect("Default.aspx"); } if (e.CommandName.ToLower() == "refresh") { LoadControl(); if (masterPage != null) { masterPage.PageMessage = SRPResources.RefreshOK; } return; } lblError.Text = ""; Page.Validate(); if (Page.IsValid) { if (e.CommandName.ToLower() == "save" || e.CommandName.ToLower() == "saveandback") { var p = new Patron(); if (!IsAdd()) { p = Patron.FetchObject(int.Parse(SA.Text)); } DateTime _d; p.Username = ((TextBox)(e.Item).FindControl("Username")).Text; p.Password = ((TextBox)(e.Item).FindControl("Password")).Text; var DOB = e.Item.FindControl("DOB") as TextBox; if (DOB != null && DOB.Text != "") { if (DateTime.TryParse(DOB.Text, out _d)) { p.DOB = _d; } } p.Age = FormatHelper.SafeToInt(((TextBox)(e.Item).FindControl("Age")).Text); //p.Custom2 = (((TextBox)(e.Item).FindControl("Custom2")).Text); p.MasterAcctPID = int.Parse(MasterPatronID); p.SchoolGrade = ((TextBox)(e.Item).FindControl("SchoolGrade")).Text; p.FirstName = ((TextBox)(e.Item).FindControl("FirstName")).Text; p.MiddleName = ((TextBox)(e.Item).FindControl("MiddleName")).Text; p.LastName = ((TextBox)(e.Item).FindControl("LastName")).Text; p.Gender = ((DropDownList)(e.Item).FindControl("Gender")).SelectedValue; p.EmailAddress = ((TextBox)(e.Item).FindControl("EmailAddress")).Text; p.PhoneNumber = ((TextBox)(e.Item).FindControl("PhoneNumber")).Text; p.PhoneNumber = FormatHelper.FormatPhoneNumber(p.PhoneNumber); p.StreetAddress1 = ((TextBox)(e.Item).FindControl("StreetAddress1")).Text; p.StreetAddress2 = ((TextBox)(e.Item).FindControl("StreetAddress2")).Text; p.City = ((TextBox)(e.Item).FindControl("City")).Text; p.State = ((TextBox)(e.Item).FindControl("State")).Text; p.ZipCode = ((TextBox)(e.Item).FindControl("ZipCode")).Text; p.ZipCode = FormatHelper.FormatZipCode(p.ZipCode); p.Country = ((TextBox)(e.Item).FindControl("Country")).Text; p.County = ((TextBox)(e.Item).FindControl("County")).Text; p.ParentGuardianFirstName = ((TextBox)(e.Item).FindControl("ParentGuardianFirstName")).Text; p.ParentGuardianLastName = ((TextBox)(e.Item).FindControl("ParentGuardianLastName")).Text; p.ParentGuardianMiddleName = ((TextBox)(e.Item).FindControl("ParentGuardianMiddleName")).Text; p.LibraryCard = ((TextBox)(e.Item).FindControl("LibraryCard")).Text; //p.PrimaryLibrary = ((DropDownList)(e.Item).FindControl("PrimaryLibrary")).SelectedValue.SafeToInt(); //p.SchoolName = ((DropDownList)(e.Item).FindControl("SchoolName")).SelectedValue; //p.District = ((DropDownList)(e.Item).FindControl("District")).SelectedValue; //p.SDistrict = ((DropDownList)(e.Item).FindControl("SDistrict")).SelectedValue.SafeToInt(); //p.SchoolType = ((DropDownList)(e.Item).FindControl("SchoolType")).SelectedValue.SafeToInt(); p.PrimaryLibrary = ((DropDownList)(e.Item).FindControl("PrimaryLibrary")).SelectedValue.SafeToInt(); p.SchoolName = ((DropDownList)(e.Item).FindControl("SchoolName")).SelectedValue; p.SchoolType = ((DropDownList)(e.Item).FindControl("SchoolType")).SelectedValue.SafeToInt(); var lc = LibraryCrosswalk.FetchObjectByLibraryID(p.PrimaryLibrary); if (lc != null) { p.District = lc.DistrictID == 0 ? ((DropDownList)(e.Item).FindControl("District")).SelectedValue : lc.DistrictID.ToString(); } else { p.District = ((DropDownList)(e.Item).FindControl("District")).SelectedValue; } var sc = SchoolCrosswalk.FetchObjectBySchoolID(p.SchoolName.SafeToInt()); if (sc != null) { p.SDistrict = sc.DistrictID == 0 ? ((DropDownList)(e.Item).FindControl("SDistrict")).SelectedValue.SafeToInt() : sc.DistrictID; p.SchoolType = sc.SchTypeID == 0 ? FormatHelper.SafeToInt(((DropDownList)(e.Item).FindControl("SchoolType")).SelectedValue) : sc.SchTypeID; } else { p.SDistrict = ((DropDownList)(e.Item).FindControl("SDistrict")).SelectedValue.SafeToInt(); } p.Teacher = ((TextBox)(e.Item).FindControl("Teacher")).Text; p.GroupTeamName = ((TextBox)(e.Item).FindControl("GroupTeamName")).Text; p.LiteracyLevel1 = ((TextBox)(e.Item).FindControl("LiteracyLevel1")).Text.SafeToInt(); p.LiteracyLevel2 = ((TextBox)(e.Item).FindControl("LiteracyLevel2")).Text.SafeToInt(); try { p.ParentPermFlag = ((CheckBox)(e.Item).FindControl("ParentPermFlag")).Checked; p.Over18Flag = ((CheckBox)(e.Item).FindControl("Over18Flag")).Checked; p.ShareFlag = ((CheckBox)(e.Item).FindControl("ShareFlag")).Checked; p.TermsOfUseflag = ((CheckBox)(e.Item).FindControl("TermsOfUseflag")).Checked; } catch { } var cr = CustomRegistrationFields.FetchObject(); p.Custom1 = cr.DDValues1 == "" ? ((TextBox)(e.Item).FindControl("Custom1")).Text : ((DropDownList)(e.Item).FindControl("Custom1DD")).SelectedValue; p.Custom2 = cr.DDValues2 == "" ? ((TextBox)(e.Item).FindControl("Custom2")).Text : ((DropDownList)(e.Item).FindControl("Custom2DD")).SelectedValue; p.Custom3 = cr.DDValues3 == "" ? ((TextBox)(e.Item).FindControl("Custom3")).Text : ((DropDownList)(e.Item).FindControl("Custom3DD")).SelectedValue; p.Custom4 = cr.DDValues4 == "" ? ((TextBox)(e.Item).FindControl("Custom4")).Text : ((DropDownList)(e.Item).FindControl("Custom4DD")).SelectedValue; p.Custom5 = cr.DDValues5 == "" ? ((TextBox)(e.Item).FindControl("Custom5")).Text : ((DropDownList)(e.Item).FindControl("Custom5DD")).SelectedValue; p.AvatarID = FormatHelper.SafeToInt(((DropDownList)e.Item.FindControl("AvatarID")).SelectedValue); p.ProgID = FormatHelper.SafeToInt(((DropDownList)e.Item.FindControl("ProgID")).SelectedValue); p.IsMasterAccount = ((CheckBox)(e.Item).FindControl("IsMasterAccount")).Checked; // do the save if (IsAdd()) { if (p.IsValid(BusinessRulesValidationMode.INSERT)) { p.Insert(); PatronID = p.PID.ToString(); SA.Text = PatronID; Session["CURR_PATRON_MODE"] = "EDIT"; LoadControl(); masterPage.PageMessage = SRPResources.AddedOK; if (e.CommandName.ToLower() == "saveandback") { Response.Redirect("Default.aspx"); } } else { string message = String.Format(SRPResources.ApplicationError1, "<ul>"); foreach (BusinessRulesValidationMessage m in p.ErrorCodes) { message = string.Format(String.Format("{0}<li>{{0}}</li>", message), m.ErrorMessage); } message = string.Format("{0}</ul>", message); masterPage.PageError = message; } var parent = Patron.FetchObject(p.MasterAcctPID); if (parent != null && !parent.IsMasterAccount) { parent.IsMasterAccount = true; parent.Update(); Session["CURR_PATRON"] = parent; PatronsRibbon.GetByAppContext((BaseControlRoomPage)Page); } } else { if (p.IsValid(BusinessRulesValidationMode.UPDATE)) { p.Update(); masterPage.PageMessage = SRPResources.SaveOK; if (e.CommandName.ToLower() == "saveandback") { Response.Redirect("Default.aspx"); } else { LoadControl(); } } else { string message = String.Format(SRPResources.ApplicationError1, "<ul>"); foreach (BusinessRulesValidationMessage m in p.ErrorCodes) { message = string.Format(String.Format("{0}<li>{{0}}</li>", message), m.ErrorMessage); } message = string.Format("{0}</ul>", message); masterPage.PageError = message; } } } } }