/// <summary> /// Function to add a new Account to the Account Array /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BTN_addAccount_Click(object sender, EventArgs e) { bool valid = true; if (CBOX_AccountType.SelectedIndex < 0) { LBL_AccountType.ForeColor = Color.Red; MessageBox.Show("Veuillez Sélectionner un type de compte."); valid = false; } else { LBL_AccountType.ForeColor = Color.White; } if (CBOX_AccountClient.SelectedIndex < 0) { LBL_AccountClient.ForeColor = Color.Red; MessageBox.Show("Veuillez Sélectionner un Client pour le Compte."); valid = false; } else { LBL_AccountClient.ForeColor = Color.White; } //If all information is valid if (valid) { //Interest if (CBOX_AccountType.Text == "Avec Interet") { string[] clientID = CBOX_AccountClient.Text.Split(' '); AccountInterest account = new AccountInterest(NUM_AccountBalance.Value, clientID[0], NUM_AccountInterest.Value); Program.AccountData.Add(account.ACCOUNTID, account); //Update the account in Client data if (Program.ClientData[clientID[0]].ACCOUNTS.Count == 0) { Program.ClientData[clientID[0]].ACCOUNTS.Clear(); } Program.ClientData[clientID[0]].ACCOUNTS.Add(account.ACCOUNTID); NUM_AccountBalance.Value = 0; NUM_AccountInterest.Value = 0; CBOX_AccountClient.SelectedIndex = -1; CBOX_AccountType.SelectedIndex = -1; UpdateAccountTab(); BTN_ExportData.Enabled = true; } //No Interest else if (CBOX_AccountType.Text == "Sans Interet") { string[] clientID = CBOX_AccountClient.Text.Split(' '); AccountNoInterest account = new AccountNoInterest(NUM_AccountBalance.Value, clientID[0], NUM_AccountLimit.Value); Program.AccountData.Add(account.ACCOUNTID, account); //Update the account in Client data if (Program.ClientData[clientID[0]].ACCOUNTS.Count == 0) { Program.ClientData[clientID[0]].ACCOUNTS.Clear(); } Program.ClientData[clientID[0]].ACCOUNTS.Add(account.ACCOUNTID); NUM_AccountBalance.Value = 0; NUM_AccountLimit.Value = 0; CBOX_AccountClient.SelectedIndex = -1; CBOX_AccountType.SelectedIndex = -1; UpdateAccountTab(); BTN_ExportData.Enabled = true; } } }
/// <summary> /// Function to import all the Account data from the XML File /// </summary> private static void importAccountData() { DataSet AccountDB = new DataSet(); AccountDB.ReadXml("myAccount.xml"); if (AccountDB.Tables.Count != 0) { foreach (DataRow row in AccountDB.Tables["Account Database"].Rows) { if (row["Type"].ToString() == "Interest") { AccountInterest tempAccountInterest = new AccountInterest(decimal.Parse(row["Balance"].ToString()), row["ClientID"].ToString(), decimal.Parse(row["Interest"].ToString())); Program.AccountData.Add(tempAccountInterest.ACCOUNTID, tempAccountInterest); } else { AccountNoInterest tempAccountNoInterest = new AccountNoInterest(decimal.Parse(row["Balance"].ToString()), row["ClientID"].ToString(), decimal.Parse(row["Limit"].ToString())); Program.AccountData.Add(tempAccountNoInterest.ACCOUNTID, tempAccountNoInterest); } } } }