public static BindingList<Employee> GenerateHardCodedEmployees () { Employee em1 = new Employee("Jari", "Korppunen"); em1.EmployeeId = 1; em1.SocialID = "120467-872J"; em1.Title = "Toimitusjohtaja"; em1.Salary = 4650; em1.ContractType = (int)Employee.ContractTypes.Permanent; em1.DateOfBirth = new DateTime(1967, 4, 12); em1.DateOfWorkStarted = new DateTime(1993, 2, 19); Employee em2 = new Employee("Eino", "Leino"); em2.EmployeeId = 2; em2.SocialID = "01021920-852A"; em2.Title = "Apulaissihteerin sijainen"; em2.Salary = 1200; em2.ContractType = (int)Employee.ContractTypes.Permanent; em2.DateOfBirth = new DateTime(1920, 2, 1); em2.DateOfWorkStarted = new DateTime(1999, 2, 2); Employee em3 = new Employee("Kalervo", "Kullervo"); em3.SocialID = "051293-1238"; em3.EmployeeId = 3; em3.ContractType = (int)Employee.ContractTypes.PartTime; em3.DateOfBirth = new DateTime(1993, 12, 5); em3.DateOfWorkStarted = new DateTime(2014, 2, 9); BindingList<Employee> em = new BindingList<Employee>(); em.Add(em1); em.Add(em2); em.Add(em3); return em; }
private void CreateOrUpdateEmployee (Employee em = null) { bool create = false; if (em == null) { create = true; em = new Employee(); } string firstName = txtBoxFirstName.Text; string lastName = txtBoxLastName.Text; string employeeIdStr = txtBoxEmployeeId.Text; string title = txtBoxTitle.Text; string salaryStr = txtBoxSalary.Text; int employeeId; if (!int.TryParse(employeeIdStr, out employeeId)) { txtBoxEmployeeId.Focus(); MessageBox.Show("Virheellinen työntekijätunnus!"); return; } int salary; if (!int.TryParse(salaryStr, out salary)) { txtBoxSalary.Focus(); MessageBox.Show("Virheellinen palkka!"); return; } if (radioBtnPartTime.IsChecked == true) { em.ContractType = (int)Employee.ContractTypes.PartTime; } else { em.ContractType = (int)Employee.ContractTypes.Permanent; } em.FirstName = firstName; em.LastName = lastName; em.Salary = salary; em.Title = title; em.EmployeeId = employeeId; if (create) { this.company.Employees.Add(em); } listBoxEmployees.ItemsSource = null; listBoxEmployees.ItemsSource = this.company.Employees; listBoxEmployees.SelectedItem = em; }