// This method is here to create an arbitrary list of employees. internal void CreateEmployeeList(int count) { Random employeeNameRand = new Random (DateTime.Now.Millisecond); Random employeeIdRand = new Random (DateTime.Now.Millisecond + DateTime.Now.Second); // Create as many employees as was passed in. for (int x=0; x < count; x++) { // All of our last names will be 7 characters long. We'll use a // StringBuilder class to add characters to the underlying string. StringBuilder lastName = new StringBuilder(7); for (int i=0; i<7; i++) { char letter; if (i==0) { // Get the first letter of the last name from the capital letters. letter = (char) employeeNameRand.Next(65, 90); } else { // Get the subsequent letters of the last name from the lower-case letters. letter = (char) employeeNameRand.Next(97, 122); } // Place the character in the string. lastName.Insert(i, letter); } // Create the employee ID. int tempId = employeeIdRand.Next (10000, 99999); // Create a new employee record. Employee e = new Employee(lastName.ToString(), tempId); // Add the new employee to the list. AddNewEmployee(e); } }
internal void PrintEmployee(Employee e) { Console.WriteLine ("\tName: {0}, ID: {1}", e.Name, e.Id); }
// TODO: Complete this method to compare the names of the employee and return the result. // The result should be one of the following: // // -1: name of e1 is less than name of e2. // 0: names are equal. // 1: name of e1 is greater than name of e2. // // Check out the String class for help on comparing the two names. internal static int CompareByName(Employee e1, Employee e2) { // Compare the names of the employees for equality. int result = String.Compare (e1.name, e2.name); // Return the comparison result. return result; }
// This method is used to add a new employee record to the list // of employees. internal void AddNewEmployee(Employee e) { _employeeList.Add (e); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.activity_main); //Assigning Views with their layout ID EditText IDEmp = (EditText)FindViewById(Resource.Id.id_emp); EditText NameEmp = (EditText)FindViewById(Resource.Id.name_emp); EditText PhoneEmp = (EditText)FindViewById(Resource.Id.phone_emp); EditText RemoveID = (EditText)FindViewById(Resource.Id.removeid_emp); Button CreateEntry = (Button)FindViewById(Resource.Id.Btn_Create); Button UpdateEntry = (Button)FindViewById(Resource.Id.Btn_Update); Button DeleteEntry = (Button)FindViewById(Resource.Id.Btn_Delete); Button ReadEntry = (Button)FindViewById(Resource.Id.Btn_Read); dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "data.db3"); db = new SQLiteConnection(dbPath); db.CreateTable <Employee>(); //Create Function CreateEntry.Click += delegate { Employee employee = new Employee(Int32.Parse(IDEmp.Text), NameEmp.Text, PhoneEmp.Text); db.Insert(employee); Toast.MakeText(Application.Context, "Created a new employee profile", ToastLength.Long).Show(); }; //Update Function UpdateEntry.Click += delegate { var table = db.Table <Employee>(); int i = 0; foreach (var item in table) { if (item.ID.ToString().Equals(IDEmp.Text)) { db.Execute("UPDATE Employee SET name = ?, phoneNumber = ? Where id = ?", NameEmp.Text, PhoneEmp.Text, IDEmp.Text); Toast.MakeText(Application.Context, "Updated employee profile associated with Employee No.: " + IDEmp.Text, ToastLength.Long).Show(); i = 1; break; } } //If no record was found if (i == 0) { Toast.MakeText(Application.Context, "Profile with this Employee No. hasn't been created yet", ToastLength.Long).Show(); } }; //Delete Function DeleteEntry.Click += delegate { var table = db.Table <Employee>(); int i = 0; foreach (var item in table) { if (item.ID.ToString().Equals(RemoveID.Text)) { //Update Query string query = "delete from Employee where id=" + RemoveID.Text; db.Execute(query); Toast.MakeText(Application.Context, "Deleted employee profile associated with Employee No.: " + RemoveID.Text, ToastLength.Long).Show(); i = 1; break; } } //If no record was found if (i == 0) { Toast.MakeText(Application.Context, "Profile with this Employee No. hasn't been created yet", ToastLength.Long).Show(); } }; message = ""; //Read Function ReadEntry.Click += delegate { var table = db.Table <Employee>(); foreach (var item in table) { message = message + item.ID + "," + item.Name + "," + item.PhoneNumber + "\n"; } StartActivity(new Android.Content.Intent(this, typeof(Read))); }; }
// TODO: Complete this method to compare the IDs of the employee and return the result. // The result should be one of the following: // // -1: ID of e1 is less than ID of e2. // 0: IDs are equal. // 1: ID of e1 is greater than ID of e2. // // The int type has a method named CompareTo that performs the same // comparison and returns the same results as the String's Compare method. internal static int CompareById(Employee e1, Employee e2) { // Use the CompareTo() method that the int type supports to // compare the two ID's. int result = e1.Id.CompareTo(e2.Id); // Return the comparison result. return result; }
public Task <int> DeleteEmployee(Employee employee) { return(this.repo.DeleteEmployee(employee)); }
public Task <int> AddEmployee(Employee employee) { return(this.repo.AddEmployee(employee)); }
private void OK_Click(object sender, RoutedEventArgs e) { bool check = true; if (changeMode == false) { Employee emp = new Employee(); if (empBoss.SelectedItem != null && subWorkerList.Items != null) { foreach (Employee item in subWorkerList.Items) { if (empBoss.SelectedItem == item) { MessageBox.Show("Ошибка! Начальник не может быть подчиненным."); check = false; subWorkerList.Items.Remove(item); empBoss.SelectedItem = null; empSubWorkers.SelectedItem = null; break; } } if (check == true) { emp.Add(this); empList.empManager.Add(emp); employeeList.Items.Clear(); foreach (Employee employee in empList.empManager) { employeeList.Items.Add(employee); } empSurname.Clear(); empName.Clear(); empMiddlename.Clear(); empPhotoPath.Clear(); empPosition.Clear(); employmentDay.SelectedItem = null; employmentMonth.SelectedItem = null; employmentYear.SelectedItem = null; isFired.IsChecked = false; dismissalDay.SelectedItem = null; dismissalMonth.SelectedItem = null; dismissalYear.SelectedItem = null; hasPrevPos.IsChecked = false; prevPosName.Clear(); prevPosTerm.Clear(); empDepartment.SelectedItem = null; empBoss.SelectedItem = null; subWorkerList.Items.Clear(); empSubWorkers.SelectedItem = null; } } else { emp.Add(this); empList.empManager.Add(emp); employeeList.Items.Clear(); foreach (Employee employee in empList.empManager) { employeeList.Items.Add(employee); } empSurname.Clear(); empName.Clear(); empMiddlename.Clear(); empPhotoPath.Clear(); empPosition.Clear(); employmentDay.SelectedItem = null; employmentMonth.SelectedItem = null; employmentYear.SelectedItem = null; isFired.IsChecked = false; dismissalDay.SelectedItem = null; dismissalMonth.SelectedItem = null; dismissalYear.SelectedItem = null; hasPrevPos.IsChecked = false; prevPosName.Clear(); prevPosTerm.Clear(); empDepartment.SelectedItem = null; empBoss.SelectedItem = null; subWorkerList.Items.Clear(); empSubWorkers.SelectedItem = null; } } else { Employee emp = new Employee(); if (empBoss.SelectedItem != null && subWorkerList.Items != null) { check = true; foreach (Employee item in subWorkerList.Items) { if (empBoss.SelectedItem == item) { MessageBox.Show("Ошибка! Начальник не может быть подчиненным."); check = false; subWorkerList.Items.Remove(item); empBoss.SelectedItem = null; empSubWorkers.SelectedItem = null; break; } } if (check == true) { emp.Add(this); empList.empManager.Remove((Employee)employeeList.SelectedItem); empList.empManager.Add(emp); employeeList.Items.Clear(); foreach (Employee employee in empList.empManager) { employeeList.Items.Add(employee); } changeMode = false; empSurname.Clear(); empName.Clear(); empMiddlename.Clear(); empPhotoPath.Clear(); empPosition.Clear(); employmentDay.SelectedItem = null; employmentMonth.SelectedItem = null; employmentYear.SelectedItem = null; isFired.IsChecked = false; dismissalDay.SelectedItem = null; dismissalMonth.SelectedItem = null; dismissalYear.SelectedItem = null; hasPrevPos.IsChecked = false; prevPosName.Clear(); prevPosTerm.Clear(); empDepartment.SelectedItem = null; empBoss.SelectedItem = null; subWorkerList.Items.Clear(); empSubWorkers.SelectedItem = null; } } else { emp.Add(this); empList.empManager.Remove((Employee)employeeList.SelectedItem); empList.empManager.Add(emp); employeeList.Items.Clear(); foreach (Employee employee in empList.empManager) { employeeList.Items.Add(employee); } changeMode = false; empSurname.Clear(); empName.Clear(); empMiddlename.Clear(); empPhotoPath.Clear(); empPosition.Clear(); employmentDay.SelectedItem = null; employmentMonth.SelectedItem = null; employmentYear.SelectedItem = null; isFired.IsChecked = false; dismissalDay.SelectedItem = null; dismissalMonth.SelectedItem = null; dismissalYear.SelectedItem = null; hasPrevPos.IsChecked = false; prevPosName.Clear(); prevPosTerm.Clear(); empDepartment.SelectedItem = null; empBoss.SelectedItem = null; subWorkerList.Items.Clear(); empSubWorkers.SelectedItem = null; } } }
// TODO: Complete this method to compare the names of the employee and return the result. // The result should be one of the following: // // -1: name of e1 is less than name of e2. // 0: names are equal. // 1: name of e1 is greater than name of e2. // // Check out the String class for help on comparing the two names. internal static int CompareByName(Employee e1, Employee e2) { }
// TODO: Complete this method to compare the IDs of the employee and return the result. // The result should be one of the following: // // -1: ID of e1 is less than ID of e2. // 0: IDs are equal. // 1: ID of e1 is greater than ID of e2. // // The int type has a method named CompareTo that performs the same // comparison and returns the same results as the String's Compare method. internal static int CompareById(Employee e1, Employee e2) { }