Beispiel #1
0
        private void openDisplayQuoteButton_Click(object sender, EventArgs e)
        {
            DisplayQuote displayQuoteForm = new DisplayQuote();

            displayQuoteForm.Tag = this;
            displayQuoteForm.Show(this);
            Hide();
        }
Beispiel #2
0
        public void navShowQuote_ref(string json)
        {
            DisplayQuote viewquote = new DisplayQuote(json);

            viewquote.Tag = this;
            viewquote.Show(this);
            Hide();
        }
Beispiel #3
0
        private void displayQuoteButton_Click(object sender, EventArgs e)
        {
            if (displayQuote == null)
            {
                displayQuote = new DisplayQuote(quoteToShow);
            }

            Hide();
            displayQuote.Show();
        }
Beispiel #4
0
        private void btnDisplay_Click(object sender, EventArgs e)
        {
            CalculateQuote();

            DisplayQuote displayQuote = new DisplayQuote(Customer, AreaCost, DrawerCost, MaterialCost,
                                                         RushDaysCost, Total, Estimated, MaterialType, DeskWidth, DeskDepth, DeskDrawer);

            displayQuote.Tag = this;
            displayQuote.Show(this);
            Hide();
        }
Beispiel #5
0
 private void buttonAdd_Click(object sender, EventArgs e)
 {
     if (Valid())
     {
         DeskQuote    deskQuote    = createDesk();
         DisplayQuote displayQuote = new DisplayQuote(deskQuote);
         displayQuote.Tag = this;
         displayQuote.Show(this);
         clearForm();
         Hide();
     }
 }
        private void addButton_Click(object sender, EventArgs e)
        {
            DisplayQuote views = new DisplayQuote();

            views.customerText.Text = "Customer Name: " + customerBox.Text;
            views.widthText.Text    = "Width: " + widthBox.Text;
            views.depthText.Text    = "Depth: " + depthBox.Text;
            views.drawersText.Text  = "Drawers: " + drawersBox.Text;
            views.materialText.Text = "Material: " + materialBox.Text;
            views.orderText.Text    = "Order: " + orderBox.Text;
            views.Show();
            this.Hide();
        }
Beispiel #7
0
 private void submitButton_Click(object sender, EventArgs e)
 {
     try
     {
         width           = Convert.ToDouble(widthInput.Text);
         depth           = Convert.ToDouble(depthInput.Text);
         numDrawers      = Convert.ToInt32(drawersInput.Value);
         rushDays        = Convert.ToInt32(rushDaysInput.Value);
         surfaceMaterial = surfaceMaterialInput.Text;
         firstName       = firstNameInput.Text;
         lastName        = lastNameInput.Text;
         desk.SetDepth(depth);
         desk.SetNumDrawers(numDrawers);
         desk.SetWidth(width);
         desk.SetSurfaceMaterial(surfaceMaterial);
         deskQuote.SetDesk(desk);
         deskQuote.SetRushOrderDays(rushDays);
         deskQuote.SetCustomerFirstName(firstName);
         deskQuote.SetCustomerLastName(lastName);
         if (deskQuote.CheckValidInputs() == true)
         {
             double totalPrice = deskQuote.GetTotalPrice();
             data = deskQuote.QuoteToString();
             DatabaseHandler.StoreJsonQuote(deskQuote);
             DisplayQuote displayQuote = new DisplayQuote(
                 width,
                 depth,
                 numDrawers,
                 rushDays,
                 surfaceMaterial,
                 firstName,
                 lastName
                 );
             displayQuote.Show();
             this.Hide();
         }
         else
         {
             errorLabel.Text = "Error with your dimensions. Please see key. Thank you.";
         }
     }
     catch (IOException er)
     {
         errorLabel.Text = "Error with submission" + er.Message;
     }
     catch (FormatException fr)
     {
         errorLabel.Text = "Error with submission" + fr.Message;
     }
 }
Beispiel #8
0
        private void Btn_submit_Click(object sender, EventArgs e)
        {
            var temp_desk = new Desk()
            {
                width          = Convert.ToInt32(deskWidth.Value),
                depth          = Convert.ToInt32(deskDepth.Value),
                numberOfDrawer = (int)numDrawers.Value,
                desktop        = (Material)MaterialsCombo.SelectedValue
            };

            var deskQuote = new DeskQuote
            {
                desk         = temp_desk,
                customerName = txtcustomerName.Text,
                quoteDate    = DateTime.Now,
                shipping     = (Shipping)comShipping.SelectedValue,
                quotePrice   = 0
            };

            deskQuote.setPrice();
            var quotesFile = @"quotes.json";
            List <DeskQuote> deskquotes = new List <DeskQuote>();

            //read existing quotes if any
            if (File.Exists(quotesFile))
            {
                using (StreamReader reader = new StreamReader(quotesFile))
                {
                    //load existing quotes
                    string quotes = reader.ReadToEnd();

                    if (quotes.Length > 0)
                    {
                        // deserialization time!
                        deskquotes = JsonConvert.DeserializeObject <List <DeskQuote> >(File.ReadAllText(quotesFile)) ?? new List <DeskQuote>();
                    }
                }
            }
            deskquotes.Add(deskQuote);
            string jsonDesks = JsonConvert.SerializeObject(deskquotes);

            File.WriteAllText(quotesFile, jsonDesks);

            //var newQuoteString = deskquotes[2];
            //MessageBox.Show(newQuoteString);

            DisplayQuote displayQuote = new DisplayQuote(deskQuote);

            displayQuote.Show();
        }
Beispiel #9
0
        private void displayQuoteForm_Click(object sender, EventArgs e)
        {
            try
            {
                quote.FirstName   = firstNameField.Text;
                quote.LastName    = lastNameField.Text;
                desk.Width        = (int)selectWidthField.Value;
                desk.Depth        = (int)selectDepthField.Value;
                desk.DrawerNum    = (int)selectDrawersField.Value;
                desk.MaterialType = deskMaterialField.SelectedItem.ToString();
                rush = RushOrderField.SelectedItem.ToString();
            }
            catch (Exception exc)
            {
                MessageBox.Show("Your input wasn't just right.");
            }
            deskArea        = quote.buildDesk(desk.Width, desk.Depth);
            quote.TotalCost = quote.calcCost(deskArea, desk.DrawerNum, desk.MaterialType);

            if (rush != "no rush")
            {
                if (rush == "3 Days")
                {
                    quote.RushCost = quote.calcRush(deskArea, 3);
                }
                else if (rush == "5 Days")
                {
                    quote.RushCost = quote.calcRush(deskArea, 5);
                }
                else // 7 days
                {
                    quote.RushCost = quote.calcRush(deskArea, 7);
                }
                quote.TotalCost += quote.RushCost;
            }

            quote.saveQuote();

            if (displayQuoteView == null)
            {
                displayQuoteView = new DisplayQuote();
            }
            Hide();
            displayQuoteView.Show();
        }
Beispiel #10
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!ValidForm())
            {
                return;
            }
            Desk newDesk = new Desk();

            newDesk.CustomerName    = txtCustomerName.Text;
            newDesk.Depth           = (int)nupDeskDepth.Value;
            newDesk.Width           = (int)nupDeskWidth.Value;
            newDesk.NumberOfDrawers = Int32.Parse(cboNumberOfDrawers.Text);

            if (rboProductionTime3.Checked)
            {
                newDesk.ProductionTime = 3;
            }
            else if (rboProductionTime5.Checked)
            {
                newDesk.ProductionTime = 5;
            }
            else if (rboProductionTime7.Checked)
            {
                newDesk.ProductionTime = 7;
            }
            else
            {
                newDesk.ProductionTime = 14;
            }

            newDesk.SurfaceMaterial = (Materials)cboSurfaceMaterial.SelectedValue;
            try
            {
                Program.Quotes.Add(newDesk.Quote);
                DisplayQuote displayQuoteForm = new DisplayQuote(newDesk.Quote);
                var          mainMenu         = (MainMenu)Tag;
                displayQuoteForm.Tag = mainMenu;
                Tag = displayQuoteForm;
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message);
            }
        }
Beispiel #11
0
        private void btnSaveQuote_Click(object sender, EventArgs e)
        {
            var desk = new Desk
            {
                Depth           = numDeskDepth.Value,
                Width           = numDeskWidth.Value,
                NumberOfDrawers = (int)numNumberOfDrawers.Value,
                Material        = (Desk.DesktopMaterial)comSurfaceMaterial.SelectedValue
            };

            var deskQuote = new DeskQuote
            {
                Desk         = desk,
                CustomerName = txtCustomerName.Text,
                QuoteDate    = DateTime.Now,
                DeliveryType = (DeskQuote.Delivery)comDelivery.SelectedValue
            };

            try
            {
                // get quote amount
                var price = deskQuote.GetQuotePrice();

                // add amount to quote
                deskQuote.QuotePrice = price;

                // add quote to file
                AddQuoteToFile(deskQuote);

                // show 'DisplayQuote' form
                DisplayQuote frmDisplayQuote = new DisplayQuote(_mainMenu, deskQuote);
                frmDisplayQuote.Show();
                Hide();
            }
            catch (Exception err)
            {
                MessageBox.Show("There was an error creating the quote. {0}", err.InnerException.ToString());
            }
        }
Beispiel #12
0
        private void SaveQuoteButton_Click(object sender, EventArgs e)
        {
            List <DeskQuote> quotes = _quoteFileManager.GetSavedQuotes();

            if (string.IsNullOrWhiteSpace(fullNameInput.Text))
            {
                nameRequiredErrorMessage.Text = Resources.Required;
                return;
            }

            Desk desk = new Desk()
            {
                depth           = (int)depthUpDown.Value,
                width           = (int)widthUpDown.Value,
                numberOfDrawers = (int)numberOfDrawersUpDown.Value,
                SurfaceMaterial = (DesktopMaterial)materialSelect.SelectedItem
            };

            DeskQuote quote = new DeskQuote()
            {
                CustomerName  = fullNameInput.Text,
                Desk          = desk,
                RushOrderType = (RushOrderType)rushOrderSelect.SelectedValue,
                Date          = DateTime.Now
            };

            quote.QuotePrice = quote.GetQuote();

            quotes.Add(quote);

            _quoteFileManager.SaveQuotes(quotes);

            DisplayQuote displayQuote = new DisplayQuote(quote);

            displayQuote.ShowDialog();
        }
Beispiel #13
0
        // Save button event click event to initiate validation and update the quote objects
        private void Save_Click(object sender, EventArgs e)
        {
            // Toggle this to enable error event triggers
            performValidation = true;

            // If validate children returns true, fields are valid,
            // proceed with operations, otherwise do nothing
            if (this.ValidateChildren(ValidationConstraints.Enabled))
            {
                try
                {
                    updateDeskConfiguration();

                    quoteRepository.Add(deskQuote);

                    MessageBox.Show("Quote Saved", "Success", MessageBoxButtons.OK);
                    Console.WriteLine("ORDER SUBMITTED:" + this.deskQuote.ToString());
                    DisplayQuote displayQuote = new DisplayQuote(deskQuote);
                    displayQuote.Show();

                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to update the desk configuration, will not save. See the application logs for details.", "Error", MessageBoxButtons.OK);
                    Console.WriteLine(ex);
                }
            }
            else
            {
                MessageBox.Show("You're INVALID!", "Error", MessageBoxButtons.OK);
            }

            // Disable validating events again to allow free-form editing
            performValidation = false;
        }
Beispiel #14
0
        private void SubmitButton_Click(object sender, EventArgs e)
        {
            DisplayQuote displayQuoteForm = new DisplayQuote(NameBox.Text, WidthBox.Text, DepthBox.Text, MaterialComboBox.Text, OrderTimeComboBox.SelectedItem, Date.Text, DrawerComboBox.Text);

            displayQuoteForm.Show();
        }
Beispiel #15
0
        private void CreateQuoteButton_Click(object sender, EventArgs e)
        {
            customerNameValue    = CustomerName.Text;
            rushDaysValue        = Convert.ToInt32(RushDays.Text);
            widthValue           = (int)Width.Value;
            depthValue           = (int)Depth.Value;
            numDrawersValue      = (int)NumDrawers.Value;
            surfaceMaterialValue = SurfaceMaterial.Text;

            currentDate = DateTime.Now;
            // saved currentdate in string so the format is nice for the JSON file
            string orderDate = currentDate.ToString("dd MMMM yyyy");
            //rushCostValue = ;

            Desk      customerDesk  = new Desk(widthValue, depthValue, numDrawersValue, surfaceMaterialValue);
            DeskQuote customerQuote = new DeskQuote(customerNameValue, customerDesk, rushDaysValue, orderDate);

            Program.Quotes.Add(customerQuote);

            //private static Desk customerDesk = new Desk(widthValue, depthValue, numDrawersValue, surfaceMaterialValue);
            //private static DeskQuote customerQuote = new DeskQuote(customerNameValue, customerDesk, rushDaysValue);

            //  Saving JSON to text file
            #region Save Quotes to JSON file / serialize/deserialize
            var json = "";
            try
            {
                json = JsonConvert.SerializeObject(Program.Quotes);

                string           fileName   = @"quotes.json";
                List <DeskQuote> deskOrders = new List <DeskQuote>();

                if (File.Exists(fileName))
                {
                    using (StreamReader reader = new StreamReader(fileName))
                    {
                        string quotes = reader.ReadToEnd();
                        if (quotes.Length > 0)
                        {
                            deskOrders = JsonConvert.DeserializeObject <List <DeskQuote> >(quotes);
                        }
                        deskOrders.Add(customerQuote);
                    }

                    // convert to Json
                    var serializedOrders = JsonConvert.SerializeObject(deskOrders);
                    // save to json
                    File.WriteAllText(fileName, serializedOrders);
                }
                else
                {
                    deskOrders = new List <DeskQuote> {
                        customerQuote
                    };
                    var serializedOrders = JsonConvert.SerializeObject(deskOrders);
                    // save to json
                    File.WriteAllText(fileName, serializedOrders);
                }
                #endregion

                //File.WriteAllText(@"quotes.json", JsonConvert.SerializeObject(Program.Quotes));
                // using (StreamWriter x = File.WriteAllText(fileName))
                //{
                //   x.WriteLine(json);
                // }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "Error writing to file.");
            }



            DisplayQuote viewDisplayQuote = new DisplayQuote();

            viewDisplayQuote.Tag = this.Tag;
            viewDisplayQuote.Show();
            Hide();
        }
        private void btnAddQuote_Click(object sender, EventArgs e)
        {
            bool allValid = true;

            string[] controls = { txtName.Text,                   txtWidth.Text,       txtDepth.Text,
                                  cbNoOfDrawers.Value.ToString(), cbOrderOptions.Text, cbSurfaceMaterial.Text, dtDateCreated.Text };

            foreach (string c in controls)
            {
                if (string.IsNullOrEmpty(c))
                {
                    allValid = false;
                }
            }

            Console.WriteLine(allValid);

            if (!allValid)
            {
                MessageBox.Show("Please fill-in all required values.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                epInvalid.SetError(txtName, "Required!");
                epInvalid.SetError(txtWidth, "Required!");
                epInvalid.SetError(txtDepth, "Required!");
            }
            else
            {
                // Get values for desk class
                decimal width;
                bool    widthIsDecimal = decimal.TryParse(txtWidth.Text, out width);

                decimal depth;
                bool    depthIsDecimal = decimal.TryParse(txtDepth.Text, out depth);

                int  numberOfDrawer;
                bool noOfDrawerIsInt = int.TryParse(cbNoOfDrawers.Text, out numberOfDrawer);

                int    rushOptionDays;
                bool   rushOptionsDaysIsInt = int.TryParse(cbOrderOptions.Text, out rushOptionDays);
                string surfaceMaterial      = cbSurfaceMaterial.Text;

                // Crete desk
                Desk d = new Desk(width, depth, numberOfDrawer, surfaceMaterial, rushOptionDays);

                // Shipping details
                string _shippingMethod = null;
                if (rushOptionDays != 14)
                {
                    _shippingMethod = $"Rush - {rushOptionDays} Days";
                }
                else
                {
                    _shippingMethod = $"Normal - {rushOptionDays} Days";
                }
                // Create DeskQuote
                DeskQuote dq = new DeskQuote(d, Convert.ToDateTime(dtDateCreated.Value), txtName.Text);
                dq.saveDeskQuote(dq);
                dq.displayDeskQuotes();

                // Create and pass data to DisplayQuote form
                DisplayQuote displayQuote = new DisplayQuote();
                dateCreated    = dtDateCreated.Text;
                customerName   = txtName.Text;
                totalSize      = $"{Math.Round(dq.computeSurfaceArea(width, depth), 2)}";
                sizeCost       = Math.Round(dq.computeDeskSizeCost(), 2).ToString("F");
                drawerCost     = Math.Round(dq.computeDrawerCost(), 2).ToString("F");
                material       = surfaceMaterial;
                materialCost   = Math.Round(dq.computeSurfaceMaterialCost(), 2).ToString("F");
                shippingMethod = _shippingMethod;
                shippingCost   = Math.Round(dq.computeShippingCost(), 2).ToString("F");
                totalCost      = Math.Round(dq.computeDeskPrice(), 2).ToString("F");

                if (ValidateChildren(ValidationConstraints.Enabled))
                {
                    displayQuote.ShowDialog();
                }
            }
        }
        private void buttonSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                CustomerName = boxName.Text;
                DeskWidth    = int.Parse(boxWidth.Text);
                DeskDepth    = int.Parse(boxDepth.Text);
                Drawers      = int.Parse(comboBoxDrawers.SelectedItem.ToString());
                Material     = (Desk.Material)comboBoxMaterial.SelectedValue;

                // Get rush order days base on radio box selections
                if (radioRushNone.Checked)
                {
                    RushDays = 0;
                }
                if (radioRush3.Checked)
                {
                    RushDays = 3;
                }
                if (radioRush5.Checked)
                {
                    RushDays = 5;
                }
                if (radioRush7.Checked)
                {
                    RushDays = 7;
                }

                // create new deskOrder and calcQuote
                DeskQuote NewQuote = new DeskQuote(CustomerName, DateTime.Now, DeskWidth, DeskDepth, Drawers, Material, RushDays);
                QuoteTotal = NewQuote.CalcQuote();

                //build string to quote save to file
                //var DeskFileWrite = CustomerName + "," + DateTime.Now + "," + DeskWidth + "," + DeskDepth + "," + Drawers + "," + Material + "," + RushDays + "," + QuoteTotal;
                //var DeskFileWrite = NewQuote;

                // ask how to do this without making all of the properties public because I know they are in and can be used
                // I just have no idea how to get the Serializer to get them when they are "private".
                string jsonWrite = JsonConvert.SerializeObject(NewQuote);
                string jsonFile  = @"quotes.json";

                if (!File.Exists(jsonFile))
                {
                    using (StreamWriter sw = File.CreateText(jsonFile)) { }
                }
                using (StreamWriter swa = File.AppendText(jsonFile)) { swa.WriteLine(jsonWrite); }

                //MessageBox.Show("Quote Submitted");
                DisplayQuote display  = new DisplayQuote();
                MainMenu     mainMenu = new MainMenu();
                display.Tag                = mainMenu;
                display.nameLabel.Text     = boxName.Text;
                display.dateLabel.Text     = DateTime.Now.ToShortDateString();
                display.widthLabel.Text    = boxWidth.Text + " inches";
                display.depthLabel.Text    = boxDepth.Text + " inches";
                display.drawerLabel.Text   = comboBoxDrawers.SelectedItem.ToString();
                display.materialLabel.Text = comboBoxMaterial.SelectedItem.ToString();
                display.Show(this);
                Hide();

                confirmQuotePanel.Visible = false;
            }
            catch (Exception)
            {
                throw;
            }
        }
        private void SubmitOrder_Click(object sender, EventArgs e)
        {
            // all entered validation
            try
            {
                if (nameInput != null)
                {
                    newQuote.CustName = nameInput.Text;
                }


                NumericUpDown widthBox = sender as NumericUpDown;
                if (widthInput != null)
                {
                    desk.Width = Convert.ToDouble(widthInput.Value);
                }

                NumericUpDown depthBox = sender as NumericUpDown;
                if (depthInput != null)
                {
                    desk.Depth = desk.Depth = Convert.ToDouble(depthInput.Value);
                }


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


                if (materialInput != null)
                {
                    desk.material = materialInput.SelectedItem.ToString();

                    switch (desk.material)
                    {
                    case "Oak":
                        //material = DesktopMaterial.Oak;
                        materialOrder = 200;
                        break;

                    case "Rosewood":
                        //material = DesktopMaterial.Rosewood;
                        materialOrder = 300;
                        break;

                    case "Laminate":
                        //material = DesktopMaterial.Laminate;
                        materialOrder = 100;
                        break;

                    case "Veneer":
                        //material = DesktopMaterial.Veneer;
                        materialOrder = 125;
                        break;

                    case "Pine":
                        //material = DesktopMaterial.Pine;
                        materialOrder = 50;
                        break;
                    }
                }


                if (rushInput != null)
                {
                    newQuote.RushOrder = uint.Parse(rushInput.SelectedItem.ToString());
                }
            }
            catch
            {
                if (nameInput == null || widthInput == null || depthInput == null || materialInput == null || rushInput == null)
                {
                    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(materialOrder, shipping, surfaceArea, desk.DrawersNum);

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

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

            DisplayQuote displayQuote = new DisplayQuote();

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