Browse Source

Создан класс Contract. ComboBox'ы функционируют в данном коммите.

master
Никита 6 years ago
parent
commit
4f55245ebe
  1. 2
      eCompanies/App.xaml.cs
  2. 4
      eCompanies/Companies.cs
  3. 2
      eCompanies/CompaniesDBContext.cs
  4. 40
      eCompanies/Contract.cs
  5. 8
      eCompanies/MainWindow.xaml
  6. 5
      eCompanies/MainWindow.xaml.cs
  7. 1
      eCompanies/eCompanies.csproj

2
eCompanies/App.xaml.cs

@ -19,7 +19,7 @@ namespace eCompanies
{
using (var db = new CompaniesDBContext())
{
db.Companies.Add(new Companies { Name = "Unknown company", ContractStatus = (int) Status.NotReachedYet });
db.Companies.Add(c);
var count = db.SaveChanges();
}
}

4
eCompanies/Companies.cs

@ -3,14 +3,16 @@ using System.Collections.Generic;
namespace eCompanies
{
public enum Status { NotReachedYet, Reached, Terminated }
public partial class Companies
{
public Companies()
{
Users = new HashSet<Users>();
contract = new Contract(this);
}
public Contract contract { get; set; }
public int CompanyId { get; set; }
public string Name { get; set; }
public int ContractStatus { get; set; }

2
eCompanies/CompaniesDBContext.cs

@ -36,6 +36,8 @@ namespace eCompanies
.IsRequired();
entity.Property(e => e.Name).IsRequired();
entity.Ignore("contract");
});
modelBuilder.Entity<Users>(entity =>

40
eCompanies/Contract.cs

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace eCompanies
{
public enum Status { NotReachedYet, Reached, Terminated }
public class Contract
{
private Companies c { get; set; }
public Contract (Companies c)
{
this.c = c;
}
public string ContractStatusString
{
get
{
switch (c.CompanyId)
{
case 1: return "Заключен";
case 2: return "Расторгнут";
default: return "Еще не заключен";
}
}
set
{
}
}
public Status ContractStatusId
{
get { return (Status)c.ContractStatus; }
set { c.ContractStatus = (int)value; }
}
}
}

8
eCompanies/MainWindow.xaml

@ -5,6 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:eCompanies"
xmlns:core="clr-namespace:System;assembly=mscorlib"
xmlns:col="clr-namespace:System.Collections;assembly=mscorlib"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
@ -18,8 +19,11 @@
<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>
<DataGridTextColumn Header="ID" Binding="{Binding CompanyId}" IsReadOnly="True"/>
<DataGridTextColumn Header="Название компании" Binding="{Binding Name}"/>
<DataGridComboBoxColumn x:Name="companyGridBox" Header="Состояние контракта" SelectedItemBinding="{Binding ContractStatus}" ItemsSource="{Binding Source={StaticResource Status}}"/>
<DataGridTextColumn Header="Название компании" Binding="{Binding Name}" Width="*"/>
<DataGridComboBoxColumn x:Name="ContractComboBox" Header="Состояние контракта"
SelectedValueBinding="{Binding Path=contract.ContractStatusId}"
ItemsSource="{Binding Source={StaticResource Status}}">
</DataGridComboBoxColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>

5
eCompanies/MainWindow.xaml.cs

@ -34,11 +34,16 @@ namespace eCompanies
}
private void companyGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
try
{
Companies company = (Companies)companyGrid.CurrentItem;
if (usersWindowInstance != null) usersWindowInstance.Close();
usersWindowInstance = new UsersWindow(company);
usersWindowInstance.Show();
}
catch { }
}
}
}

1
eCompanies/eCompanies.csproj

@ -139,6 +139,7 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="CompaniesDBContext.cs" />
<Compile Include="Contract.cs" />
<Compile Include="Users.cs" />
<Compile Include="UsersWindow.xaml.cs">
<DependentUpon>UsersWindow.xaml</DependentUpon>

Loading…
Cancel
Save