Ejemplo n.º 1
0
        private void SendQuote_Click(object sender, EventArgs e)
        {
            // create new desk
            Desk desk = new Desk();

            desk.Depth           = numDepth.Value;
            desk.Width           = numWidth.Value;
            desk.NumberOfDrawers = (int)numDrawers.Value;
            desk.SurfaceMaterial = (DesktopMaterial)comSurfaceMaterial.SelectedItem;

            // create Desk quote
            DeskQuote quote = new DeskQuote();
            DateTime  date  = DateTime.Now;

            quote.ShippingType = (Shipping)comShippingType.SelectedItem;

            quote.CustomerName = customerName.Text;
            quote.QuoteDate    = date;
            quote.Desk         = desk;
            quote.QuotePrice   = quote.getQuotePrice();

            addToFile(quote);

            // DEBUGGING:
            // System.Windows.Forms.MessageBox.Show("Added quote. The price is: " + quote.QuotePrice);

            DisplayQuote display = new DisplayQuote(quote);

            display.Show();
            Hide();
        }
Ejemplo n.º 2
0
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            DeskQuoteView currentViewItem  = (DeskQuoteView)this.dataGridView1.CurrentRow.DataBoundItem;
            DisplayQuote  displayQuoteForm = new DisplayQuote(currentViewItem.Quote);

            displayQuoteForm.Show();
        }
Ejemplo n.º 3
0
        private void viewQuotes_Click(object sender, EventArgs e)
        {
            Form viewQuote = new DisplayQuote();

            viewQuote.Show();
            this.Hide();
        }
Ejemplo n.º 4
0
        public void calculateTotal(string name, int width, int depth, int drawers, string material, int rush)
        {
            //Test with Desk Class
            int deskArea     = d.GetSurfaceArea(width, depth);
            int materialCost = d.GetMaterialCost(material);
            int drawerCost   = d.GetDrawerCost(drawers);

            totalCost = dq.CalculateQuote(deskArea, materialCost, drawerCost, rush);

            // Stream Info to AllQuotes.txt
            StreamWriter AllQuotesDoc = File.AppendText("AllQuotes.json");

            AllQuotesDoc.WriteLine("Name: " + name);
            AllQuotesDoc.WriteLine(material);
            AllQuotesDoc.WriteLine(DateTime.Now);
            AllQuotesDoc.WriteLine("Width: " + width);
            AllQuotesDoc.WriteLine("Depth: " + depth);
            AllQuotesDoc.WriteLine("Drawers: " + drawers);
            AllQuotesDoc.WriteLine("Rush Time: " + rush);
            AllQuotesDoc.WriteLine("Total Cost: " + totalCost);
            AllQuotesDoc.Close();

            DisplayQuote CurrentQuote = new DisplayQuote(width, depth, drawers, material, rush, totalCost);

            CurrentQuote.Tag = this;
            CurrentQuote.Show(this);
        }
Ejemplo n.º 5
0
        private void BttnGetQuote_Click(object sender, EventArgs e)
        {
            if (!validationErrors())
            {
                Desk newDesk = new Desk(int.Parse(numericUpDownWidth.Value.ToString()), int.Parse(numericUpDownDepth.Value.ToString()), int.Parse(numericUpDownNumOfDrawers.Value.ToString()), comboBoxSurfaceMaterial.SelectedItem.ToString());

                DeskQuote newQuote = new DeskQuote(inputCustomerName.Text, comboBoxDelivery.SelectedItem.ToString(), GetQuotePrice(), DateTime.Now, newDesk);

                string           fileName = "quotes.json";
                List <DeskQuote> quotesList;

                if (File.Exists(fileName))
                {
                    quotesList = JsonConvert.DeserializeObject <List <DeskQuote> >(File.ReadAllText(fileName));
                }
                else
                {
                    quotesList = new List <DeskQuote>();
                }

                quotesList.Add(newQuote);
                string convertedJson = JsonConvert.SerializeObject(quotesList, Formatting.Indented);

                File.WriteAllText(fileName, convertedJson);

                DisplayQuote quote = new DisplayQuote(newQuote, basePrice, getShippingCost(), getDrawerCost(), getSurfaceMaterialPrice(), getWeight());
                quote.Show();
            }
        }
Ejemplo n.º 6
0
        public void navShowQuote_ref(string json)
        {
            DisplayQuote viewquote = new DisplayQuote(json);

            viewquote.Tag = this;
            viewquote.Show(this);
            Hide();
        }
Ejemplo n.º 7
0
        private void openDisplayQuoteButton_Click(object sender, EventArgs e)
        {
            DisplayQuote displayQuoteForm = new DisplayQuote();

            displayQuoteForm.Tag = this;
            displayQuoteForm.Show(this);
            Hide();
        }
Ejemplo n.º 8
0
        private void displayQuoteButton_Click(object sender, EventArgs e)
        {
            if (displayQuote == null)
            {
                displayQuote = new DisplayQuote(quoteToShow);
            }

            Hide();
            displayQuote.Show();
        }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
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();
     }
 }
Ejemplo n.º 11
0
        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();
        }
Ejemplo n.º 12
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;
     }
 }
Ejemplo n.º 13
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();
        }
Ejemplo n.º 14
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();
        }
Ejemplo n.º 15
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());
            }
        }
Ejemplo n.º 16
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;
        }
Ejemplo n.º 17
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();
        }
Ejemplo n.º 18
0
        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;
            }
        }
Ejemplo n.º 19
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();
        }
Ejemplo n.º 20
0
        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();
        }