|
|
@ -21,6 +21,12 @@ namespace eCompanies |
|
|
|
companyGrid.DataContext = App.getCompanies(); |
|
|
|
} |
|
|
|
|
|
|
|
internal static void refreshDataGrid(DataGrid dg) |
|
|
|
{ |
|
|
|
dg.CancelEdit(); |
|
|
|
dg.Items.Refresh(); |
|
|
|
} |
|
|
|
|
|
|
|
private void updateCompanyItem(Company updatingCompany) |
|
|
|
{ |
|
|
|
if (updatingCompany == null) return; |
|
|
@ -28,8 +34,7 @@ namespace eCompanies |
|
|
|
for (int i = 0; i != c.Count(); i++) |
|
|
|
if (c[i].CompanyId.Equals(updatingCompany.CompanyId)) |
|
|
|
c[i] = updatingCompany; |
|
|
|
companyGrid.Items.Refresh(); |
|
|
|
|
|
|
|
refreshDataGrid(companyGrid); |
|
|
|
} |
|
|
|
|
|
|
|
private void companyGrid_AddingNewItem(object sender, AddingNewItemEventArgs e) |
|
|
@ -39,7 +44,7 @@ namespace eCompanies |
|
|
|
newItem.dataGridRowStatus = DataGridRowStatus.NEW; |
|
|
|
var c = ((DataGrid)sender).DataContext as ObservableCollection<Company>; |
|
|
|
if (c.Count != 0) |
|
|
|
newItem.CompanyId = ++c[c.Count - 1].CompanyId; |
|
|
|
newItem.CompanyId = c[c.Count - 1].CompanyId + 1; |
|
|
|
} |
|
|
|
|
|
|
|
private void companyGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) |
|
|
@ -61,9 +66,10 @@ namespace eCompanies |
|
|
|
private void RowDelete_Click(object sender, RoutedEventArgs e) |
|
|
|
{ |
|
|
|
((Company)companyGrid.SelectedItem).dataGridRowStatus = DataGridRowStatus.REMOVED; |
|
|
|
companyGrid.Items.Refresh(); |
|
|
|
refreshDataGrid(companyGrid); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) |
|
|
|
{ |
|
|
|
switch (App.saveResultsMsgBox()) |
|
|
@ -79,10 +85,40 @@ namespace eCompanies |
|
|
|
case MessageBoxResult.No: return; |
|
|
|
case MessageBoxResult.Yes: e.Cancel = true; return; |
|
|
|
} |
|
|
|
switch (c.dataGridRowStatus) |
|
|
|
{ |
|
|
|
case DataGridRowStatus.REMOVED: |
|
|
|
App.removeCompany(c.CompanyId); |
|
|
|
break; |
|
|
|
case DataGridRowStatus.NEW: |
|
|
|
syncUsers(c); |
|
|
|
App.addCompany(c); |
|
|
|
break; |
|
|
|
case DataGridRowStatus.UPDATED: |
|
|
|
syncUsers(c); |
|
|
|
App.updateCompany(c); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void syncUsers(Company c) |
|
|
|
{ |
|
|
|
foreach (Users u in c.Users) |
|
|
|
{ |
|
|
|
switch (u.dataGridRowStatus) |
|
|
|
{ |
|
|
|
case DataGridRowStatus.REMOVED: |
|
|
|
App.removeUser(u.UserId); |
|
|
|
break; |
|
|
|
case DataGridRowStatus.NEW: |
|
|
|
App.addUser(u); |
|
|
|
break; |
|
|
|
case DataGridRowStatus.UPDATED: |
|
|
|
App.updateUser(u.UserId); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
// нужно здесь обновить всех редактированных юзеров
|
|
|
|
// и добавить новых в базу данных
|
|
|
|
// TODO: переписать все обновления БД для [dataGridRowStatus]
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|