private void PhonesChangesUpdate(cUser Demography) { List <cPhone> phones = Session["dem_Phones"] as List <cPhone>; int userId = (int)Session["UserID"]; //For each element of the original list perform one of the following: //If update, update information //If delete, mark record for delete //If new, mark record for adding cPhone a1 = null; if (Demography.UserPhones != null) { foreach (cPhone a in Demography.UserPhones) //state in database { a1 = phones.FirstOrDefault(x => x.PhoneNumberID == a.PhoneNumberID); //If record not found in memory that means it was deleted if (a1 == null) { a.SaveUpdate(userId, true); } else { a1.SaveUpdate(userId); } } } a1 = phones.FirstOrDefault(x => x.PhoneNumberID <= 0); if (a1 != null && a1.IsValid()) // If new and valid, let push it to the database { a1.SaveUpdate(userId); } }
protected void btnSavePhone_Click(object sender, EventArgs e) { int iPhoneNumberID; if (int.TryParse(hidEnterPhoneID.Value, out iPhoneNumberID)) { cPhone UpdatePhone = new cPhone(iPhoneNumberID, _UserID, _UserName); UpdatePhone.PhoneNumberID = iPhoneNumberID; UpdatePhone.AreaCode = tbEnterAreaCode.Text; UpdatePhone.PhoneNumber = tbEnterPhoneNumber.Text; UpdatePhone.Extension = tbEnterExtension.Text; UpdatePhone.IsPrimary = cbxEnterPrimary.Checked; int iTemp; if (int.TryParse(ddlEnterPhoneType.SelectedValue, out iTemp)) { UpdatePhone.PhoneTypeID = iTemp; } if (int.TryParse(ddlEnterProvider.SelectedValue, out iTemp)) { UpdatePhone.ProviderID = iTemp; } UpdatePhone.SaveUpdate(_UserID); } }
protected void gv_PhoneNums_RowCommand(object sender, GridViewCommandEventArgs e) { List <cPhone> phones = null; int gindex = -1; cPhone phone = null; if (int.TryParse(e.CommandArgument.ToString(), out gindex)) { phones = Session["dem_Phones"] as List <cPhone>; if (gindex < phones.Count()) { phone = phones[gindex]; } } else { return; } switch (e.CommandName.ToUpper()) { case "EDIT": case "EDITITEM": { if (phones != null) { gv_PhoneNums.EditIndex = gindex; } BindAllGrids(); break; } } }
protected void btnDeletePhone_Click(object sender, EventArgs e) { int iPhoneNumberID; if (int.TryParse(hidDeletePhoneID.Value, out iPhoneNumberID)) { cPhone UpdatePhone = new cPhone(iPhoneNumberID, _UserID, _UserName); UpdatePhone.SaveUpdate(_UserID, true); } }
protected void btnAddPhoneNumber_Click(object sender, EventArgs e) { List <cPhone> clPhone = Session["dem_Phones"] as List <cPhone>; cPhone NewPhone = new cPhone(); clPhone.Add(NewPhone); Session["dem_Phones"] = clPhone; BindPhoneNumbers(); gvPhoneNumbers.EditIndex = gvPhoneNumbers.Rows.Count - 1; BindPhoneNumbers(); }
protected void gv_PhoneNums_RowUpdating(object sender, GridViewUpdateEventArgs e) { List <cPhone> phones = null; int gindex = e.RowIndex; cPhone phone = new cPhone();; GridView gv = (GridView)sender; phones = Session["dem_Phones"] as List <Classes.cPhone>; if (gindex < phones.Count()) { phone.AreaCode = ((gv.Rows[gindex].FindControl("gv_txtAreaCode") as TextBox).Text + string.Empty).Trim(); phone.PhoneNumber = ((gv.Rows[gindex].FindControl("gv_txtPhoneNumber") as TextBox).Text + string.Empty).Trim(); phone.Extension = ((gv.Rows[gindex].FindControl("gv_txtExtension") as TextBox).Text + string.Empty).Trim(); int iRetVal = 0; int.TryParse((gv.Rows[gindex].FindControl("ddPhoneNumber") as DropDownList).SelectedValue, out iRetVal); //only native types can be returned so temp variable phone.PhoneTypeID = iRetVal; phone.IsPrimary = (gv.Rows[gindex].FindControl("rbtnPrimary1") as RadioButton).Checked; if (phone.IsValid()) { phones[gindex].AreaCode = phone.AreaCode; phones[gindex].PhoneNumber = phone.PhoneNumber; phones[gindex].Extension = phone.Extension; phones[gindex].PhoneTypeID = phone.PhoneTypeID; phones[gindex].IsPrimary = phone.IsPrimary; if (phones[gindex].PhoneNumberID < 1) { phones.Add(new cPhone()); } //if the primary record is checked then all other record must not be ckeched if (phones[gindex].IsPrimary) { phones.ForAll(x => x.IsPrimary = false); phones[gindex].IsPrimary = true; } Session["dem_Phones"] = phones; gv.Rows[gindex].RowState = DataControlRowState.Normal; gv_PhoneNums.EditIndex = -1; } else { lblMessage.Text = phone.strErrorDescription; e.Cancel = true; } } BindAllGrids(); }
/// <summary> /// Load an event. /// </summary> /// <param name="EventID">The Event ID to load.</param> /// <param name="UserName">The user name of the person loading it.</param> /// <returns></returns> public int Load(int EventID, string UserName) { int iNumEventRecords = 0; SortedList Params = new SortedList(); Params.Add("@EventID", EventID.ToString()); // Go get the dataset from GetEvents. DataSet dtEvent = new DataSet(); dtEvent = cUtilities.LoadDataSet("uspGetEvent", Params, "LARPortal", UserName, "cEvents.Load"); int iTemp; bool bTemp; DateTime dtTemp; double dTemp; // Name the tables so that we can use them by name later. Makes it easier to reference them. dtEvent.Tables[0].TableName = "CMEvents"; dtEvent.Tables[1].TableName = "CMSites"; dtEvent.Tables[2].TableName = "MDBAddresses"; dtEvent.Tables[3].TableName = "MDBPhoneNumbers"; foreach (DataRow dRow in dtEvent.Tables["CMEvents"].Rows) { if (int.TryParse(dRow["EventID"].ToString(), out iTemp)) { EventID = iTemp; } if (int.TryParse(dRow["CampaignID"].ToString(), out iTemp)) { CampaignID = iTemp; } EventName = dRow["EventName"].ToString(); if (dRow["IGEventLocation"] != DBNull.Value) { IGEventLocation = dRow["IGEventLocation"].ToString(); } if (DateTime.TryParse(dRow["DecisionByDate"].ToString(), out dtTemp)) { DecisionByDate = dtTemp; } if (DateTime.TryParse(dRow["NotificationDate"].ToString(), out dtTemp)) { NotificationDate = dtTemp; } if (Boolean.TryParse(dRow["SharePlanningInfo"].ToString(), out bTemp)) { SharePlanningInfo = bTemp; } if (Int32.TryParse(dRow["StatusID"].ToString(), out iTemp)) { StatusID = iTemp; } if (dRow["StatusName"] != DBNull.Value) { StatusName = dRow["StatusName"].ToString(); } if (dRow["StatusType"] != DBNull.Value) { StatusType = dRow["StatusType"].ToString(); } if (dRow["StatusComments"] != DBNull.Value) { StatusComments = dRow["StatusComments"].ToString(); } if (dRow["EventDescription"] != DBNull.Value) { EventDescription = dRow["EventDescription"].ToString(); } if (DateTime.TryParse(dRow["StartDateTime"].ToString(), out dtTemp)) { StartDateTime = dtTemp; } if (DateTime.TryParse(dRow["EndDateTime"].ToString(), out dtTemp)) { EndDateTime = dtTemp; } if (int.TryParse(dRow["MaximumPCCount"].ToString(), out iTemp)) { MaximumPCCount = iTemp; } if (int.TryParse(dRow["BaseNPCCount"].ToString(), out iTemp)) { BaseNPCCount = iTemp; } if (int.TryParse(dRow["NPCOverrideRatio"].ToString(), out iTemp)) { NPCOverrideRatio = iTemp; } if (int.TryParse(dRow["CapThresholdNotification"].ToString(), out iTemp)) { CapThresholdNotification = iTemp; } if (bool.TryParse(dRow["CapMetNotification"].ToString(), out bTemp)) { CapMetNotification = bTemp; } if (int.TryParse(dRow["MaximumNPCCount"].ToString(), out iTemp)) { MaximumNPCCount = iTemp; } if (int.TryParse(dRow["AutoApproveWaitListOpenings"].ToString(), out iTemp)) { AutoApproveWaitListOpenings = iTemp; } if (DateTime.TryParse(dRow["RegistrationOpenDateTime"].ToString(), out dtTemp)) { RegistrationOpenDateTime = dtTemp; } if (DateTime.TryParse(dRow["PreregistrationDeadline"].ToString(), out dtTemp)) { PreregistrationDeadline = dtTemp; } if (Double.TryParse(dRow["PreregistrationPrice"].ToString(), out dTemp)) { PreregistrationPrice = dTemp; } if (Double.TryParse(dRow["LateRegistrationPrice"].ToString(), out dTemp)) { LateRegistrationPrice = dTemp; } if (Double.TryParse(dRow["CheckinPrice"].ToString(), out dTemp)) { CheckinPrice = dTemp; } if (int.TryParse(dRow["DaysToAutoCancelOtherPlayerRegistration"].ToString(), out iTemp)) { DaysToAutoCancelOtherPlayerRegistration = iTemp; } if (Boolean.TryParse(dRow["PCFoodService"].ToString(), out bTemp)) { PCFoodService = bTemp; } if (Boolean.TryParse(dRow["NPCFoodService"].ToString(), out bTemp)) { NPCFoodService = bTemp; } if (Boolean.TryParse(dRow["CookingFacilitiesAvailable"].ToString(), out bTemp)) { CookingFacilitiesAvailable = bTemp; } if (Boolean.TryParse(dRow["RefrigeratorAvailable"].ToString(), out bTemp)) { RefrigeratorAvailable = bTemp; } if (DateTime.TryParse(dRow["PELDeadlineDate"].ToString(), out dtTemp)) { PELDeadlineDate = dtTemp; } if (DateTime.TryParse(dRow["InfoSkillDeadlineDate"].ToString(), out dtTemp)) { InfoSkillDeadlineDate = dtTemp; } if (dRow["Comments"] != DBNull.Value) { Comments = dRow["Comments"].ToString(); } } foreach (DataRow dRow in dtEvent.Tables["CMSites"].Rows) { SiteInfo = new cSite(); if (int.TryParse(dRow["SiteID"].ToString(), out iTemp)) { SiteInfo.SiteID = iTemp; } SiteInfo.SiteName = dRow["SiteName"].ToString(); if (int.TryParse(dRow["AddressID"].ToString(), out iTemp)) { SiteInfo.AddressID = iTemp; } SiteInfo.URL = dRow["URL"].ToString(); SiteInfo.SiteMapURL = dRow["SiteMapURL"].ToString(); if (Boolean.TryParse(dRow["YearRound"].ToString(), out bTemp)) { SiteInfo.YearRound = bTemp; } SiteInfo.TimeRestrictions = dRow["TimeRestrictions"].ToString(); if (Boolean.TryParse(dRow["EMTCertificationRequired"].ToString(), out bTemp)) { SiteInfo.EMTCertificationRequired = bTemp; } if (Boolean.TryParse(dRow["CookingCertificationRequired"].ToString(), out bTemp)) { SiteInfo.CookingCertificationRequired = bTemp; } if (Boolean.TryParse(dRow["AdditionalWaiversRequired"].ToString(), out bTemp)) { SiteInfo.AdditionalWaiversRequired = bTemp; } SiteInfo.SiteNotes = dRow["SiteNotes"].ToString(); SiteInfo.Comments = dRow["Comments"].ToString(); foreach (DataRow dAddress in dtEvent.Tables["MDBAddresses"].Rows) { cAddress NewAdd = new cAddress(); if (int.TryParse(dAddress["AddressID"].ToString(), out iTemp)) { NewAdd.IntAddressID = iTemp; } NewAdd.StrAddress1 = dAddress["Address1"].ToString(); NewAdd.StrAddress2 = dAddress["Address2"].ToString(); NewAdd.StrCity = dAddress["City"].ToString(); NewAdd.StrStateID = dAddress["StateID"].ToString(); NewAdd.StrPostalCode = dAddress["PostalCode"].ToString(); NewAdd.StrCountry = dAddress["Country"].ToString(); NewAdd.StrComments = dAddress["Comments"].ToString(); SiteInfo.SiteAddress = NewAdd; } foreach (DataRow dPhone in dtEvent.Tables["MDBPhoneNumbers"].Rows) { cPhone NewPhone = new cPhone(); if (int.TryParse(dPhone["PhoneNumberID"].ToString(), out iTemp)) { NewPhone.PhoneNumberID = iTemp; } if (int.TryParse(dPhone["PhoneTypeID"].ToString(), out iTemp)) { NewPhone.PhoneTypeID = iTemp; } NewPhone.IDD = dPhone["IDD"].ToString(); NewPhone.CountryCode = dPhone["CountryCode"].ToString(); NewPhone.AreaCode = dPhone["AreaCode"].ToString(); NewPhone.PhoneNumber = dPhone["PhoneNumber"].ToString(); NewPhone.Extension = dPhone["Extension"].ToString(); NewPhone.Comments = dPhone["Comments"].ToString(); SiteInfo.SitePhone = NewPhone; } } return(iNumEventRecords); }
protected void gvPhoneNumbers_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if ((e.Row.RowState & DataControlRowState.Edit) > 0) { List <cPhone> clPhoneNumbers = Session["dem_Phones"] as List <cPhone>; DropDownList ddlPhoneType = (DropDownList)e.Row.FindControl("ddlPhoneType"); if (ddlPhoneType != null) { if (clPhoneNumbers.Count > 0) { ddlPhoneType.DataTextField = "PhoneType"; ddlPhoneType.DataValueField = "PhoneTypeID"; ddlPhoneType.DataSource = clPhoneNumbers[0].PhoneTypes; ddlPhoneType.DataBind(); ddlPhoneType.ClearSelection(); cPhone SourcePhone = e.Row.DataItem as cPhone; foreach (ListItem lItem in ddlPhoneType.Items) { if (lItem.Value == SourcePhone.PhoneTypeID.ToString()) { ddlPhoneType.ClearSelection(); lItem.Selected = true; } } } } DropDownList ddlProviderList = (DropDownList)e.Row.FindControl("ddlProviderList"); if (ddlProviderList != null) { if (clPhoneNumbers.Count > 0) { ddlProviderList.DataTextField = "ProviderName"; ddlProviderList.DataValueField = "PhoneProviderID"; ddlProviderList.DataSource = clPhoneNumbers[0].ProviderList; ddlProviderList.DataBind(); ddlProviderList.ClearSelection(); cPhone SourcePhone = e.Row.DataItem as cPhone; foreach (ListItem lItem in ddlProviderList.Items) { if (lItem.Value == SourcePhone.ProviderID.ToString()) { ddlProviderList.ClearSelection(); lItem.Selected = true; } } } } TextBox tbTemp; tbTemp = (TextBox)e.Row.FindControl("tbAreaCode"); if (tbTemp != null) { tbTemp.Attributes.Add("PlaceHolder", "Area Code"); } tbTemp = (TextBox)e.Row.FindControl("tbPhoneNumber"); if (tbTemp != null) { tbTemp.Attributes.Add("PlaceHolder", "Phone Number"); } tbTemp = (TextBox)e.Row.FindControl("tbExtension"); if (tbTemp != null) { tbTemp.Attributes.Add("PlaceHolder", "Extension"); } } } }
protected void gvPhoneNumbers_RowUpdating(object sender, GridViewUpdateEventArgs e) { List <cPhone> clPhoneNumbers = Session["dem_Phones"] as List <cPhone>; if (e.RowIndex < clPhoneNumbers.Count) { cPhone UpdatedPhone = clPhoneNumbers[e.RowIndex]; TextBox tbAreaCode = (TextBox)gvPhoneNumbers.Rows[e.RowIndex].FindControl("tbAreaCode"); if (tbAreaCode != null) { UpdatedPhone.AreaCode = tbAreaCode.Text; } TextBox tbPhoneNumber = (TextBox)gvPhoneNumbers.Rows[e.RowIndex].FindControl("tbPhoneNumber"); if (tbPhoneNumber != null) { UpdatedPhone.PhoneNumber = tbPhoneNumber.Text; } if (!UpdatedPhone.IsValid()) { lblMessage.Text = UpdatedPhone.strErrorDescription; e.Cancel = true; } else { TextBox tbExtension = (TextBox)gvPhoneNumbers.Rows[e.RowIndex].FindControl("tbExtension"); if (tbExtension != null) { UpdatedPhone.Extension = tbExtension.Text; } DropDownList ddlPhoneType = (DropDownList)gvPhoneNumbers.Rows[e.RowIndex].FindControl("ddlPhoneType"); if (ddlPhoneType != null) { UpdatedPhone.PhoneTypeID = ddlPhoneType.SelectedValue.ToInt32(); } DropDownList ddlProviderList = (DropDownList)gvPhoneNumbers.Rows[e.RowIndex].FindControl("ddlProviderList"); if (ddlProviderList != null) { UpdatedPhone.ProviderID = ddlProviderList.SelectedValue.ToInt32(); } RadioButton rbPrimary = (RadioButton)gvPhoneNumbers.Rows[e.RowIndex].FindControl("rbPrimary"); if (rbPrimary != null) { if (rbPrimary.Checked) { clPhoneNumbers.ForAll(x => x.IsPrimary = false); UpdatedPhone.IsPrimary = true; } } Session["dem_Phones"] = clPhoneNumbers; gvPhoneNumbers.EditIndex = -1; } BindPhoneNumbers(); } else { e.Cancel = true; } }