Example #1
0
        /// <summary>
        /// Dodaj nowa/istniejaca karte do banku
        /// </summary>
        /// <param name="owner">Użytkownik żądający dodania</param>
        /// <param name="type">Typ dodawanej karty</param>
        /// <returns>
        /// Obiekt utworzonej karty
        /// </returns>
        internal Card AddCard(Client owner, CardType type, decimal debit = 1000)
        {
            if (owner == null)
            {
                throw new NullUserException("Nie podano użytkownika");
            }
            string number = GenerateCardNumber(type);
            Card   card   = null;

            switch (type)
            {
            case CardType.CreditCard:
                card = new CreditCard(number, owner, debit);
                break;

            case CardType.DebitCard:
                card = new DebitCard(number, owner);
                break;

            case CardType.ATMCard:
                card = new ATMCard(number, owner);
                break;
            }
            Cards.Add(card);
            return(card);
        }
Example #2
0
        /// <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);
        }