예제 #1
0
        private void AddQuoteToFile(DeskQuote deskQuote)
        {
            string quotesFile = @"quotes.text";

            using (StreamWriter streamWriter = File.AppendText(quotesFile))
            {
                streamWriter.WriteLine(
                    $"{deskQuote.QuoteDate}," +
                    $"{deskQuote.CustomerName}," +
                    $"{deskQuote.Desk.Depth}," +
                    $"{deskQuote.Desk.Width}," +
                    $"{deskQuote.Desk.NumberOfDrawers}," +
                    $"{deskQuote.Desk.SurfaceMaterial}," +
                    $"{deskQuote.DeliveryType}," +
                    $"{deskQuote.QuoteAmount}");
            }
        }
예제 #2
0
        private void AddQuoteToFile(DeskQuote deskQuote)
        {
            string quotesFile = @"quotes.json";

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

            if (File.Exists(quotesFile))
            {
                using (StreamReader streamReader = new StreamReader(quotesFile))
                {
                    string quotes = streamReader.ReadToEnd();
                    currentQuotes = JsonConvert.DeserializeObject <List <DeskQuote> >(quotes);
                }
            }

            currentQuotes.Add(deskQuote);
            string newQuotes = JsonConvert.SerializeObject(currentQuotes);

            File.WriteAllText(quotesFile, newQuotes);
        }
예제 #3
0
        private void GetQuoteBtn_Click(object sender, EventArgs e)
        {
            var desk = new Desk()

            {
                Depth           = depthNumber.Value,
                Width           = widthNumber.Value,
                NumberOfDrawers = (int)numDrawerNumber.Value,
                SurfaceMaterial = (Desk.Surface)surfaceMaterialDropDown.SelectedItem
            };

            var deskQuote = new DeskQuote
            {
                Desk         = desk,
                CustomerName = txtCustomerName.Text,
                QuoteDate    = DateTime.Now,
                DeliveryType = (DeskQuote.Delivery)deliveryTimeDropDown.SelectedValue
            };

            try
            {
                //get quote amount
                var quote = deskQuote.GetQuote();

                //add amount to quote
                deskQuote.QuoteAmount = quote;

                //add quote to file
                AddQuoteToFile(deskQuote);

                //show 'DisplayQuote' form

                DisplayQuote frmDisplayQuote = new DisplayQuote(deskQuote);
                frmDisplayQuote.Show();
                Hide();
            }
            catch (Exception err)
            {
                MessageBox.Show("THERE was an error creating the quote. {0}", err.Message);
            }
        }