Beispiel #1
0
        public static decimal Buy()
        {
            AccountUser au       = new AccountUser();
            string      mainFile = @"products.xml";
            decimal     result   = 0;
            decimal     money    = au.GetBalance();

            if (money == 0 || money < 0)
            {
                Console.WriteLine("Pls take credit");
            }
            else if (!File.Exists(mainFile))
            {
                Console.WriteLine("Seller did not add products!");
                Console.ReadKey();
            }
            else
            {
                Info      info = new Info();
                XDocument doc  = XDocument.Load(mainFile);

                Console.Write("Id: ");
                info.Id = Convert.ToInt32(Console.ReadLine());
                Console.Write("Category: ");
                info.Category = Console.ReadLine();

                var node = from product in doc.Descendants("Product")
                           where (string)product.Attribute("id") == "" + info.Id && (string)product.Attribute("category") == "" + info.Category
                           select new
                {
                    id       = product.Attribute("id").Value,
                    category = product.Attribute("category").Value,
                    title    = product.Element("title").Value,
                    price    = product.Element("price").Value,
                    weight   = product.Element("description").Element("weight").Value
                };

                Console.WriteLine("You buy product or products...\n");
                foreach (var nod in node)
                {
                    Console.WriteLine("Id: " + nod.id);
                    Console.WriteLine("Category: " + nod.category);
                    Console.WriteLine("Title: " + nod.title);
                    Console.WriteLine("Price: " + nod.price + " RUB");
                    Console.WriteLine("Weight: " + nod.weight);
                    result = Convert.ToDecimal(nod.price);
                }
                doc.Element("Products")
                .Descendants("Product")
                .Where(x => (string)x.Attribute("id") == "" + info.Id && (string)x.Attribute("category") == "" + info.Category)
                .Remove();

                doc.Save(mainFile);

                var docA = new XmlDocument();
                docA.Load(mainFile);

                var nodeA = docA.SelectSingleNode("Products/Product");

                if (nodeA == null)
                {
                    File.Delete(mainFile);
                }
                else
                {
                    Console.WriteLine("O_o");
                }

                /*IEnumerable<string element = xDoc.Element("Products").Descendants("Product")
                 * .Where(x => (string)x.Attribute("id") == "" + info.Id && (string)x.Attribute("category") == "" + info.Category)
                 * .Select(r => r.Element("Price")).Value;*/

                Console.ReadKey();
            }
            return(result);
        }
Beispiel #2
0
        static void GetCredit()
        {
            AccountUser au = new AccountUser();

            au.ShowCredit();
        }
Beispiel #3
0
        static void Buy()
        {
            AccountUser au = new AccountUser();

            au.BuyProducts();
        }
Beispiel #4
0
        static void BankUser()
        {
            Bank au = new AccountUser();

            au.Print();
        }