コード例 #1
0
        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);

                // Create and pass data to DisplayQuote form

                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");

                List <string> quote = new List <string>();
                quote.Add(customerName);
                quote.Add(dateCreated);
                quote.Add(totalSize);
                quote.Add(sizeCost);
                quote.Add(drawerCost);
                quote.Add(material);
                quote.Add(materialCost);
                quote.Add(shippingMethod);
                quote.Add(shippingCost);
                quote.Add(totalCost);

                DisplayQuote displayQuote = new DisplayQuote(quote);

                if (ValidateChildren(ValidationConstraints.Enabled))
                {
                    displayQuote.ShowDialog();
                }
            }
        }
コード例 #2
0
ファイル: Quotes.cs プロジェクト: Jihusen/MegaDesk-Group
 public void addQuote(Desk desk)
 {
     quotes.Push(desk);
 }
コード例 #3
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            var desk      = new Desk();
            var deskQuote = new DeskQuote();

            try
            {
                desk.Width      = width.Value;
                desk.Depth      = width.Value;
                desk.NumDrawers = int.Parse(numDrawers.SelectedItem.ToString());

                desk.Material = (Desk.DesktopMaterial)comDesktopMaterials.SelectedValue;

                deskQuote.Desk            = desk;
                deskQuote.CustomerName    = txtCustomerName.Text;
                deskQuote.NumShippingDays = int.Parse(comShipping.SelectedItem.ToString());
                deskQuote.QuoteDate       = DateTime.Now;
                deskQuote.ShippingCost    = deskQuote.GetShippingCost();
                deskQuote.StructureCost   = deskQuote.GetStructureCost();
                deskQuote.SurfaceCost     = deskQuote.GetSurfaceCost();
                deskQuote.Quote           = deskQuote.GetQuote();

                System.Diagnostics.Debug.WriteLine(desk.NumDrawers);
                System.Diagnostics.Debug.WriteLine(deskQuote.StructureCost);
                System.Diagnostics.Debug.WriteLine(deskQuote.ShippingCost);
                System.Diagnostics.Debug.WriteLine(deskQuote.SurfaceCost);
            }
            catch (Exception ex)
            {
            }
            lblStructureCost.Text = deskQuote.GetStructureCost().ToString();
            lblSurfaceCost.Text   = deskQuote.GetSurfaceCost().ToString();
            lblShippingCost.Text  = deskQuote.GetShippingCost().ToString();
            lblTotalCost.Text     = deskQuote.GetQuote().ToString();



            List <DeskQuote> deskQuotes = new List <DeskQuote>();

            if (!File.Exists(@"quotes.json"))
            {
                deskQuotes.Add(deskQuote);
                var list = JsonConvert.SerializeObject(deskQuotes);
                File.WriteAllText(@"quotes.json", JsonConvert.SerializeObject(deskQuotes));
            }
            else
            {
                using (StreamReader reader = new StreamReader(@"quotes.json"))
                {
                    string allQuotes = reader.ReadToEnd();
                    deskQuotes = JsonConvert.DeserializeObject <List <DeskQuote> >(allQuotes);
                }
                deskQuotes.Add(deskQuote);
                var list = JsonConvert.SerializeObject(deskQuotes);
                File.WriteAllText(@"quotes.json", list);
            }

            var mainMenu = (MainMenu)Tag;

            mainMenu.Show();
            Close();
        }
コード例 #4
0
        private void GetQuoteButton_Click(object sender, EventArgs e)
        {
            try
            {
                Desk desk = new Desk
                {
                    Width           = (int)widthNumericUpDown.Value,
                    Depth           = (int)depthNumericUpDown.Value,
                    NumberOfDrawers = (int)numberOfDrawersNumericUpDown.Value,
                    SurfaceMaterial = (Desk.DesktopSurfaceMaterial)surfaceMaterialSelectionComboBox.SelectedItem
                };

                DeskQuote deskQuote = new DeskQuote
                {
                    Desk          = desk,
                    CustomerName  = customerNameTextBox.Text,
                    ShippingSpeed = GetRushShippingChoice(),
                    QuoteDate     = DateTime.Now
                };

                if (string.IsNullOrEmpty(deskQuote.CustomerName))
                {
                    throw new InvalidOperationException(@"Please enter your name.");
                }

                totalPriceAmountLabel.Text = $@"${deskQuote.CalculateQuote()}";
                shippingPriceLabel.Text    = $@"${deskQuote.GetShippingPrice()}";

                string quotesFile = @"quotes.txt";
                if (!File.Exists(quotesFile))
                {
                    using (StreamWriter writer = File.CreateText(quotesFile))
                    {
                        writer.WriteLine(
                            $"{deskQuote.QuoteDate}," +
                            $"{deskQuote.CustomerName}," +
                            $"{deskQuote.Desk.Width}," +
                            $"{deskQuote.Desk.Depth}," +
                            $"{deskQuote.Desk.NumberOfDrawers}," +
                            $"{deskQuote.Desk.SurfaceMaterial}," +
                            $"{deskQuote.ShippingSpeed}," +
                            $"{deskQuote.GetShippingPrice()}," +
                            $"{deskQuote.CalculateQuote()}");
                        writer.Close();
                    }
                }
                else
                {
                    using (StreamWriter writer = File.AppendText(quotesFile))
                    {
                        writer.WriteLine(
                            $"{deskQuote.QuoteDate}," +
                            $"{deskQuote.CustomerName}," +
                            $"{deskQuote.Desk.Width}," +
                            $"{deskQuote.Desk.Depth}," +
                            $"{deskQuote.Desk.NumberOfDrawers}," +
                            $"{deskQuote.Desk.SurfaceMaterial}," +
                            $"{deskQuote.ShippingSpeed}," +
                            $"{deskQuote.GetShippingPrice()}," +
                            $"{deskQuote.CalculateQuote()}");
                        writer.Close();
                    }
                }

                DisplayQuote();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
コード例 #5
0
ファイル: DeskQuote.cs プロジェクト: kdoda/04-MegaDesk
 public override string ToString()
 {
     return($"{CustomerName},{Price},{DateOrdered.ToString()},{DaysOrdered},{Desk.ToString()}\n");
 }
コード例 #6
0
ファイル: DeskQuote.cs プロジェクト: kdoda/04-MegaDesk
 public static string CSVHeader()
 {
     return($"CustomerName,Price,DateOrdered,DaysOrdered,{Desk.CSVHeader()}");
 }
コード例 #7
0
 public DeskQuote(Desk quotedDesk)
 {
     this.QuotedDesk = quotedDesk;
     this.QuoteDate  = DateTime.Now;
 }
コード例 #8
0
 public DeskQuote(string CustomerName, string ShippingType, decimal QuotePrice, DateTime QuoteDate, Desk Desk)
 {
     this.CustomerName = CustomerName;
     this.ShippingType = ShippingType;
     this.QuotePrice   = QuotePrice;
     this.QuoteDate    = QuoteDate;
     this.Desk         = Desk;
 }