private void Form1_Load(object sender, EventArgs e) { listView1.View = View.Details; listView1.Columns.Add("FirstName"); listView1.Columns.Add("LastName"); listView1.Columns.Add("Address"); listView1.Columns.Add("Age"); listView1.Columns.Add("GrossMoPay"); listView1.Columns.Add("DeptID"); listView1.Columns.Add("DevType"); listView1.Columns.Add("TaxType"); listView1.Columns.Add("AnnaulTax"); listView1.Columns.Add("AnnualNetPay"); // List<T> object for holding the JSON file information. List <Employee> empList = new List <Employee>(); using (StreamReader sr = new StreamReader("data.json")) { string jsonFile = sr.ReadToEnd(); empList = JsonConvert.DeserializeObject <List <Employee> >(jsonFile); } // 'match' for seacrhing and placing the right block of employee information // within the proper class. First names are used for filtering. Employee match = empList.Find(em => em.FirstName == "John"); var emp1 = new W2 { FirstName = match.FirstName, LastName = match.LastName, Address = match.Address, Age = match.Age, GrossMoPay = match.GrossMoPay, DeptID = match.DeptID, DevType = match.DevType, TaxType = match.TaxType }; emp1.AnnualPay = Convert.ToDouble(emp1.GrossMoPay); emp1.TaxCalc(); string[] item = emp1.GetInfo(); var im = new ListViewItem(item); listView1.Items.Add(im); match = empList.Find(em => em.FirstName == "Mary"); var emp2 = new T1099 { FirstName = match.FirstName, LastName = match.LastName, Address = match.Address, Age = match.Age, GrossMoPay = match.GrossMoPay, DeptID = match.DeptID, DevType = match.DevType, TaxType = match.TaxType }; emp2.AnnualPay = Convert.ToDouble(emp2.GrossMoPay); emp2.TaxCalc(); item = emp2.GetInfo(); im = new ListViewItem(item); listView1.Items.Add(im); match = empList.Find(em => em.FirstName == "Angela"); var emp3 = new T1099 { FirstName = match.FirstName, LastName = match.LastName, Address = match.Address, Age = match.Age, GrossMoPay = match.GrossMoPay, DeptID = match.DeptID, DevType = match.DevType, TaxType = match.TaxType }; emp3.AnnualPay = Convert.ToDouble(emp3.GrossMoPay); emp3.TaxCalc(); item = emp3.GetInfo(); im = new ListViewItem(item); listView1.Items.Add(im); match = empList.Find(em => em.FirstName == "Michael"); var emp4 = new W2 { FirstName = match.FirstName, LastName = match.LastName, Address = match.Address, Age = match.Age, GrossMoPay = match.GrossMoPay, DeptID = match.DeptID, DevType = match.DevType, TaxType = match.TaxType }; emp4.AnnualPay = Convert.ToDouble(emp4.GrossMoPay); emp4.TaxCalc(); item = emp4.GetInfo(); im = new ListViewItem(item); listView1.Items.Add(im); listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); }
private void Form1_Load(object sender, EventArgs e) { listView1.View = View.Details; listView1.Columns.Add("FirstName"); listView1.Columns.Add("LastName"); listView1.Columns.Add("Address"); listView1.Columns.Add("Age"); listView1.Columns.Add("GrossMoPay"); listView1.Columns.Add("DeptID"); listView1.Columns.Add("DevType"); listView1.Columns.Add("TaxType"); listView1.Columns.Add("AnnaulTax"); listView1.Columns.Add("AnnualNetPay"); // LINQ query to separate the W2 employees into own file. var getW2 = from line in File.ReadLines("data.txt") where (line.Contains("W2")) select line; File.WriteAllLines(@"W2.txt", getW2); // LINQ query to separate the 1099 employees into own file. var get1099 = from line in File.ReadLines("data.txt") where (line.Contains("1099")) select line; File.WriteAllLines(@"1099.txt", get1099); // Reads the newly created W2 file to create and calculate W2 class using (StreamReader sr = new StreamReader("W2.txt")) { string line; while ((line = sr.ReadLine()) != null) { string[] info = line.Split(','); var w2 = new W2 { First = info[0], Last = info[1], Address = info[2], Age = info[3], Gross = info[4], ID = info[5], DevType = info[6], TaxType = info[7] }; w2.AnnualPay = Convert.ToDouble(w2.Gross); w2.TaxCalc(); string[] w2row = { w2.First, w2.Last, w2.Address, w2.Age, FormatString(w2.Gross), w2.ID, w2.DevType, w2.TaxType,w2.Tax, w2.NetPay }; var w2Item = new ListViewItem(w2row); listView1.Items.Add(w2Item); } } // Reads the newly created 1099 file to create and calculate 1099 class using (StreamReader sr = new StreamReader("1099.txt")) { string line; while ((line = sr.ReadLine()) != null) { string[] info = line.Split(','); var t99 = new T1099 { First = info[0], Last = info[1], Address = info[2], Age = info[3], Gross = info[4], ID = info[5], DevType = info[6], TaxType = info[7] }; t99.AnnualPay = Convert.ToDouble(t99.Gross); t99.TaxCalc(); string[] t99row = { t99.First, t99.Last, t99.Address, t99.Age, FormatString(t99.Gross), t99.ID, t99.DevType, t99.TaxType,t99.Tax, t99.NetPay }; var t99Item = new ListViewItem(t99row); listView1.Items.Add(t99Item); } } listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); }