/// <summary> /// Function to add a new Client to the Client Array. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BTN_addClient_Click(object sender, EventArgs e) { bool valid = true; //Check First name if (TXTBX_ClientFirstName.TextLength == 0) { LBL_ClientFirstName.ForeColor = Color.Red; MessageBox.Show("Le Prénom du client n'est pas entré."); valid = false; } else { LBL_ClientFirstName.ForeColor = Color.White; } //Check Last name if (TXTBX_ClientLastName.TextLength == 0) { LBL_ClientLastName.ForeColor = Color.Red; MessageBox.Show("Le Nom du client n'est pas entré."); valid = false; } else { LBL_ClientLastName.ForeColor = Color.White; } //Check Adress if (TXTBX_ClientAdress.TextLength == 0) { LBL_ClientAdress.ForeColor = Color.Red; MessageBox.Show("L'Adresse du client n'est pas entrée."); valid = false; } else { LBL_ClientAdress.ForeColor = Color.White; } //Check Title if (TXTBX_ClientTitle.TextLength == 0) { LBL_ClientTitle.ForeColor = Color.Red; MessageBox.Show("Le Poste/Titre du client n'est pas entré."); valid = false; } else { LBL_ClientTitle.ForeColor = Color.White; } //Check if Client Canadian Resident was Selected if (CBOX_ClientResident.SelectedIndex < 0) { LBL_ClientResident.ForeColor = Color.Red; MessageBox.Show("Veuillez selectionner une option pour la résidence."); valid = false; } else { LBL_ClientResident.ForeColor = Color.White; } //Check if Country was Selected if (CBOX_ClientCountry.SelectedIndex < 0) { LBL_ClientCountry.ForeColor = Color.Red; MessageBox.Show("Veuillez selectionner un Pays de Naissance."); valid = false; } else { LBL_ClientCountry.ForeColor = Color.White; } //Check if Employee was selected if(CBOX_ClientEmploye.SelectedIndex < 0) { LBL_ClientEmploye.ForeColor = Color.Red; MessageBox.Show("Veuillez Selectionner un Conseiller."); valid = false; } else { LBL_ClientEmploye.ForeColor = Color.White; } //Create new Client in Dictionnary if all info is valid. if (valid) { //Add the New client to the DataSource bool resident = false; if (CBOX_ClientResident.SelectedIndex == 0) { resident = true; } string[] employeeID = CBOX_ClientEmploye.Text.Split(' '); Client newClient = new Client(TXTBX_ClientFirstName.Text, TXTBX_ClientLastName.Text, TXTBX_ClientAdress.Text, TXTBX_ClientTitle.Text, resident, CBOX_ClientCountry.Text, employeeID[0]); Program.ClientData.Add(newClient.CLIENTID, newClient); Program.EmployeeData[employeeID[0]].CLIENTS.Add(newClient.CLIENTID); //Empty all the fields TXTBX_ClientFirstName.Clear(); TXTBX_ClientLastName.Clear(); TXTBX_ClientTitle.Clear(); TXTBX_ClientAdress.Clear(); CBOX_ClientCountry.SelectedIndex = -1; CBOX_ClientResident.SelectedIndex = -1; CBOX_ClientEmploye.SelectedIndex = -1; UpdateClientTab(); BTN_ExportData.Enabled = true; } }
/// <summary> /// Function to import all the Client data from the XML File /// </summary> private static void importClientData() { DataSet ClientDB = new DataSet(); ClientDB.ReadXml("myClient.xml"); if (ClientDB.Tables.Count != 0) { foreach (DataRow row in ClientDB.Tables["Client Database"].Rows) { Client tempClient = new Client(row["ClientID"].ToString(), row["Prenom"].ToString(), row["Nom"].ToString(), row["Adresse"].ToString(), row["Title"].ToString(), Convert.ToBoolean(row["Resident"].ToString()), row["Country"].ToString(), row["Consultant"].ToString()); char separatingChar = ';'; string tempStr = row["Accounts"].ToString(); string[] allAccounts = tempStr.Split(separatingChar); for (int i = 0; i < allAccounts.Length - 1; i++) { if (allAccounts[i] != "Pas de compte") { tempClient.ACCOUNTS.Add(allAccounts[i]); } } Program.ClientData.Add(tempClient.CLIENTID, tempClient); } } }