|
|
@ -13,34 +13,39 @@ namespace eCompanies |
|
|
|
public partial class UsersWindow : Window |
|
|
|
{ |
|
|
|
Company currentCompany; |
|
|
|
public UsersWindow(Company c) |
|
|
|
UpdateCompanyGridDelegate updateCompanyGrid; |
|
|
|
public UsersWindow(Company c, UpdateCompanyGridDelegate d) |
|
|
|
{ |
|
|
|
InitializeComponent(); |
|
|
|
currentCompany = c; |
|
|
|
currentCompany.Users = App.getUsers(currentCompany.CompanyId); |
|
|
|
companyNameBox.Text = c.Name; |
|
|
|
contractStatusComboBox.SelectedIndex = c.ContractStatus; |
|
|
|
usersGrid.DataContext = new ObservableCollection<Users>(c.Users.AsEnumerable()); |
|
|
|
updateCompanyGrid = d; |
|
|
|
updateUsersGrid(); |
|
|
|
} |
|
|
|
|
|
|
|
private void usersGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e) |
|
|
|
private void updateUsersGrid() |
|
|
|
{ |
|
|
|
currentCompany.Users = App.getUsers(currentCompany.CompanyId); |
|
|
|
companyNameBox.Text = currentCompany.Name; |
|
|
|
contractStatusComboBox.SelectedIndex = currentCompany.ContractStatus; |
|
|
|
usersGrid.DataContext = new ObservableCollection<Users>(currentCompany.Users.AsEnumerable()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) |
|
|
|
{ |
|
|
|
MessageBoxResult mbr = MessageBox.Show("Вы закрываете окно с компанией. Хотите сохранить результаты?", "Сохранение изменений", MessageBoxButton.YesNo); |
|
|
|
if (mbr == MessageBoxResult.No) |
|
|
|
return; |
|
|
|
currentCompany.ContractStatus = contractStatusComboBox.SelectedIndex; |
|
|
|
currentCompany.Name = companyNameBox.Text; |
|
|
|
foreach (Users u in (ObservableCollection<Users>)usersGrid.DataContext) |
|
|
|
{ |
|
|
|
u.CompanyId = currentCompany.CompanyId; |
|
|
|
u.Company = currentCompany; |
|
|
|
currentCompany.Users.Add(u); |
|
|
|
} |
|
|
|
currentCompany.ContractStatus = contractStatusComboBox.SelectedIndex; |
|
|
|
currentCompany.Name = companyNameBox.Text; |
|
|
|
App.updateCompany(currentCompany); |
|
|
|
updateCompanyGrid(); |
|
|
|
} |
|
|
|
|
|
|
|
private void usersGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e) |
|
|
@ -50,5 +55,11 @@ namespace eCompanies |
|
|
|
private void usersGrid_AddingNewItem(object sender, AddingNewItemEventArgs e) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
private void RowDelete_Click(object sender, RoutedEventArgs e) |
|
|
|
{ |
|
|
|
App.removeUser(((Users)usersGrid.CurrentItem).UserId); |
|
|
|
updateUsersGrid(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|