public ViewAllQuotes() { InitializeComponent(); viewAllQuotesBox.View = View.Details; viewAllQuotesBox.Columns.Add("Name", -2, HorizontalAlignment.Left); viewAllQuotesBox.Columns.Add("Quote Date", -2, HorizontalAlignment.Left); viewAllQuotesBox.Columns.Add("Width", -2, HorizontalAlignment.Left); viewAllQuotesBox.Columns.Add("Depth", -2, HorizontalAlignment.Left); viewAllQuotesBox.Columns.Add("# of Drawers", -2, HorizontalAlignment.Left); viewAllQuotesBox.Columns.Add("Material", -2, HorizontalAlignment.Left); viewAllQuotesBox.Columns.Add("Rush Days", -2, HorizontalAlignment.Left); viewAllQuotesBox.Columns.Add("Price", -2, HorizontalAlignment.Left); try { string cFile = @"quotes.json"; using (StreamReader sr = new StreamReader(cFile)) { string line; //string display; while ((line = sr.ReadLine()) != null) { DeskQuote fromFile = JsonConvert.DeserializeObject <DeskQuote>(line); //display = fromFile.CustomerName + ", " + fromFile.QuoteDate.ToString("dd MMMMM yyyy") + ", " //+ fromFile.Desk.Width + ", " + fromFile.Desk.Depth + ", " + fromFile.Desk.NumOfDrawers + ", " //+ fromFile.Desk.MaterialName + ", " + fromFile.RushDays + ", " + fromFile.QuotePrice; viewAllQuotesBox.Items.Add(new ListViewItem(new[] { fromFile.CustomerName, fromFile.QuoteDate.ToString("dd MMM yyyy"), fromFile.Desk.Width.ToString(), fromFile.Desk.Depth.ToString(), fromFile.Desk.NumOfDrawers.ToString(), fromFile.Desk.MaterialName, fromFile.RushDays.ToString(), fromFile.QuotePrice.ToString() } )); } } } catch (Exception ex) { MessageBox.Show(ex.Message + "There is a problem"); } }
private void searchByMaterial(object sender, EventArgs e) { searchResults.Items.Clear(); MaterialType MaterialType; string searchInput = materialSearchBox.SelectedItem.ToString(); Enum.TryParse(searchInput, out MaterialType); try { string cFile = @"quotes.json"; using (StreamReader sr = new StreamReader(cFile)) { string line; //string display; while ((line = sr.ReadLine()) != null) { DeskQuote fromFile = JsonConvert.DeserializeObject <DeskQuote>(line); if (fromFile.Desk.MaterialName == MaterialType.ToString()) { //display = fromFile.CustomerName + ", " + fromFile.QuoteDate.ToString("dd MMMMM yyyy") + ", " // + fromFile.Desk.Width + ", " + fromFile.Desk.Depth + ", " + fromFile.Desk.NumOfDrawers + ", " // + fromFile.Desk.MaterialName + ", " + fromFile.RushDays + ", " + fromFile.QuotePrice; searchResults.Items.Add(new ListViewItem(new[] { fromFile.CustomerName, fromFile.QuoteDate.ToString("dd MMM yyyy"), fromFile.Desk.Width.ToString(), fromFile.Desk.Depth.ToString(), fromFile.Desk.NumOfDrawers.ToString(), fromFile.Desk.MaterialName, fromFile.RushDays.ToString(), fromFile.QuotePrice.ToString() } )); } } } } catch (Exception ex) { MessageBox.Show(ex.Message + "There is a problem"); } }
//End Validation private void AddDeskQuoteButton_Click(object sender, EventArgs e) { DeskQuote NewOrder = null; var json = ""; if (customerName.Text == "" || width.Text == "" || depth.Text == "" || numOfDrawers.SelectedItem == null || materialTypeBox.SelectedItem == null || rushOptions.SelectedItem == null) { MessageBox.Show("All Fields are Required", "Alert"); } else { try { CustomerName = customerName.Text; DeskWidth = decimal.Parse(width.Text); DeskDepth = decimal.Parse(depth.Text); Drawers = int.Parse(numOfDrawers.SelectedItem.ToString()); string Material = materialTypeBox.SelectedItem.ToString(); Enum.TryParse(Material, out MaterialType); //rush order selection RushOrderInput = rushOptions.SelectedItem.ToString(); switch (RushOrderInput) { case "3 Days": RushOrderDays = 3; break; case "5 Days": RushOrderDays = 5; break; case "7 Days": RushOrderDays = 7; break; default: RushOrderDays = 0; break; } NewOrder = new DeskQuote(CustomerName, DateTime.Now, DeskWidth, DeskDepth, Drawers, MaterialType, RushOrderDays); DeskQuotePrice = NewOrder.CalculateQuoteTotal(); NewOrder.QuotePrice = DeskQuotePrice; DeskQuotePrice = Math.Round(DeskQuotePrice, 2); } catch (Exception ex) { MessageBox.Show(ex.Message, "Check input methods"); } string QuoteDate = DateTime.Now.ToString("dd MMMMM yyyy"); //save to a file try { //var DeskRecord = CustomerName + ", " + QuoteDate + ", " + DeskWidth + ", " + DeskDepth //+ ", " + Drawers + ", " + MaterialType + ", " + RushOrderDays + ", " + DeskQuotePrice; json = JsonConvert.SerializeObject(NewOrder); string cFile = @"quotes.json"; if (!File.Exists(cFile)) { using (StreamWriter sw = File.CreateText(cFile)) { } } using (StreamWriter sw = File.AppendText(cFile)) { sw.WriteLine(json); } } catch (Exception ex) { MessageBox.Show(ex.Message + "There is a problem"); } //Show quote into on new page var MainMenu = (MainMenu)Tag; DisplayQuote newOrderView = new DisplayQuote(CustomerName, QuoteDate, DeskWidth, DeskDepth, Drawers, MaterialType, RushOrderDays, DeskQuotePrice) { Tag = MainMenu }; newOrderView.Show(); this.Close(); } }