/// <summary> /// Function to add a new Agency to the Agency Array. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BTN_addAgency_Click(object sender, EventArgs e) { bool valid = true; //Check Agency Name if (TXTBX_AgencyName.TextLength == 0) { LBL_AgencyBank.ForeColor = Color.Red; MessageBox.Show("Le Nom de l'Agence n'est pas entré."); valid = false; } else { LBL_AgencyBank.ForeColor = Color.White; } //Check Agency Adress if (TXTBX_AgencyAdress.TextLength == 0) { LBL_AgencyAdress.ForeColor = Color.Red; MessageBox.Show("L'Adresse de l'Agence n'est pas entré."); valid = false; } else { LBL_AgencyAdress.ForeColor = Color.White; } //Check Agency Bank if (CBOX_AgencyBank.SelectedIndex < 0) { LBL_AgencyBank.ForeColor = Color.Red; MessageBox.Show("Veuillez choisir une Banque. (Creer une banque avant de creer une Agence)"); valid = false; } else { LBL_AgencyBank.ForeColor = Color.White; } //Create new Agency in Dictionnary if all info is valid. if (valid) { //Add the New Agency to the DataSource string[] BankID = CBOX_AgencyBank.Text.Split(' '); Agency newAgency = new Agency(TXTBX_AgencyName.Text, TXTBX_AgencyAdress.Text, BankID[0]); Program.AgencyData.Add(newAgency.AGENCYID, newAgency); Program.BankData[BankID[0]].AGENCY.Add(newAgency.AGENCYID); //Empty all the fields TXTBX_AgencyAdress.Clear(); TXTBX_AgencyName.Clear(); CBOX_AgencyBank.SelectedIndex = -1; UpdateAgencyTab(); BTN_ExportData.Enabled = true; } }
/// <summary> /// Function to import all the Agency data from the XML File /// </summary> private static void importAgencies() { DataSet AgenciesDB = new DataSet(); AgenciesDB.ReadXml("myAgencies.xml"); if (AgenciesDB.Tables.Count != 0) { foreach (DataRow row in AgenciesDB.Tables["Agency Database"].Rows) { Agency tempAgency = new Agency(row["AgencyID"].ToString(), row["Nom"].ToString(), row["Adresse"].ToString(), row["Bank"].ToString()); char separatingChar = ';'; string tempStr = row["Employées"].ToString(); string[] allEmployers = tempStr.Split(separatingChar); for (int i = 0; i < allEmployers.Length - 1; i++) { if (allEmployers[i] != "Pas d'Employées") { tempAgency.EMPLOYEE.Add(allEmployers[i]); } } Program.AgencyData.Add(tempAgency.AGENCYID, tempAgency); } } }