Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data;
  8. using System.Net.Mail;
  9.  
  10. public partial class ShoppingCartContent : System.Web.UI.Page
  11. {
  12. protected void Page_Load(object sender, EventArgs e)
  13. {
  14. //if (!Page.IsPostBack)
  15. //{
  16. // //if (Session["newCustomer"].ToString() == "nobody" || Session["NewUser"].ToString() == "nobody")
  17. // //{
  18. // // lblNewcust.Text = " Welcome " + Session["newCustomer"].ToString();
  19. // //lblNewcust.Text = "Welcome back " + Session["UserName"].ToString();
  20. // //}
  21.  
  22.  
  23. //}
  24.  
  25. gvShoppingCart.DataSource = ShoppingCart.Instance.Items;
  26. gvShoppingCart.DataBind();
  27.  
  28. if (Session["LoggedIN"].ToString() == "false")
  29. {
  30. Response.Redirect("SignIn.aspx");
  31.  
  32. }
  33.  
  34. #region
  35. //if (!Page.IsPostBack)
  36. //{
  37. //if loged in
  38. //if (Session["UserName"].ToString() == "nobody")
  39. //// if (Session["CustomerFirstName"].ToString() == "nobody" &&
  40. ////Session["CustomerLastName"].ToString() == "nobody")
  41. ////&& Session["UserName"].ToString() == "nobody"
  42. //{
  43. // //save the current location
  44. // Session["StartPage"] = Request.ServerVariables["URL"].ToString();
  45.  
  46. // //send user to register page
  47. // Response.Redirect("Register.aspx");
  48. //}
  49. //else
  50. // //if (Session["UserName"].ToString() == "nobody")
  51. //{
  52. // Session["StartPage"] = Request.ServerVariables["URL"].ToString();
  53.  
  54. // //send user to register page
  55. // Response.Redirect("RegisterContent.aspx");
  56. //}
  57. //}
  58.  
  59. //lblNewcust.Text = " Welcome " + Session["UserName"].ToString() +" " + "and thank you for choosing BDB";
  60. #endregion
  61. }
  62.  
  63. protected void gvShoppingCart_SelectedIndexChanged(object sender, EventArgs e)
  64. {
  65.  
  66. gvShoppingCart.DataSource=ShoppingCart.Instance.Items;
  67. gvShoppingCart.DataBind();
  68.  
  69.  
  70. }
  71. protected void btnUpdateCart_Click(object sender, EventArgs e)
  72. {
  73. //TextBox Qnt = (TextBox)gvShoppingCart.FindControl("MainPlaceHolder_gvShoppingCart_txtQuantity_0");
  74.  
  75. #region
  76. //foreach(GridViewRow gvr in gvShoppingCart.Rows)
  77. //{
  78.  
  79. // for(int i =0; i < gvr.Controls.Count;i++ )
  80. // {
  81. // int ProdID = -1;
  82. // if(gvr.Controls[i] is LinkButton)
  83. // {
  84. // LinkButton btn = (LinkButton)gvr.Controls[i];
  85. // ProdID=int.Parse( btn.CommandArgument);
  86. // }
  87. // if (gvr.Controls[i] is TextBox)
  88. // {
  89. // int resultQnt;
  90. // TextBox textC = (TextBox)gvr.Controls[i];
  91. // if(int.TryParse(textC.Text,out resultQnt))//checking if txt contains the number,if yes result contain the number
  92.  
  93. // if (ProdID != -1)
  94. // {
  95. // ShoppingCart.Instance.SetItemQuantity(ProdID, resultQnt);
  96. // }
  97.  
  98. // }
  99.  
  100.  
  101. // }
  102. // }
  103. #endregion
  104. // TextBox QntTxt = (TextBox)gvShoppingCart.Rows[0].Cells[2].Controls[0];
  105.  
  106. gvShoppingCart.DataSource = ShoppingCart.Instance.Items;
  107. gvShoppingCart.DataBind();
  108. }
  109. protected void gvShoppingCart_RowDataBound(object sender, GridViewRowEventArgs e)
  110. {
  111.  
  112. if(e.Row.RowType == DataControlRowType.Footer)
  113. {
  114. Label lbltotal = (Label)e.Row.FindControl("LBLTotal");
  115. lbltotal.Text +=ShoppingCart.Instance.GetSubTotal().ToString("c");
  116. lbltotal.DataBind();
  117. }
  118. //if(e.Row.RowType == DataControlRowType.DataRow)
  119. //{
  120. TextBox txtqnt = (TextBox)e.Row.FindControl("txtQuantity");
  121. //txtqnt.Text = txtqnt.Text;
  122.  
  123. //}
  124.  
  125. //DataRowView dview = e.Row.DataItem as DataRowView;
  126. //if(e.Row.RowType==DataControlRowType.DataRow)
  127. //{
  128.  
  129. //// //int prodID = (int)e.Row.FindControl("btnRemove");
  130. // TextBox qnt = (TextBox)gvShoppingCart.FindControl("txtQuantity");
  131. //string qntt = qnt.Text;
  132. //int quantity = Convert.ToInt32(qntt);
  133. // // ShoppingCart.Instance.SetItemQuantity(prodID, quantity);
  134.  
  135. //}
  136.  
  137. }
  138. protected void gvShoppingCart_RowCommand(object sender, GridViewCommandEventArgs e)
  139. {
  140. //GridViewRow gvr = sender as GridViewRow;
  141.  
  142. int prodID = int.Parse(e.CommandArgument.ToString());
  143. //string qntt = ((TextBox)gvShoppingCart.FindControl("txtQuantity")).Text;
  144. //TextBox Qnt = (TextBox)gvShoppingCart.FindControl("txtQuantity");
  145. //TextBox qntt = (TextBox)gvShoppingCart.Controls[3];
  146. //int quantity = Convert.ToInt32(qntt);
  147.  
  148.  
  149. if(e.CommandName=="Remove")
  150. {
  151. ShoppingCart.Instance.RemoveItem(prodID);
  152. gvShoppingCart.DataBind();
  153. }
  154. if(e.CommandName.Equals("Modify",StringComparison.OrdinalIgnoreCase))
  155. {
  156. // TextBox txtqnt = ((TextBox)gvShoppingCart.FooterRow.FindControl("MainPlaceHolder_gvShoppingCart_txtQuantity_0"));
  157. // string h = txtqnt.Text;
  158. }
  159. if(e.CommandName=="Modify")
  160. {
  161. ContentPlaceHolder MainContent = Page.Master.FindControl("MainPlaceHolder") as ContentPlaceHolder;
  162. GridView gridView = MainContent.FindControl("gvShoppingCart") as GridView;
  163. TextBox qnt = gridView.FindControl("MainPlaceHolder_gvShoppingCart_txtQuantity_0") as TextBox;
  164.  
  165. // ShoppingCart.Instance.SetItemQuantity(prodID,quantity);
  166. }
  167. }
  168. protected void txtQuantity_TextChanged(object sender, EventArgs e)
  169. {
  170. int x = 1;
  171. }
  172. protected void btnsubmit_Click(object sender, EventArgs e)
  173. {
  174. List<CartItem> CartList = ShoppingCart.Instance.Items;
  175. SendEmail(CartList);
  176. Response.Redirect("homepage.aspx");
  177. }
  178. protected void SendEmail(List<CartItem> list)
  179. {
  180. string Body = "";
  181. foreach(CartItem c in list)
  182. {
  183. string productName = c.Name;
  184. string proQ = c.Name;
  185. bool delivery = chkDelivery.Checked;
  186. bool PickUp = chkPickup.Checked;
  187. string notes = txtNotes.Text;
  188.  
  189. if (delivery)
  190. {
  191. Body += productName + " " + proQ + " " + "delivery" + notes + "\n";
  192. }
  193. else if(PickUp)
  194. {
  195. Body += productName + proQ + " " +" " + "pick up" + notes + "\n";
  196. }
  197. else
  198. {
  199. //warn user to check box
  200. }
  201. }
  202. MailMessage mailObj = new MailMessage("yuliyapryymak@gmail.com",
  203. "yuliyapryymak@gmail.com", "BDB - New Order in", Body);
  204. SmtpClient SMTPServer = new SmtpClient("smtp.gmail.com");
  205. SMTPServer.Credentials = new System.Net.NetworkCredential("yuliyapryymak@gmail.com", "medicine21");
  206. try
  207. { SMTPServer.Send(mailObj); }
  208. catch (Exception ex)
  209. { lblNewcust.Text = ex.ToString(); }
  210. }
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement