예제 #1
0
        private void SubmitOrder_Click(object sender, EventArgs e)
        {
            Desk      desk     = new Desk();
            DeskQuote newQuote = new DeskQuote();
            int       material = 0;

            // all entered validation
            try
            {
                if (nameInput != null)
                {
                    newQuote.CustName = nameInput.Text;
                }
                if (widthInput != null)
                {
                    desk.Width = double.Parse(widthInput.Text.ToString());
                }

                if (depthInput != null)
                {
                    desk.Depth = double.Parse(depthInput.Text.ToString());
                }

                if (drawersInput != null)
                {
                    desk.DrawersNum = uint.Parse(drawersInput.SelectedItem.ToString());
                }


                if (materialInput != null)
                {
                    string selectedMaterial = materialInput.SelectedItem.ToString();

                    switch (selectedMaterial)
                    {
                    case "Oak":
                        material = (int)DesktopMaterial.Oak;
                        break;

                    case "Rosewood":
                        material = (int)DesktopMaterial.Rosewood;
                        break;

                    case "Laminate":
                        material = (int)DesktopMaterial.Laminate;
                        break;

                    case "Veneer":
                        material = (int)DesktopMaterial.Veneer;
                        break;

                    case "Pine":
                        material = (int)DesktopMaterial.Pine;
                        break;
                    }
                }

                if (rushInput != null)
                {
                    newQuote.RushOrder = uint.Parse(rushInput.SelectedItem.ToString());
                }
            }
            catch
            {
                MessageBox.Show("Please enter a value in every field", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            double   surfaceArea = newQuote.calcSurfaceArea(desk.Width, desk.Depth);
            double   shipping    = newQuote.calcShippingCost(surfaceArea, newQuote.RushOrder);
            DateTime quoteDate   = DateTime.Today;

            newQuote.QuoteDate = quoteDate;

            double quoteTotal = newQuote.QuoteTotal(material, shipping, surfaceArea, desk.DrawersNum);

            StreamWriter writeQuote = new StreamWriter("newQuote.txt");

            writeQuote.WriteLine(newQuote.CustName);
            writeQuote.WriteLine(newQuote.QuoteDate);
            writeQuote.WriteLine("$" + quoteTotal);
            writeQuote.Close();

            DisplayQuote displayNewQuoteForm = new DisplayQuote();

            displayNewQuoteForm.Tag = this;
            displayNewQuoteForm.Show(this);
            Hide();
        }