/// <summary> /// Function to add a new Employee to the Employee Array. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BTN_addEmpl_Click(object sender, EventArgs e) { bool valid = true; //Check Employee Name if (TXTBX_EmployeeName.TextLength == 0) { LBL_EmployeeName.ForeColor = Color.Red; MessageBox.Show("Le Prénom de l'Employé n'est pas entré."); valid = false; } else { LBL_EmployeeName.ForeColor = Color.White; } //Check Employee LastName if (TXTBX_EmployeeLastName.TextLength == 0) { LBL_EmployeeLastName.ForeColor = Color.Red; MessageBox.Show("Le Nom de l'Employé n'est pas entré."); valid = false; } else { LBL_EmployeeLastName.ForeColor = Color.White; } //Check Employee Poste if (TXTBX_EmployeePoste.TextLength == 0) { LBL_EmployeePoste.ForeColor = Color.Red; MessageBox.Show("Le Poste de l'Employé n'est pas entré."); valid = false; } else { LBL_EmployeePoste.ForeColor = Color.White; } //Check Employee Salary if (NUM_EmployeeSalary.Value == 0) { LBL_EmployeeSalary.ForeColor = Color.Red; MessageBox.Show("Le Salaire de l'Employé n'est pas entré."); valid = false; } else { LBL_EmployeeSalary.ForeColor = Color.White; } //Check Employe Agency if(CBOX_EmployeeAgency.SelectedIndex < 0) { LBL_EmployeeAgency.ForeColor = Color.Red; MessageBox.Show("Veuillez choisir une Agence pour l'Employé. (Créer une Agence avant l'Employé)"); valid = false; } else { LBL_EmployeeAgency.ForeColor = Color.White; } //Create new Employe in Dictionnary if all info is valid. if (valid) { //Add the New Employe to the DataSource string[] AgencyID = CBOX_EmployeeAgency.Text.Split(' ');///////////////////////////////////////////////FIX THIS Employee newEmployee = new Employee(TXTBX_EmployeeName.Text, TXTBX_EmployeeLastName.Text, DTE_EmployeeHire.Value, TXTBX_EmployeePoste.Text, NUM_EmployeeSalary.Value, AgencyID[0]); Program.EmployeeData.Add(newEmployee.EMPLOYEEID, newEmployee); Program.AgencyData[AgencyID[0]].EMPLOYEE.Add(newEmployee.EMPLOYEEID); //Empty all the fields TXTBX_EmployeeLastName.Clear(); TXTBX_EmployeeName.Clear(); TXTBX_EmployeePoste.Clear(); CBOX_EmployeeAgency.SelectedIndex = -1; NUM_EmployeeSalary.Value = 0; UpdateEmployeeTab(); BTN_ExportData.Enabled = true; } }
/// <summary> /// Function to import all the Employee data from the XML File /// </summary> private static void importEmployerData() { DataSet EmployerDB = new DataSet(); EmployerDB.ReadXml("myEmployer.xml"); if (EmployerDB.Tables.Count != 0) { foreach (DataRow row in EmployerDB.Tables["Employer Database"].Rows) { Employee tempEmployer = new Employee(row["EmployerID"].ToString(), row["Prenom"].ToString(), row["Nom"].ToString(), DateTime.Parse(row["HiringDate"].ToString()), row["Poste"].ToString(), decimal.Parse(row["Salaire"].ToString()), row["Agency"].ToString()); char separatingChar = ';'; string tempStr = row["Clients"].ToString(); string[] allClients = tempStr.Split(separatingChar); for (int i = 0; i < allClients.Length - 1; i++) { if (allClients[i] != "Pas de Client") { tempEmployer.CLIENTS.Add(allClients[i]); } } Program.EmployeeData.Add(tempEmployer.EMPLOYEEID, tempEmployer); } } }