Browse Source

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

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

8
eCompanies/App.xaml.cs

@ -27,7 +27,13 @@ namespace eCompanies
public static ObservableCollection<Companies> getCompanies() public static ObservableCollection<Companies> getCompanies()
{ {
using (var db = new CompaniesDBContext()) 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) public static void updateCompany(Companies c)

2
eCompanies/Contract.cs

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

2
eCompanies/MainWindow.xaml

@ -18,7 +18,7 @@
<Grid> <Grid>
<DataGrid x:Name="companyGrid" HorizontalAlignment="Left" Height="354" Margin="10,55,0,0" VerticalAlignment="Top" Width="772" ItemsSource="{Binding}" AutoGenerateColumns="False" MouseDoubleClick="companyGrid_MouseDoubleClick"> <DataGrid x:Name="companyGrid" HorizontalAlignment="Left" Height="354" Margin="10,55,0,0" VerticalAlignment="Top" Width="772" ItemsSource="{Binding}" AutoGenerateColumns="False" MouseDoubleClick="companyGrid_MouseDoubleClick">
<DataGrid.Columns> <DataGrid.Columns>
<DataGridTextColumn Header="ID" Binding="{Binding CompanyId}" IsReadOnly="True"/> <DataGridTextColumn Header="ID" Binding="{Binding CompanyId}" IsReadOnly="True"/>
<DataGridTextColumn Header="Название компании" Binding="{Binding Name}" Width="*"/> <DataGridTextColumn Header="Название компании" Binding="{Binding Name}" Width="*"/>
<DataGridComboBoxColumn x:Name="ContractComboBox" Header="Состояние контракта" <DataGridComboBoxColumn x:Name="ContractComboBox" Header="Состояние контракта"
SelectedValueBinding="{Binding Path=contract.ContractStatusId}" SelectedValueBinding="{Binding Path=contract.ContractStatusId}"

10
eCompanies/UsersWindow.xaml

@ -11,12 +11,12 @@
<ColumnDefinition/> <ColumnDefinition/>
<ColumnDefinition Width="0*"/> <ColumnDefinition Width="0*"/>
</Grid.ColumnDefinitions> </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> <DataGrid.Columns>
<DataGridTextColumn Header="ID" Binding="{Binding UsersId}"/> <DataGridTextColumn Header="ID" IsReadOnly="True" Binding="{Binding UserId}"/>
<DataGridTextColumn Header="Имя пользователя" Binding="{Binding Name}" /> <DataGridTextColumn Header="Имя пользователя" Width="*" Binding="{Binding Name}" />
<DataGridTextColumn Header="Логин" Binding="{Binding Login}" /> <DataGridTextColumn Header="Логин" Width="*" Binding="{Binding Login}" />
<DataGridTextColumn Header="Пароль" Binding="{Binding Password}" /> <DataGridTextColumn Header="Пароль" Width="*" Binding="{Binding Password}" />
</DataGrid.Columns> </DataGrid.Columns>
</DataGrid> </DataGrid>
<TextBox x:Name="companyNameBox" HorizontalAlignment="Left" Height="40" Margin="10,10,0,0" TextWrapping="Wrap" Text="none" VerticalAlignment="Top" Width="470" FontSize="22"/> <TextBox x:Name="companyNameBox" HorizontalAlignment="Left" Height="40" Margin="10,10,0,0" TextWrapping="Wrap" Text="none" VerticalAlignment="Top" Width="470" FontSize="22"/>

24
eCompanies/UsersWindow.xaml.cs

@ -25,9 +25,10 @@ namespace eCompanies
{ {
InitializeComponent(); InitializeComponent();
currentCompany = c; currentCompany = c;
currentCompany.Users = App.getUsers(currentCompany.CompanyId);
companyNameBox.Text = c.Name; companyNameBox.Text = c.Name;
contractStatusComboBox.SelectedIndex = c.ContractStatus; 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) private void usersGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
@ -37,8 +38,25 @@ namespace eCompanies
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.Yes) if (mbr == MessageBoxResult.No)
App.updateCompany(currentCompany); 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