コード例 #1
0
ファイル: AddQuote.cs プロジェクト: danverde/MegaDesk3
        private void SaveQuote(DeskQuote quote)
        {
            // @"" means you don't have to escape \ characters in the string
            string fileName = @"H:\Documents\S8\CIT 365\MegaDesk-2\MegaDesk2\quotes.json";

            try
            {
                if (File.Exists(fileName))
                {
                    //Creating an object to store the data in
                    QuoteData jsonData = new QuoteData();

                    //Storing the data
                    jsonData.Date  = quote.OrderDate;
                    jsonData.Name  = quote.CustomerName;
                    jsonData.Total = (int)quote.Price;
                    jsonData.Order = (int)((DeskQuote.Delivery)RushOrderInput.SelectedValue);
                    Desk.Surface mType;
                    Enum.TryParse(MaterialInput.SelectedValue.ToString(), out mType);
                    jsonData.Material = mType.ToString();
                    jsonData.Drawers  = quote.Desk.NumDrawers;
                    jsonData.Width    = (int)quote.Desk.Width;
                    jsonData.Depth    = (int)quote.Desk.Depth;


                    //Serializing the object
                    string quoteString = JsonConvert.SerializeObject(jsonData);

                    //Writing to the file
                    File.AppendAllText(fileName, quoteString + Environment.NewLine);

                    Message.Text = $"Price: ${quote.Price}";
                }
                else
                {
                    throw new Exception($"Unable to find {fileName}");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }