Example #1
0
        public void viewQuoteButton_Click(object sender, EventArgs e)
        {
            DeskQuote quote = new DeskQuote();
            Desk      desk  = new Desk();

            // If Desk object is empty catch the exception
            try
            {
                desk.Width            = Convert.ToInt32(widthBox.Text);
                desk.Depth            = Convert.ToInt32(depthBox.Text);
                desk.NumberOfDrawers  = Convert.ToInt32(drawerBox.Text);
                desk.SurfaceMaterial  = (DesktopMaterial)materialBox.SelectedIndex - 1;
                desk.CustomerName     = customerNameBox.Text;
                desk.ShippingCost     = quote.CalcShipping(Convert.ToInt32(shippingBox.SelectedIndex), desk.Width, desk.Depth);
                desk.Date             = quote.ShowDate();
                desk.OversizeCost     = quote.CalcOversizeCost(desk.Width, desk.Depth);
                desk.DrawerCost       = quote.CalcDrawerCost(desk.NumberOfDrawers);
                desk.MaterialCost     = quote.CalcMaterialCost(Convert.ToInt32(materialBox.SelectedIndex));
                desk.Area             = desk.Width * desk.Depth;
                desk.MaterialNotEmpty = materialBox.SelectedIndex;
                desk.ShippingNotEmpty = shippingBox.SelectedIndex;

                if (desk.MaterialNotEmpty == -1 || desk.ShippingNotEmpty == -1)
                {
                    errorLabel.Text = "Please make sure that all fields are filled or selected!";
                }
                else
                {
                    DisplayQuote openDisplayQuote = new DisplayQuote(desk);
                    openDisplayQuote.Tag = this;
                    openDisplayQuote.Show(this);
                    Hide();
                }
            }
            catch
            {
                errorLabel.Text = "Please make sure that all fields are filled or selected!";
            }
        }
Example #2
0
        public void viewQuoteButton_Click(object sender, EventArgs e)
        {
            DeskQuote quote = new DeskQuote();
            Desk      desk  = new Desk();

            // If Desk object is empty catch the exception
            try
            {
                desk.Width            = Convert.ToInt32(widthBox.Text);
                desk.Depth            = Convert.ToInt32(depthBox.Text);
                desk.NumberOfDrawers  = Convert.ToInt32(drawerBox.Text);
                desk.SurfaceMaterial  = (DesktopMaterial)materialBox.SelectedIndex;
                desk.CustomerName     = customerNameBox.Text;
                desk.Date             = quote.ShowDate();
                desk.MaterialNotEmpty = materialBox.SelectedIndex;
                desk.ShippingNotEmpty = shippingBox.SelectedIndex;
                if (shippingBox.SelectedIndex == 0)
                {
                    desk.ShippingIndex = 99;
                }
                else
                {
                    desk.ShippingIndex = shippingBox.SelectedIndex - 1;
                }


                if (desk.MaterialNotEmpty == -1 || desk.ShippingNotEmpty == -1)
                {
                    errorLabel.Text = "Please make sure that all fields are filled or selected!";
                }
                else
                {
                    try
                    {
                        var         baseJson   = File.ReadAllText("../../data/quotes.json");
                        List <Desk> quoteToAdd = new List <Desk>()
                        {
                            desk
                        };

                        string updatedJson = AddObjectToJson(baseJson, quoteToAdd);

                        File.WriteAllText("../../data/quotes.json", updatedJson);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    finally
                    {
                        DisplayQuote openDisplayQuote = new DisplayQuote(desk);
                        openDisplayQuote.Tag = this;
                        openDisplayQuote.Show(this);
                        Hide();
                    }
                }
            }
            catch
            {
                errorLabel.Text = "Please make sure that all fields are filled or selected!";
            }
        }