Esempio n. 1
0
        private void PlaceOrder_Click(object sender, EventArgs e)
        {
            DeskQuote deskQuote = null;

            try
            {
                Desk desk = new Desk()
                {
                    Width           = this.WidthNumericUpDown.Value,
                    Depth           = DepthNumericUpDown.Value,
                    NumDrawers      = (int)DrawersNumericUpDown.Value,
                    SurfaceMaterial = (SurfaceMaterial)Enum.Parse(typeof(SurfaceMaterial), MaterialListBox.Text)
                };
                try
                {
                    deskQuote = new DeskQuote()
                    {
                        NewDesk   = desk,
                        Name      = this.NameTextBox.Text,
                        QuoteDate = DateTime.Now,
                        Rush      = (Rush)Enum.Parse(typeof(Rush), RushComboBox.SelectedValue.ToString())
                    };
                }
                catch (System.NullReferenceException) { System.Windows.Forms.MessageBox.Show("Please Enter Values for All Parameters!", "ERROR"); }
            }
            catch (System.ArgumentException)
            {
                System.Windows.Forms.MessageBox.Show("Please Enter Values for All Parameters!", "ERROR");
            }

            DisplayQuote displayQuote = new DisplayQuote(deskQuote);
            HomeForm     homeform     = (HomeForm)Tag;

            displayQuote.Tag = homeform;
            displayQuote.Show();
            Hide();
            // reads the json from the file
            string currentQuotes = File.ReadAllText("quotes.json");

            // create the deskQoute list here so that we retain scope access
            List <DeskQuote> deskQuoteList;

            // if there are no previous qoutes, create the first quote list, otherwise deserialize the JSON into the list
            if (string.IsNullOrEmpty(currentQuotes))
            {
                deskQuoteList = new List <DeskQuote>();
            }
            else
            {
                deskQuoteList = JsonConvert.DeserializeObject <List <DeskQuote> >(currentQuotes);
            }
            // add the new qoute to the list
            deskQuoteList.Add(deskQuote);
            // using a string as a buffer, serialize the quote list back to JSON format
            string newJson = JsonConvert.SerializeObject(deskQuoteList, Formatting.Indented);

            //write the JSON to the file.
            File.WriteAllText("quotes.json", newJson);
        }
Esempio n. 2
0
        private void DisplayQuote_FormClosing(object sender, FormClosingEventArgs e)
        {
            HomeForm homeForm = (HomeForm)Tag;

            homeForm.Show();
        }
Esempio n. 3
0
        private void ViewQuotes_FormClosing(object sender, FormClosingEventArgs e)
        {
            HomeForm homeForm = (HomeForm)Tag;

            homeForm.Show();
        }