Пример #1
0
 public static void addXML()
 {
     string fileName = "rent.xml";
     Rent rent = new Rent();
     Console.WriteLine("Input please second name of owner");
     String name = Console.ReadLine();
     rent.OwnerSecondName = name;
     Console.WriteLine("Input please phone of owner");
     String phone = Console.ReadLine();
     rent.PhoneOwner = phone;
     Console.WriteLine("Input please district");
     String district = Console.ReadLine();
     rent.District = district;
     Console.WriteLine("Input please street");
     String street = Console.ReadLine();
     rent.Street = street;
     Console.WriteLine("Input please number of house");
     int house = Int32.Parse(Console.ReadLine());
     rent.House = house;
     Console.WriteLine("Input please number of flat");
     int flat = Int32.Parse(Console.ReadLine());
     rent.Flat = flat;
     Console.WriteLine("Input please square");
     int square = Int32.Parse(Console.ReadLine());
     rent.Square = square;
     Console.WriteLine("Input please cout of room");
     int countRoom = Int32.Parse(Console.ReadLine());
     rent.CountRoom = countRoom;
     Console.WriteLine("Input please time of rent");
     int timeRent = Int32.Parse(Console.ReadLine());
     rent.TimeRent = timeRent;
     Console.WriteLine("Input please price");
     int price = Int32.Parse(Console.ReadLine());
     rent.Price = price;
     rent.CountView = 0;
     XDocument doc = XDocument.Load(fileName);
     int maxId = doc.Root.Elements("RentAppartment").Max(t => Int32.Parse(t.Attribute("RentAppartmentId").Value));
     XElement newRent = new XElement("RentAppartment",
     new XAttribute("RentAppartmentId", ++maxId),
     new XElement("OwnerSecondName", rent.OwnerSecondName),
     new XElement("PhoneOwner", rent.PhoneOwner),
     new XElement("Adress", new XAttribute("Street", rent.Street), new XAttribute("House", rent.House), new XAttribute("Flat", rent.Flat)),
     new XElement("District", rent.District),
     new XElement("Square", rent.Square),
     new XElement("CountRoom", rent.CountRoom),
     new XElement("TimeRent", rent.TimeRent),
     new XElement("Price", rent.Price),
     new XElement("CountView", rent.CountView));
     doc.Root.Add(newRent);
     doc.Save(fileName);
 }
Пример #2
0
        public static List<Rent> readXML()
        {
            string fileName = "rent.xml";
            XDocument doc = XDocument.Load(fileName);
            foreach (XElement el in doc.Root.Elements())
            {

            Rent obj = new Rent();
            obj.OwnerSecondName = (el.Attribute("RentAppartmentId").Value);
            obj.PhoneOwner = (el.Element("PhoneOwner").Value);
            obj.Street = (el.Element("Adress").Attribute("Street").Value);
            obj.House = (Int32.Parse(el.Element("Adress").Attribute("House").Value));
            obj.Flat = (Int32.Parse(el.Element("Adress").Attribute("Flat").Value));
            obj.District = (el.Element("District").Value);
            obj.Square = (Int32.Parse(el.Element("Square").Value));
            obj.CountRoom = (Int32.Parse(el.Element("CountRoom").Value));
            obj.TimeRent = (Int32.Parse(el.Element("TimeRent").Value));
            obj.Price = (Int32.Parse(el.Element("Price").Value));
            obj.CountView = (Int32.Parse(el.Element("CountView").Value));

            Client.rents.Add(obj);
            }
            return Client.rents;
        }
Пример #3
0
        public static void saveRent()
        {
            Rent rent = new Rent();
            Console.WriteLine("Input please id of rent");
            int id = Int32.Parse(Console.ReadLine());
            foreach (Rent rnt in Client.rents)
            {
                if (rnt.Id == id)
                    rent = rnt;

            }
            string s = rent.ToString();
            StringBuilder directory = new StringBuilder();
            directory.Append("D:\\");
            Console.WriteLine("Input name of file");
            directory.Append(Console.ReadLine());
            directory.Append(".txt");
            StreamWriter SW = new StreamWriter(new FileStream(directory.ToString(), FileMode.Create, FileAccess.Write));
            SW.Write(s);
            SW.Close();
        }