Exemplo n.º 1
0
        private void btnSelect_Click(object sender, EventArgs e)
        {
            DataGridViewRow row       = (DataGridViewRow)dgvRooms.Rows[dgvRooms.SelectedCells[0].RowIndex];
            Apartment       apartment = new Apartment();

            apartment.Id     = short.Parse(row.Cells[0].Value.ToString()); //gets the reservation_apartment_id
            apartment.Number = short.Parse(row.Cells[2].Value.ToString());
            ApartmentCategory apartmentCategory = new ApartmentCategory();

            apartmentCategory.Title     = row.Cells[3].Value.ToString();
            apartment.ApartmentCategory = apartmentCategory;
            this.Apartment = apartment;
            this.Close();
        }
Exemplo n.º 2
0
        public void RemoveElement(ApartmentCategory apartmentCategory)
        {
            Type fileType = apartmentCategory.GetType();

            var reader = new XmlApartmentCategoryReader(this._filePath);

            _ = reader.Exist(apartmentCategory) ? "Delete this one" : throw new ArgumentException($"There is no the same {fileType.Name}.");

            XmlElement xRoot = this.Xml.DocumentElement;
            XmlNode    child = xRoot.SelectSingleNode(fileType.Name + $"[Id='{fileType.GetProperty("Id").GetValue(apartmentCategory)}']");

            this.Xml.DocumentElement.RemoveChild(child);

            this.Xml.Save(this._filePath);
        }
Exemplo n.º 3
0
        private void btnSelect_Click(object sender, EventArgs e)
        {
            DataGridViewRow row       = (DataGridViewRow)dgvRooms.Rows[dgvRooms.SelectedCells[0].RowIndex];
            Apartment       apartment = new Apartment();

            apartment.Id     = short.Parse(row.Cells[0].Value.ToString());
            apartment.Number = short.Parse(row.Cells[1].Value.ToString());
            apartment.Value  = this.Value;
            ApartmentCategory apartmentCategory = new ApartmentCategory();

            apartmentCategory.Title        = row.Cells[2].Value.ToString();
            apartmentCategory.RoomCapacity = byte.Parse(row.Cells[3].Value.ToString());
            apartment.ApartmentCategory    = apartmentCategory;
            Globals.apartments.Add(apartment);
            this.Close();
        }
Exemplo n.º 4
0
        public void AppendElement(ApartmentCategory apartmentCategory)
        {
            Type fileType = apartmentCategory.GetType();

            XmlApartmentCategoryReader reader = new XmlApartmentCategoryReader(this._filePath);

            _ = reader.Exist(apartmentCategory) ? throw new ArgumentException($"The same {fileType.Name} already exists.") : "Create new one";

            XmlElement newElement = this.Xml.CreateElement(string.Empty, fileType.Name, string.Empty);

            _ = this.Xml.DocumentElement?.AppendChild(newElement) ?? throw new ArgumentException("There is no root in xml file");

            foreach (var propertyInfo in fileType.GetProperties())
            {
                XmlElement child     = this.Xml.CreateElement(string.Empty, propertyInfo.Name, string.Empty);
                XmlText    childText = this.Xml.CreateTextNode(propertyInfo.GetValue(apartmentCategory).ToString());
                child.AppendChild(childText);
                newElement.AppendChild(child);
            }

            this.Xml.Save(this._filePath);
        }