Example #1
0
 public void WriteQuote(DeskQuote quote)
 {
     try
     {
         var json   = File.ReadAllText("quotes.json");
         var quotes = JsonConvert.DeserializeObject <List <DeskQuote> >(json);
         quotes.Add(quote);
         File.WriteAllText("quotes.json", JsonConvert.SerializeObject(quotes));
     }
     catch (Exception e)
     {
         Console.WriteLine("An error occurred: '{0}'", e);
     }
 }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                // check all the error providers to make sure
                bool success = true;
                foreach (Control c in this.Controls)
                {
                    if (errorProvider1.GetError(c).Length > 0)
                    {
                        success = false;
                    }
                    if (c is ComboBox && string.IsNullOrEmpty(c.Text))
                    {
                        success = false;
                    }
                }

                // okay, run the quote and display the quote view!
                if (success)
                {
                    name     = textBox1.Text;
                    width    = int.Parse(comboBox1.SelectedItem.ToString());
                    depth    = int.Parse(comboBox2.SelectedItem.ToString());
                    drawers  = int.Parse(comboBox3.SelectedItem.ToString());
                    material = comboBox4.SelectedItem.ToString();
                    rushDays = int.Parse(comboBox5.SelectedItem.ToString());
                    DeskQuote quote = new DeskQuote(name, width, depth, drawers, material, rushDays);
                    quote.rushOrder();

                    // write the quote to file
                    quote.WriteQuote(quote);

                    // head over to the view!
                    DisplayQuoteView view = new DisplayQuoteView(quote);
                    view.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Please fix all errors and submit again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception)
            {
                textBox1.Text = "Error";
            }
        }
 public DisplayQuoteView(DeskQuote quote)
 {
     TheQuote = quote;
     InitializeComponent();
 }
 public DisplayQuoteView(int quotePrice, DeskQuote quote)
 {
     QuotePrice = quotePrice;
     TheQuote   = quote;
     InitializeComponent();
 }