protected void ButtonSave_Click(object sender, EventArgs e) { if (txtUName.Text != "" && txtPass.Text != "" && txtPass2.Text != "" && txtFName.Text != "" && txtLName.Text != "" && txtSal.Text != "" && txtAddress.Text != "" && txtCity.Text != "" && txtZip.Text != "" && txtEmail.Text != "") { try { usrID = Convert.ToInt32(Session["UserID"]); User usr = new User(); usr.GetUserByID(usrID); //take all values from text boxes and send them to User.cs usr.Username = txtUName.Text; if (txtPass.Text != txtPass2.Text) { LabelOutput.ForeColor = System.Drawing.Color.Red; LabelOutput.Text = "Passwords do not match!"; } else { usr.Password = txtPass.Text; usr.Salutation = txtSal.Text; usr.FirstName = txtFName.Text; usr.LastName = txtLName.Text; usr.Address1 = txtAddress.Text; usr.Address2 = txtAddress2.Text; usr.City = txtCity.Text; usr.StateProvinceID = Convert.ToInt32(dropStateProv.SelectedValue); usr.ZipCodePostal = txtZip.Text; usr.Email = txtEmail.Text; usr.IsReceiveNewsletters = ckBox.Checked; // call addusr method to add usr and display success/fail text to usr if (usr.UpdateUser()) { LabelOutput.ForeColor = System.Drawing.Color.Green; LabelOutput.Text = "Thank you " + txtUName.Text + "! You have successfully changed your information."; } else { LabelOutput.ForeColor = System.Drawing.Color.Red; LabelOutput.Text = "Update Failed.<br />Please verify entered values."; throw new Exception(); } } } catch (Exception ex) { String strEx = ex.Message; LabelOutput.ForeColor = System.Drawing.Color.Red; LabelOutput.Text = "Problem Updating, try again"; } }// end if else { LabelOutput.ForeColor = System.Drawing.Color.Red; LabelOutput.Text = "Problem Updating, some required fields have not been filled."; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //Obtain User ID from query string int userid = Convert.ToInt32(Request.QueryString["userid"]); //Get User by its code User user = new User(); user.GetUserByID(userid); //Populate States/Provinces dropdown list StateProvince sp = new StateProvince(); List<StateProvince> states = sp.GetAllStatesProvinces(); DropDownListStateProvince.DataSource = states; DropDownListStateProvince.DataTextField = "Name"; DropDownListStateProvince.DataValueField = "StateProvinceID"; DropDownListStateProvince.DataBind(); //Put user details into fields LabelUserID.Text = Request.QueryString["userid"].ToString(); TextBoxUsername.Text = Convert.ToString(user.Username); TextBoxPassword.Text = Convert.ToString(user.Password); TextBoxSalutation.Text = Convert.ToString(user.Salutation); TextBoxFirstName.Text = Convert.ToString(user.FirstName); TextBoxLastName.Text = Convert.ToString(user.LastName); TextBoxAddress1.Text = Convert.ToString(user.Address1); TextBoxAddress2.Text = Convert.ToString(user.Address2); TextBoxCity.Text = Convert.ToString(user.City); DropDownListStateProvince.SelectedValue = Convert.ToString(user.StateProvinceID); TextBoxZipPostalCode.Text = Convert.ToString(user.ZipCodePostal); TextBoxEmail.Text = Convert.ToString(user.Email); CheckBoxIsReceiveNewsletters.Checked = Convert.ToBoolean(user.IsReceiveNewsletters); LabelCreated.Text = Convert.ToDateTime(user.Created).ToShortDateString(); if (Convert.ToDateTime(user.Modified) > DateTime.MinValue) { LabelModified.Text = Convert.ToDateTime(user.Modified).ToShortDateString(); } else { LabelModified.Text = "N/A"; } } }
protected void ButtonSubmit_Click(object sender, EventArgs e) { try { //Create a User object User user = new User(); //Get existing user by its id user.GetUserByID(Convert.ToInt32(LabelUserID.Text)); //Update all fields user.Username = TextBoxUsername.Text; user.Password = TextBoxPassword.Text; user.Salutation = TextBoxSalutation.Text; user.FirstName = TextBoxFirstName.Text; user.LastName = TextBoxLastName.Text; user.Address1 = TextBoxAddress1.Text; user.Address2 = TextBoxAddress2.Text; user.City = TextBoxCity.Text; user.StateProvinceID = Convert.ToInt32(DropDownListStateProvince.SelectedValue); user.ZipCodePostal = TextBoxZipPostalCode.Text; user.Email = TextBoxEmail.Text; user.IsReceiveNewsletters = CheckBoxIsReceiveNewsletters.Checked; user.Modified = DateTime.Now; //Update the product if (user.UpdateUser()) { ScriptManager.RegisterStartupScript(this, GetType(), "", "window.top.window.$.fancybox.close();", true); //Response.Redirect("~/Admin/Users.aspx"); } else { LabelOutput.ForeColor = System.Drawing.Color.Red; LabelOutput.Text = "Error: Update Failed"; } } catch (Exception ex) { LabelOutput.ForeColor = System.Drawing.Color.Red; LabelOutput.Text = "Error: " + ex.Message; } }
protected void ButtonGoToPayInfo_Click(object sender, EventArgs e) { //Get a reference to the original datasource for the datalist (doesn't take into account DeliveryType changes) DataTable dt = new DataTable(); dt.Columns.Add("Prodcd"); dt.Columns.Add("Name"); dt.Columns.Add("Msrp", System.Type.GetType("System.Double")); dt.Columns.Add("Quantity"); dt.Columns.Add("DeliveryTypeID"); dt.Columns.Add("DeliveryTypeName"); dt.Columns.Add("DeliveryCost", System.Type.GetType("System.Double")); dt.Columns.Add("Taxes", System.Type.GetType("System.Double")); dt.Columns.Add("Total", System.Type.GetType("System.Double")); dt.Columns.Add("FirstName"); dt.Columns.Add("LastName"); dt.Columns.Add("Address1"); dt.Columns.Add("Address2"); dt.Columns.Add("City"); dt.Columns.Add("Country"); dt.Columns.Add("StateProvinceID"); dt.Columns.Add("StateProvinceName"); dt.Columns.Add("ZipPostalCode"); dt.Columns.Add("Email"); //For each data list item... for (int i = 0; i < DataListCheckout.Items.Count; i++) { //Get reference to this data list item DataListItem item = DataListCheckout.Items[i]; if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem) { //Get reference to original datarow for this datalist item DataRow dr = dt.NewRow(); //Get reference to the product for this datalist item Product prod = new Product(); prod.GetProductByCode(DataListCheckout.DataKeys[i].ToString()); dr["Prodcd"] = prod.ProductCode; dr["Name"] = prod.Name; dr["Msrp"] = prod.Msrp; dr["Quantity"] = ((Label)(item.FindControl("LabelQuantity"))).Text; dr["DeliveryTypeID"] = ((DropDownList)(item.FindControl("DropDownListDeliveryType"))).SelectedValue; //Get the delivery type name and cost DeliveryType dtype = new DeliveryType(); dtype.GetDeliveryTypeByID(Convert.ToInt32(dr["DeliveryTypeID"])); dr["DeliveryTypeName"] = dtype.Name; dr["DeliveryCost"] = dtype.Cost; if (((CheckBox)item.FindControl("CheckBoxUseUserAddress")).Checked == true) //use account delivery info { //Get the current user User user = new User(); user.GetUserByID(Convert.ToInt32(Session["UserID"])); dr["FirstName"] = user.FirstName; dr["LastName"] = user.LastName; dr["Address1"] = user.Address1; dr["Address2"] = user.Address2; dr["City"] = user.City; dr["StateProvinceID"] = user.StateProvinceID; //dr["Country"] = user. MUST DEAL WITH COUNTRY LATER dr["ZipPostalCode"] = user.ZipCodePostal; dr["Email"] = user.Email; } else //use customized delivery info { dr["FirstName"] = ((TextBox)(item.FindControl("txtFName"))).Text; dr["LastName"] = ((TextBox)(item.FindControl("txtLName"))).Text; dr["Address1"] = ((TextBox)(item.FindControl("txtAddress"))).Text; dr["Address2"] = ((TextBox)(item.FindControl("txtAddress2"))).Text; dr["City"] = ((TextBox)(item.FindControl("txtCity"))).Text; //dr["Country"] = ((DropDownList)(item.FindControl("dropCountry"))).SelectedValue; MUST DEAL WITH COUNTRY LATER dr["StateProvinceID"] = ((DropDownList)(item.FindControl("dropStateProv"))).SelectedValue; dr["ZipPostalCode"] = ((TextBox)(item.FindControl("txtZipPostal"))).Text; dr["Email"] = ((TextBox)(item.FindControl("txtEmail"))).Text; } //Get the state/province name and tax cost StateProvince sp = new StateProvince(); sp.GetStateProvinceByID(Convert.ToInt32(dr["StateProvinceID"])); dr["StateProvinceName"] = sp.Name; dr["Taxes"] = sp.TaxRatePercentage / 100 * Convert.ToDouble(dr["Msrp"]); //Calculate the total cost dr["Total"] = Convert.ToDouble(dr["Msrp"]) + Convert.ToDouble(dr["DeliveryCost"]) + Convert.ToDouble(dr["Taxes"]); //Add row to datatable dt.Rows.Add(dr); } } //Add checkout list to session Session.Add("CheckoutDataTable",dt); //Go to next page Response.Redirect("~/PaymentInfo.aspx"); }
protected void Page_Load(object sender, EventArgs e) { if (Session["UserID"] == null) { //Not logged in LabelWelcome.Text = "Welcome, Guest"; LinkButtonLoginLogout.Text = "Login"; } else { if (!Page.IsPostBack) { //Get the first name of the current user User user = new User(); user.GetUserByID(Convert.ToInt32(Session["UserID"])); LabelWelcome.Text = "Welcome, " + user.FirstName; //Change login button to logout LinkButtonLoginLogout.Text = "Logout"; } } if (!Page.IsPostBack) { //Get all active categories Category cat = new Category(); List<Category> cats = cat.GetAllCategories(true); foreach (var cs in cats) { MenuItem mi = new MenuItem(); MenuItem m = new MenuItem(); foreach (MenuItem main in appleNav.Items) { if (main.Text == "Categories") { m = main; break; } } if (cs.ParentCategoryID > 0) { foreach (MenuItem ms in m.ChildItems) { if (ms.Value == cs.ParentCategoryID.ToString()) { mi.Value = cs.ParentCategoryID.ToString(); mi.Text = cs.Name.ToString(); mi.NavigateUrl = "~/Category.aspx?id=" + cs.CategoryID; ms.ChildItems.Add(mi); break; } } } else { mi.Value = cs.CategoryID.ToString(); mi.Text = cs.Name.ToString(); mi.Selectable = false; m.ChildItems.Add(mi); } } } }
protected void Page_Load(object sender, EventArgs e) { if (Session["UserID"] == null) Response.Redirect("~/Login.aspx"); else { if (!Page.IsPostBack) { usrID = Convert.ToInt32(Session["UserID"]); User usr = new User(); usr.GetUserByID(usrID); // Load users data into the fields txtUName.Text = usr.Username.ToString(); txtPass.Text = usr.Password.ToString(); txtSal.Text = usr.Salutation.ToString(); txtFName.Text = usr.FirstName.ToString(); txtLName.Text = usr.LastName.ToString(); txtAddress.Text = usr.Address1.ToString(); txtAddress2.Text = usr.Address2.ToString(); pID = usr.StateProvinceID; // populate the drop downs SelectCountryAndProv(); txtCity.Text = usr.City.ToString(); txtZip.Text = usr.ZipCodePostal.ToString(); txtEmail.Text = usr.Email.ToString(); if(Convert.ToBoolean(usr.IsReceiveNewsletters)) ckBox.Checked = true; } } }