Пример #1
0
        private void dgProp_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            ViewProp prop = dgProp.CurrentItem as ViewProp;

            if (prop != null)
            {
                selected = db.Properties.Find(prop.Id);

                cbMarket.Text     = selected.Market.Name;
                cbTypes.Text      = selected.Types.Name;
                tbarea.Text       = selected.Area.ToString();
                tbrooms.Text      = selected.Rooms.ToString();
                cbDistricts.Text  = selected.District.Name;
                tbAdress.Text     = selected.Address;
                cbSettlemets.Text = selected.Settlement1.Name;
                tbPrice.Text      = ((decimal)selected.Price).ToString("#");
                cbOwners.Text     = selected.Owners.Name;

                if (selected.Status == 1)
                {
                    statusbox.IsChecked = true;
                }
                else
                {
                    statusbox.IsChecked = false;
                }
            }

            btnAddProp.Visibility    = Visibility.Hidden;
            btnUpdateProp.Visibility = Visibility.Visible;
        }
Пример #2
0
        private void dgSearch_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            ViewProp prop = dgSearch.CurrentItem as ViewProp;

            if (prop != null)
            {
                selected = db.Properties.Find(prop.Id);
                MessageBox.Show(selected.Owners.Phone);
            }
        }
Пример #3
0
        private void btnNewProp_Click(object sender, RoutedEventArgs e)
        {
            string  make       = cbMarket.Text;
            string  type       = cbTypes.Text;
            int     area       = Convert.ToInt32(tbarea.Text);
            int     rooms      = Convert.ToInt32(tbrooms.Text);
            string  district   = cbDistricts.Text;
            string  adress     = tbAdress.Text;
            string  settlement = cbSettlemets.Text;
            decimal price      = Convert.ToDecimal(tbPrice.Text);
            string  owner      = cbOwners.Text;
            byte    status     = 0;

            if (statusbox.IsChecked == true)
            {
                status = 1;
            }

            if (cbMarket.Text == string.Empty || cbTypes.Text == string.Empty || tbarea.Text == string.Empty || tbrooms.Text == string.Empty || cbDistricts.Text == string.Empty || tbAdress.Text == string.Empty || cbSettlemets.Text == string.Empty || tbPrice.Text == string.Empty || cbOwners.Text == string.Empty)
            {
                MessageBox.Show("Fill all Fields");
                return;
            }

            Model.Properties add = new Model.Properties
            {
                MarketId   = db.Market.FirstOrDefault(o => o.Name == make).id,
                TypeId     = db.Types.FirstOrDefault(o => o.Name == type).id,
                Area       = area,
                Rooms      = rooms,
                DistrictId = db.District.FirstOrDefault(o => o.Name == district).id,
                Address    = adress,
                Settlement = db.Settlement.FirstOrDefault(o => o.Name == settlement).id,
                Price      = price,
                Owner      = db.Owners.FirstOrDefault(o => o.Name == owner).id,
                Status     = status
            };

            db.Properties.Add(add);
            db.SaveChanges();
            FillProperties();

            cbMarket.Text             = "";
            cbTypes.Text              = "";
            tbarea.Text               = "";
            tbrooms.Text              = "";
            cbDistricts.Text          = "";
            tbAdress.Text             = "";
            cbSettlemets.Text         = "";
            tbPrice.Text              = "";
            cbOwners.Text             = "";
            statusbox.IsChecked       = false;
            lblPhoneNumber.Visibility = Visibility.Hidden;
        }
Пример #4
0
        private void btnUpdateProp_Click(object sender, RoutedEventArgs e)
        {
            string  make       = cbMarket.Text;
            string  type       = cbTypes.Text;
            int     area       = Convert.ToInt32(tbarea.Text);
            int     rooms      = Convert.ToInt32(tbrooms.Text);
            string  district   = cbDistricts.Text;
            string  adress     = tbAdress.Text;
            string  settlement = cbSettlemets.Text;
            decimal price      = Convert.ToDecimal(tbPrice.Text);
            string  owner      = cbOwners.Text;
            byte    status     = 0;

            if (statusbox.IsChecked == true)
            {
                status = 1;
            }

            if (cbMarket.Text == string.Empty || cbTypes.Text == string.Empty || tbarea.Text == string.Empty || tbrooms.Text == string.Empty || cbDistricts.Text == string.Empty || tbAdress.Text == string.Empty || cbSettlemets.Text == string.Empty || tbPrice.Text == string.Empty || cbOwners.Text == string.Empty)
            {
                MessageBox.Show("There is an empty field. That's not OK for us ;)");
                return;
            }

            selected.MarketId   = db.Market.FirstOrDefault(o => o.Name == make).id;
            selected.TypeId     = db.Types.FirstOrDefault(o => o.Name == type).id;
            selected.Area       = area;
            selected.Rooms      = rooms;
            selected.DistrictId = db.District.FirstOrDefault(o => o.Name == district).id;
            selected.Address    = adress;
            selected.Settlement = db.Settlement.FirstOrDefault(o => o.Name == settlement).id;
            selected.Price      = price;
            selected.Owner      = db.Owners.FirstOrDefault(o => o.Name == owner).id;
            selected.Status     = status;
            db.SaveChanges();
            this.selected = null;
            FillProperties();

            btnUpdateProp.Visibility  = Visibility.Hidden;
            btnAddProp.Visibility     = Visibility.Visible;
            lblPhoneNumber.Visibility = Visibility.Hidden;
        }