コード例 #1
0
        public void lapdisplay1()
        {
            int    price   = 0;
            int    qty     = 0;
            String user_id = Console.ReadLine();

            Console.Clear();
            XElement xelement = XElement.Load("Laptop.xml");
            IEnumerable <XElement> Laptops = xelement.Elements();
            var x = from Laptop in xelement.Elements("Laptop")
                    where (string)Laptop.Element("ID") == user_id
                    select Laptop;

            Console.WriteLine("---------------------------Your Selection-----------------------------");
            Console.WriteLine();
            foreach (XElement lap in x)
            {
                String id           = lap.Element("ID").Value;
                String brandname    = lap.Element("brand").Value;
                String price_detail = lap.Element("price").Value;
                String model_detail = lap.Element("model").Value;

                price = Convert.ToInt32(price_detail);

                Console.WriteLine("Id: {0}", id);
                Console.WriteLine("Brand: {0}", brandname);
                Console.WriteLine("Model: {0}", model_detail);
                Console.WriteLine("Price: Rs. {0}", price_detail);
                Console.WriteLine("----------------------------------------------------------------------");
            }
            String user_choice;

            do
            {
                Console.WriteLine("Enter the Quantity Required");
                qty = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Total Price: Rs. {0}", qty * price);

                Console.WriteLine();
                Console.WriteLine("Do you want to Change quantity? (y/n)");
                user_choice = Console.ReadLine();
                Console.WriteLine();

                if (user_choice == "n")
                {
                    Console.WriteLine("Thank you for visiting us...");
                }

                while ((user_choice != "y") && (user_choice != "n"))
                {
                    Console.WriteLine();
                    Console.WriteLine("Invalid Option. Please Choose 'y' or 'n'");
                    user_choice = Console.ReadLine();
                }
            } while (user_choice == "y");
        }
コード例 #2
0
        public void delete()
        {
            Console.Write("Enter the LAPTOP_ID to be deleted :");
            String user_id = Console.ReadLine();

            XElement xelement = XElement.Load("Laptop.xml");
            IEnumerable <XElement> Laptops = xelement.Elements();
            var x = from Laptop in xelement.Elements("Laptop")
                    where (string)Laptop.Element("ID") == user_id
                    select Laptop;

            x.Remove();
            xelement.Save("Laptop.xml");
            Console.WriteLine("The Laptop_ID " + user_id + "is deleted Successfully");
        }
コード例 #3
0
        public void edit()
        {
            Console.Write("Enter the Id to be edited :");
            String user_id = Console.ReadLine();

            Console.Write("Enter the new updated price of the  " + user_id + "  :");
            String pricenew = Console.ReadLine();

            XElement xelement = XElement.Load("Laptop.xml");
            IEnumerable <XElement> Laptops = xelement.Elements();
            var x = from Laptop in xelement.Elements("Laptop")
                    where (string)Laptop.Element("ID") == user_id
                    select Laptop;

            foreach (XElement id in x)
            {
                String price_detail = id.Element("price").Value;

                id.SetElementValue("price", pricenew);
            }
            xelement.Save("Laptop.xml");
            Console.WriteLine("Editing done");
        }