public DisplayQuote(DeskQuote quote) : this()
 {
     Quote = quote;
 }
Exemplo n.º 2
0
        private void SubmitQuoteButton_Click(object sender, EventArgs e)
        {
            var item     = DesktopMaterialBox.SelectedItem.ToString();
            var material = DesktopMaterial.Veneer;

            if (item == DesktopMaterial.Laminate.ToString())
            {
                material = DesktopMaterial.Laminate;
            }
            else if (item == DesktopMaterial.Oak.ToString())
            {
                material = DesktopMaterial.Oak;
            }
            else if (item == DesktopMaterial.Pine.ToString())
            {
                material = DesktopMaterial.Pine;
            }
            else if (item == DesktopMaterial.Rosewood.ToString())
            {
                material = DesktopMaterial.Rosewood;
            }
            var days = 14;

            if (rushDays.SelectedIndex == DeskQuote.THREEDAYRUSH)
            {
                days = 3;
            }
            else if (rushDays.SelectedIndex == DeskQuote.FIVEDAYRUSH)
            {
                days = 5;
            }
            else if (rushDays.SelectedIndex == DeskQuote.SEVENDAYRUSH)
            {
                days = 7;
            }
            var quote = new DeskQuote(customerName.Text, ToDouble(width.Text), ToDouble(depth.Text), ToInt(drawers.Text), material, days, quoteDateLabel.Text);

            //This is Saving to a JSON file
            try
            {
                // name where the file is located
                var quoteJSONFile = @"quote.json";
                //creating a new DeskQuotes list called deskOrders to store my information in
                List <DeskQuote> deskOrders = new List <DeskQuote>();
                //if my file exists then add the information to my list that already exists
                if (File.Exists(quoteJSONFile))
                {
                    using (StreamReader reader = new StreamReader(quoteJSONFile))
                    {
                        string newQuotes = reader.ReadToEnd();
                        if (newQuotes.Length > 0)
                        {
                            deskOrders = JsonConvert.DeserializeObject <List <DeskQuote> >(newQuotes);
                        }
                        deskOrders.Add(quote);
                    }
                    //convert to JSON formate
                    var serializeQuotes = JsonConvert.SerializeObject(deskOrders);
                    //save to JSON file.
                    File.WriteAllText(quoteJSONFile, serializeQuotes);
                }
                //if not, create a new list to add too.
                else
                {
                    //create a list object of orders
                    deskOrders = new List <DeskQuote> {
                        quote
                    };
                    //convert to JSON formate
                    var serializeQuotes = JsonConvert.SerializeObject(deskOrders);
                    //save to JSON file.
                    File.WriteAllText(quoteJSONFile, serializeQuotes);
                }
            }

            catch (Exception)
            {
                throw;
            }
            DisplayQuote viewDisplayQuote = new DisplayQuote(quote);

            viewDisplayQuote.Tag = Tag;
            viewDisplayQuote.Show(this);
            Hide();
        }