Ejemplo n.º 1
0
        public DisplayQuote(DeskQuote NewDeskQuote)
        {
            //getting all the data entered in to get a newQuote
            InitializeComponent();

            _deskQuote = NewDeskQuote;


            widthupanddown.Value          = NewDeskQuote.Desk.Width;
            depthupdown.Value             = NewDeskQuote.Desk.Depth;
            Surface_Matrial.SelectedValue = NewDeskQuote.Desk.SurfaceMaterial;
            Num_Drawers.SelectedValue     = NewDeskQuote.Desk.NumberOfDrawers;
            Delivery_Time.SelectedValue   = NewDeskQuote.DeliveryType;
            CustomerName.Text             = NewDeskQuote.CustomerName;
            TotalPrice.Text = NewDeskQuote.PriceAmount.ToString();
        }
        private void Get_NewQuote_Click(object sender, EventArgs e)
        {
            //This if statement is to check if the add quote form is complete.
            if (CustomerName.Text == "" || Delivery_Time.Text == "")
            {
                MessageBox.Show("Please fill all the values", "Form Imcomplete", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // gets the information of the desk
            Desk NameOfNewDesk = new Desk();

            NameOfNewDesk.Width           = widthupanddown.Value;
            NameOfNewDesk.Depth           = depthupdown.Value;
            NameOfNewDesk.NumberOfDrawers = (int)Num_Drawers.Value;
            NameOfNewDesk.SurfaceMaterial = (Desk.Surface)Surface_Matrial.SelectedValue;

            //gets the information entered by the user.
            DeskQuote NewDeskQuote = new DeskQuote();

            NewDeskQuote.CustomerName = CustomerName.Text;
            NewDeskQuote.DeliveryType = (DeskQuote.Delivery)Delivery_Time.SelectedValue;

            // get the quote amount and add amount to quote
            NewDeskQuote.Desk = NameOfNewDesk;
            DateTime today = DateTime.Today;

            NewDeskQuote.QuoteDate   = today;
            NewDeskQuote.PriceAmount = NewDeskQuote.GetQuote();



            try
            {
                // add quote to file
                AddQuoteToFile(NewDeskQuote);

                //show displayquote form
                DisplayQuote NewDeskForm = new DisplayQuote(NewDeskQuote);
                NewDeskForm.Show();
                Hide();
            }
            catch (Exception err)
            {
                MessageBox.Show("There was an error creating the quote. {0}", err.Message);
            }
        }
        //gets the new quote and adds it to the new file
        public void AddQuoteToFile(DeskQuote NewDeskQuote)
        {
            string quotesFile = @"quotes.txt";

            using (StreamWriter streamWriter = File.AppendText(quotesFile))
            {
                // this will display it when we open the displayquote and leave it as long as the program is open.
                streamWriter.WriteLine(
                    $"{NewDeskQuote.QuoteDate}," +
                    $"{NewDeskQuote.CustomerName}," +
                    $"{NewDeskQuote.Desk.Width}," +
                    $"{NewDeskQuote.Desk.Depth}," +
                    $"{NewDeskQuote.Desk.NumberOfDrawers}," +
                    $"{NewDeskQuote.Desk.SurfaceMaterial}," +
                    $"{NewDeskQuote.DeliveryType}," +
                    $"{NewDeskQuote.PriceAmount}");
            }
        }