private void loadGrid(Desk.DesktopMaterial desktopMaterial) { try { var quotesFile = "quotes.json"; string json = File.ReadAllText(@quotesFile); List <DeskQuote> deskQuotes = JsonConvert.DeserializeObject <List <DeskQuote> >(json); dtblSearchQuotes.DataSource = deskQuotes.Select(d => new { Date = d.Date, Customer = d.CustomerName, Depth = d.Depth, Width = d.Width, Drawers = d.NumDrawers, SurfaceMaterial = d.MaterialType, DeliveryType = d.ShippingDays, QuoteAmount = d.GetQuotePrice().ToString("c") }).Where(q => q.SurfaceMaterial == desktopMaterial).ToList(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void loadGrid(Desk.DesktopMaterial desktopMaterial) { var quotesFile = @"quotes.json"; using (StreamReader reader = new StreamReader(quotesFile)) { // load existing quotes string quotes = reader.ReadToEnd(); List <DeskQuote> deskQuotes = JsonConvert.DeserializeObject <List <DeskQuote> >(quotes); dataGridView1.DataSource = deskQuotes.Select(d => new { Date = d.QuoteDate, Customer = d.CustomerName, Depth = d.Desk.Depth, Width = d.Desk.Width, Drawers = d.Desk.NumberOfDrawers, SurfaceMaterial = d.Desk.Material, DeliveryType = d.DeliveryType, QuoteAmount = d.QuotePrice }) .Where(q => q.SurfaceMaterial == desktopMaterial) .ToList(); } }
private void btnAddNewQuote_Click(object sender, EventArgs e) { if (!(customerName.Text == string.Empty)) { // Parse and assign value deskWidth = int.Parse(width.Text); deskDepth = int.Parse(depth.Text); deskDrawer = int.Parse(drawerCount.Text); deskMaterial = (Desk.DesktopMaterial)surfaceMaterial.SelectedValue; rushDays = int.Parse(((KeyValuePair <string, string>)rushOrder.SelectedItem).Key); _customerName = customerName.Text; // Call DeskQuote Class with parameters DeskQuote deskQuote = new DeskQuote(_customerName, rushDays, DateTime.Now, deskWidth, deskDepth, deskDrawer, deskMaterial); // Assign value to get quote controls lblArea.Text = deskQuote.calcArea().ToString(); excessSize.Text = deskQuote.calcSizeOverage().ToString(); sizeCost.Text = deskQuote.calcSizeCost().ToString() + ".00"; drawerCost.Text = deskQuote.calcDrawer().ToString() + ".00"; materialCost.Text = deskQuote.calcMaterial().ToString() + ".00"; shipCost.Text = deskQuote.calcShippingCost().ToString() + ".00"; totalCost.Text = deskQuote.calcQuote().ToString() + ".00"; totalQuote = deskQuote.calcQuote(); //write to the quotes.json file MainMenu.write(_customerName, rushDays, Convert.ToString(DateTime.Now), deskWidth, deskDepth, deskDrawer, Convert.ToString(deskMaterial), totalQuote); // Disable the submit button to avoid double submission btnAddNewQuote.Enabled = false; } else { customerName.BackColor = Color.Red; customerName.ForeColor = Color.White; MessageBox.Show("You have not entered a customer's name."); customerName.Focus(); } }
// DesQuote constructor public DeskQuote(string customer, int rush, DateTime date, int width, int depth, int drawer, Desk.DesktopMaterial material) { customerName = customer; rushDays = rush; quoteDate = date; desk.Depth = depth; desk.Width = width; desk.Drawer = drawer; desk.desktopMaterial = material; }