private void AddressesChangesUpdate(cUser Demography) { List <cAddress> addresses = Session["dem_Addresses"] as List <cAddress>; 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 cAddress a1 = null; if (Demography.UserAddresses != null) { foreach (cAddress a in Demography.UserAddresses) //state in database { a1 = addresses.FirstOrDefault(x => x.AddressID == a.AddressID); //If record not found in memory that means it was deleted if (a1 == null) { a.SaveUpdate(userId, true); } else { a1.SaveUpdate(userId); } } } a1 = addresses.FirstOrDefault(x => x.AddressID <= 0); if (a1 != null && a1.IsValid()) // If new and valid, let push it to the database { a1.SaveUpdate(userId); } }
protected void btnSaveAddress_Click(object sender, EventArgs e) { int iAddressID; if (int.TryParse(hidAddressID.Value, out iAddressID)) { cAddress UpdateAddress = new cAddress(iAddressID, _UserName, _UserID); UpdateAddress.AddressID = iAddressID; UpdateAddress.Address1 = tbEnterAddress1.Text; UpdateAddress.Address2 = tbEnterAddress2.Text; UpdateAddress.City = tbEnterCity.Text; UpdateAddress.StateID = ddlEnterState.SelectedValue; UpdateAddress.PostalCode = tbEnterZipCode.Text; UpdateAddress.Country = tbEnterCountry.Text; UpdateAddress.IsPrimary = cbxEnterAddressPrimary.Checked; int iTemp; if (int.TryParse(ddlEnterAddressType.SelectedValue, out iTemp)) { UpdateAddress.AddressTypeID = iTemp; } UpdateAddress.SaveUpdate(_UserID); } }
protected void btnDeleteAddress_Click(object sender, EventArgs e) { int iAddressID; if (int.TryParse(hidDeleteAddressID.Value, out iAddressID)) { cAddress UpdateAddress = new cAddress(iAddressID, _UserName, _UserID); UpdateAddress.SaveUpdate(_UserID, true); } }
protected void gv_Address_RowUpdating(object sender, GridViewUpdateEventArgs e) { List <cAddress> addresses = null; int gindex = e.RowIndex; cAddress address = new cAddress(); GridView gv = (GridView)sender; addresses = Session["dem_Addresses"] as List <Classes.cAddress>; if (gindex < addresses.Count()) { address.StrAddress1 = ((gv.Rows[gindex].FindControl("gv_txtAddress1") as TextBox).Text + string.Empty).Trim(); address.StrAddress2 = ((gv.Rows[gindex].FindControl("gv_txtAddress2") as TextBox).Text + string.Empty).Trim(); address.StrCity = ((gv.Rows[gindex].FindControl("gv_txtCity") as TextBox).Text + string.Empty).Trim(); address.StrStateID = ((gv.Rows[gindex].FindControl("gv_txtState") as TextBox).Text + string.Empty).Trim(); address.StrPostalCode = ((gv.Rows[gindex].FindControl("gv_txtZipCode") as TextBox).Text + string.Empty).Trim(); address.StrCountry = ((gv.Rows[gindex].FindControl("gv_txtCountry") as TextBox).Text + string.Empty).Trim(); int iRetVal = 0; int.TryParse((gv.Rows[gindex].FindControl("ddAddressType") as DropDownList).SelectedValue, out iRetVal); //only native types can be returned so temp variable address.IntAddressTypeID = iRetVal; address.IsPrimary = (gv.Rows[gindex].FindControl("rbtnPrimary") as RadioButton).Checked; if (address.IsValid()) { addresses[gindex].StrAddress1 = address.StrAddress1; addresses[gindex].StrAddress2 = address.StrAddress2; addresses[gindex].StrCity = address.StrCity; addresses[gindex].StrStateID = address.StrStateID; addresses[gindex].StrPostalCode = address.StrPostalCode; addresses[gindex].StrCountry = address.StrCountry; addresses[gindex].IntAddressTypeID = address.IntAddressTypeID; addresses[gindex].IsPrimary = address.IsPrimary; if (addresses[gindex].IntAddressID < 1)//Always make sure that there is an extra records to edit, since there is not option to add records { addresses.Add(new cAddress()); } //if the primary record is checked then all other record must not be ckeched if (addresses[gindex].IsPrimary) { addresses.ForAll(x => x.IsPrimary = false); addresses[gindex].IsPrimary = true; } Session["dem_Addresses"] = addresses; gv.Rows[gindex].RowState = DataControlRowState.Normal; gv_Address.EditIndex = -1; } else { lblMessage.Text = address.strErrorDescription; e.Cancel = true; } } BindAllGrids(); }
protected void gv_Address_RowCommand(object sender, GridViewCommandEventArgs e) { List <cAddress> addresses = null; int gindex = -1; cAddress address = null; if (int.TryParse(e.CommandArgument.ToString(), out gindex)) { addresses = Session["dem_Addresses"] as List <Classes.cAddress>; if (gindex < addresses.Count()) { address = addresses[gindex]; } } else { //maybe send error on the screen to notify that the record does not exists return; } switch (e.CommandName.ToUpper()) { //case "DELETEITEM": // { // if (address != null) //We need to have at least one record so we adding can be possible // { // if (addresses.Count > 0) // { // addresses.Remove(address); // } // else //If they want to delete the only item we have, we still need an empty element to add information..... // { // addresses = new List<cAddress>() { new cAddress() }; // } // Session["dem_Addresses"] = addresses; // BindAllGrids(); // } // break; // } case "EDIT": case "EDITITEM": { if (address != null) { gv_Address.EditIndex = gindex; } BindAllGrids(); break; } } }
protected void btnAddAddress_Click(object sender, EventArgs e) { List <cAddress> clAddress = Session["dem_Addresses"] as List <cAddress>; cAddress NewAddress = new cAddress(); clAddress.Add(NewAddress); Session["dem_Addresses"] = clAddress; BindAddresses(); gvAddresses.EditIndex = gvAddresses.Rows.Count - 1; BindAddresses(); GridViewRow dRow = gvAddresses.Rows[gvAddresses.EditIndex]; if (dRow != null) { TextBox tbAddress1 = (TextBox)dRow.FindControl("tbAddress1"); if (tbAddress1 != null) { tbAddress1.Focus(); } } }
/// <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 gvAddresses_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if ((e.Row.RowState & DataControlRowState.Edit) > 0) { List <cAddress> clAddress = Session["dem_Addresses"] as List <cAddress>; DropDownList ddlAddressType = (DropDownList)e.Row.FindControl("ddlAddressType"); if (ddlAddressType != null) { if (clAddress.Count > 0) { ddlAddressType.DataTextField = "AddressType"; ddlAddressType.DataValueField = "AddressTypeID"; ddlAddressType.DataSource = clAddress[0].AddressTypes; ddlAddressType.DataBind(); ddlAddressType.ClearSelection(); cAddress SourceAddress = e.Row.DataItem as cAddress; foreach (ListItem lItem in ddlAddressType.Items) { if (lItem.Value == SourceAddress.AddressTypeID.ToString()) { ddlAddressType.ClearSelection(); lItem.Selected = true; } } } } TextBox tbTemp; tbTemp = (TextBox)e.Row.FindControl("tbAddress1"); if (tbTemp != null) { tbTemp.Attributes.Add("PlaceHolder", "Address 1"); } tbTemp = (TextBox)e.Row.FindControl("tbAddress2"); if (tbTemp != null) { tbTemp.Attributes.Add("PlaceHolder", "Address 2"); } tbTemp = (TextBox)e.Row.FindControl("tbCity"); if (tbTemp != null) { tbTemp.Attributes.Add("PlaceHolder", "City"); } tbTemp = (TextBox)e.Row.FindControl("tbState"); if (tbTemp != null) { tbTemp.Attributes.Add("PlaceHolder", "State Abbrev"); } tbTemp = (TextBox)e.Row.FindControl("tbPostalCode"); if (tbTemp != null) { tbTemp.Attributes.Add("PlaceHolder", "Postal Code"); } tbTemp = (TextBox)e.Row.FindControl("tbCountry"); if (tbTemp != null) { tbTemp.Attributes.Add("PlaceHolder", "Country"); } } } }
protected void gvAddresses_RowUpdating(object sender, GridViewUpdateEventArgs e) { List <cAddress> clAddresses = Session["dem_Addresses"] as List <cAddress>; if (e.RowIndex < clAddresses.Count) { cAddress UpdatedAddress = clAddresses[e.RowIndex]; TextBox tbAddress1 = (TextBox)gvAddresses.Rows[e.RowIndex].FindControl("tbAddress1"); if (tbAddress1 != null) { UpdatedAddress.Address1 = tbAddress1.Text; } TextBox tbCity = (TextBox)gvAddresses.Rows[e.RowIndex].FindControl("tbCity"); if (tbCity != null) { UpdatedAddress.City = tbCity.Text; } TextBox tbPostalCode = (TextBox)gvAddresses.Rows[e.RowIndex].FindControl("tbPostalCode"); if (tbPostalCode != null) { UpdatedAddress.PostalCode = tbPostalCode.Text; } if (!UpdatedAddress.IsValid()) { lblMessage.Text = UpdatedAddress.strErrorDescription; e.Cancel = true; } else { TextBox tbAddress2 = (TextBox)gvAddresses.Rows[e.RowIndex].FindControl("tbAddress2"); if (tbAddress2 != null) { UpdatedAddress.Address2 = tbAddress2.Text; } TextBox tbState = (TextBox)gvAddresses.Rows[e.RowIndex].FindControl("tbState"); if (tbState != null) { UpdatedAddress.StateID = tbState.Text; } TextBox tbCountry = (TextBox)gvAddresses.Rows[e.RowIndex].FindControl("tbCountry"); if (tbCountry != null) { UpdatedAddress.Country = tbCountry.Text; } DropDownList ddlAddressType = (DropDownList)gvAddresses.Rows[e.RowIndex].FindControl("ddlAddressType"); if (ddlAddressType != null) { UpdatedAddress.AddressTypeID = ddlAddressType.SelectedValue.ToInt32(); } RadioButton rbPrimary = (RadioButton)gvAddresses.Rows[e.RowIndex].FindControl("rbPrimary"); if (rbPrimary != null) { if (rbPrimary.Checked) { clAddresses.ForAll(x => x.IsPrimary = false); UpdatedAddress.IsPrimary = true; } } Session["dem_Addresses"] = clAddresses; gvAddresses.EditIndex = -1; } BindAddresses(); } else { e.Cancel = true; } }