protected void btnAddProducts_Click(object sender, EventArgs e)
        {
            Quote qte;
            if ((Session["quote"] != null))
            {
                qte = (Quote)Session["quote"];
                if (qte != null)
                {
                    //Add dimensions when quote is edited
                    qte.Quote_Details.Add(new Quote_Details()
                                              {
                                                  Cap_Height = float.Parse(SlabHeight.Value),
                                                  Cap_Width = float.Parse(SlabWidth.Value),
                                                  Cap_Length = float.Parse(SlabLength.Value),
                                                  Cap_Point = float.Parse(PryHeight.Value),
                                                  Stone_ID = Convert.ToInt32(HF_CapStoneType.Value),
                                                  Product_Option_ID = 1,
                                                  Item_Price = Convert.ToDecimal(lblCalculateAnswer.Text),
                                                  Quantity = Convert.ToInt16(txtQuantity.Text)
                                              });

                    qte.Quote_Details.Add(new Quote_Details()
                                              {
                                                  Pillar_Height = float.Parse(HF_PillarHeight.Value),
                                                  Pillar_Width = float.Parse(HF_PillarWidth.Value),
                                                  Pillar_Length = float.Parse(HF_PillarLength.Value),
                                                  Stone_ID = Convert.ToInt32(HF_PillarStone.Value),
                                                  Product_Option_ID = 2,
                                                  Item_Price = Convert.ToDecimal(HF_PillarTotal.Value),
                                                  Quantity = Convert.ToInt16(txtQuantity.Text)
                                              });

                    Session["quote"] = qte;
                }
            }
            else
            {
                string qRef = Guid.NewGuid().ToString("N").Substring(0, 6).ToUpper();
                qte = new Quote() {Quote_Ref = qRef};

                //Check if quantity as a value.  If not use the value from label.  They're the same
                if (txtQuantity.Text == "")
                {
                    qte.Quote_Details.Add(new Quote_Details()
                                              {
                                                  Cap_Height = float.Parse(SlabHeight.Value),
                                                  Cap_Width = float.Parse(SlabWidth.Value),
                                                  Cap_Length = float.Parse(SlabLength.Value),
                                                  Cap_Point = float.Parse(PryHeight.Value),
                                                  Stone_ID = Convert.ToInt32(HF_CapStoneType.Value),
                                                  Product_Option_ID = 1,
                                                  Item_Price = Convert.ToDecimal(txtInvisibleTotal.Text),
                                                  Quantity = Convert.ToInt16(lblPillCapQuantityPanel.Text)
                                              });
                }

                //Check if text box quantity as a value.
                else
                {
                    qte.Quote_Details.Add(new Quote_Details()
                                              {
                                                  Cap_Height = float.Parse(SlabHeight.Value),
                                                  Cap_Width = float.Parse(SlabWidth.Value),
                                                  Cap_Length = float.Parse(SlabLength.Value),
                                                  Cap_Point = float.Parse(PryHeight.Value),
                                                  Stone_ID = Convert.ToInt32(HF_CapStoneType.Value),
                                                  Product_Option_ID = 1,
                                                  Item_Price = Convert.ToDecimal(lblCalculateAnswer.Text),
                                                  Quantity = Convert.ToInt16(txtQuantity.Text)

                                              });
                }

                //Check if quantity as a value.  If not use the value from label.  They're the same
                if (txtQuantity.Text == "")
                {
                    qte.Quote_Details.Add(new Quote_Details()
                                              {
                                                  Pillar_Height = float.Parse(HF_PillarHeight.Value),
                                                  Pillar_Width = float.Parse(HF_PillarWidth.Value),
                                                  Pillar_Length = float.Parse(HF_PillarLength.Value),
                                                  Stone_ID = Convert.ToInt32(HF_PillarStone.Value),
                                                  Product_Option_ID = 2,
                                                  Item_Price = Convert.ToDecimal(txtInvisibleTotal.Text),
                                                  Quantity = Convert.ToInt16(lblPillCapQuantityPanel.Text)

                                              });
                }

                //Check if text box quantity as a value.
                else
                {
                    qte.Quote_Details.Add(new Quote_Details()
                                              {
                                                  Pillar_Height = float.Parse(HF_PillarHeight.Value),
                                                  Pillar_Width = float.Parse(HF_PillarWidth.Value),
                                                  Pillar_Length = float.Parse(HF_PillarLength.Value),
                                                  Stone_ID = Convert.ToInt32(HF_PillarStone.Value),
                                                  Product_Option_ID = 2,
                                                  Item_Price = Convert.ToDecimal(HF_PillarTotal.Value),
                                                  Quantity = Convert.ToInt16(txtQuantity.Text)

                                              });
                }

                Session.Add("quote", qte);

            }

            //Send quote id back to landing page.
            //This is needed so customer info can be used on quote page
            int qteID = Convert.ToInt32(Request["QuoteDetailsID"]);
            Quote_Details qid = db.Quote_Details.Where(a => a.Quote_Details_ID == qteID).FirstOrDefault();
            if (qid != null)
            {
                Response.Redirect("LandingPage.aspx?QuoteDetailsID=" + qid.Quote_ID);

            }
            else
            {
                Response.Redirect("LandingPage.aspx");
            }
        }
        //Save user inputs
        protected void btnSaveConfirm_Click(object sender, EventArgs e)
        {
            //generate a random alphanumeric string for Quote Reference
            string qRef = Guid.NewGuid().ToString("N").Substring(0, 6).ToUpper();

            //This is for editing a quote which is implemented yet
            if (Page.IsValid)
            {
                Quote qte;
                    if ((Session["quote"] != null))
                    {
                        qte = (Quote)Session["quote"];
                        if (qte != null)
                        {
                            //Add dimensions of newly added product to session
                            //for cap and pillar
                            qte.Quote_Details.Add(new Quote_Details()
                                                      {
                                                          Cap_Height = float.Parse(SlabHeight.Value),
                                                          Cap_Width = float.Parse(SlabWidth.Value),
                                                          Cap_Length = float.Parse(SlabLength.Value),
                                                          Cap_Point = float.Parse(PryHeight.Value),
                                                          Stone_ID = Convert.ToInt32(HF_CapStoneType.Value),
                                                          Product_Option_ID = 1,
                                                          Item_Price = Convert.ToDecimal(lblCalculateAnswer.Text),
                                                          Quantity = Convert.ToInt16(txtQuantity.Text)
                                                      });
                            qte.Quote_Details.Add(new Quote_Details()
                                                      {
                                                          Pillar_Height = float.Parse(HF_PillarHeight.Value),
                                                          Pillar_Width = float.Parse(HF_PillarWidth.Value),
                                                          Pillar_Length = float.Parse(HF_PillarLength.Value),
                                                          Stone_ID = Convert.ToInt32(HF_PillarStone.Value),
                                                          Product_Option_ID = 2,
                                                          Item_Price = Convert.ToDecimal(HF_PillarTotal.Value),
                                                          Quantity = Convert.ToInt16(txtQuantity.Text)
                                                      });

                            int qteID = Convert.ToInt32(Request["QuoteDetailsID"]);

                            Quote qid = db.Quotes.Where(a => a.QuoteId == qteID).FirstOrDefault();

                            Session["quote"] = qte;
                            if (qid != null)
                            {
                                Response.Redirect("Quote.aspx?QuoteDetailsID=" + qid.QuoteId);

                            }
                            else
                            {
                                Response.Redirect("Quote.aspx");
                            }

                        }
                    }
                    else
                    {
                        qte = new Quote() { Quote_Ref = qRef };

                        //Save dimensions of cap and pillar
                        qte.Quote_Details.Add(new Quote_Details()
                                                  {
                                                      Cap_Height = float.Parse(SlabHeight.Value),
                                                      Cap_Width = float.Parse(SlabWidth.Value),
                                                      Cap_Length = float.Parse(SlabLength.Value),
                                                      Cap_Point = float.Parse(PryHeight.Value),
                                                      Stone_ID = Convert.ToInt32(HF_CapStoneType.Value),
                                                      Product_Option_ID = 1,
                                                      Item_Price = Convert.ToDecimal(HF_CapTotal.Value),
                                                      Quantity = Convert.ToInt16(txtQuantity.Text)
                                                  });

                      qte.Quote_Details.Add(new Quote_Details()
                                                  {
                                                      Pillar_Height = float.Parse(HF_PillarHeight.Value),
                                                      Pillar_Width = float.Parse(HF_PillarWidth.Value),
                                                      Pillar_Length = float.Parse(HF_PillarLength.Value),
                                                      Stone_ID = Convert.ToInt32(HF_PillarStone.Value),
                                                      Product_Option_ID = 2,
                                                      Item_Price = Convert.ToDecimal(HF_PillarTotal.Value),
                                                      Quantity = Convert.ToInt16(txtQuantity.Text)
                                                  });

                        Session.Add("quote", qte);

                        //Get quote details id and send it to quote page
                        int qteID = Convert.ToInt32(Request["QuoteDetailsID"]);
                        Quote_Details qid = db.Quote_Details.Where(a => a.Quote_Details_ID == qteID).FirstOrDefault();

                        if (qid == null)
                        {
                            Response.Redirect("Quote.aspx");
                        }
                        else
                        {
                            Response.Redirect("Quote.aspx?QuoteDetailsID=" + qid.Quote_ID);
                        }

                    }
                }
        }
Esempio n. 3
0
        //Add the quote, customer and product to the database and send an automated email.
        //Code found at - http://asp.net-tutorials.com/misc/sending-mails/
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            //create the message
            MailMessage mail = new MailMessage();
            //add the email address we will be sending the message to
            mail.To.Add(txtEmail.Text);
            //add our email here
            mail.From = new MailAddress("*****@*****.**");
            //email's subject
            mail.Subject = "Your quote from SetInStone";
            //email's body, this is going to be html. note that we attach the image as using cid
            mail.Body = "Dear " + txtFirstName.Text + Environment.NewLine +
                        "Your quote price for quote reference: " + lblDisplayQuoteRef.Text + "is €" +
                        lblDisplayQuote.Text
                        + Environment.NewLine +
                        "Please refer to the quote reference if you need to contact us."
                        + Environment.NewLine +
                        "Regards" + Environment.NewLine + "The SetInStoneTeam";

            //set email's body to html
            mail.IsBodyHtml = true;

            //setup our smtp client, these are Gmail specific settings
            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
            client.EnableSsl = true; //ssl must be enabled for Gmail
            //our Gmail account credentials
            NetworkCredential credentials = new NetworkCredential("*****@*****.**", "project400");
            //add credentials to our smtp client
            client.Credentials = credentials;

            try
            {
                //try to send the mail message
                client.Send(mail);
            }
            catch
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Automated email failure", "<script>alert('The automated email service failed.');</script>");

            }

            if (Session["quote"] != null)
            {
                qte = (Quote) Session["quote"];
                if (qte != null)
                {
                    Customer cust = db.Customers.Where(a => a.First_Name == txtFirstName.Text && a.Surname == txtSurname.Text).FirstOrDefault();

                    if (cust == null)
                    {
                        cust = new Customer
                                   {
                                       First_Name = txtFirstName.Text,
                                       Surname = txtSurname.Text,
                                       Address = txtAddress.Text,
                                       Email = txtEmail.Text,
                                       Phone = (txtPhoneNo.Text)

                                   };
                        db.Customers.Add(cust);

                        db.SaveChanges();
                    }

                    qte.CustomerId = cust.CustomerID;

                    qte.Quote_Price = Convert.ToDecimal(lblDisplayQuote.Text);
                    qte.Quote_Date = Convert.ToDateTime(txtDate.Text);

                    db.Quotes.Add(qte);

                    db.SaveChanges();
                    Session["quote"] = null;
                    //send user back to landing page after details are saved
                    Response.Write(
                        "<script LANGUAGE='JavaScript' >alert('Quote has been saved.');document.location='" +
                        ResolveClientUrl("~/LandingPage.aspx") + "';</script>");
                }

            }
        }
        protected void btnSaveConfirm_Click(object sender, EventArgs e)
        {
            //generate a random alphanumeric string for Quote Reference
            string qRef = Guid.NewGuid().ToString("N").Substring(0, 6).ToUpper();

            //This is for editing a quote which is implemented yet
            if (Page.IsValid)
            {
                Quote qte;

                if ((Session["quote"] != null))
                {
                    qte = (Quote)Session["quote"];
                    if (qte != null)
                    {
                        //Add dimensions of newly added product to session
                        qte.Quote_Details.Add(new Quote_Details()
                                                  {
                                                      Fireplace_Base_Height = float.Parse(BaseHeight.Value),
                                                      Fireplace_Base_Width = float.Parse(BaseWidth.Value),

                                                      Fireplace_Top_Height = float.Parse(TopHeight.Value),
                                                      Fireplace_Top_Width = float.Parse(TopWidth.Value),
                                                      Stone_ID = Convert.ToInt32(HF_MarbleSelection.Value),

                                                      Fireplace_Depth = float.Parse(Depth.Value),
                                                      Product_Option_ID = 4,
                                                      Item_Price = Convert.ToDecimal(lblCalculateAnswer.Text),
                                                      Quantity = Convert.ToInt16(txtQuantity.Text)

                                                  });

                        int qteID = Convert.ToInt32(Request["QuoteDetailsID"]);

                        Quote qid = db.Quotes.Where(a => a.QuoteId == qteID).FirstOrDefault();
                        Session["quote"] = qte;

                        //Send qoute id to landing page
                        if (qid != null)
                        {
                            Response.Redirect("Quote.aspx?QuoteDetailsID=" + qid.QuoteId);

                        }
                        else
                        {
                            Response.Redirect("Quote.aspx");
                        }

                    }
                }
                else
                {
                    qte = new Quote() { Quote_Ref = qRef };

                    //Save dimensions
                    qte.Quote_Details.Add(new Quote_Details()
                                              {
                                                  Fireplace_Base_Height = float.Parse(BaseHeight.Value),
                                                  Fireplace_Base_Width = float.Parse(BaseWidth.Value),

                                                  Fireplace_Top_Height = float.Parse(TopHeight.Value),
                                                  Fireplace_Top_Width = float.Parse(TopWidth.Value),
                                                  Fireplace_Depth = float.Parse(Depth.Value),
                                                  Stone_ID = Convert.ToInt32(HF_MarbleSelection.Value),

                                                  Product_Option_ID = 4,
                                                  Item_Price = Convert.ToDecimal(lblCalculateAnswer.Text),
                                                  Quantity = Convert.ToInt16(txtQuantity.Text)
                                              });

                    Session.Add("quote", qte);
                    int qteID = Convert.ToInt32(Request["QuoteDetailsID"]);
                    Quote_Details qid = db.Quote_Details.Where(a => a.Quote_Details_ID == qteID).FirstOrDefault();

                    //Send qoute id to quote page
                    if (qid == null)
                    {
                        Response.Redirect("Quote.aspx");
                    }
                    else
                    {
                        Response.Redirect("Quote.aspx?QuoteDetailsID=" + qid.Quote_ID);
                    }

                }
            }
        }
Esempio n. 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Edit mode
            int qteID = Convert.ToInt32(Request["QuoteDetailsID"]);
            Quote qid = db.Quotes.Where(a => a.QuoteId == qteID).FirstOrDefault();
            if (!Page.IsPostBack)
            {

                if (!String.IsNullOrEmpty(Request["QuoteDetailsID"]))
                {
                    qte = (Quote)Session["quote"];
                    //Display quote price generated on product page
                    lblDisplayQuoteRef.Text = qte.Quote_Ref;

                    decimal totalQuote = 0;

                    foreach (var item in qte.Quote_Details)
                    {

                        totalQuote += item.Item_Price;

                    }

                    lblDisplayQuote.Text = (totalQuote).ToString();

                    lblDisplayQuoteRef.Text = qid.Quote_Ref;
                    txtFirstName.Text = qid.Customer.First_Name;
                    txtSurname.Text = qid.Customer.Surname;
                    txtAddress.Text = qid.Customer.Address;
                    txtDate.Text = dte.ToString();
                    txtEmail.Text = qid.Customer.Email;
                    txtPhoneNo.Text = qid.Customer.Phone;
                }
                else
                {
                    qte = (Quote)Session["quote"];
                    if (qte != null)
                    {
                        //Display quote ref generated on product page
                        lblDisplayQuoteRef.Text = qte.Quote_Ref;

                        decimal totalQuote = 0;

                        //Display quote price generated on product page
                        foreach (var item in qte.Quote_Details)
                        {
                            totalQuote += item.Item_Price;
                        }
                        lblDisplayQuote.Text = totalQuote.ToString("#.##");

                        txtDate.Text = dte.ToString();
                    }

                }

            }
        }