Ejemplo n.º 1
0
 public DisplayQuote(DeskQuote newQuote)
 {
     InitializeComponent();
     this.newQuote = newQuote;
 }
Ejemplo n.º 2
0
        // submit the quote.
        private void SubmitQuote_Click(object sender, EventArgs e)
        {
            try
            {
                CustomerName = userName.Text;
                DeskWidth    = int.Parse(userWidth.Text);
                DeskDepth    = int.Parse(userDepth.Text);
                Drawers      = int.Parse(userDrawers.Text);
                Finish       = (Materials)materialComboBox.SelectedValue;
                RushDays     = int.Parse(userSpeed.Text);
                Date         = DateTime.Now;


                // instantiate new deskQuote
                DeskQuote NewQuote = new DeskQuote(CustomerName, DeskWidth, DeskDepth, Drawers, Finish, RushDays, QuotePrice, Date);
                // Save the Quote Price
                QuotePrice = NewQuote.CalculateQuotePrice();

                // store the user input, the quote amount, and the date of the quote
                // create CSV string

                /*string csvString = CustomerName + "," + DeskWidth + "," + DeskDepth + "," + Drawers + "," +
                 *  Finish + "," + RushDays + "," + QuotePrice + "," + DateTime.Now;*/
                var convertedJson = "";
                if (!File.Exists(JSON))
                {
                    List <DeskQuote> list = new List <DeskQuote>
                    {
                        new DeskQuote(CustomerName, DeskWidth, DeskDepth, Drawers, Finish, RushDays, QuotePrice, Date)
                    };
                    convertedJson = JsonConvert.SerializeObject(list, Formatting.Indented);
                }
                else
                {
                    using (StreamReader sr = File.OpenText(JSON))
                    {
                        string json = sr.ReadToEnd();
                        var    list = JsonConvert.DeserializeObject <List <DeskQuote> >(json);

                        list.Add(new DeskQuote(CustomerName, DeskWidth, DeskDepth, Drawers, Finish, RushDays, QuotePrice, Date));
                        convertedJson = JsonConvert.SerializeObject(list, Formatting.Indented);
                    }
                }
                using (StreamWriter sw = File.CreateText(JSON))
                {
                    sw.Write(convertedJson);
                }

                /*string csvFile = @"quotes.txt";
                 * // check if file exists. If no, create file
                 * if (!File.Exists(csvFile))
                 * {
                 *  using (StreamWriter sw = File.CreateText(csvFile))
                 *  {
                 *      sw.WriteLine(csvString);
                 *  }
                 * }
                 * // if yes, append to file
                 * else
                 * {
                 *  using (StreamWriter sw = File.AppendText(csvFile))
                 *  {
                 *      sw.WriteLine(csvString);
                 *  }
                 * }*/
                // output the price quote to the screen along with the original user input
                //DisplayQuote displayQuote = new DisplayQuote(NewQuote)
                //{ Tag = this };
                //displayQuote.Show(this);
                //Hide();

                var          MainMenu     = (MainMenu)Tag;
                DisplayQuote displayQuote = new DisplayQuote(NewQuote)
                {
                    Tag = MainMenu
                };
                displayQuote.Show();
                this.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Please fill in all fields.");

                // validate fields
                if (CustomerName == "")
                {
                    userName.BackColor = Color.LightPink;
                }
                if (DeskWidth == 0)
                {
                    userWidth.BackColor = Color.LightPink;
                }
                if (DeskDepth == 0)
                {
                    userDepth.BackColor = Color.LightPink;
                }
                if (userSpeed.Text == "")
                {
                    userSpeed.BackColor = Color.LightPink;
                }
                this.Show();
            }


            {
            }
        }