Example #1
0
        public static void Action(User user)
        {
            bool flag = true;
            XmlParser xmlp = new XmlParser();
            user.Сalculation();
            xmlp.UpdateUser(user, "../../xmls/Users.xml", "user", "id", user.GetId().ToString());
            do
            {
                switch (Menu())
                {
                    case 1:
                        Console.WriteLine("Сумма:" + user.showCashAmount());
                        HistoryUnit log = new HistoryUnit();
                        log.Date = DateTime.Today;
                        log.Operation = "Запрос баланса пользователем";

                        xmlp.UpdateUserHistory(log, user.fio);

                        break;
                    case 2:
                        Console.WriteLine("Введите сумму, которую хотите добавить ");
                        double money = Double.Parse(Console.ReadLine());
                        user.addFund(money);

                        HistoryUnit log2 = new HistoryUnit();
                        log2.Date = DateTime.Today;
                        log2.Operation = "Зачислено " + money + " денежных единиц на счёт";

                        xmlp.UpdateUserHistory(log2, user.fio);
                        xmlp.UpdateUser(user, "../../xmls/Users.xml", "user", "id", user.GetId().ToString());
                        break;
                    case 3:
                        Console.WriteLine("Введите сумму, которую хотите снять ");
                        double moneyOut = Double.Parse(Console.ReadLine());
                        user.getProfit(moneyOut);

                        HistoryUnit log3 = new HistoryUnit();
                        log3.Date = DateTime.Today;
                        log3.Operation = "Снято " + moneyOut + " денежных единиц со счёта";

                        xmlp.UpdateUserHistory(log3, user.fio);

                        xmlp.UpdateUser(user, "../../xmls/Users.xml", "user", "id", user.GetId().ToString());

                        
                        break;
                    case 4:
                        Console.WriteLine("Выписка: ");

                        foreach (HistoryUnit hu in xmlp.ReadUserHistory(user.fio))
                        {
                            if (hu.Date >= DateTime.Today.AddMonths(-1))
                            {
                                System.Console.WriteLine("\n");
                                System.Console.WriteLine(hu.Date);
                                System.Console.WriteLine(hu.Operation);
                                System.Console.WriteLine("===================");
                            }
                        }

                        break;
                    case 5: 
                        Console.WriteLine("Вы действительно хотите закрыть свой депозит???  1 - Да 2 - Нет. ");
                        int decision = Int32.Parse(Console.ReadLine());
                        if (decision == 1)
                        {
                            xmlp.DeleteRootInFileByRootnameAndId("../../xmls/Users.xml", "user", "id", user.GetId().ToString());
                            flag = false;                           
                        }
                        else break;
                        break;
                    case 0:
                        flag = false;
                        break;
                }


            } while (flag);

        }
Example #2
0
        public void UpdateUserHistory(HistoryUnit hu, String FIO)
        {
            XDocument doc = XDocument.Load(historyFile);

            XElement user = new XElement("user",
                new XElement("FIO", FIO),
                new XElement("operation", hu.Operation),
                new XElement("date", hu.Date));
            doc.Root.Add(user);
            doc.Save(historyFile);

        }
Example #3
0
        public List<HistoryUnit> ReadUserHistory(String fio)
        {
            XDocument doc = XDocument.Load(historyFile);

            List<HistoryUnit> history = new List<HistoryUnit>();
            XNode node = doc.Root.FirstNode;

            while (node != null)
            {
                if (node.NodeType == System.Xml.XmlNodeType.Element)
                {
                    HistoryUnit hu = new HistoryUnit();
                    XElement el = (XElement)node;

                    hu.Date = DateTime.Parse(el.Element("date").Value);
                    hu.Operation = el.Element("operation").Value;

                    if (el.Element("FIO").Value.Equals(fio))
                    {
                        history.Add(hu);
                    }
                }
                node = node.NextNode;
            }
            return history;

        }
Example #4
0
        public double showCashAmount()
        {
            HistoryUnit log = new HistoryUnit();
            log.Date = DateTime.Today;
            log.Operation = "Пользователь запросил состояние баланса ";
             return summa;


        }