115 lines
4.4 KiB
C#
115 lines
4.4 KiB
C#
// Copyright (c) 2017 schick Informatik
|
|
// Description: Tabelle Reporting Party (bearbeitet wird im Dialog)
|
|
//
|
|
|
|
using System;
|
|
using System.Windows;
|
|
|
|
using bsmd.database;
|
|
using ENI2.EditControls;
|
|
using System.Collections.ObjectModel;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media.Imaging;
|
|
|
|
namespace ENI2.Controls
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ReportingPartyControl.xaml
|
|
/// </summary>
|
|
public partial class ReportingPartyControl : UserControl
|
|
{
|
|
public ReportingPartyControl()
|
|
{
|
|
InitializeComponent();
|
|
Loaded += ReportingPartyControl_Loaded;
|
|
}
|
|
|
|
public ObservableCollection<ReportingParty> ReportingParties { get; set; }
|
|
|
|
private void ReportingPartyControl_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
this.dataGridReportingParties.Initialize();
|
|
this.dataGridReportingParties.ItemsSource = this.ReportingParties;
|
|
|
|
this.dataGridReportingParties.CreateRequested += DataGridReportingParties_CreateRequested;
|
|
this.dataGridReportingParties.AddingNewItem += DataGridReportingParties_AddingNewItem;
|
|
this.dataGridReportingParties.EditRequested += DataGridReportingParties_EditRequested;
|
|
this.dataGridReportingParties.DeleteRequested += DataGridReportingParties_DeleteRequested;
|
|
|
|
MenuItem resetItem = new MenuItem();
|
|
resetItem.Header = Properties.Resources.textResetPassword;
|
|
resetItem.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/recycle.png")) };
|
|
resetItem.Click += ResetItem_Click;
|
|
this.dataGridReportingParties.ContextMenu.Items.Add(resetItem);
|
|
|
|
}
|
|
|
|
private void ResetItem_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if ((this.dataGridReportingParties.SelectedItems?.Count == 1) && !this.dataGridReportingParties.IsReadOnly)
|
|
{
|
|
if (this.dataGridReportingParties.SelectedItems[0] is ReportingParty selectedParty)
|
|
{
|
|
string confirmText = string.Format(Properties.Resources.textConfirmPasswordReset, selectedParty.Logon);
|
|
MessageBoxResult result = MessageBox.Show(confirmText, Properties.Resources.textCaptionDeleteConfirm, MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
if (result == MessageBoxResult.Yes)
|
|
{
|
|
selectedParty.PasswordHash = null;
|
|
selectedParty.Salt = null;
|
|
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Save(selectedParty);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#region grid event handler
|
|
|
|
private void DataGridReportingParties_DeleteRequested(DatabaseEntity obj)
|
|
{
|
|
if (obj is ReportingParty rp)
|
|
{
|
|
// are you sure dialog is in base class
|
|
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(rp);
|
|
this.ReportingParties.Remove(rp);
|
|
this.dataGridReportingParties.Items.Refresh();
|
|
}
|
|
}
|
|
|
|
private void DataGridReportingParties_EditRequested(DatabaseEntity obj)
|
|
{
|
|
if (obj is ReportingParty rp)
|
|
{
|
|
EditReportingPartyDialog eld = new EditReportingPartyDialog();
|
|
eld.ReportingParty = rp;
|
|
|
|
if (eld.ShowDialog() ?? false)
|
|
{
|
|
this.dataGridReportingParties.Items.Refresh();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void DataGridReportingParties_AddingNewItem(object sender, AddingNewItemEventArgs e)
|
|
{
|
|
this.DataGridReportingParties_CreateRequested();
|
|
}
|
|
|
|
private void DataGridReportingParties_CreateRequested()
|
|
{
|
|
ReportingParty rp = new ReportingParty();
|
|
EditReportingPartyDialog ebd = new EditReportingPartyDialog();
|
|
ebd.ReportingParty = rp;
|
|
|
|
if (ebd.ShowDialog() ?? false)
|
|
{
|
|
DBManager.Instance.GetReportingPartyDict().Add(Guid.NewGuid(), rp);
|
|
this.ReportingParties.Add(rp);
|
|
this.dataGridReportingParties.Items.Refresh();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|