Beispiel #1
0
        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);
        }