You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
3.8 KiB
97 lines
3.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
|
|
namespace eCompanies
|
|
{
|
|
/// <summary>
|
|
/// Логика взаимодействия для UsersWindow.xaml
|
|
/// </summary>
|
|
public partial class UsersWindow : Window
|
|
{
|
|
Company currentCompany;
|
|
UpdateCompanyGridDelegate updateCompanyItem;
|
|
|
|
public UsersWindow(Company c, UpdateCompanyGridDelegate d)
|
|
{
|
|
InitializeComponent();
|
|
currentCompany = c;
|
|
updateCompanyItem = d;
|
|
updateUsersGrid(c);
|
|
}
|
|
|
|
private void updateUsersGrid(Company c)
|
|
{
|
|
companyNameBox.Text = c.Name;
|
|
contractStatusComboBox.SelectedIndex = c.ContractStatus;
|
|
usersGrid.DataContext = new ObservableCollection<Users>(c.Users.AsEnumerable());
|
|
}
|
|
|
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
MessageBoxResult mbr = MessageBox.Show("Вы закрываете окно компании. Хотите сохранить результаты?", "Сохранение изменений", MessageBoxButton.YesNoCancel);
|
|
switch (mbr)
|
|
{
|
|
case MessageBoxResult.No: return;
|
|
case MessageBoxResult.Cancel: e.Cancel = true;
|
|
break;
|
|
}
|
|
currentCompany.Users.Clear();
|
|
foreach (Users u in (ObservableCollection<Users>)usersGrid.DataContext)
|
|
{
|
|
if (u.Login == null || u.Password == null || u.Name == null)
|
|
{
|
|
mbr = MessageBox.Show("Вы не полностью заполнили поле одного из пользователей! " +
|
|
"Вернуться к форме для исправления? (При ответе Нет все данные будут потеряны!)",
|
|
"Поле Логин/Пароль не может быть пустым!",
|
|
MessageBoxButton.YesNo);
|
|
|
|
if (mbr == MessageBoxResult.Yes)
|
|
{
|
|
e.Cancel = true;
|
|
return;
|
|
} else if (mbr == MessageBoxResult.No)
|
|
return;
|
|
}
|
|
|
|
if (u.UserId == 0)
|
|
{
|
|
u.CompanyId = currentCompany.CompanyId;
|
|
u.Company = currentCompany;
|
|
currentCompany.Users.Add(u);
|
|
}
|
|
}
|
|
|
|
currentCompany.ContractStatus = contractStatusComboBox.SelectedIndex;
|
|
currentCompany.Name = companyNameBox.Text;
|
|
updateCompanyItem(currentCompany);
|
|
}
|
|
|
|
private void RowDelete_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
((Users)usersGrid.SelectedItem).dataGridRowStatus = DataGridRowStatus.REMOVED;
|
|
usersGrid.Items.Refresh();
|
|
}
|
|
|
|
private void usersGrid_CellEditEnding(object sender, System.Windows.Controls.DataGridCellEditEndingEventArgs e)
|
|
{
|
|
var context = e.Row.DataContext as Users;
|
|
if (context.dataGridRowStatus != DataGridRowStatus.NEW)
|
|
context.dataGridRowStatus = DataGridRowStatus.UPDATED;
|
|
}
|
|
|
|
private void usersGrid_AddingNewItem(object sender, System.Windows.Controls.AddingNewItemEventArgs e)
|
|
{
|
|
e.NewItem = new Users();
|
|
var newItem = e.NewItem as Users;
|
|
newItem.dataGridRowStatus = DataGridRowStatus.NEW;
|
|
var c = ((DataGrid)sender).DataContext as ObservableCollection<Users>;
|
|
if (c.Count != 0)
|
|
newItem.UserId = ++c[c.Count - 1].UserId;
|
|
}
|
|
}
|
|
}
|
|
|