コード例 #1
0
ファイル: Pendrive.cs プロジェクト: adharsh8/C-
        public void pendrivedisplay1()
        {
            int    price   = 0;
            int    qty     = 0;
            String user_id = Console.ReadLine();

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

            Console.WriteLine("---------------------------Your Selection-----------------------------");
            Console.WriteLine();
            foreach (XElement pendrive in x)
            {
                String id           = pendrive.Element("ID").Value;
                String brandname    = pendrive.Element("brand").Value;
                String price_detail = pendrive.Element("price").Value;
                String model_detail = pendrive.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
ファイル: Pendrive.cs プロジェクト: adharsh8/C-
        public void delete()
        {
            Console.Write("Enter the PENDRIVE_ID to be deleted :");
            String user_id = Console.ReadLine();

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

            x.Remove();
            xelement.Save("Pendrive.xml");
            Console.WriteLine("The PENDRIVE_ID " + user_id + "is deleted Successfully");
        }
コード例 #3
0
ファイル: Pendrive.cs プロジェクト: adharsh8/C-
        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("Pendrive.xml");
            IEnumerable <XElement> Pendrives = xelement.Elements();
            var x = from Pendrive in xelement.Elements("Pendrive")
                    where (string)Pendrive.Element("ID") == user_id
                    select Pendrive;

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

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