private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     Instance     = this;
     ActiveWindow = this;
     UpdateDealers();
     Dealers.SelectItem();
 }
 private void Edit_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     if (Dealer.Exists((long)(Dealers.SelectedItem as TextBlock).Tag))
     {
         DealerWindow dealerWindow = new DealerWindow(Dealer.FromDataRow(Dealer.Select((long)(Dealers.SelectedItem as TextBlock).Tag)));
         if ((bool)dealerWindow.ShowDialog(this))
         {
             if (Dealer.Exists((long)(Dealers.SelectedItem as TextBlock).Tag))
             {
                 if (BusinessEntity.Exists(dealerWindow.Dealer.BusinessEntityId) &&
                     Entities.Activity.Exists(dealerWindow.Dealer.ActivityId) &&
                     Entities.ActivityDirection.Exists(dealerWindow.Dealer.ActivityDirectionId))
                 {
                     long selectedDealerId = (long)(Dealers.SelectedItem as TextBlock).Tag;
                     dealerWindow.Dealer.Update();
                     UpdateDealers();
                     Dealers.SelectItem(Dealers.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == selectedDealerId));
                 }
                 else
                 {
                     ShowErrorWindow(1);
                 }
             }
             else
             {
                 ShowErrorWindow(2);
             }
         }
     }
     else
     {
         ShowErrorWindow(2);
     }
 }
        private void ComboBox_DropDownClosed(object sender, EventArgs e)
        {
            ComboBox comboBox = sender as ComboBox;

            if ((long)comboBox.Tag != (long)(comboBox.SelectedItem as TextBlock).Tag)
            {
                UpdateDealers();
                Dealers.SelectItem();
            }
        }
        private void Add_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            DealerWindow dealerWindow = new DealerWindow();

            if ((bool)dealerWindow.ShowDialog(this))
            {
                if (BusinessEntity.Exists(dealerWindow.Dealer.BusinessEntityId) &&
                    Entities.Activity.Exists(dealerWindow.Dealer.ActivityId) &&
                    Entities.ActivityDirection.Exists(dealerWindow.Dealer.ActivityDirectionId))
                {
                    long insertedDealerId = dealerWindow.Dealer.Insert();
                    UpdateDealers();
                    Dealers.SelectItem(Dealers.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == insertedDealerId));
                }
                else
                {
                    ShowErrorWindow(0);
                }
            }
        }
 private void Delete_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     if (Dealer.Exists((long)(Dealers.SelectedItem as TextBlock).Tag))
     {
         if ((bool)new ConfirmationWindow().ShowDialog(this))
         {
             if (Dealer.Exists((long)(Dealers.SelectedItem as TextBlock).Tag))
             {
                 Dealer.Delete((long)(Dealers.SelectedItem as TextBlock).Tag);
                 UpdateDealers();
                 Dealers.SelectItem();
             }
             else
             {
                 ShowErrorWindow(3);
             }
         }
     }
     else
     {
         ShowErrorWindow(3);
     }
 }
 private void ShowErrorWindow(byte errorCode)
 {
     new ErrorWindow(errorCode).ShowDialog(this);
     UpdateDealers();
     Dealers.SelectItem();
 }
 private void Update_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     UpdateDealers();
     Dealers.SelectItem();
 }
 private void Constants_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     new ConstantsWindow().ShowDialog(this);
     UpdateDealers();
     Dealers.SelectItem();
 }