public Employee(String firstname, String lastname, EmployeeGender gender, Department department) { Id = 0; Firstname = firstname; Lastname = lastname; Gender = gender; Department = department; }
public static Employee CreateEmployee(int id, String firstname, String lastname, int gender, Int32 department_id, String department_name) { Department employeeDepartment = null; if (department_id != 0) { employeeDepartment = new Department(department_id, department_name); } return new Employee(id, firstname, lastname, (EmployeeGender)gender, employeeDepartment); }
private void btnSaveDepartment_Click(object sender, RoutedEventArgs e) { if (tbDepartment.Text.Equals("")) { MessageBox.Show("Please enter a Department name"); return; } Department dep = new Department(tbDepartment.Text); service.insertDepartment(dep); this.loadList(); }
public void InsertEmpl() { int selectionIntGender; Console.WriteLine("Input firstname:"); string firstname = Console.ReadLine(); if (firstname.Trim().Equals("") || !Regex.IsMatch(firstname, "^\\w[a-zA-Z\\s]+$")) { Console.WriteLine("Error, please enter a valid firstname"); InsertEmpl(); return; } bool sacksession = true; string lastname = ""; while (sacksession) { Console.WriteLine("Input lastname:"); lastname = Console.ReadLine(); if (lastname.Trim().Equals("") || !Regex.IsMatch(lastname, "^\\w[a-zA-Z\\s]+$")) { Console.WriteLine("Error, please enter a valid lastname"); } else { sacksession = false; } } bool successGender = false; do { Console.WriteLine("Choose gender: {0} = Male | {1} = Female", (int)EmployeeGender.Male, (int)EmployeeGender.Female); string selectionGender = Console.ReadLine(); successGender = int.TryParse(selectionGender, out selectionIntGender); switch (selectionIntGender) { case ((int) EmployeeGender.Male): case ((int) EmployeeGender.Female): successGender = successGender && true; break; default: successGender = false; break; } if (!successGender) { Console.WriteLine("Invalid Input - try again"); Console.WriteLine("Choose gender: {0} = Male | {1} = Female", (int)EmployeeGender.Male, (int)EmployeeGender.Female); } } while (!successGender); Console.WriteLine("Input department or create a new one:"); List<Department> listDeps = service.getDepartments(); foreach (Department d_temp in listDeps) Console.WriteLine(d_temp.Id + " -> " + d_temp.Name); Department result = null; if (listDeps.Count == 0) { Console.WriteLine("No Departmens found - Create a new one!"); string selDepID = ""; do { Console.WriteLine("Department name"); selDepID = Console.ReadLine(); if (selDepID.Trim().Equals("") || !Regex.IsMatch(selDepID, "^\\w[a-zA-Z\\s]+$")) { Console.WriteLine("Please enter a valid department name"); selDepID = null; } } while (selDepID == null); result = new Department(selDepID); service.insertDepartment(result); result = service.getDepartment(result.Id); Console.WriteLine("Department inserted"); } else { int selDepID; sacksession = true; while (sacksession) { Console.WriteLine("Input ID."); string selectionEmplIDString = Console.ReadLine(); //try to parse string to int bool successEmplID = int.TryParse(selectionEmplIDString, out selDepID); result = service.getDepartment(selDepID); if (result == null) { Console.WriteLine("Error, please enter a valid id"); } else { sacksession = false; } } } Employee emp = new Employee(0, firstname, lastname, (EmployeeGender)selectionIntGender, result); service.insertEmployee(emp); Console.WriteLine("Employee inserted"); Console.WriteLine("Press Enter to go back to mainmenu"); Console.ReadLine(); Console.Clear(); }
public bool updateDepartment(Department department) { if (department.Id == 0) throw new ArgumentException(); SQLiteConnection connection = DbConnection; try { connection.Open(); SQLiteCommand command = new SQLiteCommand(connection); command.CommandText = "UPDATE `departments` SET name = @name WHERE id = @id"; command.Prepare(); command.Parameters.AddWithValue("@name", department.Name); command.Parameters.AddWithValue("@id", department.Id); command.ExecuteNonQuery(); } catch (Exception e) { throw e; } finally { connection.Close(); } return true; }
public void InsertDep() { Console.WriteLine("Input departmentname"); string depname = Console.ReadLine(); if (depname.Trim().Equals("") || !Regex.IsMatch(depname, "^\\w[a-zA-Z\\s]+$")) { Console.WriteLine("Please enter a valid department name"); InsertDep(); return; } Department dep = new Department(depname); service.insertDepartment(dep); Console.WriteLine("Department inserted"); Console.WriteLine("Press Enter to go back to mainmenu"); Console.ReadLine(); Console.Clear(); }
public bool insertDepartment(Department department) { SQLiteConnection connection = DbConnection; try { connection.Open(); SQLiteCommand command = new SQLiteCommand(connection); command.CommandText = "INSERT INTO `departments` (name) VALUES (@name)"; command.Prepare(); command.Parameters.AddWithValue("@name", department.Name); command.ExecuteNonQuery(); // update the new id command.CommandText = @"SELECT last_insert_rowid()"; SQLiteDataReader reader = command.ExecuteReader(); reader.Read(); department.setId(reader.GetInt32(0)); } catch (Exception e) { throw e; } finally { connection.Close(); } return true; }
public bool updateDepartment(Department department) { if (department.Id == 0) throw new ArgumentException(); deleteDepartmentById(department.Id); insertDepartment(department); /* foreach (XmlNode dep in departmentsRoot.ChildNodes) { if (Convert.ToInt32(dep.Attributes["Id"].InnerText) == department.Id) { dep.Attributes["Name"].InnerText = department.Name; departmentsDoc.Save(@"..\\..\\data\\xml\\departments.xml"); return true; } } return false; * */ return true; }
public bool insertDepartment(Department department) { int Id = 0; foreach (XmlNode dep2 in departmentsRoot.ChildNodes) { if (Convert.ToInt32(dep2.Attributes["Id"].InnerText) > Id) Id = Convert.ToInt32(dep2.Attributes["Id"].InnerText); } XmlNode dep = departmentsDoc.CreateElement("department"); XmlAttribute depId = departmentsDoc.CreateAttribute("Id"); depId.Value = Convert.ToString(Id + 1); XmlAttribute depName = departmentsDoc.CreateAttribute("Name"); depName.Value = department.Name; dep.Attributes.Append(depId); dep.Attributes.Append(depName); departmentsRoot.AppendChild(dep); departmentsDoc.Save(@"..\\..\\data\\xml\\departments.xml"); return true; }
public bool updateDepartment(Department department) { return store.updateDepartment(department); }
public bool insertDepartment(Department department) { return store.insertDepartment(department); }