Esempio n. 1
0
        private void GridDeal_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            try
            {
                using (ModelBD model = new ModelBD())
                {
                    if (GridDeal.SelectedItems.Count > 0)
                    {
                        for (int i = 0; i < GridDeal.SelectedItems.Count; i++)
                        {
                            DopDeal      deal   = GridDeal.SelectedItems[i] as DopDeal;
                            ChangeWindow change = new ChangeWindow();

                            change.FIOText.Text         = deal.FIORieltor;
                            change.PercentText.Text     = deal.Percent.ToString();
                            change.FIOComb.SelectedItem = deal.FIORieltor + " - ID: " + deal.IDR;

                            var apartament = from a in model.Apartaments
                                             where a.ID == deal.IDAP
                                             select a;

                            foreach (var item in apartament)
                            {
                                change.STNameText.Text     = item.StreetName;
                                change.HouseNumText.Text   = item.HouseNumber;
                                change.APNumText.Text      = item.ApartamentNumber.ToString();
                                change.SquareText.Text     = item.SquareApartament.ToString();
                                change.AmountRoomText.Text = item.AmountRoom.ToString();
                                change.PriceText.Text      = item.Price.ToString();

                                change.APComb.SelectedItem = item.StreetName + " - ID: " + item.ID;
                            }

                            if (deal != null)
                            {
                                if (change.ShowDialog() == true)
                                {
                                    Dealings dealings = model.Dealings.Where(p => p.IDDeal == deal.IDD).FirstOrDefault();
                                    dealings.IDRealtor    = change.GetAgentID();
                                    dealings.IDApartamemt = change.GetAPID();

                                    model.Entry(dealings).State = System.Data.Entity.EntityState.Modified;
                                }
                                model.SaveChanges();
                                SetDeal();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        private void DeleteDeal_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (ModelBD model = new ModelBD())
                {
                    if (GridDeal.SelectedItems.Count > 0)
                    {
                        for (int i = 0; i < GridDeal.SelectedItems.Count; i++)
                        {
                            DopDeal idDeal = GridDeal.SelectedItems[i] as DopDeal;
                            if (idDeal != null)
                            {
                                MessageBoxResult result = MessageBox.Show("Вы точно хотите удалить?", "Удаление", MessageBoxButton.YesNo);
                                switch (result)
                                {
                                case MessageBoxResult.Yes:
                                    Dealings id = model.Dealings.Where(p => p.IDDeal == idDeal.IDD).FirstOrDefault();
                                    model.Dealings.Remove(id);
                                    break;

                                case MessageBoxResult.No:
                                    break;
                                }
                            }
                        }
                        model.SaveChanges();
                        AsSetDeal();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }