Exemple #1
0
        //public DeskQuote Quote { get; }

        public DisplayQuote(DeskQuote quote)

        {
            InitializeComponent();
            //Quote = quote;
            fullNameOutput.Text        = quote.CustomerName;
            widthOutput.Text           = $"{quote.Desk.width}in";
            depthOutput.Text           = $"{quote.Desk.depth}in";
            numberOfDrawersOutput.Text = quote.Desk.numberOfDrawers.ToString();
            surfaceMaterialOutput.Text = quote.Desk.SurfaceMaterial.ToString();
            rushOrderOutput.Text       = (System.Attribute.GetCustomAttribute(quote.DayLengths.GetType().GetField(quote.DayLengths.ToString()), typeof(DescriptionAttribute)) as DescriptionAttribute)?.Description
                                         ?? quote.DayLengths.ToString();
            dateOutput.Text       = quote.Date.ToShortDateString();
            quotePriceOutput.Text = $"${quote.QuotePrice}";
        }
        public void writeQuoteToFile(string customerName, Desk desk, int width, int depth,
                                     SurfaceMaterial material, int numberOfDrawers, int rushOrderOptions)
        {
            DeskQuote deskQuote = new DeskQuote();

            deskQuote.CustomerName         = customerName;
            deskQuote.Desk                 = desk;
            deskQuote.Desk.Width           = width;
            deskQuote.Desk.Depth           = depth;
            deskQuote.Desk.DeskMaterial    = material;
            deskQuote.Desk.NumberOfDrawers = numberOfDrawers;
            deskQuote.ShippingDays         = rushOrderOptions;
            deskQuote.QuoteTotal           = calculateTotalQuote(deskQuote.Desk, deskQuote.Desk.Width,
                                                                 deskQuote.Desk.Depth, deskQuote.Desk.DeskMaterial, deskQuote.Desk.NumberOfDrawers, deskQuote.ShippingDays);
            deskQuote.QuoteDate       = DateTime.Now;
            deskQuote.DeskMaterial    = material;
            deskQuote.NumberOfDrawers = numberOfDrawers;
            deskQuote.Depth           = depth;
            deskQuote.Width           = width;

            string date = deskQuote.QuoteDate.ToString("MM/dd/yyyy");


            string displayOutput = "Customer Name: " + deskQuote.CustomerName + Environment.NewLine +
                                   "Desk Width: " + deskQuote.Desk.Width + Environment.NewLine +
                                   "Desk Depth: " + deskQuote.Desk.Depth + Environment.NewLine +
                                   "Desk Material: " + deskQuote.Desk.DeskMaterial + Environment.NewLine +
                                   "Desk Drawer Count: " + deskQuote.Desk.NumberOfDrawers + Environment.NewLine +
                                   "Rush Order: " + deskQuote.ShippingDays + Environment.NewLine +
                                   "Quate Date: " + date + Environment.NewLine +
                                   "Quote Total: $" + deskQuote.QuoteTotal;

            DisplayQuote.Quote = displayOutput;

            if (!File.Exists("..\\..\\quotes.json"))
            {
                File.Create("..\\..\\quotes.json").Close();
            }

            var data = File.ReadAllText("..\\..\\quotes.json");

            var listQuotes = JsonConvert.DeserializeObject <List <DeskQuote> >(data) ?? new List <DeskQuote>();

            listQuotes.Add(deskQuote);

            data = JsonConvert.SerializeObject(listQuotes.ToArray());
            File.WriteAllText("..\\..\\quotes.json", data);
        }
Exemple #3
0
        private async void SerializeQuotes(DeskQuote[] quotes)

        {
            string    path    = ".\\quotes.json";
            int       width   = Convert.ToInt32(this.widthInput.Text);
            int       depth   = Convert.ToInt32(this.depthInput.Text);
            int       drawers = Convert.ToInt32(this.numDrawers.Text);
            Desk      desk    = new Desk(width, depth, drawers, (Desk.DesktopMaterial)materialChoice.SelectedValue);
            DeskQuote current = new DeskQuote(this.nameBox.Text, (int)this.rushOrderDays.SelectedValue, desk);

            //Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
            //Windows.Storage.StorageFile sampleFile = await storageFolder.GetFileAsync(path);

            // var stream = await sampleFile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);
            List <DeskQuote> deskQuoteList = new List <DeskQuote>();

            foreach (DeskQuote quote in quotes)
            {
                deskQuoteList.Add(quote);
            }
            deskQuoteList.Add(current);
            var json = JsonConvert.SerializeObject(deskQuoteList);


            Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
            Windows.Storage.StorageFile   file          = await storageFolder.CreateFileAsync(
                path, Windows.Storage.CreationCollisionOption.ReplaceExisting);



            //StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appdata:///local/quotes.json"));
            using (Stream stream = await file.OpenStreamForWriteAsync())
            {
                byte[] toBytes = Encoding.UTF8.GetBytes(json.ToString());
                await stream.WriteAsync(toBytes, 0, toBytes.Length);
            }
            this.deskQuote = current;
        }