Ejemplo n.º 1
0
        //When load form, then Load the values into the list
        private void LoadList(object sender, EventArgs e)
        {
            try
            {
                //Load if file exist
                if (File.Exists(FILE_NAME))
                {
                    using (StreamReader reader = new StreamReader(FILE_NAME))
                    {
                        while (!reader.EndOfStream)
                        {
                            string[] quoteField = reader.ReadLine().Split(',');
                            try
                            {
                                string   name     = quoteField[0];
                                string   material = quoteField[1];
                                string   rush     = quoteField[2];
                                int      width    = Int32.Parse(quoteField[3]);
                                int      depth    = Int32.Parse(quoteField[4]);
                                int      drawer   = Int32.Parse(quoteField[5]);
                                DateTime time     = DateTime.Parse(quoteField[6]);
                                int      price    = Int32.Parse(quoteField[7]);

                                DeskQuotes desk = new DeskQuotes(name, material, rush, width, depth, drawer, time, price);
                                QuotesList.Add(desk);
                            }
                            catch (Exception ex1)
                            {
                                MessageBox.Show("Error: Can't creating the quote record.\n" + ex1);
                            }
                        }
                    }
                }
            } catch (Exception ex)
            {
                MessageBox.Show("Error: Unable to read quote records.\n" + ex);
            }
        }
Ejemplo n.º 2
0
        //Add quote to external file
        public void AddQuoteToFile(DeskQuotes desk)
        {
            try
            {
                string deskCommaFormat;
                deskCommaFormat  = desk.Name + ",";
                deskCommaFormat += desk.Desk.Material.ToString() + ",";
                deskCommaFormat += desk.OrderSpeed.ToString() + ",";
                deskCommaFormat += desk.Desk.Width.ToString() + ",";
                deskCommaFormat += desk.Desk.Depth.ToString() + ",";
                deskCommaFormat += desk.Desk.Drawers.ToString() + ",";
                deskCommaFormat += desk.QuoteDate.ToString() + ",";
                deskCommaFormat += desk.PriceQuote.ToString();

                using (var writer = new StreamWriter(FILE_NAME, true))
                {
                    writer.WriteLine(deskCommaFormat);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to save to file\n" + ex);
            }
        }
Ejemplo n.º 3
0
        //Validates and creates DeskQuote object
        private void AddQuotesBtn_Click(object sender, EventArgs e)
        {
            bool noError = true;

            NameNote.Text     = "";
            MaterialNote.Text = "";
            IntNote.Text      = "";

            string nameInput = nameBox.Text;

            if (nameBox.Text == "")
            {
                NameNote.Text = "Please enter name";
                noError       = false;
            }

            string materialInput = materialSelect.Text;

            if (!CheckMaterial(materialInput))
            {
                MaterialNote.Text = "Select material";
                noError           = false;
            }

            string rushInput = rushOrderVal.Text;

            if (!checkRush(rushInput))
            {
                RushNote.Text = "Select order speed";
                noError       = false;
            }

            int widthInput   = 0;
            int depthInput   = 0;
            int drawersInput = 0;

            try
            {
                widthInput   = Convert.ToInt32(widthVal.Value);
                depthInput   = Convert.ToInt32(depthVal.Value);
                drawersInput = Convert.ToInt32(numberDrawersVal.Value);
            }
            catch
            {
                IntNote.Text = "Enter Valid Number";
                noError      = false;
            }

            if (noError)
            {
                DeskQuotes desk = new DeskQuotes(nameInput, materialInput, rushInput, widthInput, depthInput, drawersInput);
                QuotesList.Add(desk);

                AddQuoteToFile(desk);

                //Open the quote
                DisplayQuote DisplayQuoteForm = new DisplayQuote(QuotesList)
                {
                    Tag = (MainMenu)Tag
                };
                DisplayQuoteForm.Show((MainMenu)Tag);
                CancelPress = true;
                Close();
            }
        }
Ejemplo n.º 4
0
        private void DisplayInfo(object sender, EventArgs e)
        {
            if (QuotesList.Count > 0)
            {
                DeskQuotes quote = QuotesList[QuotesList.Count - 1];
                NameLbl.Text     = quote.Name;
                DateLbl.Text     = quote.QuoteDate.ToString("MM-dd-yyyy");
                MaterialLbl.Text = "Material: " + quote.Desk.Material.ToString();

                if (quote.Desk.Drawers != 1)
                {
                    DrawersLbl.Text = quote.Desk.Drawers.ToString() + " Drawers";
                }
                else
                {
                    DrawersLbl.Text = quote.Desk.Drawers.ToString() + " Drawer";
                }

                WidthLbl.Text = "Width: " + quote.Desk.Width.ToString() + " in";
                DepthLbl.Text = "Depth: " + quote.Desk.Depth.ToString() + " in";
                AreaLbl.Text  = "Total Area: " + quote.Desk.Area.ToString() + " in\x00B2";

                string rushText;
                switch (quote.OrderSpeed)
                {
                case DeskQuotes.RushOrder.None:
                    rushText = "No Rush Shipping";
                    break;

                case DeskQuotes.RushOrder.Day3:
                    rushText = "3 Day Rush Shipping";
                    break;

                case DeskQuotes.RushOrder.Day5:
                    rushText = "5 Day Rush Shipping";
                    break;

                case DeskQuotes.RushOrder.Day7:
                    rushText = "7 Day Rush Shipping";
                    break;

                default:
                    rushText = "None";
                    break;
                }
                RushLbl.Text = rushText;

                QuoteLbl.Text = "QUOTE: $" + quote.PriceQuote.ToString();
            }
            else
            {
                NameLbl.Text     = "";
                DateLbl.Text     = "";
                MaterialLbl.Text = "";
                DrawersLbl.Text  = "";
                WidthLbl.Text    = "";
                DepthLbl.Text    = "";
                AreaLbl.Text     = "";
                QuoteLbl.Text    = "No quote was found.";
            }
        }