Browse Source

Реализовано отображение и редактирование элементов в UsersWindow

master
Никита 6 years ago
parent
commit
22e3436a4b
  1. 8
      eCompanies/App.xaml.cs
  2. 2
      eCompanies/Contract.cs
  3. 10
      eCompanies/UsersWindow.xaml
  4. 22
      eCompanies/UsersWindow.xaml.cs

8
eCompanies/App.xaml.cs

@ -27,7 +27,13 @@ namespace eCompanies
public static ObservableCollection<Companies> getCompanies()
{
using (var db = new CompaniesDBContext())
return new ObservableCollection<Companies>(db.Companies.AsEnumerable<Companies>());
return new ObservableCollection<Companies>(db.Companies.AsEnumerable());
}
public static HashSet<Users> getUsers(int id)
{
using (var db = new CompaniesDBContext())
return new HashSet<Users>(db.Users.Where(b => b.CompanyId.Equals(id)));
}
public static void updateCompany(Companies c)

2
eCompanies/Contract.cs

@ -9,7 +9,7 @@ namespace eCompanies
public enum Status { NotReachedYet, Reached, Terminated }
public class Contract
{
private Companies c { get; set; }
private Companies c;
public Contract (Companies c)
{
this.c = c;

10
eCompanies/UsersWindow.xaml

@ -11,12 +11,12 @@
<ColumnDefinition/>
<ColumnDefinition Width="0*"/>
</Grid.ColumnDefinitions>
<DataGrid x:Name="usersGrid" HorizontalAlignment="Left" Height="354" Margin="10,55,0,0" VerticalAlignment="Top" Width="772" ItemsSource="{Binding}" AutoGenerateColumns="False" MouseDoubleClick="usersGrid_MouseDoubleClick">
<DataGrid x:Name="usersGrid" HorizontalAlignment="Left" Height="354" Margin="10,55,0,0" VerticalAlignment="Top" Width="772" ItemsSource="{Binding}" AutoGenerateColumns="False" RowEditEnding="usersGrid_RowEditEnding" AddingNewItem="usersGrid_AddingNewItem">
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Binding="{Binding UsersId}"/>
<DataGridTextColumn Header="Имя пользователя" Binding="{Binding Name}" />
<DataGridTextColumn Header="Логин" Binding="{Binding Login}" />
<DataGridTextColumn Header="Пароль" Binding="{Binding Password}" />
<DataGridTextColumn Header="ID" IsReadOnly="True" Binding="{Binding UserId}"/>
<DataGridTextColumn Header="Имя пользователя" Width="*" Binding="{Binding Name}" />
<DataGridTextColumn Header="Логин" Width="*" Binding="{Binding Login}" />
<DataGridTextColumn Header="Пароль" Width="*" Binding="{Binding Password}" />
</DataGrid.Columns>
</DataGrid>
<TextBox x:Name="companyNameBox" HorizontalAlignment="Left" Height="40" Margin="10,10,0,0" TextWrapping="Wrap" Text="none" VerticalAlignment="Top" Width="470" FontSize="22"/>

22
eCompanies/UsersWindow.xaml.cs

@ -25,9 +25,10 @@ namespace eCompanies
{
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<Users>());
usersGrid.DataContext = new ObservableCollection<Users>(c.Users.AsEnumerable());
}
private void usersGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
@ -37,8 +38,25 @@ namespace eCompanies
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
MessageBoxResult mbr = MessageBox.Show("Вы закрываете окно с компанией. Хотите сохранить результаты?", "Сохранение изменений", MessageBoxButton.YesNo);
if (mbr == MessageBoxResult.Yes)
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);
}
App.updateCompany(currentCompany);
}
private void usersGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
}
private void usersGrid_AddingNewItem(object sender, AddingNewItemEventArgs e)
{
}
}
}

Loading…
Cancel
Save