Ejemplo n.º 1
0
        private void SaveDataGridChanges(object sender, RoutedEventArgs e)
        {
            if (!(clientID.Text != "" && realtorID.Text != "" && type.Text != ""))
            {
                MessageBox.Show("Поля 'Клиент', 'Риэлтор', 'Тип недвижимости' обязательны к заполнению. ");
                return;
            }

            int    clientId  = Convert.ToInt32(clientID.Text);
            int    realtorId = Convert.ToInt32(realtorID.Text);
            string Type      = type.Text;
            string Address   = String.IsNullOrEmpty(address.Text) ? "" : address.Text;
            int    MinPrice  = String.IsNullOrEmpty(minPrice.Text) ? 0 : Convert.ToInt32(minPrice.Text);
            int    MaxPrice  = String.IsNullOrEmpty(maxPrice.Text) ? 0 : Convert.ToInt32(maxPrice.Text);



            Demand demand = new Demand(typeDemand);

            switch (typeDemand)
            {
            case "Квартира":
                demand.Update(clientId, realtorId, Type, Address, MinPrice, MaxPrice, demandID);

                int     apartmentMinFloorsU = String.IsNullOrEmpty(apartmentMinFloor.Text) ? 0 : Convert.ToInt32(apartmentMinFloor.Text);
                int     apartmentMaxFloorsU = String.IsNullOrEmpty(apartmentMaxFloor.Text) ? 0 : Convert.ToInt32(apartmentMaxFloor.Text);
                decimal apartmentMinAreaU   = String.IsNullOrEmpty(apartmentMinArea.Text) ? 0 : Convert.ToDecimal(apartmentMinArea.Text);
                decimal apartmentMaxAreaU   = String.IsNullOrEmpty(apartmentMaxArea.Text) ? 0 : Convert.ToDecimal(apartmentMaxArea.Text);
                int     apartmentMinRoomsU  = String.IsNullOrEmpty(apartmentMinRooms.Text) ? 0 : Convert.ToInt32(apartmentMinRooms.Text);
                int     apartmentMaxRoomsU  = String.IsNullOrEmpty(apartmentMaxRooms.Text) ? 0 : Convert.ToInt32(apartmentMaxRooms.Text);

                demand.UpdateApartment(apartmentMinFloorsU, apartmentMaxFloorsU, apartmentMinAreaU, apartmentMaxAreaU, apartmentMinRoomsU, apartmentMaxRoomsU, demandID);
                break;

            case "Дом":
                demand.Update(clientId, realtorId, Type, Address, MinPrice, MaxPrice, demandID);

                int     houseMinFloorsU = String.IsNullOrEmpty(houseMinFloors.Text) ? 0 : Convert.ToInt32(houseMinFloors.Text);
                int     houseMaxFloorsU = String.IsNullOrEmpty(houseMaxFloors.Text) ? 0 : Convert.ToInt32(houseMaxFloors.Text);
                decimal houseMinAreaU   = String.IsNullOrEmpty(houseMinArea.Text) ? 0 : Convert.ToDecimal(houseMinArea.Text);
                decimal houseMaxAreaU   = String.IsNullOrEmpty(houseMaxArea.Text) ? 0 : Convert.ToDecimal(houseMaxArea.Text);
                int     houseMinRoomsU  = String.IsNullOrEmpty(houseMinRooms.Text) ? 0 : Convert.ToInt32(houseMinRooms.Text);
                int     houseMaxRoomsU  = String.IsNullOrEmpty(houseMaxRooms.Text) ? 0 : Convert.ToInt32(houseMaxRooms.Text);

                demand.UpdateHouse(houseMinFloorsU, houseMaxFloorsU, houseMinAreaU, houseMaxAreaU, houseMinRoomsU, houseMaxRoomsU, demandID);
                break;

            case "Земля":
                demand.Update(clientId, realtorId, Type, Address, MinPrice, MaxPrice, demandID);

                decimal landMinAreaU = String.IsNullOrEmpty(landMinArea.Text) ? 0 : Convert.ToDecimal(landMinArea.Text);
                decimal landMaxAreaU = String.IsNullOrEmpty(landMaxArea.Text) ? 0 : Convert.ToDecimal(landMaxArea.Text);

                demand.UpdateLand(landMinAreaU, landMaxAreaU, demandID);
                break;
            }

            demandDataGrid.ItemsSource = demand.GetData();

            MessageBox.Show("Успешно");
        }