Example #1
0
 private void button_addTimeToSession_Click(object sender, RoutedEventArgs e)
 {
     Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, (DispatcherOperationCallback) delegate(object o)
     {
         if (listView_clients.SelectedItems.Count > 0)
         {
             bool isNotValidToEdit = false;
             SessionTariff tarrif  = new SessionTariff();
             foreach (Client client in listView_clients.SelectedItems)
             {
                 if (!(client.EndSession.HasValue && client.Tariff.LimitedTimeMode))
                 {
                     isNotValidToEdit = true;
                     break;
                 }
             }
             if (isNotValidToEdit)
             {
                 if (MessageBox.Show("Будет создан новый сеанс. Продолжить?", "", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                 {
                     var wnd = new SessionCreationView {
                         Owner = this
                     };
                     wnd.View(listView_clients.SelectedItems);
                 }
             }
             else
             {
                 var wnd = new TimeEditionView {
                     Owner = this
                 };
                 wnd.View(listView_clients.SelectedItems);
             }
         }
         else
         {
             MessageBox.Show("Не выбран ни один клиент", "", MessageBoxButton.OK, MessageBoxImage.Information);
         }
         var scope = FocusManager.GetFocusScope(sender as Button); // elem is the UIElement to unfocus
         FocusManager.SetFocusedElement(scope, null);              // remove logical focus
         Keyboard.ClearFocus();                                    // remove keyboard focus
         return(null);
     }, null);
 }
Example #2
0
        private void CreateSession(object sender, RoutedEventArgs e)
        {
            Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, (DispatcherOperationCallback) delegate(object o)
            {
                if (listView_clients.SelectedItems.Count > 0)
                {
                    bool toCreate = true;
                    foreach (Client client in listView_clients.SelectedItems)
                    {
                        if (client.IsSessionStarted)
                        {
                            toCreate = MessageBox.Show("Будет создан новый сеанс. Продолжить?", "", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes ? true : false;
                            break;
                        }
                    }
                    if (toCreate)
                    {
                        var wnd = new SessionCreationView {
                            Owner = this
                        };
                        wnd.View(listView_clients.SelectedItems);
                    }
                }
                else
                {
                    MessageBox.Show("Не выбран ни один клиент", "", MessageBoxButton.OK, MessageBoxImage.Information);
                }

                if (sender is Button)
                {
                    var scope = FocusManager.GetFocusScope(sender as Button); // elem is the UIElement to unfocus
                    FocusManager.SetFocusedElement(scope, null);              // remove logical focus
                    Keyboard.ClearFocus();                                    // remove keyboard focus
                }
                return(null);
            }, null);
        }
Example #3
0
 private void button_changeSession_Click(object sender, RoutedEventArgs e)
 {
     Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, (DispatcherOperationCallback) delegate(object o)
     {
         if (listView_clients.SelectedItems.Count > 0)
         {
             bool isDifferent       = false;
             bool isNotValidToEdit  = false;
             bool isFirst           = true;
             bool isInternetSession = false;
             DateTime expireDate    = DateTime.Now;
             SessionTariff tarrif   = new SessionTariff();
             Double payment         = 0;
             foreach (Client client in listView_clients.SelectedItems)
             {
                 if (client.EndSession.HasValue && client.Tariff.LimitedTimeMode)
                 {
                     if (isFirst)
                     {
                         payment           = client.TotalPayment;
                         expireDate        = client.EndSession.Value;
                         tarrif            = client.Tariff;
                         isInternetSession = client.IsInternetSession;
                         isFirst           = false;
                     }
                     else
                     {
                         if (!isDifferent)
                         {
                             if (!(
                                     expireDate < client.EndSession.Value.AddSeconds(5) &&
                                     expireDate > client.EndSession.Value.AddSeconds(-5) &&
                                     tarrif.Equals(client.Tariff) &&
                                     isInternetSession.Equals(client.IsInternetSession)
                                     ))
                             {
                                 isDifferent = true;
                             }
                         }
                     }
                 }
                 else
                 {
                     isNotValidToEdit = true;
                     break;
                 }
             }
             if (isNotValidToEdit)
             {
                 if (MessageBox.Show("Будет создан новый сеанс. Продолжить?", "", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                 {
                     var wnd = new SessionCreationView {
                         Owner = this
                     };
                     wnd.View(listView_clients.SelectedItems);
                 }
             }
             else
             {
                 if (!isDifferent) //сеансы одинаковые
                 {
                     var wnd = new SessionExtensionView {
                         Owner = this
                     };
                     wnd.View(listView_clients.SelectedItems, expireDate, tarrif, payment);
                 }
                 else
                 {
                     MessageBox.Show("Сеансы различны и не могут быть изменены!\nПопробуйте добавить платеж или время.", "", MessageBoxButton.OK, MessageBoxImage.Warning);
                 }
             }
         }
         else
         {
             MessageBox.Show("Не выбран ни один клиент", "", MessageBoxButton.OK, MessageBoxImage.Information);
         }
         var scope = FocusManager.GetFocusScope(sender as Button); // elem is the UIElement to unfocus
         FocusManager.SetFocusedElement(scope, null);              // remove logical focus
         Keyboard.ClearFocus();                                    // remove keyboard focus
         return(null);
     }, null);
 }