Пример #1
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();
        }
        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();
                }
            }
        }