Ejemplo n.º 1
0
        //Sends the quote information to the DisplayQuote view for customer conformation.
        private void submitButton_Click(object sender, EventArgs e)
        {
            //Creates an instance of DeskOrderQuote
            DeskOrderQuote newDeskQuote = new DeskOrderQuote(newDesk, newOrder);

            //Calls the RecordOrder() function.
            RecordOrder(newDeskQuote);

            //Create instance of DisplayOrder displays the displayOrderForm and hides the addQuoteForm.
            DisplayOrder orderForm = new DisplayOrder(newDesk, newOrder);

            orderForm.Show();
            Hide();
        }
Ejemplo n.º 2
0
        //Writes the submitted order to a text file.
        private void RecordOrder(DeskOrderQuote newDeskQuote)
        {
            try
            {
                //Create output JSON.
                string jFile = @"quotes.json";
                //Creates JSON file file if one hasn't been created yet.
                if (!File.Exists(jFile))
                {
                    using (StreamWriter sw = File.CreateText("quotes.json")){}
                }
                //Creates a JSON object using the values of newDeskQuote
                var quoteArray = new JObject
                {
                    ["quoteDate"]  = newDeskQuote.quoteDate.ToString(),
                    ["lastName"]   = newDeskQuote.lastName,
                    ["firstName"]  = newDeskQuote.firstName,
                    ["width"]      = newDeskQuote.width,
                    ["depth"]      = newDeskQuote.depth,
                    ["numDrawers"] = newDeskQuote.numDrawers,
                    ["surface"]    = newDeskQuote.surface.ToString(),
                    ["rushDays"]   = newDeskQuote.rushDays,
                    ["quote"]      = newDeskQuote.quote
                };

                //Creates a serialized version of quoteArray.
                var convertedQuoteArray = JsonConvert.SerializeObject(quoteArray, Formatting.Indented);
                //Writes convertedQuoteArray to the quotes.json file.
                using (StreamWriter sw = File.AppendText("quotes.json"))
                {
                    sw.WriteLine(convertedQuoteArray);
                }

                //Store deskOrders into a text file.
                string cFile = @"desk_orders.txt";
                //Determines if the file already exists.
                //If the desk_orders file does not exist, it is created, populated with header information, and the quote that was submitted.
                if (!File.Exists(cFile))
                {
                    //Use StreamWriter to create a text file and write the quote to the file and closing the stream upon completion.
                    using (StreamWriter sw = File.CreateText("desk_orders.txt"))
                    {
                        //Header and format key
                        sw.WriteLine("Mega Escritorio - Desk Orders");
                        sw.WriteLine("(Date and Time, Last Name, First Name, Width, Depth, Number of Drawers, Surface, Production Speed, Price)");
                        sw.WriteLine("========================================================================================================");
                        //Writes each value of newDeskQuote to the text file
                        sw.WriteLine(newDeskQuote.quoteDate.ToString() + ", " + newDeskQuote.lastName + ", " + newDeskQuote.firstName + ", " + newDeskQuote.width + ", " + newDeskQuote.depth + ", " + newDeskQuote.numDrawers + ", " + newDeskQuote.surface + ", " + newDeskQuote.rushDays + ", " + newDeskQuote.quote);
                    }
                }
                //If the text file already exists the quote is just add.
                else
                {
                    //Use StreamWriter to append the text file write the new quote and closing the stream upon completion.
                    using (StreamWriter sw = File.AppendText("desk_orders.txt"))
                    {
                        //Writes each value of newDeskQuote to the text file
                        sw.WriteLine(newDeskQuote.quoteDate.ToString() + ", " + newDeskQuote.lastName + ", " + newDeskQuote.firstName + ", " + newDeskQuote.width + ", " + newDeskQuote.depth + ", " + newDeskQuote.numDrawers + ", " + newDeskQuote.surface + ", " + newDeskQuote.rushDays + ", " + newDeskQuote.quote);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }