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.
84 lines
3.2 KiB
84 lines
3.2 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;
|
|
if (currentCompany.dataGridRowStatus == DataGridRowStatus.DEFAULT)
|
|
currentCompany.Users = App.getUsers(c.CompanyId);
|
|
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)
|
|
{
|
|
switch (App.saveResultsMsgBox())
|
|
{
|
|
case MessageBoxResult.No: return;
|
|
case MessageBoxResult.Cancel: e.Cancel = true; return;
|
|
}
|
|
currentCompany.Users.Clear();
|
|
foreach (Users u in (ObservableCollection<Users>)usersGrid.DataContext)
|
|
{
|
|
if (u.dataGridRowStatus != DataGridRowStatus.REMOVED)
|
|
if (u.Login == null || u.Password == null || u.Name == null)
|
|
switch (App.fieldHasNotFilled())
|
|
{
|
|
case MessageBoxResult.No: return;
|
|
case MessageBoxResult.Yes: e.Cancel = true; return;
|
|
}
|
|
u.CompanyId = currentCompany.CompanyId;
|
|
u.Company = currentCompany;
|
|
currentCompany.Users.Add(u);
|
|
}
|
|
currentCompany.ContractStatus = contractStatusComboBox.SelectedIndex;
|
|
currentCompany.Name = companyNameBox.Text;
|
|
if (currentCompany.dataGridRowStatus != DataGridRowStatus.NEW)
|
|
currentCompany.dataGridRowStatus = DataGridRowStatus.UPDATED;
|
|
updateCompanyItem(currentCompany);
|
|
}
|
|
|
|
private void RowDelete_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
((Users)usersGrid.SelectedItem).dataGridRowStatus = DataGridRowStatus.REMOVED;
|
|
MainWindow.refreshDataGrid(usersGrid);
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|