//If Customer has already addresses protected void ButtonUserAddrSave_Click(object sender, EventArgs e) { //If all controls aren't valid if (!Page.IsValid) { return; } //If all controls are valid, proceed the underneath code string fullAddr = String.Concat(TboxLine1.Text, " ", TboxLine2.Text).Trim(); //Set the objects properties cust.CustShippAddr = fullAddr; cust.CustShipCountry = DropDownListUserCountry.SelectedItem.Text; cust.CustShipState = DropDownListUserState.SelectedItem.Text; cust.CustShipCity = TboxCity.Text; cust.CustShipPinCode = Convert.ToInt32(TboxPinCode.Text); cust.MyId = id; // save info into Database at the paricular AddressId //Of the customer cust.SaveShipAddr(Convert.ToInt32(ButtonUserAddrSave.CommandArgument)); //Fetch from database cust.DisplayCustomerData(); cust.CheckShipAddr(); //Update the ManipulateCustom obj custMpData = cust.ShowCustManupulatedData(); //Store updated Customer Obj in ViewState // ViewState["Customer"] = cust; //Sore updated Manupulated Obj in ViewState ViewState["CustManupData"] = custMpData; //Fect the Dicitionary Obj & Update the Repeater RptUserAddr.DataSource = custMpData.ShowCustIdentity(); RptUserAddr.DataBind(); //Switch to 1st tab MultiViewUserAddr.ActiveViewIndex = 0; //Update UI ShowDisplayedData(); }
protected void BtnShipNewAddrSave_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } //If all controls are valid, proceed the underneath code string fullAddr = String.Concat(TBoxNewAddrLine1.Text, TBoxNewAddrLine2.Text).Trim(); //Set the objects properties cust.CustShippAddr = fullAddr; cust.CustShipCountry = ListShipNewCountry.SelectedItem.Text; cust.CustShipState = ListShipNewState.SelectedItem.Text; cust.CustShipCity = TBoxNewAddrCity.Text; cust.CustShipPinCode = Convert.ToInt32(TBoxNewAddrPinCode.Text); cust.MyId = id; // save info into Database cust.SaveShipNewAddr(); //Fetch from database cust.DisplayCustomerData(); cust.CheckShipAddr(); //Update the ManipulateCustom obj custMpData = cust.ShowCustManupulatedData(); //Sore updated Manupulated Obj in ViewState ViewState["CustManupData"] = custMpData; //Fect the Dicitionary Obj & Update the Repeater RptUserAddr.DataSource = custMpData.ShowCustIdentity(); RptUserAddr.DataBind(); //Switch to 1st tab MultiViewUserAddr.ActiveViewIndex = 0; //Update UI ShowDisplayedData(); }
//This will delete saved Address public void DeleteShipAddr(int theCustAddrId) { string deleteSqlQury = "DELETE FROM customer_address "; deleteSqlQury += " WHERE CustAddrId IN ("; deleteSqlQury += "@CustAddrId)"; custMpData = new ManipulateCustomerData(); MySqlConnection connection = new MySqlConnection(connectionString); MySqlCommand cmd = new MySqlCommand(deleteSqlQury, connection); //Add parameters for Selct cmd.Parameters.AddWithValue("@CustId", MyId); cmd.Parameters.AddWithValue("@CustAddrId", theCustAddrId); //Will give 1 if record successfully updated int deleted = 0; try { using (connection) { // Open database connection connection.Open(); deleted = cmd.ExecuteNonQuery(); } } catch (Exception err) { System.Diagnostics.Debug.WriteLine("Update Query Error" + err); } //If deleted successfully //if (deleted > 0) //{ // custMpData.AddCustIdentity(theCustAddrId,) //} }
protected void ButtonUserAddrDelete_Command(object sender, CommandEventArgs e) { cust.MyId = id; // save info into Database at the paricular AddressId //Of the customer cust.DeleteShipAddr(Convert.ToInt32(e.CommandArgument)); //Fetch from database cust.DisplayCustomerData(); //Check ship Address cust.CheckShipAddr(); //Store updated Customer Obj in ViewState custMpData = cust.ShowCustManupulatedData(); Response.Redirect(Request.RawUrl); }
protected void BtnUserDtlSaved_Click(object sender, EventArgs e) { //If all controls aren't valid if (!Page.IsValid) { return; } //Id all controls are valid , proceed the underneath code //Set obj's properties cust.CustFirstName = TBoxFirstName.Text.Trim(); cust.CustLastName = TBoxLastName.Text.Trim(); cust.CustMobNo = Convert.ToInt32(TBoxMobNo.Text.Trim()); cust.EmailId = TBoxEmail.Text; cust.MyId = id; //Save the details cust.SaveCustmerInfo(); //Fetch from database cust.DisplayCustomerData(); cust.CheckShipAddr(); //Store updated Customer Obj in ViewState custMpData = cust.ShowCustManupulatedData(); //Update UI ShowDisplayedData(); }
public void CheckShipAddr() { string selectSqlQueryCust = "SELECT CustAddrId, CustShipAddr, CustShipCountry, CustShipState, CustShipCity, CustShipPinCode FROM customer_address"; selectSqlQueryCust += " WHERE CustId = @CustId"; int custAddrId; custMpData = new ManipulateCustomerData(); MySqlConnection connection = new MySqlConnection(connectionString); MySqlCommand cmd; MySqlDataReader readerShipAddr; cmd = new MySqlCommand(selectSqlQueryCust, connection); //Add the paramaters cmd.Parameters.AddWithValue("@CustId", MyId); try { //To automatically dispose the connction Obj using (connection) { // Open the database connection connection.Open(); readerShipAddr = cmd.ExecuteReader(); //Read the data from Customer table //and Set the Customer's Object fields while (readerShipAddr.Read()) { custAddrId = Convert.ToInt32(readerShipAddr["CustAddrId"]); //if data present in CustAddress table i.e(not null) //Convert.To method will give null as O/P if null is there if (custAddrId != 0) { CustShippAddr = readerShipAddr["CustShipAddr"].ToString(); CustShipCountry = readerShipAddr["CustShipCountry"].ToString(); CustShipState = readerShipAddr["CustShipState"].ToString(); CustShipCity = readerShipAddr["CustShipCity"].ToString(); CustShipPinCode = Convert.ToInt32(readerShipAddr["CustShipPinCode"]); //To store the entire obj custMpData.AddCustIdentity(custAddrId, CustFirstName, CustLastName, CustFullName, CustMobNo, EmailId, CustShippAddr, CustShipCountry, CustShipState, CustShipCity, CustShipPinCode); } } } } catch (Exception error) { System.Diagnostics.Debug.WriteLine(error); } }
/* Note: If customer Signs up or logins successfully * Retrive all customer data with associated customer Id * i.e Troughout their name to what they ardered */ public void DisplayCustomerData() { string selectSqlQueryCust = "SELECT CustFirstName, CustLastName, CustMobNo, CustEmailAddr, CustImg FROM customer"; //string selectSqlQueryCust = "SELECT CustFirstName, CustLastName, CustMobNo, CustEmailAddr, CustImg, CustAddrId, CustShipAddr, CustShipCountry, CustShipState, CustShipCity, CustShipPinCode FROM customer "; //selectSqlQueryCust += "INNER JOIN customer_address "; //selectSqlQueryCust += " ON customer.CustId = customer_address.CustId "; //selectSqlQueryCust += " WHERE customer.CustId = @CustId"; selectSqlQueryCust += " WHERE CustId=@CustId"; // int custAddrId; custMpData = new ManipulateCustomerData(); MySqlConnection connection = new MySqlConnection(connectionString); MySqlCommand cmd; MySqlDataReader reader; cmd = new MySqlCommand(selectSqlQueryCust, connection); //Add the paramaters cmd.Parameters.AddWithValue("@CustId", MyId); try { //To automatically dispose the connction Obj using (connection) { // Open the database connection connection.Open(); reader = cmd.ExecuteReader(); //Read the data from Customer table //and Set the Customer's Object fields while (reader.Read()) { CustFirstName = reader["CustFirstName"].ToString(); CustLastName = reader["CustLastName"].ToString(); CustMobNo = Convert.ToInt32(reader["CustMobNo"]); EmailId = reader["CustEmailAddr"].ToString(); CustImg = reader["CustImg"].ToString(); //if data present in CustAddress table i.e(not null) //Convert.To method will give null as O/P if null is there } } } catch (Exception error) { Label errorLbl = new Label(); errorLbl.Text = error.ToString(); } }
protected void Page_Load(object sender, EventArgs e) { //Display user info cust = new Customer(); if (!this.IsPostBack) { userSelectionTab = Request.QueryString["TabSelection"]; if (cust.CheckCookie()) { //Store customer in view state ViewState["CustId"] = cust.MyId; cust.DisplayCustomerData(); cust.CheckShipAddr(); custMpData = cust.ShowCustManupulatedData(); custMpData.ShowCustIdentity(); ShowDisplayedData(); //Check for clicked links i.e User Profile or User Address tab switch (userSelectionTab) { case "Profile": //To set the Multiview property LinkButtonUserProf_Click(LinkButtonUserProf, null); break; case "Addr": LinkButtonUserAddr_Click(LinkButtonUserAddr, null); break; case "Order": LinkButtonuserOrdered_Click(LinkButtonuserOrdered, null); break; } } else { Response.Redirect("~/UserAccount/Login.aspx"); } //This function will add the Country and state //In the dropdown List AddCountryList(); } if (this.IsPostBack) { //Retreive CustId id = (int)ViewState["CustId"]; // cust = (Customer)ViewState["Customer"]; //Retreive CustManupulated Obj custMpData = (ManipulateCustomerData)ViewState["CustManupData"]; } }