public static void AddPlasticCard(string name, string BankAccount, string CardHolder, string CardNumber, string Date, CurrencyType currency, decimal Amount) { PlasticCard newPlasticCard = new PlasticCard() { Name = name, BankAccount = BankAccount, CardHolder = CardHolder, CardNumber = CardNumber, Date = Date, Currency = currency, AccountAmount = Amount }; { //Добавление в XML файл XmlElement xmlAccount = XmlAccountsDocument.CreateElement("account"); XmlAttribute attributeType = XmlAccountsDocument.CreateAttribute("type"); attributeType.Value = "PlasticCard"; xmlAccount.Attributes.Append(attributeType); XmlElement XmlName = XmlAccountsDocument.CreateElement("name"); XmlName.InnerText = newPlasticCard.Name; XmlElement XmlBankAccount = XmlAccountsDocument.CreateElement("BankAccount"); XmlBankAccount.InnerText = newPlasticCard.BankAccount; XmlElement XmlCardHolder = XmlAccountsDocument.CreateElement("CardHolder"); XmlCardHolder.InnerText = newPlasticCard.CardHolder; XmlElement XmlCardNumber = XmlAccountsDocument.CreateElement("CardNumber"); XmlCardNumber.InnerText = newPlasticCard.CardNumber; XmlElement XmlDate = XmlAccountsDocument.CreateElement("date"); XmlDate.InnerText = newPlasticCard.Date; XmlElement XmlCurrency = XmlAccountsDocument.CreateElement("currency"); XmlCurrency.InnerText = newPlasticCard.Currency.ToString(); XmlElement XmlAmount = XmlAccountsDocument.CreateElement("Amount"); XmlAmount.InnerText = newPlasticCard.AccountAmount.ToString(); xmlAccount.AppendChild(XmlName); xmlAccount.AppendChild(XmlBankAccount); xmlAccount.AppendChild(XmlCardHolder); xmlAccount.AppendChild(XmlCardNumber); xmlAccount.AppendChild(XmlDate); xmlAccount.AppendChild(XmlCurrency); xmlAccount.AppendChild(XmlAmount); XmlAccountsDocument.DocumentElement.AppendChild(xmlAccount); //Добавление ссылки на представление карты в XML в структуру newPlasticCard.PlasticCardInXml = xmlAccount; } List_PlasticCards.Add(newPlasticCard); }
private void информацияОКартеToolStripMenuItem_Click(object sender, EventArgs e) { //Вывести информацию по карте PlasticCard cardInfo = Accounts.PlasticCards.GetPlasticCardByTile(tile); FinanceManager.Forms.InformationsForms.Show_CardInfo InfoForm = new Forms.InformationsForms.Show_CardInfo( cardInfo.CardNumber, cardInfo.Date, cardInfo.CardHolder, "123", cardInfo.AccountAmount, cardInfo.Currency.ToString() ); InfoForm.ShowDialog(); }
/// <summary> /// Зачислить средства на карту /// </summary> /// <param name="cardName">Наименование карты</param> /// <param name="value">Количество денег</param> /// <param name="type">Валюта</param> public static void AddToCard(string cardName, decimal value, CurrencyType type) { int index = GetCardIndexByName(cardName); if (List_PlasticCards[index].Currency == type) { //Валюты совпадают, не нужно конвертировать курс PlasticCard buffer = List_PlasticCards[index]; buffer.AccountAmount += value; List_PlasticCards[index] = buffer; List_PlasticCards[index].UpdateXmlAmount(); } else { //Нужно конвертировать курс throw new Exception("Currency not equal"); } }
/// <summary> /// Вычесть из карты средства /// </summary> /// <param name="cardName">Наименование карты</param> /// <param name="value">Количество денег</param> /// <param name="type">Валюта</param> public static void WithdrawFromCard(string cardName, decimal value, CurrencyType type) { int index = GetCardIndexByName(cardName); if (List_PlasticCards[index].Currency == type) { //Валюты совпадают, не нужно конвертировать курс #warning "ПОДУМАТЬ НАД ЭТИМ БАГОМ ИЗМЕНЕНИЯ ЗНАЧЕНИЯ ПЕРЕМЕННОЙ" PlasticCard buffer = List_PlasticCards[index]; buffer.AccountAmount -= value; List_PlasticCards[index] = buffer; List_PlasticCards[index].UpdateXmlAmount(); } else { //Нужно конвертировать курс throw new Exception("Currency not equal"); } }
/// <summary> /// Загрузка информации о счетах, карточках, кошельках и т.д. из файла /// </summary> public static void Init() { if (!File.Exists(Properties.Resources.AccountsFile)) { StreamWriter fileWriter = File.CreateText(Properties.Resources.AccountsFile); fileWriter.WriteLine("<?xml version=\"1.0\"?>\n<accounts>\n</accounts> "); fileWriter.Close(); } XmlAccountsDocument.Load(Properties.Resources.AccountsFile); foreach (XmlNode node in XmlAccountsDocument.DocumentElement) { switch (node.Attributes["type"].Value) { case "Bank": { BankAccount newAccount = new BankAccount(); newAccount.AccountName = node.ChildNodes[0].InnerText; newAccount.AccountNumber = node.ChildNodes[1].InnerText; Enum.TryParse(node.ChildNodes[2].InnerText, out newAccount.Currency); newAccount.AccountAmount = decimal.Parse(node.ChildNodes[3].InnerText); List_BankAccounts.Add(newAccount); TileManager.BankAccountsTab.AddTile(newAccount.AccountName); break; } case "PlasticCard": { PlasticCard newCard = new PlasticCard(); newCard.Name = node.ChildNodes[0].InnerText; newCard.BankAccount = node.ChildNodes[1].InnerText; newCard.CardHolder = node.ChildNodes[2].InnerText; newCard.CardNumber = node.ChildNodes[3].InnerText; newCard.Date = node.ChildNodes[4].InnerText; newCard.PlasticCardInXml = node; Enum.TryParse(node.ChildNodes[5].InnerText, out newCard.Currency); newCard.AccountAmount = decimal.Parse(node.ChildNodes[6].InnerText); List_PlasticCards.Add(newCard); TileManager.PlasticCardsTab.AddTile(newCard.Name); break; } case "Crypto": { CryptoWallet newCryptoWallet = new CryptoWallet(); newCryptoWallet.Name = node.ChildNodes[0].InnerText; newCryptoWallet.WalletID = node.ChildNodes[1].InnerText; newCryptoWallet.WalletAddress = node.ChildNodes[2].InnerText; newCryptoWallet.WalletPassword = node.ChildNodes[3].InnerText; Enum.TryParse(node.ChildNodes[4].InnerText, out newCryptoWallet.CryptoCurrency); List_CryptoWallets.Add(newCryptoWallet); break; } case "Other": { OtherAccount newOtherAccount = new OtherAccount(); newOtherAccount.AccountName = node.ChildNodes[0].InnerText; Enum.TryParse(node.ChildNodes[1].InnerText, out newOtherAccount.Currency); newOtherAccount.AccountAmount = decimal.Parse(node.ChildNodes[2].InnerText); List_OtherAccounts.Add(newOtherAccount); break; } } } }