コード例 #1
0
        private void buttonSubmit_Click(object sender, EventArgs e)
        {
            // material form drop down lost, then search for and display in list view area
            listViewResults.Clear();
            try
            {
                // grab combo box selection as a string
                string MaterialSelected = comboBoxMaterial.SelectedItem.ToString();

                // find and read CSV file if they exist
                if (!File.Exists(QUOTEFILE))
                {
                    MessageBox.Show("A Quote file was not found in application Root", "Error Reading File");
                }
                else
                {
                    // add column headings to search output List View
                    // Make sure View properity is set to Details
                    listViewResults.Columns.Add("#", 30, HorizontalAlignment.Center);
                    listViewResults.Columns.Add("Name", 170, HorizontalAlignment.Center);
                    listViewResults.Columns.Add("Date", 180, HorizontalAlignment.Center);
                    listViewResults.Columns.Add("Width", 70, HorizontalAlignment.Center);
                    listViewResults.Columns.Add("Depth", 70, HorizontalAlignment.Center);
                    listViewResults.Columns.Add("Drawers", 80, HorizontalAlignment.Center);
                    listViewResults.Columns.Add("Material", 120, HorizontalAlignment.Center);
                    listViewResults.Columns.Add("Days", 70, HorizontalAlignment.Center);
                    listViewResults.Columns.Add("Total", 170, HorizontalAlignment.Center);

                    using (StreamReader sr = new StreamReader(QUOTEFILE))
                    {
                        int quoteCount = 0;
                        while (!sr.EndOfStream)
                        {
                            //string[] fieldvalue = .Split(',');
                            var       line = sr.ReadLine();
                            DeskQuote jsonLineDeskQuote = JsonConvert.DeserializeObject <DeskQuote>(line);
                            if (jsonLineDeskQuote.Desk.DeskMaterial.ToString() == MaterialSelected)
                            {
                                quoteCount++;
                                listViewResults.Items.Add(new ListViewItem(new[]
                                {
                                    quoteCount.ToString(),
                                    jsonLineDeskQuote.CustomerName,
                                    jsonLineDeskQuote.QuoteDate.ToString(),
                                    jsonLineDeskQuote.Desk.Width.ToString(),
                                    jsonLineDeskQuote.Desk.Depth.ToString(),
                                    jsonLineDeskQuote.Desk.Drawers.ToString(),
                                    jsonLineDeskQuote.Desk.DeskMaterial.ToString(),
                                    jsonLineDeskQuote.RushDays.ToString(),
                                    jsonLineDeskQuote.QuoteTotal.ToString()
                                }));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error with poplulating Results List." + "\n\n" + ex);
            }
        }