/// <summary> /// Dodaje obiekt karty i obiekt jej właściciela /// </summary> /// <param name="clientNr">Id klienta</param> /// <param name="type">Typ karty</param> /// <param name="bankName">Nazwa banku</param> /// <param name="name">Podpis klienta</param> /// <param name="clientType">Typ klienta</param> /// <returns>Obiekt karty</returns> internal Card AddCardWithOwnerRequest(string clientNr, CardType type, string bankName, string name, ClientType clientType) { Card card = null; int bankId = FindBankByName(bankName); Client client = null; switch (clientType) { case ClientType.NaturalPerson: client = new NaturalPerson(name, clientNr); break; case ClientType.ServiceCompany: client = new ServiceCompany(name, clientNr); break; case ClientType.Shop: client = new Shop(name, clientNr); break; case ClientType.TransportCompany: client = new TransportCompany(name, clientNr); break; } foreach (var bank in bankList) { if (bankId == bank.Id) { card = bank.AddCard(client, type); break; } } return(card); }
/// <summary> /// Odczytuje stan systemu z pliku o podanej ścieżce. /// UWAGA: Obecny stan systemu zostanie utracony na rzecz nowego stanu /// </summary> /// <param name="filePath">Ścieżka do pliku do odczytania</param> /// <returns>Zwraca true, jeżeli udało się poprawnie załadować stan systemu, a false, jeżeli wystąpił błąd</returns> internal bool LoadSystemState(string filePath) { Stream fileStream = FileHandling.GetReadingStream(filePath); if (fileStream == null) { throw new NoSuchFileException("Nie znaleziono podanego pliku do czytania", filePath); } // Czyszczenie listy banków bankList.Clear(); // XMLParser (reader) using (XmlReader reader = XmlReader.Create(fileStream)) { string currentBankName = null, currentBankId = null; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "bank") { currentBankName = reader.GetAttribute("name"); currentBankId = reader.GetAttribute("id"); CreateBankIfNotExists(currentBankName, currentBankId); } if (reader.NodeType == XmlNodeType.Element && reader.Name == "card") { if (reader.HasAttributes) { string clientName, clientNumber, cardNumber, cardLimitString; decimal cardLimit = 0, balance = 0; bool isActive = false; ClientType clientType; CardType cardType; //TODO: dodać wczytywanie isActive i balance clientName = reader.GetAttribute("ownerName"); clientNumber = reader.GetAttribute("ownerNumber"); clientType = (ClientType)int.Parse(reader.GetAttribute("ownerType")); cardNumber = reader.GetAttribute("number"); cardType = (CardType)int.Parse(reader.GetAttribute("cardType")); cardLimitString = reader.GetAttribute("cardLimit"); isActive = bool.Parse(reader.GetAttribute("isActive")); balance = decimal.Parse(reader.GetAttribute("balance")); if (cardLimitString != null) { cardLimit = decimal.Parse(cardLimitString); } Client owner; if (clientType == ClientType.NaturalPerson) { owner = new NaturalPerson(clientName, clientNumber); } else if (clientType == ClientType.ServiceCompany) { owner = new ServiceCompany(clientName, clientNumber); } else if (clientType == ClientType.Shop) { owner = new Shop(clientName, clientNumber); } else if (clientType == ClientType.ServiceCompany) { owner = new ServiceCompany(clientName, clientNumber); } else { continue; } Card newCard; if (cardType == CardType.CreditCard) { newCard = new CreditCard(cardNumber, owner, isActive, balance, cardLimit); } else if (cardType == CardType.DebitCard) { newCard = new DebitCard(cardNumber, owner, isActive, balance); } else if (cardType == CardType.ATMCard) { newCard = new ATMCard(cardNumber, owner, isActive, balance); } else { continue; } CreateBankIfNotExists(currentBankName, currentBankId); AddNewCardRequest(newCard, int.Parse(currentBankId)); } } if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "bank") { currentBankName = null; currentBankId = null; } } } // .... return(true); }