Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- using System.Net.Mail;
- public partial class ShoppingCartContent : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- //if (!Page.IsPostBack)
- //{
- // //if (Session["newCustomer"].ToString() == "nobody" || Session["NewUser"].ToString() == "nobody")
- // //{
- // // lblNewcust.Text = " Welcome " + Session["newCustomer"].ToString();
- // //lblNewcust.Text = "Welcome back " + Session["UserName"].ToString();
- // //}
- //}
- gvShoppingCart.DataSource = ShoppingCart.Instance.Items;
- gvShoppingCart.DataBind();
- if (Session["LoggedIN"].ToString() == "false")
- {
- Response.Redirect("SignIn.aspx");
- }
- #region
- //if (!Page.IsPostBack)
- //{
- //if loged in
- //if (Session["UserName"].ToString() == "nobody")
- //// if (Session["CustomerFirstName"].ToString() == "nobody" &&
- ////Session["CustomerLastName"].ToString() == "nobody")
- ////&& Session["UserName"].ToString() == "nobody"
- //{
- // //save the current location
- // Session["StartPage"] = Request.ServerVariables["URL"].ToString();
- // //send user to register page
- // Response.Redirect("Register.aspx");
- //}
- //else
- // //if (Session["UserName"].ToString() == "nobody")
- //{
- // Session["StartPage"] = Request.ServerVariables["URL"].ToString();
- // //send user to register page
- // Response.Redirect("RegisterContent.aspx");
- //}
- //}
- //lblNewcust.Text = " Welcome " + Session["UserName"].ToString() +" " + "and thank you for choosing BDB";
- #endregion
- }
- protected void gvShoppingCart_SelectedIndexChanged(object sender, EventArgs e)
- {
- gvShoppingCart.DataSource=ShoppingCart.Instance.Items;
- gvShoppingCart.DataBind();
- }
- protected void btnUpdateCart_Click(object sender, EventArgs e)
- {
- //TextBox Qnt = (TextBox)gvShoppingCart.FindControl("MainPlaceHolder_gvShoppingCart_txtQuantity_0");
- #region
- //foreach(GridViewRow gvr in gvShoppingCart.Rows)
- //{
- // for(int i =0; i < gvr.Controls.Count;i++ )
- // {
- // int ProdID = -1;
- // if(gvr.Controls[i] is LinkButton)
- // {
- // LinkButton btn = (LinkButton)gvr.Controls[i];
- // ProdID=int.Parse( btn.CommandArgument);
- // }
- // if (gvr.Controls[i] is TextBox)
- // {
- // int resultQnt;
- // TextBox textC = (TextBox)gvr.Controls[i];
- // if(int.TryParse(textC.Text,out resultQnt))//checking if txt contains the number,if yes result contain the number
- // if (ProdID != -1)
- // {
- // ShoppingCart.Instance.SetItemQuantity(ProdID, resultQnt);
- // }
- // }
- // }
- // }
- #endregion
- // TextBox QntTxt = (TextBox)gvShoppingCart.Rows[0].Cells[2].Controls[0];
- gvShoppingCart.DataSource = ShoppingCart.Instance.Items;
- gvShoppingCart.DataBind();
- }
- protected void gvShoppingCart_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if(e.Row.RowType == DataControlRowType.Footer)
- {
- Label lbltotal = (Label)e.Row.FindControl("LBLTotal");
- lbltotal.Text +=ShoppingCart.Instance.GetSubTotal().ToString("c");
- lbltotal.DataBind();
- }
- //if(e.Row.RowType == DataControlRowType.DataRow)
- //{
- TextBox txtqnt = (TextBox)e.Row.FindControl("txtQuantity");
- //txtqnt.Text = txtqnt.Text;
- //}
- //DataRowView dview = e.Row.DataItem as DataRowView;
- //if(e.Row.RowType==DataControlRowType.DataRow)
- //{
- //// //int prodID = (int)e.Row.FindControl("btnRemove");
- // TextBox qnt = (TextBox)gvShoppingCart.FindControl("txtQuantity");
- //string qntt = qnt.Text;
- //int quantity = Convert.ToInt32(qntt);
- // // ShoppingCart.Instance.SetItemQuantity(prodID, quantity);
- //}
- }
- protected void gvShoppingCart_RowCommand(object sender, GridViewCommandEventArgs e)
- {
- //GridViewRow gvr = sender as GridViewRow;
- int prodID = int.Parse(e.CommandArgument.ToString());
- //string qntt = ((TextBox)gvShoppingCart.FindControl("txtQuantity")).Text;
- //TextBox Qnt = (TextBox)gvShoppingCart.FindControl("txtQuantity");
- //TextBox qntt = (TextBox)gvShoppingCart.Controls[3];
- //int quantity = Convert.ToInt32(qntt);
- if(e.CommandName=="Remove")
- {
- ShoppingCart.Instance.RemoveItem(prodID);
- gvShoppingCart.DataBind();
- }
- if(e.CommandName.Equals("Modify",StringComparison.OrdinalIgnoreCase))
- {
- // TextBox txtqnt = ((TextBox)gvShoppingCart.FooterRow.FindControl("MainPlaceHolder_gvShoppingCart_txtQuantity_0"));
- // string h = txtqnt.Text;
- }
- if(e.CommandName=="Modify")
- {
- ContentPlaceHolder MainContent = Page.Master.FindControl("MainPlaceHolder") as ContentPlaceHolder;
- GridView gridView = MainContent.FindControl("gvShoppingCart") as GridView;
- TextBox qnt = gridView.FindControl("MainPlaceHolder_gvShoppingCart_txtQuantity_0") as TextBox;
- // ShoppingCart.Instance.SetItemQuantity(prodID,quantity);
- }
- }
- protected void txtQuantity_TextChanged(object sender, EventArgs e)
- {
- int x = 1;
- }
- protected void btnsubmit_Click(object sender, EventArgs e)
- {
- List<CartItem> CartList = ShoppingCart.Instance.Items;
- SendEmail(CartList);
- Response.Redirect("homepage.aspx");
- }
- protected void SendEmail(List<CartItem> list)
- {
- string Body = "";
- foreach(CartItem c in list)
- {
- string productName = c.Name;
- string proQ = c.Name;
- bool delivery = chkDelivery.Checked;
- bool PickUp = chkPickup.Checked;
- string notes = txtNotes.Text;
- if (delivery)
- {
- Body += productName + " " + proQ + " " + "delivery" + notes + "\n";
- }
- else if(PickUp)
- {
- Body += productName + proQ + " " +" " + "pick up" + notes + "\n";
- }
- else
- {
- //warn user to check box
- }
- }
- MailMessage mailObj = new MailMessage("yuliyapryymak@gmail.com",
- "yuliyapryymak@gmail.com", "BDB - New Order in", Body);
- SmtpClient SMTPServer = new SmtpClient("smtp.gmail.com");
- SMTPServer.Credentials = new System.Net.NetworkCredential("yuliyapryymak@gmail.com", "medicine21");
- try
- { SMTPServer.Send(mailObj); }
- catch (Exception ex)
- { lblNewcust.Text = ex.ToString(); }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement