public BankDatabase(string _FileName) { XmlTextReader reader=null; try { reader = new XmlTextReader(_FileName); int texttype = 0; Account newAccount = null; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.Name == "Account") { newAccount = new Account(); newAccount.accountNumber = reader.GetAttribute("id"); } if (reader.Name == "accountPIN") { texttype = 1; } if (reader.Name == "accountTotalBalance") { texttype = 2; } if (reader.Name == "accountAvailableBalance") { texttype = 3; } if (reader.Name == "accountPrefLanguage") { texttype = 4; } break; case XmlNodeType.Text: switch (texttype) { case 1: newAccount.accountPIN = reader.Value; break; case 2: newAccount.accountTotalBalance = Convert.ToInt32(reader.Value); break; case 3: newAccount.accountAvailableBalance = Convert.ToInt32(reader.Value); break; case 4: newAccount.accountLanguage = reader.Value; break; } texttype = 0; break; case XmlNodeType.EndElement: if (reader.Name == "Account") { accounts.Add(newAccount); newAccount = null; } break; } } } catch (XmlException e) { Console.WriteLine("error occured: " + e.Message); } finally { reader.Close(); } }
private void codeActivity2_ExecuteCode_1(object sender, EventArgs e) { Account changeAccount = new Account(); changeAccount.accountNumber = currentAccountNumber; changeAccount.accountPIN = newPIN; changeAccount.accountAvailableBalance = BD.GetAvailableBalanceFromAccount(currentAccountNumber); changeAccount.accountTotalBalance = BD.GetTotalBalanceFromAccount(currentAccountNumber); BD.accounts[BD.GetAccInd(currentAccountNumber)] = changeAccount; BD.SaveToXml("BankDatabase.xml"); Console.WriteLine("Vrode Save"); }