Example #1
0
        //Вызов окна подтверждения удаления записи для таблицы Подписок, а также удаление записи
        private void DeleteInSubscription()
        {
            DeleteSubscription = new ShowOrDeleteInSubscription();
            int selectedIndex;
            int selectedRow = dataGrid_Subscription.SelectedIndex;

            if (selectedRow >= 0)
            {
                DeleteSubscription.SetData(subscriptionArr[selectedRow], ShowOrDeleteInSubscription.ModeWindow.DeleteConfirm);
                selectedIndex = subscriptionArr[selectedRow].subscription_Id;
            }
            else
            {
                MessageBox.Show("Выделите запись которую желаете удалить", "Внимание", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            DeleteSubscription.Owner = this;

            bool?result = DeleteSubscription.ShowDialog();

            if (result == true)
            {
                using (MailContext context = new MailContext())
                {
                    Subscription subscription = (Subscription)context.Subscriptions.FirstOrDefault(c => c.subscription_Id == selectedIndex);
                    List <Mail>  mails        = context.Mail.Where(c => c.id_Subscription.subscription_Id == subscription.subscription_Id).ToList();
                    if (mails.Count > 0)
                    {
                        if (MessageBox.Show("Внимание! Удаление " + selectedIndex
                                            + " записи таблице приведет к обнулению " + mails.Count
                                            + " ссылок на подписчика в Главной таблице!"
                                            + "\n Вы уверены что хотите удалить " + selectedIndex + " запись в таблице Подписок?"
                                            , "Внимание", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                        {
                            return;
                        }
                    }
                    context.Subscriptions.Remove(subscription);
                    context.SaveChanges();

                    MessageBox.Show("Запись №" + selectedIndex + " в таблице Подписок удалена успешно!", "Успешно", MessageBoxButton.OK, MessageBoxImage.Information);

                    RefreshSubscriptionTable();
                    RefreshMainTable();
                }
            }
        }
Example #2
0
        //Метод вызова окна просмотра записи, а также контроля за ними
        private void ShowInSubscription()
        {
            int rowIndex = dataGrid_Subscription.SelectedIndex;

            if (rowIndex >= 0)
            {
                int index = subscriberArrNow[rowIndex].subscriber_Id;
                if (ShowSubscriptionList.Count != 0)
                {
                    //Очистка листа ShowSubscriptionList от закрытых окон
                    ShowOrDeleteInSubscription[] tempArr = ShowSubscriptionList.ToArray();
                    foreach (ShowOrDeleteInSubscription SODISubion in tempArr)
                    {
                        if (SODISubion.IsVisible == false)
                        {
                            ShowSubscriptionList.Remove(SODISubion);
                        }
                    }

                    //Вывод окна на передний план если оно уже было открыто
                    foreach (ShowOrDeleteInSubscription SODISubion in ShowSubscriptionList)
                    {
                        //MessageBox.Show(SODISubion.id.ToString());
                        if (SODISubion.id == index)
                        {
                            SODISubion.Activate();
                            return;
                        }
                    }
                }
                ShowSubscription = new ShowOrDeleteInSubscription();

                ShowSubscription.Owner = this;
                ShowSubscription.Show();
                ShowSubscription.SetData(index, ShowOrDeleteInSubscription.ModeWindow.Show);
                ShowSubscriptionList.Add(ShowSubscription);
            }
        }