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