Добавьте файлы проекта.
This commit is contained in:
parent
6c3308b665
commit
cbaa21c016
25
musicschoolapp.sln
Normal file
25
musicschoolapp.sln
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.6.33815.320
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "musicschoolapp", "musicschoolapp\musicschoolapp.csproj", "{CD4C9F97-7E80-4EDB-879E-9CFF6FC040D6}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{CD4C9F97-7E80-4EDB-879E-9CFF6FC040D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{CD4C9F97-7E80-4EDB-879E-9CFF6FC040D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{CD4C9F97-7E80-4EDB-879E-9CFF6FC040D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{CD4C9F97-7E80-4EDB-879E-9CFF6FC040D6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {6DD357E3-9398-459A-8E17-7C87A3B99D95}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
26
musicschoolapp/App.Config
Normal file
26
musicschoolapp/App.Config
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<configSections>
|
||||||
|
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||||
|
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||||
|
</configSections>
|
||||||
|
<connectionStrings>
|
||||||
|
<add name="musicschoolEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=C:\Users\g5org\Desktop\musicschool.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
|
||||||
|
<add name="musicschoolEntities1" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=C:\Users\g5org\Desktop\pre\musicschool.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
|
||||||
|
</connectionStrings>
|
||||||
|
<entityFramework>
|
||||||
|
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
|
||||||
|
</entityFramework>
|
||||||
|
<runtime>
|
||||||
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-2.6.8.0" newVersion="2.6.8.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-2.6.8.0" newVersion="2.6.8.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
</assemblyBinding>
|
||||||
|
</runtime>
|
||||||
|
</configuration>
|
9
musicschoolapp/App.xaml
Normal file
9
musicschoolapp/App.xaml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<Application x:Class="musicschoolapp.App"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:local="clr-namespace:musicschoolapp"
|
||||||
|
StartupUri="MainWindow.xaml">
|
||||||
|
<Application.Resources>
|
||||||
|
|
||||||
|
</Application.Resources>
|
||||||
|
</Application>
|
16
musicschoolapp/App.xaml.cs
Normal file
16
musicschoolapp/App.xaml.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace musicschoolapp
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Логика взаимодействия для App.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class App : Application
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
29
musicschoolapp/Class1.cs
Normal file
29
musicschoolapp/Class1.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace musicschoolapp
|
||||||
|
{
|
||||||
|
public partial class Student
|
||||||
|
{
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return LastName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public partial class Course
|
||||||
|
{
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public partial class Instruments
|
||||||
|
{
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return Name_instrument;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
musicschoolapp/Course.cs
Normal file
30
musicschoolapp/Course.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// Этот код был создан из шаблона.
|
||||||
|
//
|
||||||
|
// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения.
|
||||||
|
// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace musicschoolapp
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
public partial class Course
|
||||||
|
{
|
||||||
|
public Course()
|
||||||
|
{
|
||||||
|
this.Enrollment = new HashSet<Enrollment>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int CourseID { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
public int Duration { get; set; }
|
||||||
|
public decimal Price { get; set; }
|
||||||
|
|
||||||
|
public virtual ICollection<Enrollment> Enrollment { get; set; }
|
||||||
|
}
|
||||||
|
}
|
26
musicschoolapp/Enrollment.cs
Normal file
26
musicschoolapp/Enrollment.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// Этот код был создан из шаблона.
|
||||||
|
//
|
||||||
|
// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения.
|
||||||
|
// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace musicschoolapp
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
public partial class Enrollment
|
||||||
|
{
|
||||||
|
public int EnrollmentID { get; set; }
|
||||||
|
public int StudentID { get; set; }
|
||||||
|
public int CourseID { get; set; }
|
||||||
|
public System.DateTime EnrollmentDate { get; set; }
|
||||||
|
public Nullable<decimal> Grade { get; set; }
|
||||||
|
|
||||||
|
public virtual Course Course { get; set; }
|
||||||
|
public virtual Student Student { get; set; }
|
||||||
|
}
|
||||||
|
}
|
29
musicschoolapp/Instruments.cs
Normal file
29
musicschoolapp/Instruments.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// Этот код был создан из шаблона.
|
||||||
|
//
|
||||||
|
// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения.
|
||||||
|
// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace musicschoolapp
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
public partial class Instruments
|
||||||
|
{
|
||||||
|
public Instruments()
|
||||||
|
{
|
||||||
|
this.Student = new HashSet<Student>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Id_instrument { get; set; }
|
||||||
|
public string Name_instrument { get; set; }
|
||||||
|
public Nullable<System.DateTime> Date_receiving { get; set; }
|
||||||
|
public Nullable<bool> isPersonal { get; set; }
|
||||||
|
|
||||||
|
public virtual ICollection<Student> Student { get; set; }
|
||||||
|
}
|
||||||
|
}
|
43
musicschoolapp/MainWindow.xaml
Normal file
43
musicschoolapp/MainWindow.xaml
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<Window x:Class="musicschoolapp.MainWindow"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:musicschoolapp"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="Авторизация" Height="450" Width="800">
|
||||||
|
<Grid>
|
||||||
|
<!-- Define the rows and columns of the grid -->
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition/>
|
||||||
|
<RowDefinition Height="Auto" MinHeight="207.04"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Image Grid.Row="0" Grid.Column="1" Margin="10,10,10,10"/>
|
||||||
|
<TextBlock Grid.Row="1" Grid.Column="1" Text="Приложение музыкальной школы" FontSize="36" FontWeight="Bold" VerticalAlignment="Center" Height="48"/>
|
||||||
|
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Vertical" Margin="150,10,180,82">
|
||||||
|
<Label Margin="10,0,0,0" Content="Логин"/>
|
||||||
|
<TextBox x:Name="usernameTextBox" Margin="5"/>
|
||||||
|
<Label Margin="10,0,0,0" Content="Пароль"/>
|
||||||
|
<PasswordBox x:Name="passwordBox" Margin="5"/>
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
<ColumnDefinition Width="154"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Button x:Name="loginButton" Grid.Row="1" Grid.Column="1" Content="Вход" Margin="5" Click="loginButton_Click"/>
|
||||||
|
<Button x:Name="registerButton" Content="Регистрация" Margin="5" Click="registerButton_Click"/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
|
|
94
musicschoolapp/MainWindow.xaml.cs
Normal file
94
musicschoolapp/MainWindow.xaml.cs
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.Eventing.Reader;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Management.Instrumentation;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
using System.Windows.Shell;
|
||||||
|
using System.Runtime;
|
||||||
|
|
||||||
|
namespace musicschoolapp
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Логика взаимодействия для MainWindow.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class MainWindow : Window
|
||||||
|
{
|
||||||
|
|
||||||
|
public MainWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void registerButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
await executeDB(usernameTextBox.Text, passwordBox.Password, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void loginButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
await executeDB(usernameTextBox.Text, passwordBox.Password, false);
|
||||||
|
|
||||||
|
|
||||||
|
//await DbHandlerAsync();
|
||||||
|
|
||||||
|
}
|
||||||
|
//async Task DbHandlerAsync()
|
||||||
|
//{
|
||||||
|
// await executeDB(usernameTextBox.Text, passwordBox.Password);
|
||||||
|
//}
|
||||||
|
static async Task<bool> executeDB(string login, string password, bool isreg)
|
||||||
|
{
|
||||||
|
musicschoolEntities1 musicschoolEntities = new musicschoolEntities1();
|
||||||
|
string[] strings = new string[] { login, password };
|
||||||
|
var isunique = from s in musicschoolEntities.User where s.username == login select s;
|
||||||
|
if (string.Join("", strings) != String.Empty)
|
||||||
|
{
|
||||||
|
var query = from s in musicschoolEntities.User where s.username == login && s.password == password select s;
|
||||||
|
if (query.Count() > 0 && !isreg)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Авторизация успешна.");
|
||||||
|
|
||||||
|
WorkingWindow workingWindow = new WorkingWindow(query.FirstOrDefault());
|
||||||
|
workingWindow.Show();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (isreg && isunique.Count() == 0)
|
||||||
|
{
|
||||||
|
User user = new User();
|
||||||
|
user.username = login;
|
||||||
|
user.password = password;
|
||||||
|
musicschoolEntities.User.Add(user);
|
||||||
|
musicschoolEntities.SaveChanges();
|
||||||
|
MessageBox.Show("Регистрация выполнена.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(isunique.Count() > 0)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Пользователь уже существует.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
MessageBox.Show("Ошибка логина или пароля.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
MessageBox.Show("заполните все поля!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
34
musicschoolapp/Model1.Context.cs
Normal file
34
musicschoolapp/Model1.Context.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// Этот код был создан из шаблона.
|
||||||
|
//
|
||||||
|
// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения.
|
||||||
|
// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace musicschoolapp
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
using System.Data.Entity;
|
||||||
|
using System.Data.Entity.Infrastructure;
|
||||||
|
|
||||||
|
public partial class musicschoolEntities1 : DbContext
|
||||||
|
{
|
||||||
|
public musicschoolEntities1()
|
||||||
|
: base("name=musicschoolEntities1")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
throw new UnintentionalCodeFirstException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DbSet<Course> Course { get; set; }
|
||||||
|
public DbSet<Enrollment> Enrollment { get; set; }
|
||||||
|
public DbSet<Student> Student { get; set; }
|
||||||
|
public DbSet<User> User { get; set; }
|
||||||
|
public DbSet<Instruments> Instruments { get; set; }
|
||||||
|
}
|
||||||
|
}
|
735
musicschoolapp/Model1.Context.tt
Normal file
735
musicschoolapp/Model1.Context.tt
Normal file
@ -0,0 +1,735 @@
|
|||||||
|
<#@ template language="C#" debug="false" hostspecific="true"#>
|
||||||
|
<#@ include file="EF.Utility.CS.ttinclude"#><#@
|
||||||
|
output extension=".cs"#><#
|
||||||
|
|
||||||
|
const string inputFile = @"Model1.edmx";
|
||||||
|
var textTransform = DynamicTextTransformation.Create(this);
|
||||||
|
var code = new CodeGenerationTools(this);
|
||||||
|
var ef = new MetadataTools(this);
|
||||||
|
var typeMapper = new TypeMapper(code, ef, textTransform.Errors);
|
||||||
|
var loader = new EdmMetadataLoader(textTransform.Host, textTransform.Errors);
|
||||||
|
var itemCollection = loader.CreateEdmItemCollection(inputFile);
|
||||||
|
var modelNamespace = loader.GetModelNamespace(inputFile);
|
||||||
|
var codeStringGenerator = new CodeStringGenerator(code, typeMapper, ef);
|
||||||
|
|
||||||
|
var container = itemCollection.OfType<EntityContainer>().FirstOrDefault();
|
||||||
|
if (container == null)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
#>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// <#=GetResourceString("Template_GeneratedCodeCommentLine1")#>
|
||||||
|
//
|
||||||
|
// <#=GetResourceString("Template_GeneratedCodeCommentLine2")#>
|
||||||
|
// <#=GetResourceString("Template_GeneratedCodeCommentLine3")#>
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
<#
|
||||||
|
|
||||||
|
var codeNamespace = code.VsNamespaceSuggestion();
|
||||||
|
if (!String.IsNullOrEmpty(codeNamespace))
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
namespace <#=code.EscapeNamespace(codeNamespace)#>
|
||||||
|
{
|
||||||
|
<#
|
||||||
|
PushIndent(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
#>
|
||||||
|
using System;
|
||||||
|
using System.Data.Entity;
|
||||||
|
using System.Data.Entity.Infrastructure;
|
||||||
|
<#
|
||||||
|
if (container.FunctionImports.Any())
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
using System.Data.Objects;
|
||||||
|
using System.Data.Objects.DataClasses;
|
||||||
|
using System.Linq;
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
#>
|
||||||
|
|
||||||
|
<#=Accessibility.ForType(container)#> partial class <#=code.Escape(container)#> : DbContext
|
||||||
|
{
|
||||||
|
public <#=code.Escape(container)#>()
|
||||||
|
: base("name=<#=container.Name#>")
|
||||||
|
{
|
||||||
|
<#
|
||||||
|
if (!loader.IsLazyLoadingEnabled(container))
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
this.Configuration.LazyLoadingEnabled = false;
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
#>
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
throw new UnintentionalCodeFirstException();
|
||||||
|
}
|
||||||
|
|
||||||
|
<#
|
||||||
|
foreach (var entitySet in container.BaseEntitySets.OfType<EntitySet>())
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
<#=codeStringGenerator.DbSet(entitySet)#>
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var edmFunction in container.FunctionImports)
|
||||||
|
{
|
||||||
|
WriteFunctionImport(typeMapper, codeStringGenerator, edmFunction, modelNamespace, includeMergeOption: false);
|
||||||
|
}
|
||||||
|
#>
|
||||||
|
}
|
||||||
|
<#
|
||||||
|
|
||||||
|
if (!String.IsNullOrEmpty(codeNamespace))
|
||||||
|
{
|
||||||
|
PopIndent();
|
||||||
|
#>
|
||||||
|
}
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
#>
|
||||||
|
<#+
|
||||||
|
|
||||||
|
private void WriteFunctionImport(TypeMapper typeMapper, CodeStringGenerator codeStringGenerator, EdmFunction edmFunction, string modelNamespace, bool includeMergeOption)
|
||||||
|
{
|
||||||
|
if (typeMapper.IsComposable(edmFunction))
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
|
||||||
|
[EdmFunction("<#=edmFunction.NamespaceName#>", "<#=edmFunction.Name#>")]
|
||||||
|
<#=codeStringGenerator.ComposableFunctionMethod(edmFunction, modelNamespace)#>
|
||||||
|
{
|
||||||
|
<#+
|
||||||
|
codeStringGenerator.WriteFunctionParameters(edmFunction, WriteFunctionParameter);
|
||||||
|
#>
|
||||||
|
<#=codeStringGenerator.ComposableCreateQuery(edmFunction, modelNamespace)#>
|
||||||
|
}
|
||||||
|
<#+
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
|
||||||
|
<#=codeStringGenerator.FunctionMethod(edmFunction, modelNamespace, includeMergeOption)#>
|
||||||
|
{
|
||||||
|
<#+
|
||||||
|
codeStringGenerator.WriteFunctionParameters(edmFunction, WriteFunctionParameter);
|
||||||
|
#>
|
||||||
|
<#=codeStringGenerator.ExecuteFunction(edmFunction, modelNamespace, includeMergeOption)#>
|
||||||
|
}
|
||||||
|
<#+
|
||||||
|
if (typeMapper.GenerateMergeOptionFunction(edmFunction, includeMergeOption))
|
||||||
|
{
|
||||||
|
WriteFunctionImport(typeMapper, codeStringGenerator, edmFunction, modelNamespace, includeMergeOption: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteFunctionParameter(string name, string isNotNull, string notNullInit, string nullInit)
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
var <#=name#> = <#=isNotNull#> ?
|
||||||
|
<#=notNullInit#> :
|
||||||
|
<#=nullInit#>;
|
||||||
|
|
||||||
|
<#+
|
||||||
|
}
|
||||||
|
|
||||||
|
public const string TemplateId = "CSharp_DbContext_Context_EF5";
|
||||||
|
|
||||||
|
public class CodeStringGenerator
|
||||||
|
{
|
||||||
|
private readonly CodeGenerationTools _code;
|
||||||
|
private readonly TypeMapper _typeMapper;
|
||||||
|
private readonly MetadataTools _ef;
|
||||||
|
|
||||||
|
public CodeStringGenerator(CodeGenerationTools code, TypeMapper typeMapper, MetadataTools ef)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(code, "code");
|
||||||
|
ArgumentNotNull(typeMapper, "typeMapper");
|
||||||
|
ArgumentNotNull(ef, "ef");
|
||||||
|
|
||||||
|
_code = code;
|
||||||
|
_typeMapper = typeMapper;
|
||||||
|
_ef = ef;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Property(EdmProperty edmProperty)
|
||||||
|
{
|
||||||
|
return string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"{0} {1} {2} {{ {3}get; {4}set; }}",
|
||||||
|
Accessibility.ForProperty(edmProperty),
|
||||||
|
_typeMapper.GetTypeName(edmProperty.TypeUsage),
|
||||||
|
_code.Escape(edmProperty),
|
||||||
|
_code.SpaceAfter(Accessibility.ForGetter(edmProperty)),
|
||||||
|
_code.SpaceAfter(Accessibility.ForSetter(edmProperty)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string NavigationProperty(NavigationProperty navigationProperty)
|
||||||
|
{
|
||||||
|
var endType = _typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType());
|
||||||
|
return string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"{0} {1} {2} {{ {3}get; {4}set; }}",
|
||||||
|
AccessibilityAndVirtual(Accessibility.ForProperty(navigationProperty)),
|
||||||
|
navigationProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many ? ("ICollection<" + endType + ">") : endType,
|
||||||
|
_code.Escape(navigationProperty),
|
||||||
|
_code.SpaceAfter(Accessibility.ForGetter(navigationProperty)),
|
||||||
|
_code.SpaceAfter(Accessibility.ForSetter(navigationProperty)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string AccessibilityAndVirtual(string accessibility)
|
||||||
|
{
|
||||||
|
return accessibility + (accessibility != "private" ? " virtual" : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public string EntityClassOpening(EntityType entity)
|
||||||
|
{
|
||||||
|
return string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"{0} {1}partial class {2}{3}",
|
||||||
|
Accessibility.ForType(entity),
|
||||||
|
_code.SpaceAfter(_code.AbstractOption(entity)),
|
||||||
|
_code.Escape(entity),
|
||||||
|
_code.StringBefore(" : ", _typeMapper.GetTypeName(entity.BaseType)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string EnumOpening(SimpleType enumType)
|
||||||
|
{
|
||||||
|
return string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"{0} enum {1} : {2}",
|
||||||
|
Accessibility.ForType(enumType),
|
||||||
|
_code.Escape(enumType),
|
||||||
|
_code.Escape(_typeMapper.UnderlyingClrType(enumType)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteFunctionParameters(EdmFunction edmFunction, Action<string, string, string, string> writeParameter)
|
||||||
|
{
|
||||||
|
var parameters = FunctionImportParameter.Create(edmFunction.Parameters, _code, _ef);
|
||||||
|
foreach (var parameter in parameters.Where(p => p.NeedsLocalVariable))
|
||||||
|
{
|
||||||
|
var isNotNull = parameter.IsNullableOfT ? parameter.FunctionParameterName + ".HasValue" : parameter.FunctionParameterName + " != null";
|
||||||
|
var notNullInit = "new ObjectParameter(\"" + parameter.EsqlParameterName + "\", " + parameter.FunctionParameterName + ")";
|
||||||
|
var nullInit = "new ObjectParameter(\"" + parameter.EsqlParameterName + "\", typeof(" + parameter.RawClrTypeName + "))";
|
||||||
|
writeParameter(parameter.LocalVariableName, isNotNull, notNullInit, nullInit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ComposableFunctionMethod(EdmFunction edmFunction, string modelNamespace)
|
||||||
|
{
|
||||||
|
var parameters = _typeMapper.GetParameters(edmFunction);
|
||||||
|
|
||||||
|
return string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"{0} IQueryable<{1}> {2}({3})",
|
||||||
|
AccessibilityAndVirtual(Accessibility.ForMethod(edmFunction)),
|
||||||
|
_typeMapper.GetTypeName(_typeMapper.GetReturnType(edmFunction), modelNamespace),
|
||||||
|
_code.Escape(edmFunction),
|
||||||
|
string.Join(", ", parameters.Select(p => p.FunctionParameterType + " " + p.FunctionParameterName).ToArray()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ComposableCreateQuery(EdmFunction edmFunction, string modelNamespace)
|
||||||
|
{
|
||||||
|
var parameters = _typeMapper.GetParameters(edmFunction);
|
||||||
|
|
||||||
|
return string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"return ((IObjectContextAdapter)this).ObjectContext.CreateQuery<{0}>(\"[{1}].[{2}]({3})\"{4});",
|
||||||
|
_typeMapper.GetTypeName(_typeMapper.GetReturnType(edmFunction), modelNamespace),
|
||||||
|
edmFunction.NamespaceName,
|
||||||
|
edmFunction.Name,
|
||||||
|
string.Join(", ", parameters.Select(p => "@" + p.EsqlParameterName).ToArray()),
|
||||||
|
_code.StringBefore(", ", string.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray())));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string FunctionMethod(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption)
|
||||||
|
{
|
||||||
|
var parameters = _typeMapper.GetParameters(edmFunction);
|
||||||
|
var returnType = _typeMapper.GetReturnType(edmFunction);
|
||||||
|
|
||||||
|
var paramList = String.Join(", ", parameters.Select(p => p.FunctionParameterType + " " + p.FunctionParameterName).ToArray());
|
||||||
|
if (includeMergeOption)
|
||||||
|
{
|
||||||
|
paramList = _code.StringAfter(paramList, ", ") + "MergeOption mergeOption";
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"{0} {1} {2}({3})",
|
||||||
|
AccessibilityAndVirtual(Accessibility.ForMethod(edmFunction)),
|
||||||
|
returnType == null ? "int" : "ObjectResult<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">",
|
||||||
|
_code.Escape(edmFunction),
|
||||||
|
paramList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ExecuteFunction(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption)
|
||||||
|
{
|
||||||
|
var parameters = _typeMapper.GetParameters(edmFunction);
|
||||||
|
var returnType = _typeMapper.GetReturnType(edmFunction);
|
||||||
|
|
||||||
|
var callParams = _code.StringBefore(", ", String.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray()));
|
||||||
|
if (includeMergeOption)
|
||||||
|
{
|
||||||
|
callParams = ", mergeOption" + callParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction{0}(\"{1}\"{2});",
|
||||||
|
returnType == null ? "" : "<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">",
|
||||||
|
edmFunction.Name,
|
||||||
|
callParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string DbSet(EntitySet entitySet)
|
||||||
|
{
|
||||||
|
return string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"{0} DbSet<{1}> {2} {{ get; set; }}",
|
||||||
|
Accessibility.ForReadOnlyProperty(entitySet),
|
||||||
|
_typeMapper.GetTypeName(entitySet.ElementType),
|
||||||
|
_code.Escape(entitySet));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string UsingDirectives(bool inHeader, bool includeCollections = true)
|
||||||
|
{
|
||||||
|
return inHeader == string.IsNullOrEmpty(_code.VsNamespaceSuggestion())
|
||||||
|
? string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"{0}using System;{1}" +
|
||||||
|
"{2}",
|
||||||
|
inHeader ? Environment.NewLine : "",
|
||||||
|
includeCollections ? (Environment.NewLine + "using System.Collections.Generic;") : "",
|
||||||
|
inHeader ? "" : Environment.NewLine)
|
||||||
|
: "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TypeMapper
|
||||||
|
{
|
||||||
|
private const string ExternalTypeNameAttributeName = @"http://schemas.microsoft.com/ado/2006/04/codegeneration:ExternalTypeName";
|
||||||
|
|
||||||
|
private readonly System.Collections.IList _errors;
|
||||||
|
private readonly CodeGenerationTools _code;
|
||||||
|
private readonly MetadataTools _ef;
|
||||||
|
|
||||||
|
public TypeMapper(CodeGenerationTools code, MetadataTools ef, System.Collections.IList errors)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(code, "code");
|
||||||
|
ArgumentNotNull(ef, "ef");
|
||||||
|
ArgumentNotNull(errors, "errors");
|
||||||
|
|
||||||
|
_code = code;
|
||||||
|
_ef = ef;
|
||||||
|
_errors = errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetTypeName(TypeUsage typeUsage)
|
||||||
|
{
|
||||||
|
return typeUsage == null ? null : GetTypeName(typeUsage.EdmType, _ef.IsNullable(typeUsage), modelNamespace: null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetTypeName(EdmType edmType)
|
||||||
|
{
|
||||||
|
return GetTypeName(edmType, isNullable: null, modelNamespace: null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetTypeName(TypeUsage typeUsage, string modelNamespace)
|
||||||
|
{
|
||||||
|
return typeUsage == null ? null : GetTypeName(typeUsage.EdmType, _ef.IsNullable(typeUsage), modelNamespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetTypeName(EdmType edmType, string modelNamespace)
|
||||||
|
{
|
||||||
|
return GetTypeName(edmType, isNullable: null, modelNamespace: modelNamespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetTypeName(EdmType edmType, bool? isNullable, string modelNamespace)
|
||||||
|
{
|
||||||
|
if (edmType == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var collectionType = edmType as CollectionType;
|
||||||
|
if (collectionType != null)
|
||||||
|
{
|
||||||
|
return String.Format(CultureInfo.InvariantCulture, "ICollection<{0}>", GetTypeName(collectionType.TypeUsage, modelNamespace));
|
||||||
|
}
|
||||||
|
|
||||||
|
var typeName = _code.Escape(edmType.MetadataProperties
|
||||||
|
.Where(p => p.Name == ExternalTypeNameAttributeName)
|
||||||
|
.Select(p => (string)p.Value)
|
||||||
|
.FirstOrDefault())
|
||||||
|
?? (modelNamespace != null && edmType.NamespaceName != modelNamespace ?
|
||||||
|
_code.CreateFullName(_code.EscapeNamespace(edmType.NamespaceName), _code.Escape(edmType)) :
|
||||||
|
_code.Escape(edmType));
|
||||||
|
|
||||||
|
if (edmType is StructuralType)
|
||||||
|
{
|
||||||
|
return typeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (edmType is SimpleType)
|
||||||
|
{
|
||||||
|
var clrType = UnderlyingClrType(edmType);
|
||||||
|
if (!IsEnumType(edmType))
|
||||||
|
{
|
||||||
|
typeName = _code.Escape(clrType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return clrType.IsValueType && isNullable == true ?
|
||||||
|
String.Format(CultureInfo.InvariantCulture, "Nullable<{0}>", typeName) :
|
||||||
|
typeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ArgumentException("edmType");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type UnderlyingClrType(EdmType edmType)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(edmType, "edmType");
|
||||||
|
|
||||||
|
var primitiveType = edmType as PrimitiveType;
|
||||||
|
if (primitiveType != null)
|
||||||
|
{
|
||||||
|
return primitiveType.ClrEquivalentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsEnumType(edmType))
|
||||||
|
{
|
||||||
|
return GetEnumUnderlyingType(edmType).ClrEquivalentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
return typeof(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public object GetEnumMemberValue(MetadataItem enumMember)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(enumMember, "enumMember");
|
||||||
|
|
||||||
|
var valueProperty = enumMember.GetType().GetProperty("Value");
|
||||||
|
return valueProperty == null ? null : valueProperty.GetValue(enumMember, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetEnumMemberName(MetadataItem enumMember)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(enumMember, "enumMember");
|
||||||
|
|
||||||
|
var nameProperty = enumMember.GetType().GetProperty("Name");
|
||||||
|
return nameProperty == null ? null : (string)nameProperty.GetValue(enumMember, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public System.Collections.IEnumerable GetEnumMembers(EdmType enumType)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(enumType, "enumType");
|
||||||
|
|
||||||
|
var membersProperty = enumType.GetType().GetProperty("Members");
|
||||||
|
return membersProperty != null
|
||||||
|
? (System.Collections.IEnumerable)membersProperty.GetValue(enumType, null)
|
||||||
|
: Enumerable.Empty<MetadataItem>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool EnumIsFlags(EdmType enumType)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(enumType, "enumType");
|
||||||
|
|
||||||
|
var isFlagsProperty = enumType.GetType().GetProperty("IsFlags");
|
||||||
|
return isFlagsProperty != null && (bool)isFlagsProperty.GetValue(enumType, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsEnumType(GlobalItem edmType)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(edmType, "edmType");
|
||||||
|
|
||||||
|
return edmType.GetType().Name == "EnumType";
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrimitiveType GetEnumUnderlyingType(EdmType enumType)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(enumType, "enumType");
|
||||||
|
|
||||||
|
return (PrimitiveType)enumType.GetType().GetProperty("UnderlyingType").GetValue(enumType, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string CreateLiteral(object value)
|
||||||
|
{
|
||||||
|
if (value == null || value.GetType() != typeof(TimeSpan))
|
||||||
|
{
|
||||||
|
return _code.CreateLiteral(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Format(CultureInfo.InvariantCulture, "new TimeSpan({0})", ((TimeSpan)value).Ticks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool VerifyCaseInsensitiveTypeUniqueness(IEnumerable<string> types, string sourceFile)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(types, "types");
|
||||||
|
ArgumentNotNull(sourceFile, "sourceFile");
|
||||||
|
|
||||||
|
var hash = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
|
||||||
|
if (types.Any(item => !hash.Add(item)))
|
||||||
|
{
|
||||||
|
_errors.Add(
|
||||||
|
new CompilerError(sourceFile, -1, -1, "6023",
|
||||||
|
String.Format(CultureInfo.CurrentCulture, GetResourceString("Template_CaseInsensitiveTypeConflict"))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<SimpleType> GetEnumItemsToGenerate(IEnumerable<GlobalItem> itemCollection)
|
||||||
|
{
|
||||||
|
return GetItemsToGenerate<SimpleType>(itemCollection)
|
||||||
|
.Where(e => IsEnumType(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<T> GetItemsToGenerate<T>(IEnumerable<GlobalItem> itemCollection) where T: EdmType
|
||||||
|
{
|
||||||
|
return itemCollection
|
||||||
|
.OfType<T>()
|
||||||
|
.Where(i => !i.MetadataProperties.Any(p => p.Name == ExternalTypeNameAttributeName))
|
||||||
|
.OrderBy(i => i.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<string> GetAllGlobalItems(IEnumerable<GlobalItem> itemCollection)
|
||||||
|
{
|
||||||
|
return itemCollection
|
||||||
|
.Where(i => i is EntityType || i is ComplexType || i is EntityContainer || IsEnumType(i))
|
||||||
|
.Select(g => GetGlobalItemName(g));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetGlobalItemName(GlobalItem item)
|
||||||
|
{
|
||||||
|
if (item is EdmType)
|
||||||
|
{
|
||||||
|
return ((EdmType)item).Name;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return ((EntityContainer)item).Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<EdmProperty> GetSimpleProperties(EntityType type)
|
||||||
|
{
|
||||||
|
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<EdmProperty> GetSimpleProperties(ComplexType type)
|
||||||
|
{
|
||||||
|
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<EdmProperty> GetComplexProperties(EntityType type)
|
||||||
|
{
|
||||||
|
return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<EdmProperty> GetComplexProperties(ComplexType type)
|
||||||
|
{
|
||||||
|
return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<EdmProperty> GetPropertiesWithDefaultValues(EntityType type)
|
||||||
|
{
|
||||||
|
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<EdmProperty> GetPropertiesWithDefaultValues(ComplexType type)
|
||||||
|
{
|
||||||
|
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<NavigationProperty> GetNavigationProperties(EntityType type)
|
||||||
|
{
|
||||||
|
return type.NavigationProperties.Where(np => np.DeclaringType == type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<NavigationProperty> GetCollectionNavigationProperties(EntityType type)
|
||||||
|
{
|
||||||
|
return type.NavigationProperties.Where(np => np.DeclaringType == type && np.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FunctionParameter GetReturnParameter(EdmFunction edmFunction)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(edmFunction, "edmFunction");
|
||||||
|
|
||||||
|
var returnParamsProperty = edmFunction.GetType().GetProperty("ReturnParameters");
|
||||||
|
return returnParamsProperty == null
|
||||||
|
? edmFunction.ReturnParameter
|
||||||
|
: ((IEnumerable<FunctionParameter>)returnParamsProperty.GetValue(edmFunction, null)).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsComposable(EdmFunction edmFunction)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(edmFunction, "edmFunction");
|
||||||
|
|
||||||
|
var isComposableProperty = edmFunction.GetType().GetProperty("IsComposableAttribute");
|
||||||
|
return isComposableProperty != null && (bool)isComposableProperty.GetValue(edmFunction, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<FunctionImportParameter> GetParameters(EdmFunction edmFunction)
|
||||||
|
{
|
||||||
|
return FunctionImportParameter.Create(edmFunction.Parameters, _code, _ef);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TypeUsage GetReturnType(EdmFunction edmFunction)
|
||||||
|
{
|
||||||
|
var returnParam = GetReturnParameter(edmFunction);
|
||||||
|
return returnParam == null ? null : _ef.GetElementType(returnParam.TypeUsage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GenerateMergeOptionFunction(EdmFunction edmFunction, bool includeMergeOption)
|
||||||
|
{
|
||||||
|
var returnType = GetReturnType(edmFunction);
|
||||||
|
return !includeMergeOption && returnType != null && returnType.EdmType.BuiltInTypeKind == BuiltInTypeKind.EntityType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EdmMetadataLoader
|
||||||
|
{
|
||||||
|
private readonly IDynamicHost _host;
|
||||||
|
private readonly System.Collections.IList _errors;
|
||||||
|
|
||||||
|
public EdmMetadataLoader(IDynamicHost host, System.Collections.IList errors)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(host, "host");
|
||||||
|
ArgumentNotNull(errors, "errors");
|
||||||
|
|
||||||
|
_host = host;
|
||||||
|
_errors = errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<GlobalItem> CreateEdmItemCollection(string sourcePath)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(sourcePath, "sourcePath");
|
||||||
|
|
||||||
|
if (!ValidateInputPath(sourcePath))
|
||||||
|
{
|
||||||
|
return new EdmItemCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
var schemaElement = LoadRootElement(_host.ResolvePath(sourcePath));
|
||||||
|
if (schemaElement != null)
|
||||||
|
{
|
||||||
|
using (var reader = schemaElement.CreateReader())
|
||||||
|
{
|
||||||
|
IList<EdmSchemaError> errors;
|
||||||
|
var itemCollection = MetadataItemCollectionFactory.CreateEdmItemCollection(new[] { reader }, out errors);
|
||||||
|
|
||||||
|
ProcessErrors(errors, sourcePath);
|
||||||
|
|
||||||
|
return itemCollection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new EdmItemCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetModelNamespace(string sourcePath)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(sourcePath, "sourcePath");
|
||||||
|
|
||||||
|
if (!ValidateInputPath(sourcePath))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
var model = LoadRootElement(_host.ResolvePath(sourcePath));
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
var attribute = model.Attribute("Namespace");
|
||||||
|
return attribute != null ? attribute.Value : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool ValidateInputPath(string sourcePath)
|
||||||
|
{
|
||||||
|
if (sourcePath == "$" + "edmxInputFile" + "$")
|
||||||
|
{
|
||||||
|
_errors.Add(
|
||||||
|
new CompilerError(_host.TemplateFile ?? sourcePath, 0, 0, string.Empty,
|
||||||
|
GetResourceString("Template_ReplaceVsItemTemplateToken")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public XElement LoadRootElement(string sourcePath)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(sourcePath, "sourcePath");
|
||||||
|
|
||||||
|
var root = XElement.Load(sourcePath, LoadOptions.SetBaseUri | LoadOptions.SetLineInfo);
|
||||||
|
return root.Elements()
|
||||||
|
.Where(e => e.Name.LocalName == "Runtime")
|
||||||
|
.Elements()
|
||||||
|
.Where(e => e.Name.LocalName == "ConceptualModels")
|
||||||
|
.Elements()
|
||||||
|
.Where(e => e.Name.LocalName == "Schema")
|
||||||
|
.FirstOrDefault()
|
||||||
|
?? root;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ProcessErrors(IEnumerable<EdmSchemaError> errors, string sourceFilePath)
|
||||||
|
{
|
||||||
|
foreach (var error in errors)
|
||||||
|
{
|
||||||
|
_errors.Add(
|
||||||
|
new CompilerError(
|
||||||
|
error.SchemaLocation ?? sourceFilePath,
|
||||||
|
error.Line,
|
||||||
|
error.Column,
|
||||||
|
error.ErrorCode.ToString(CultureInfo.InvariantCulture),
|
||||||
|
error.Message)
|
||||||
|
{
|
||||||
|
IsWarning = error.Severity == EdmSchemaErrorSeverity.Warning
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsLazyLoadingEnabled(EntityContainer container)
|
||||||
|
{
|
||||||
|
string lazyLoadingAttributeValue;
|
||||||
|
var lazyLoadingAttributeName = MetadataConstants.EDM_ANNOTATION_09_02 + ":LazyLoadingEnabled";
|
||||||
|
bool isLazyLoading;
|
||||||
|
return !MetadataTools.TryGetStringMetadataPropertySetting(container, lazyLoadingAttributeName, out lazyLoadingAttributeValue)
|
||||||
|
|| !bool.TryParse(lazyLoadingAttributeValue, out isLazyLoading)
|
||||||
|
|| isLazyLoading;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ArgumentNotNull<T>(T arg, string name) where T : class
|
||||||
|
{
|
||||||
|
if (arg == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly Lazy<System.Resources.ResourceManager> ResourceManager =
|
||||||
|
new Lazy<System.Resources.ResourceManager>(
|
||||||
|
() => new System.Resources.ResourceManager("System.Data.Entity.Design", typeof(MetadataItemCollectionFactory).Assembly), isThreadSafe: true);
|
||||||
|
|
||||||
|
public static string GetResourceString(string resourceName)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(resourceName, "resourceName");
|
||||||
|
|
||||||
|
return ResourceManager.Value.GetString(resourceName, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
#>
|
10
musicschoolapp/Model1.Designer.cs
generated
Normal file
10
musicschoolapp/Model1.Designer.cs
generated
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// Создание кода T4 для модели "C:\Users\g5org\Desktop\pre\musicschoolapp\musicschoolapp\Model1.edmx" включено.
|
||||||
|
// Чтобы включить формирование кода прежних версий, измените значение свойства "Стратегия создания кода" конструктора
|
||||||
|
// на "Legacy ObjectContext". Это свойство доступно в окне "Свойства", если модель
|
||||||
|
// открыта в конструкторе.
|
||||||
|
|
||||||
|
// Если не сформированы контекст и классы сущности, возможная причина в том, что вы создали пустую модель, но
|
||||||
|
// еще не выбрали версию Entity Framework для использования. Чтобы сформировать класс контекста и классы сущностей
|
||||||
|
// для своей модели, откройте модель в конструкторе, щелкните правой кнопкой область конструктора и
|
||||||
|
// выберите "Обновить модель из базы данных", "Сформировать базу данных из модели" или "Добавить элемент формирования
|
||||||
|
// кода...".
|
9
musicschoolapp/Model1.cs
Normal file
9
musicschoolapp/Model1.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// Этот код был создан из шаблона.
|
||||||
|
//
|
||||||
|
// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения.
|
||||||
|
// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
315
musicschoolapp/Model1.edmx
Normal file
315
musicschoolapp/Model1.edmx
Normal file
@ -0,0 +1,315 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx">
|
||||||
|
<!-- EF Runtime content -->
|
||||||
|
<edmx:Runtime>
|
||||||
|
<!-- SSDL content -->
|
||||||
|
<edmx:StorageModels>
|
||||||
|
<Schema Namespace="Хранилище musicschoolModel" Provider="System.Data.SqlClient" ProviderManifestToken="2008" Alias="Self" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
|
||||||
|
<EntityType Name="Course">
|
||||||
|
<Key>
|
||||||
|
<PropertyRef Name="CourseID" />
|
||||||
|
</Key>
|
||||||
|
<Property Name="CourseID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
|
||||||
|
<Property Name="Name" Type="nvarchar" MaxLength="100" Nullable="false" />
|
||||||
|
<Property Name="Description" Type="nvarchar" MaxLength="500" />
|
||||||
|
<Property Name="Duration" Type="int" Nullable="false" />
|
||||||
|
<Property Name="Price" Type="decimal" Precision="10" Scale="2" Nullable="false" />
|
||||||
|
</EntityType>
|
||||||
|
<EntityType Name="Enrollment">
|
||||||
|
<Key>
|
||||||
|
<PropertyRef Name="EnrollmentID" />
|
||||||
|
</Key>
|
||||||
|
<Property Name="EnrollmentID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
|
||||||
|
<Property Name="StudentID" Type="int" Nullable="false" />
|
||||||
|
<Property Name="CourseID" Type="int" Nullable="false" />
|
||||||
|
<Property Name="EnrollmentDate" Type="date" Nullable="false" />
|
||||||
|
<Property Name="Grade" Type="decimal" Precision="3" Scale="2" />
|
||||||
|
</EntityType>
|
||||||
|
<EntityType Name="Instruments">
|
||||||
|
<Key>
|
||||||
|
<PropertyRef Name="Id_instrument" />
|
||||||
|
</Key>
|
||||||
|
<Property Name="Id_instrument" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
|
||||||
|
<Property Name="Name_instrument" Type="nvarchar" MaxLength="50" Nullable="false" />
|
||||||
|
<Property Name="Date_receiving" Type="datetime" />
|
||||||
|
<Property Name="isPersonal" Type="bit" />
|
||||||
|
</EntityType>
|
||||||
|
<EntityType Name="Student">
|
||||||
|
<Key>
|
||||||
|
<PropertyRef Name="StudentID" />
|
||||||
|
</Key>
|
||||||
|
<Property Name="StudentID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
|
||||||
|
<Property Name="FirstName" Type="nvarchar" MaxLength="50" Nullable="false" />
|
||||||
|
<Property Name="LastName" Type="nvarchar" MaxLength="50" Nullable="false" />
|
||||||
|
<Property Name="BirthDate" Type="date" Nullable="false" />
|
||||||
|
<Property Name="Phone" Type="nvarchar" MaxLength="20" />
|
||||||
|
<Property Name="Email" Type="nvarchar" MaxLength="50" />
|
||||||
|
<Property Name="photo" Type="image" />
|
||||||
|
<Property Name="Id_instrument" Type="int" />
|
||||||
|
</EntityType>
|
||||||
|
<EntityType Name="User">
|
||||||
|
<Key>
|
||||||
|
<PropertyRef Name="UserID" />
|
||||||
|
</Key>
|
||||||
|
<Property Name="UserID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
|
||||||
|
<Property Name="username" Type="nvarchar" MaxLength="50" Nullable="false" />
|
||||||
|
<Property Name="password" Type="nvarchar" MaxLength="50" Nullable="false" />
|
||||||
|
<Property Name="permission_level" Type="int" Nullable="false" />
|
||||||
|
</EntityType>
|
||||||
|
<Association Name="FK__Enrollmen__Cours__14270015">
|
||||||
|
<End Role="Course" Type="Self.Course" Multiplicity="1" />
|
||||||
|
<End Role="Enrollment" Type="Self.Enrollment" Multiplicity="*" />
|
||||||
|
<ReferentialConstraint>
|
||||||
|
<Principal Role="Course">
|
||||||
|
<PropertyRef Name="CourseID" />
|
||||||
|
</Principal>
|
||||||
|
<Dependent Role="Enrollment">
|
||||||
|
<PropertyRef Name="CourseID" />
|
||||||
|
</Dependent>
|
||||||
|
</ReferentialConstraint>
|
||||||
|
</Association>
|
||||||
|
<Association Name="FK__Enrollmen__Stude__151B244E">
|
||||||
|
<End Role="Student" Type="Self.Student" Multiplicity="1" />
|
||||||
|
<End Role="Enrollment" Type="Self.Enrollment" Multiplicity="*" />
|
||||||
|
<ReferentialConstraint>
|
||||||
|
<Principal Role="Student">
|
||||||
|
<PropertyRef Name="StudentID" />
|
||||||
|
</Principal>
|
||||||
|
<Dependent Role="Enrollment">
|
||||||
|
<PropertyRef Name="StudentID" />
|
||||||
|
</Dependent>
|
||||||
|
</ReferentialConstraint>
|
||||||
|
</Association>
|
||||||
|
<Association Name="FK_Student_ToTable">
|
||||||
|
<End Role="Instruments" Type="Self.Instruments" Multiplicity="0..1" />
|
||||||
|
<End Role="Student" Type="Self.Student" Multiplicity="*" />
|
||||||
|
<ReferentialConstraint>
|
||||||
|
<Principal Role="Instruments">
|
||||||
|
<PropertyRef Name="Id_instrument" />
|
||||||
|
</Principal>
|
||||||
|
<Dependent Role="Student">
|
||||||
|
<PropertyRef Name="Id_instrument" />
|
||||||
|
</Dependent>
|
||||||
|
</ReferentialConstraint>
|
||||||
|
</Association>
|
||||||
|
<EntityContainer Name="Хранилище musicschoolModelContainer">
|
||||||
|
<EntitySet Name="Course" EntityType="Self.Course" Schema="dbo" store:Type="Tables" />
|
||||||
|
<EntitySet Name="Enrollment" EntityType="Self.Enrollment" Schema="dbo" store:Type="Tables" />
|
||||||
|
<EntitySet Name="Instruments" EntityType="Self.Instruments" Schema="dbo" store:Type="Tables" />
|
||||||
|
<EntitySet Name="Student" EntityType="Self.Student" Schema="dbo" store:Type="Tables" />
|
||||||
|
<EntitySet Name="User" EntityType="Self.User" Schema="dbo" store:Type="Tables" />
|
||||||
|
<AssociationSet Name="FK__Enrollmen__Cours__14270015" Association="Self.FK__Enrollmen__Cours__14270015">
|
||||||
|
<End Role="Course" EntitySet="Course" />
|
||||||
|
<End Role="Enrollment" EntitySet="Enrollment" />
|
||||||
|
</AssociationSet>
|
||||||
|
<AssociationSet Name="FK__Enrollmen__Stude__151B244E" Association="Self.FK__Enrollmen__Stude__151B244E">
|
||||||
|
<End Role="Student" EntitySet="Student" />
|
||||||
|
<End Role="Enrollment" EntitySet="Enrollment" />
|
||||||
|
</AssociationSet>
|
||||||
|
<AssociationSet Name="FK_Student_ToTable" Association="Self.FK_Student_ToTable">
|
||||||
|
<End Role="Instruments" EntitySet="Instruments" />
|
||||||
|
<End Role="Student" EntitySet="Student" />
|
||||||
|
</AssociationSet>
|
||||||
|
</EntityContainer>
|
||||||
|
</Schema></edmx:StorageModels>
|
||||||
|
<!-- CSDL content -->
|
||||||
|
<edmx:ConceptualModels>
|
||||||
|
<Schema Namespace="musicschoolModel" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
|
||||||
|
<EntityContainer Name="musicschoolEntities1" annotation:LazyLoadingEnabled="true">
|
||||||
|
<EntitySet Name="Course" EntityType="musicschoolModel.Course" />
|
||||||
|
<EntitySet Name="Enrollment" EntityType="musicschoolModel.Enrollment" />
|
||||||
|
<EntitySet Name="Student" EntityType="musicschoolModel.Student" />
|
||||||
|
<EntitySet Name="User" EntityType="musicschoolModel.User" />
|
||||||
|
<AssociationSet Name="FK__Enrollmen__Cours__14270015" Association="musicschoolModel.FK__Enrollmen__Cours__14270015">
|
||||||
|
<End Role="Course" EntitySet="Course" />
|
||||||
|
<End Role="Enrollment" EntitySet="Enrollment" />
|
||||||
|
</AssociationSet>
|
||||||
|
<AssociationSet Name="FK__Enrollmen__Stude__151B244E" Association="musicschoolModel.FK__Enrollmen__Stude__151B244E">
|
||||||
|
<End Role="Student" EntitySet="Student" />
|
||||||
|
<End Role="Enrollment" EntitySet="Enrollment" />
|
||||||
|
</AssociationSet>
|
||||||
|
<EntitySet Name="Instruments" EntityType="musicschoolModel.Instruments" />
|
||||||
|
<AssociationSet Name="FK_Student_ToTable" Association="musicschoolModel.FK_Student_ToTable">
|
||||||
|
<End Role="Instruments" EntitySet="Instruments" />
|
||||||
|
<End Role="Student" EntitySet="Student" />
|
||||||
|
</AssociationSet>
|
||||||
|
</EntityContainer>
|
||||||
|
<EntityType Name="Course">
|
||||||
|
<Key>
|
||||||
|
<PropertyRef Name="CourseID" />
|
||||||
|
</Key>
|
||||||
|
<Property Name="CourseID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
|
||||||
|
<Property Name="Name" Type="String" Nullable="false" MaxLength="100" FixedLength="false" Unicode="true" />
|
||||||
|
<Property Name="Description" Type="String" MaxLength="500" FixedLength="false" Unicode="true" />
|
||||||
|
<Property Name="Duration" Type="Int32" Nullable="false" />
|
||||||
|
<Property Name="Price" Type="Decimal" Nullable="false" Precision="10" Scale="2" />
|
||||||
|
<NavigationProperty Name="Enrollment" Relationship="musicschoolModel.FK__Enrollmen__Cours__14270015" FromRole="Course" ToRole="Enrollment" />
|
||||||
|
</EntityType>
|
||||||
|
<EntityType Name="Enrollment">
|
||||||
|
<Key>
|
||||||
|
<PropertyRef Name="EnrollmentID" />
|
||||||
|
</Key>
|
||||||
|
<Property Name="EnrollmentID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
|
||||||
|
<Property Name="StudentID" Type="Int32" Nullable="false" />
|
||||||
|
<Property Name="CourseID" Type="Int32" Nullable="false" />
|
||||||
|
<Property Name="EnrollmentDate" Type="DateTime" Nullable="false" Precision="0" />
|
||||||
|
<Property Name="Grade" Type="Decimal" Precision="3" Scale="2" />
|
||||||
|
<NavigationProperty Name="Course" Relationship="musicschoolModel.FK__Enrollmen__Cours__14270015" FromRole="Enrollment" ToRole="Course" />
|
||||||
|
<NavigationProperty Name="Student" Relationship="musicschoolModel.FK__Enrollmen__Stude__151B244E" FromRole="Enrollment" ToRole="Student" />
|
||||||
|
</EntityType>
|
||||||
|
<EntityType Name="Student">
|
||||||
|
<Key>
|
||||||
|
<PropertyRef Name="StudentID" />
|
||||||
|
</Key>
|
||||||
|
<Property Name="StudentID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
|
||||||
|
<Property Name="FirstName" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
|
||||||
|
<Property Name="LastName" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
|
||||||
|
<Property Name="BirthDate" Type="DateTime" Nullable="false" Precision="0" />
|
||||||
|
<Property Name="Phone" Type="String" MaxLength="20" FixedLength="false" Unicode="true" />
|
||||||
|
<Property Name="Email" Type="String" MaxLength="50" FixedLength="false" Unicode="true" />
|
||||||
|
<Property Name="photo" Type="Binary" MaxLength="Max" FixedLength="false" />
|
||||||
|
<NavigationProperty Name="Enrollment" Relationship="musicschoolModel.FK__Enrollmen__Stude__151B244E" FromRole="Student" ToRole="Enrollment" />
|
||||||
|
<Property Name="Id_instrument" Type="Int32" />
|
||||||
|
<NavigationProperty Name="Instruments" Relationship="musicschoolModel.FK_Student_ToTable" FromRole="Student" ToRole="Instruments" />
|
||||||
|
</EntityType>
|
||||||
|
<EntityType Name="User">
|
||||||
|
<Key>
|
||||||
|
<PropertyRef Name="UserID" />
|
||||||
|
</Key>
|
||||||
|
<Property Name="UserID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
|
||||||
|
<Property Name="username" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
|
||||||
|
<Property Name="password" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
|
||||||
|
<Property Name="permission_level" Type="Int32" Nullable="false" />
|
||||||
|
</EntityType>
|
||||||
|
<Association Name="FK__Enrollmen__Cours__14270015">
|
||||||
|
<End Type="musicschoolModel.Course" Role="Course" Multiplicity="1" />
|
||||||
|
<End Type="musicschoolModel.Enrollment" Role="Enrollment" Multiplicity="*" />
|
||||||
|
<ReferentialConstraint>
|
||||||
|
<Principal Role="Course">
|
||||||
|
<PropertyRef Name="CourseID" />
|
||||||
|
</Principal>
|
||||||
|
<Dependent Role="Enrollment">
|
||||||
|
<PropertyRef Name="CourseID" />
|
||||||
|
</Dependent>
|
||||||
|
</ReferentialConstraint>
|
||||||
|
</Association>
|
||||||
|
<Association Name="FK__Enrollmen__Stude__151B244E">
|
||||||
|
<End Type="musicschoolModel.Student" Role="Student" Multiplicity="1" />
|
||||||
|
<End Type="musicschoolModel.Enrollment" Role="Enrollment" Multiplicity="*" />
|
||||||
|
<ReferentialConstraint>
|
||||||
|
<Principal Role="Student">
|
||||||
|
<PropertyRef Name="StudentID" />
|
||||||
|
</Principal>
|
||||||
|
<Dependent Role="Enrollment">
|
||||||
|
<PropertyRef Name="StudentID" />
|
||||||
|
</Dependent>
|
||||||
|
</ReferentialConstraint>
|
||||||
|
</Association>
|
||||||
|
<EntityType Name="Instruments">
|
||||||
|
<Key>
|
||||||
|
<PropertyRef Name="Id_instrument" />
|
||||||
|
</Key>
|
||||||
|
<Property Name="Id_instrument" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
|
||||||
|
<Property Name="Name_instrument" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
|
||||||
|
<Property Name="Date_receiving" Type="DateTime" Precision="3" />
|
||||||
|
<Property Name="isPersonal" Type="Boolean" />
|
||||||
|
<NavigationProperty Name="Student" Relationship="musicschoolModel.FK_Student_ToTable" FromRole="Instruments" ToRole="Student" />
|
||||||
|
</EntityType>
|
||||||
|
<Association Name="FK_Student_ToTable">
|
||||||
|
<End Type="musicschoolModel.Instruments" Role="Instruments" Multiplicity="0..1" />
|
||||||
|
<End Type="musicschoolModel.Student" Role="Student" Multiplicity="*" />
|
||||||
|
<ReferentialConstraint>
|
||||||
|
<Principal Role="Instruments">
|
||||||
|
<PropertyRef Name="Id_instrument" />
|
||||||
|
</Principal>
|
||||||
|
<Dependent Role="Student">
|
||||||
|
<PropertyRef Name="Id_instrument" />
|
||||||
|
</Dependent>
|
||||||
|
</ReferentialConstraint>
|
||||||
|
</Association>
|
||||||
|
</Schema>
|
||||||
|
</edmx:ConceptualModels>
|
||||||
|
<!-- C-S mapping content -->
|
||||||
|
<edmx:Mappings>
|
||||||
|
<Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs">
|
||||||
|
<EntityContainerMapping StorageEntityContainer="Хранилище musicschoolModelContainer" CdmEntityContainer="musicschoolEntities1">
|
||||||
|
<EntitySetMapping Name="Course">
|
||||||
|
<EntityTypeMapping TypeName="musicschoolModel.Course">
|
||||||
|
<MappingFragment StoreEntitySet="Course">
|
||||||
|
<ScalarProperty Name="Price" ColumnName="Price" />
|
||||||
|
<ScalarProperty Name="Duration" ColumnName="Duration" />
|
||||||
|
<ScalarProperty Name="Description" ColumnName="Description" />
|
||||||
|
<ScalarProperty Name="Name" ColumnName="Name" />
|
||||||
|
<ScalarProperty Name="CourseID" ColumnName="CourseID" />
|
||||||
|
</MappingFragment>
|
||||||
|
</EntityTypeMapping>
|
||||||
|
</EntitySetMapping>
|
||||||
|
<EntitySetMapping Name="Enrollment">
|
||||||
|
<EntityTypeMapping TypeName="musicschoolModel.Enrollment">
|
||||||
|
<MappingFragment StoreEntitySet="Enrollment">
|
||||||
|
<ScalarProperty Name="Grade" ColumnName="Grade" />
|
||||||
|
<ScalarProperty Name="EnrollmentDate" ColumnName="EnrollmentDate" />
|
||||||
|
<ScalarProperty Name="CourseID" ColumnName="CourseID" />
|
||||||
|
<ScalarProperty Name="StudentID" ColumnName="StudentID" />
|
||||||
|
<ScalarProperty Name="EnrollmentID" ColumnName="EnrollmentID" />
|
||||||
|
</MappingFragment>
|
||||||
|
</EntityTypeMapping>
|
||||||
|
</EntitySetMapping>
|
||||||
|
<EntitySetMapping Name="Student">
|
||||||
|
<EntityTypeMapping TypeName="musicschoolModel.Student">
|
||||||
|
<MappingFragment StoreEntitySet="Student">
|
||||||
|
<ScalarProperty Name="Id_instrument" ColumnName="Id_instrument" />
|
||||||
|
<ScalarProperty Name="photo" ColumnName="photo" />
|
||||||
|
<ScalarProperty Name="Email" ColumnName="Email" />
|
||||||
|
<ScalarProperty Name="Phone" ColumnName="Phone" />
|
||||||
|
<ScalarProperty Name="BirthDate" ColumnName="BirthDate" />
|
||||||
|
<ScalarProperty Name="LastName" ColumnName="LastName" />
|
||||||
|
<ScalarProperty Name="FirstName" ColumnName="FirstName" />
|
||||||
|
<ScalarProperty Name="StudentID" ColumnName="StudentID" />
|
||||||
|
</MappingFragment>
|
||||||
|
</EntityTypeMapping>
|
||||||
|
</EntitySetMapping>
|
||||||
|
<EntitySetMapping Name="User">
|
||||||
|
<EntityTypeMapping TypeName="musicschoolModel.User">
|
||||||
|
<MappingFragment StoreEntitySet="User">
|
||||||
|
<ScalarProperty Name="permission_level" ColumnName="permission_level" />
|
||||||
|
<ScalarProperty Name="password" ColumnName="password" />
|
||||||
|
<ScalarProperty Name="username" ColumnName="username" />
|
||||||
|
<ScalarProperty Name="UserID" ColumnName="UserID" />
|
||||||
|
</MappingFragment>
|
||||||
|
</EntityTypeMapping>
|
||||||
|
</EntitySetMapping>
|
||||||
|
<EntitySetMapping Name="Instruments">
|
||||||
|
<EntityTypeMapping TypeName="musicschoolModel.Instruments">
|
||||||
|
<MappingFragment StoreEntitySet="Instruments">
|
||||||
|
<ScalarProperty Name="isPersonal" ColumnName="isPersonal" />
|
||||||
|
<ScalarProperty Name="Date_receiving" ColumnName="Date_receiving" />
|
||||||
|
<ScalarProperty Name="Name_instrument" ColumnName="Name_instrument" />
|
||||||
|
<ScalarProperty Name="Id_instrument" ColumnName="Id_instrument" />
|
||||||
|
</MappingFragment>
|
||||||
|
</EntityTypeMapping>
|
||||||
|
</EntitySetMapping>
|
||||||
|
</EntityContainerMapping>
|
||||||
|
</Mapping>
|
||||||
|
</edmx:Mappings>
|
||||||
|
</edmx:Runtime>
|
||||||
|
<!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
|
||||||
|
<Designer xmlns="http://schemas.microsoft.com/ado/2008/10/edmx">
|
||||||
|
<Connection>
|
||||||
|
<DesignerInfoPropertySet>
|
||||||
|
<DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
|
||||||
|
</DesignerInfoPropertySet>
|
||||||
|
</Connection>
|
||||||
|
<Options>
|
||||||
|
<DesignerInfoPropertySet>
|
||||||
|
<DesignerProperty Name="ValidateOnBuild" Value="true" />
|
||||||
|
<DesignerProperty Name="EnablePluralization" Value="false" />
|
||||||
|
<DesignerProperty Name="IncludeForeignKeysInModel" Value="true" />
|
||||||
|
<DesignerProperty Name="UseLegacyProvider" Value="true" />
|
||||||
|
<DesignerProperty Name="CodeGenerationStrategy" Value="Нет" />
|
||||||
|
</DesignerInfoPropertySet>
|
||||||
|
</Options>
|
||||||
|
<!-- Diagram content (shape and connector positions) -->
|
||||||
|
<Diagrams></Diagrams>
|
||||||
|
</Designer>
|
||||||
|
</edmx:Edmx>
|
19
musicschoolapp/Model1.edmx.diagram
Normal file
19
musicschoolapp/Model1.edmx.diagram
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx">
|
||||||
|
<!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
|
||||||
|
<edmx:Designer xmlns="http://schemas.microsoft.com/ado/2008/10/edmx">
|
||||||
|
<!-- Diagram content (shape and connector positions) -->
|
||||||
|
<edmx:Diagrams>
|
||||||
|
<Diagram DiagramId="90d49020b05e4c1a9bf536bde0b7d523" Name="Diagram1">
|
||||||
|
<EntityTypeShape EntityType="musicschoolModel.Course" Width="1.5" PointX="0.75" PointY="1" />
|
||||||
|
<EntityTypeShape EntityType="musicschoolModel.Enrollment" Width="1.5" PointX="3" PointY="1" />
|
||||||
|
<EntityTypeShape EntityType="musicschoolModel.Student" Width="1.5" PointX="0.75" PointY="4.875" />
|
||||||
|
<EntityTypeShape EntityType="musicschoolModel.User" Width="1.5" PointX="2.75" PointY="4.75" />
|
||||||
|
<AssociationConnector Association="musicschoolModel.FK__Enrollmen__Cours__14270015" />
|
||||||
|
<AssociationConnector Association="musicschoolModel.FK__Enrollmen__Stude__151B244E" />
|
||||||
|
<EntityTypeShape EntityType="musicschoolModel.Instruments" Width="1.5" PointX="0.75" PointY="9.375" />
|
||||||
|
<AssociationConnector Association="musicschoolModel.FK_Student_ToTable" />
|
||||||
|
</Diagram>
|
||||||
|
</edmx:Diagrams>
|
||||||
|
</edmx:Designer>
|
||||||
|
</edmx:Edmx>
|
845
musicschoolapp/Model1.tt
Normal file
845
musicschoolapp/Model1.tt
Normal file
@ -0,0 +1,845 @@
|
|||||||
|
<#@ template language="C#" debug="false" hostspecific="true"#>
|
||||||
|
<#@ include file="EF.Utility.CS.ttinclude"#><#@
|
||||||
|
output extension=".cs"#><#
|
||||||
|
|
||||||
|
const string inputFile = @"Model1.edmx";
|
||||||
|
var textTransform = DynamicTextTransformation.Create(this);
|
||||||
|
var code = new CodeGenerationTools(this);
|
||||||
|
var ef = new MetadataTools(this);
|
||||||
|
var typeMapper = new TypeMapper(code, ef, textTransform.Errors);
|
||||||
|
var fileManager = EntityFrameworkTemplateFileManager.Create(this);
|
||||||
|
var itemCollection = new EdmMetadataLoader(textTransform.Host, textTransform.Errors).CreateEdmItemCollection(inputFile);
|
||||||
|
var codeStringGenerator = new CodeStringGenerator(code, typeMapper, ef);
|
||||||
|
|
||||||
|
if (!typeMapper.VerifyCaseInsensitiveTypeUniqueness(typeMapper.GetAllGlobalItems(itemCollection), inputFile))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
WriteHeader(codeStringGenerator, fileManager);
|
||||||
|
|
||||||
|
foreach (var entity in typeMapper.GetItemsToGenerate<EntityType>(itemCollection))
|
||||||
|
{
|
||||||
|
fileManager.StartNewFile(entity.Name + ".cs");
|
||||||
|
BeginNamespace(code);
|
||||||
|
#>
|
||||||
|
<#=codeStringGenerator.UsingDirectives(inHeader: false)#>
|
||||||
|
<#=codeStringGenerator.EntityClassOpening(entity)#>
|
||||||
|
{
|
||||||
|
<#
|
||||||
|
var propertiesWithDefaultValues = typeMapper.GetPropertiesWithDefaultValues(entity);
|
||||||
|
var collectionNavigationProperties = typeMapper.GetCollectionNavigationProperties(entity);
|
||||||
|
var complexProperties = typeMapper.GetComplexProperties(entity);
|
||||||
|
|
||||||
|
if (propertiesWithDefaultValues.Any() || collectionNavigationProperties.Any() || complexProperties.Any())
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
public <#=code.Escape(entity)#>()
|
||||||
|
{
|
||||||
|
<#
|
||||||
|
foreach (var edmProperty in propertiesWithDefaultValues)
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
this.<#=code.Escape(edmProperty)#> = <#=typeMapper.CreateLiteral(edmProperty.DefaultValue)#>;
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var navigationProperty in collectionNavigationProperties)
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
this.<#=code.Escape(navigationProperty)#> = new HashSet<<#=typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType())#>>();
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var complexProperty in complexProperties)
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
this.<#=code.Escape(complexProperty)#> = new <#=typeMapper.GetTypeName(complexProperty.TypeUsage)#>();
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
#>
|
||||||
|
}
|
||||||
|
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
|
||||||
|
var simpleProperties = typeMapper.GetSimpleProperties(entity);
|
||||||
|
if (simpleProperties.Any())
|
||||||
|
{
|
||||||
|
foreach (var edmProperty in simpleProperties)
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
<#=codeStringGenerator.Property(edmProperty)#>
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (complexProperties.Any())
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
|
||||||
|
<#
|
||||||
|
foreach(var complexProperty in complexProperties)
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
<#=codeStringGenerator.Property(complexProperty)#>
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var navigationProperties = typeMapper.GetNavigationProperties(entity);
|
||||||
|
if (navigationProperties.Any())
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
|
||||||
|
<#
|
||||||
|
foreach (var navigationProperty in navigationProperties)
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
<#=codeStringGenerator.NavigationProperty(navigationProperty)#>
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#>
|
||||||
|
}
|
||||||
|
<#
|
||||||
|
EndNamespace(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var complex in typeMapper.GetItemsToGenerate<ComplexType>(itemCollection))
|
||||||
|
{
|
||||||
|
fileManager.StartNewFile(complex.Name + ".cs");
|
||||||
|
BeginNamespace(code);
|
||||||
|
#>
|
||||||
|
<#=codeStringGenerator.UsingDirectives(inHeader: false, includeCollections: false)#>
|
||||||
|
<#=Accessibility.ForType(complex)#> partial class <#=code.Escape(complex)#>
|
||||||
|
{
|
||||||
|
<#
|
||||||
|
var complexProperties = typeMapper.GetComplexProperties(complex);
|
||||||
|
var propertiesWithDefaultValues = typeMapper.GetPropertiesWithDefaultValues(complex);
|
||||||
|
|
||||||
|
if (propertiesWithDefaultValues.Any() || complexProperties.Any())
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
public <#=code.Escape(complex)#>()
|
||||||
|
{
|
||||||
|
<#
|
||||||
|
foreach (var edmProperty in propertiesWithDefaultValues)
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
this.<#=code.Escape(edmProperty)#> = <#=typeMapper.CreateLiteral(edmProperty.DefaultValue)#>;
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var complexProperty in complexProperties)
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
this.<#=code.Escape(complexProperty)#> = new <#=typeMapper.GetTypeName(complexProperty.TypeUsage)#>();
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
#>
|
||||||
|
}
|
||||||
|
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
|
||||||
|
var simpleProperties = typeMapper.GetSimpleProperties(complex);
|
||||||
|
if (simpleProperties.Any())
|
||||||
|
{
|
||||||
|
foreach(var edmProperty in simpleProperties)
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
<#=codeStringGenerator.Property(edmProperty)#>
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (complexProperties.Any())
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
|
||||||
|
<#
|
||||||
|
foreach(var edmProperty in complexProperties)
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
<#=codeStringGenerator.Property(edmProperty)#>
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#>
|
||||||
|
}
|
||||||
|
<#
|
||||||
|
EndNamespace(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var enumType in typeMapper.GetEnumItemsToGenerate(itemCollection))
|
||||||
|
{
|
||||||
|
fileManager.StartNewFile(enumType.Name + ".cs");
|
||||||
|
BeginNamespace(code);
|
||||||
|
#>
|
||||||
|
<#=codeStringGenerator.UsingDirectives(inHeader: false, includeCollections: false)#>
|
||||||
|
<#
|
||||||
|
if (typeMapper.EnumIsFlags(enumType))
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
[Flags]
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
#>
|
||||||
|
<#=codeStringGenerator.EnumOpening(enumType)#>
|
||||||
|
{
|
||||||
|
<#
|
||||||
|
var foundOne = false;
|
||||||
|
|
||||||
|
foreach (MetadataItem member in typeMapper.GetEnumMembers(enumType))
|
||||||
|
{
|
||||||
|
foundOne = true;
|
||||||
|
#>
|
||||||
|
<#=code.Escape(typeMapper.GetEnumMemberName(member))#> = <#=typeMapper.GetEnumMemberValue(member)#>,
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foundOne)
|
||||||
|
{
|
||||||
|
this.GenerationEnvironment.Remove(this.GenerationEnvironment.Length - 3, 1);
|
||||||
|
}
|
||||||
|
#>
|
||||||
|
}
|
||||||
|
<#
|
||||||
|
EndNamespace(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
fileManager.Process();
|
||||||
|
|
||||||
|
#>
|
||||||
|
<#+
|
||||||
|
|
||||||
|
public void WriteHeader(CodeStringGenerator codeStringGenerator, EntityFrameworkTemplateFileManager fileManager)
|
||||||
|
{
|
||||||
|
fileManager.StartHeader();
|
||||||
|
#>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// <#=GetResourceString("Template_GeneratedCodeCommentLine1")#>
|
||||||
|
//
|
||||||
|
// <#=GetResourceString("Template_GeneratedCodeCommentLine2")#>
|
||||||
|
// <#=GetResourceString("Template_GeneratedCodeCommentLine3")#>
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
<#=codeStringGenerator.UsingDirectives(inHeader: true)#>
|
||||||
|
<#+
|
||||||
|
fileManager.EndBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void BeginNamespace(CodeGenerationTools code)
|
||||||
|
{
|
||||||
|
var codeNamespace = code.VsNamespaceSuggestion();
|
||||||
|
if (!String.IsNullOrEmpty(codeNamespace))
|
||||||
|
{
|
||||||
|
#>
|
||||||
|
namespace <#=code.EscapeNamespace(codeNamespace)#>
|
||||||
|
{
|
||||||
|
<#+
|
||||||
|
PushIndent(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void EndNamespace(CodeGenerationTools code)
|
||||||
|
{
|
||||||
|
if (!String.IsNullOrEmpty(code.VsNamespaceSuggestion()))
|
||||||
|
{
|
||||||
|
PopIndent();
|
||||||
|
#>
|
||||||
|
}
|
||||||
|
<#+
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public const string TemplateId = "CSharp_DbContext_Types_EF5";
|
||||||
|
|
||||||
|
public class CodeStringGenerator
|
||||||
|
{
|
||||||
|
private readonly CodeGenerationTools _code;
|
||||||
|
private readonly TypeMapper _typeMapper;
|
||||||
|
private readonly MetadataTools _ef;
|
||||||
|
|
||||||
|
public CodeStringGenerator(CodeGenerationTools code, TypeMapper typeMapper, MetadataTools ef)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(code, "code");
|
||||||
|
ArgumentNotNull(typeMapper, "typeMapper");
|
||||||
|
ArgumentNotNull(ef, "ef");
|
||||||
|
|
||||||
|
_code = code;
|
||||||
|
_typeMapper = typeMapper;
|
||||||
|
_ef = ef;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Property(EdmProperty edmProperty)
|
||||||
|
{
|
||||||
|
return string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"{0} {1} {2} {{ {3}get; {4}set; }}",
|
||||||
|
Accessibility.ForProperty(edmProperty),
|
||||||
|
_typeMapper.GetTypeName(edmProperty.TypeUsage),
|
||||||
|
_code.Escape(edmProperty),
|
||||||
|
_code.SpaceAfter(Accessibility.ForGetter(edmProperty)),
|
||||||
|
_code.SpaceAfter(Accessibility.ForSetter(edmProperty)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string NavigationProperty(NavigationProperty navigationProperty)
|
||||||
|
{
|
||||||
|
var endType = _typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType());
|
||||||
|
return string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"{0} {1} {2} {{ {3}get; {4}set; }}",
|
||||||
|
AccessibilityAndVirtual(Accessibility.ForProperty(navigationProperty)),
|
||||||
|
navigationProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many ? ("ICollection<" + endType + ">") : endType,
|
||||||
|
_code.Escape(navigationProperty),
|
||||||
|
_code.SpaceAfter(Accessibility.ForGetter(navigationProperty)),
|
||||||
|
_code.SpaceAfter(Accessibility.ForSetter(navigationProperty)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string AccessibilityAndVirtual(string accessibility)
|
||||||
|
{
|
||||||
|
return accessibility + (accessibility != "private" ? " virtual" : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public string EntityClassOpening(EntityType entity)
|
||||||
|
{
|
||||||
|
return string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"{0} {1}partial class {2}{3}",
|
||||||
|
Accessibility.ForType(entity),
|
||||||
|
_code.SpaceAfter(_code.AbstractOption(entity)),
|
||||||
|
_code.Escape(entity),
|
||||||
|
_code.StringBefore(" : ", _typeMapper.GetTypeName(entity.BaseType)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string EnumOpening(SimpleType enumType)
|
||||||
|
{
|
||||||
|
return string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"{0} enum {1} : {2}",
|
||||||
|
Accessibility.ForType(enumType),
|
||||||
|
_code.Escape(enumType),
|
||||||
|
_code.Escape(_typeMapper.UnderlyingClrType(enumType)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteFunctionParameters(EdmFunction edmFunction, Action<string, string, string, string> writeParameter)
|
||||||
|
{
|
||||||
|
var parameters = FunctionImportParameter.Create(edmFunction.Parameters, _code, _ef);
|
||||||
|
foreach (var parameter in parameters.Where(p => p.NeedsLocalVariable))
|
||||||
|
{
|
||||||
|
var isNotNull = parameter.IsNullableOfT ? parameter.FunctionParameterName + ".HasValue" : parameter.FunctionParameterName + " != null";
|
||||||
|
var notNullInit = "new ObjectParameter(\"" + parameter.EsqlParameterName + "\", " + parameter.FunctionParameterName + ")";
|
||||||
|
var nullInit = "new ObjectParameter(\"" + parameter.EsqlParameterName + "\", typeof(" + parameter.RawClrTypeName + "))";
|
||||||
|
writeParameter(parameter.LocalVariableName, isNotNull, notNullInit, nullInit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ComposableFunctionMethod(EdmFunction edmFunction, string modelNamespace)
|
||||||
|
{
|
||||||
|
var parameters = _typeMapper.GetParameters(edmFunction);
|
||||||
|
|
||||||
|
return string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"{0} IQueryable<{1}> {2}({3})",
|
||||||
|
AccessibilityAndVirtual(Accessibility.ForMethod(edmFunction)),
|
||||||
|
_typeMapper.GetTypeName(_typeMapper.GetReturnType(edmFunction), modelNamespace),
|
||||||
|
_code.Escape(edmFunction),
|
||||||
|
string.Join(", ", parameters.Select(p => p.FunctionParameterType + " " + p.FunctionParameterName).ToArray()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ComposableCreateQuery(EdmFunction edmFunction, string modelNamespace)
|
||||||
|
{
|
||||||
|
var parameters = _typeMapper.GetParameters(edmFunction);
|
||||||
|
|
||||||
|
return string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"return ((IObjectContextAdapter)this).ObjectContext.CreateQuery<{0}>(\"[{1}].[{2}]({3})\"{4});",
|
||||||
|
_typeMapper.GetTypeName(_typeMapper.GetReturnType(edmFunction), modelNamespace),
|
||||||
|
edmFunction.NamespaceName,
|
||||||
|
edmFunction.Name,
|
||||||
|
string.Join(", ", parameters.Select(p => "@" + p.EsqlParameterName).ToArray()),
|
||||||
|
_code.StringBefore(", ", string.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray())));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string FunctionMethod(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption)
|
||||||
|
{
|
||||||
|
var parameters = _typeMapper.GetParameters(edmFunction);
|
||||||
|
var returnType = _typeMapper.GetReturnType(edmFunction);
|
||||||
|
|
||||||
|
var paramList = String.Join(", ", parameters.Select(p => p.FunctionParameterType + " " + p.FunctionParameterName).ToArray());
|
||||||
|
if (includeMergeOption)
|
||||||
|
{
|
||||||
|
paramList = _code.StringAfter(paramList, ", ") + "MergeOption mergeOption";
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"{0} {1} {2}({3})",
|
||||||
|
AccessibilityAndVirtual(Accessibility.ForMethod(edmFunction)),
|
||||||
|
returnType == null ? "int" : "ObjectResult<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">",
|
||||||
|
_code.Escape(edmFunction),
|
||||||
|
paramList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ExecuteFunction(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption)
|
||||||
|
{
|
||||||
|
var parameters = _typeMapper.GetParameters(edmFunction);
|
||||||
|
var returnType = _typeMapper.GetReturnType(edmFunction);
|
||||||
|
|
||||||
|
var callParams = _code.StringBefore(", ", String.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray()));
|
||||||
|
if (includeMergeOption)
|
||||||
|
{
|
||||||
|
callParams = ", mergeOption" + callParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction{0}(\"{1}\"{2});",
|
||||||
|
returnType == null ? "" : "<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">",
|
||||||
|
edmFunction.Name,
|
||||||
|
callParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string DbSet(EntitySet entitySet)
|
||||||
|
{
|
||||||
|
return string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"{0} DbSet<{1}> {2} {{ get; set; }}",
|
||||||
|
Accessibility.ForReadOnlyProperty(entitySet),
|
||||||
|
_typeMapper.GetTypeName(entitySet.ElementType),
|
||||||
|
_code.Escape(entitySet));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string UsingDirectives(bool inHeader, bool includeCollections = true)
|
||||||
|
{
|
||||||
|
return inHeader == string.IsNullOrEmpty(_code.VsNamespaceSuggestion())
|
||||||
|
? string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"{0}using System;{1}" +
|
||||||
|
"{2}",
|
||||||
|
inHeader ? Environment.NewLine : "",
|
||||||
|
includeCollections ? (Environment.NewLine + "using System.Collections.Generic;") : "",
|
||||||
|
inHeader ? "" : Environment.NewLine)
|
||||||
|
: "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TypeMapper
|
||||||
|
{
|
||||||
|
private const string ExternalTypeNameAttributeName = @"http://schemas.microsoft.com/ado/2006/04/codegeneration:ExternalTypeName";
|
||||||
|
|
||||||
|
private readonly System.Collections.IList _errors;
|
||||||
|
private readonly CodeGenerationTools _code;
|
||||||
|
private readonly MetadataTools _ef;
|
||||||
|
|
||||||
|
public TypeMapper(CodeGenerationTools code, MetadataTools ef, System.Collections.IList errors)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(code, "code");
|
||||||
|
ArgumentNotNull(ef, "ef");
|
||||||
|
ArgumentNotNull(errors, "errors");
|
||||||
|
|
||||||
|
_code = code;
|
||||||
|
_ef = ef;
|
||||||
|
_errors = errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetTypeName(TypeUsage typeUsage)
|
||||||
|
{
|
||||||
|
return typeUsage == null ? null : GetTypeName(typeUsage.EdmType, _ef.IsNullable(typeUsage), modelNamespace: null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetTypeName(EdmType edmType)
|
||||||
|
{
|
||||||
|
return GetTypeName(edmType, isNullable: null, modelNamespace: null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetTypeName(TypeUsage typeUsage, string modelNamespace)
|
||||||
|
{
|
||||||
|
return typeUsage == null ? null : GetTypeName(typeUsage.EdmType, _ef.IsNullable(typeUsage), modelNamespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetTypeName(EdmType edmType, string modelNamespace)
|
||||||
|
{
|
||||||
|
return GetTypeName(edmType, isNullable: null, modelNamespace: modelNamespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetTypeName(EdmType edmType, bool? isNullable, string modelNamespace)
|
||||||
|
{
|
||||||
|
if (edmType == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var collectionType = edmType as CollectionType;
|
||||||
|
if (collectionType != null)
|
||||||
|
{
|
||||||
|
return String.Format(CultureInfo.InvariantCulture, "ICollection<{0}>", GetTypeName(collectionType.TypeUsage, modelNamespace));
|
||||||
|
}
|
||||||
|
|
||||||
|
var typeName = _code.Escape(edmType.MetadataProperties
|
||||||
|
.Where(p => p.Name == ExternalTypeNameAttributeName)
|
||||||
|
.Select(p => (string)p.Value)
|
||||||
|
.FirstOrDefault())
|
||||||
|
?? (modelNamespace != null && edmType.NamespaceName != modelNamespace ?
|
||||||
|
_code.CreateFullName(_code.EscapeNamespace(edmType.NamespaceName), _code.Escape(edmType)) :
|
||||||
|
_code.Escape(edmType));
|
||||||
|
|
||||||
|
if (edmType is StructuralType)
|
||||||
|
{
|
||||||
|
return typeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (edmType is SimpleType)
|
||||||
|
{
|
||||||
|
var clrType = UnderlyingClrType(edmType);
|
||||||
|
if (!IsEnumType(edmType))
|
||||||
|
{
|
||||||
|
typeName = _code.Escape(clrType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return clrType.IsValueType && isNullable == true ?
|
||||||
|
String.Format(CultureInfo.InvariantCulture, "Nullable<{0}>", typeName) :
|
||||||
|
typeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ArgumentException("edmType");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type UnderlyingClrType(EdmType edmType)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(edmType, "edmType");
|
||||||
|
|
||||||
|
var primitiveType = edmType as PrimitiveType;
|
||||||
|
if (primitiveType != null)
|
||||||
|
{
|
||||||
|
return primitiveType.ClrEquivalentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsEnumType(edmType))
|
||||||
|
{
|
||||||
|
return GetEnumUnderlyingType(edmType).ClrEquivalentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
return typeof(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public object GetEnumMemberValue(MetadataItem enumMember)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(enumMember, "enumMember");
|
||||||
|
|
||||||
|
var valueProperty = enumMember.GetType().GetProperty("Value");
|
||||||
|
return valueProperty == null ? null : valueProperty.GetValue(enumMember, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetEnumMemberName(MetadataItem enumMember)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(enumMember, "enumMember");
|
||||||
|
|
||||||
|
var nameProperty = enumMember.GetType().GetProperty("Name");
|
||||||
|
return nameProperty == null ? null : (string)nameProperty.GetValue(enumMember, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public System.Collections.IEnumerable GetEnumMembers(EdmType enumType)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(enumType, "enumType");
|
||||||
|
|
||||||
|
var membersProperty = enumType.GetType().GetProperty("Members");
|
||||||
|
return membersProperty != null
|
||||||
|
? (System.Collections.IEnumerable)membersProperty.GetValue(enumType, null)
|
||||||
|
: Enumerable.Empty<MetadataItem>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool EnumIsFlags(EdmType enumType)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(enumType, "enumType");
|
||||||
|
|
||||||
|
var isFlagsProperty = enumType.GetType().GetProperty("IsFlags");
|
||||||
|
return isFlagsProperty != null && (bool)isFlagsProperty.GetValue(enumType, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsEnumType(GlobalItem edmType)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(edmType, "edmType");
|
||||||
|
|
||||||
|
return edmType.GetType().Name == "EnumType";
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrimitiveType GetEnumUnderlyingType(EdmType enumType)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(enumType, "enumType");
|
||||||
|
|
||||||
|
return (PrimitiveType)enumType.GetType().GetProperty("UnderlyingType").GetValue(enumType, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string CreateLiteral(object value)
|
||||||
|
{
|
||||||
|
if (value == null || value.GetType() != typeof(TimeSpan))
|
||||||
|
{
|
||||||
|
return _code.CreateLiteral(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Format(CultureInfo.InvariantCulture, "new TimeSpan({0})", ((TimeSpan)value).Ticks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool VerifyCaseInsensitiveTypeUniqueness(IEnumerable<string> types, string sourceFile)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(types, "types");
|
||||||
|
ArgumentNotNull(sourceFile, "sourceFile");
|
||||||
|
|
||||||
|
var hash = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
|
||||||
|
if (types.Any(item => !hash.Add(item)))
|
||||||
|
{
|
||||||
|
_errors.Add(
|
||||||
|
new CompilerError(sourceFile, -1, -1, "6023",
|
||||||
|
String.Format(CultureInfo.CurrentCulture, GetResourceString("Template_CaseInsensitiveTypeConflict"))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<SimpleType> GetEnumItemsToGenerate(IEnumerable<GlobalItem> itemCollection)
|
||||||
|
{
|
||||||
|
return GetItemsToGenerate<SimpleType>(itemCollection)
|
||||||
|
.Where(e => IsEnumType(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<T> GetItemsToGenerate<T>(IEnumerable<GlobalItem> itemCollection) where T: EdmType
|
||||||
|
{
|
||||||
|
return itemCollection
|
||||||
|
.OfType<T>()
|
||||||
|
.Where(i => !i.MetadataProperties.Any(p => p.Name == ExternalTypeNameAttributeName))
|
||||||
|
.OrderBy(i => i.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<string> GetAllGlobalItems(IEnumerable<GlobalItem> itemCollection)
|
||||||
|
{
|
||||||
|
return itemCollection
|
||||||
|
.Where(i => i is EntityType || i is ComplexType || i is EntityContainer || IsEnumType(i))
|
||||||
|
.Select(g => GetGlobalItemName(g));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetGlobalItemName(GlobalItem item)
|
||||||
|
{
|
||||||
|
if (item is EdmType)
|
||||||
|
{
|
||||||
|
return ((EdmType)item).Name;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return ((EntityContainer)item).Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<EdmProperty> GetSimpleProperties(EntityType type)
|
||||||
|
{
|
||||||
|
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<EdmProperty> GetSimpleProperties(ComplexType type)
|
||||||
|
{
|
||||||
|
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<EdmProperty> GetComplexProperties(EntityType type)
|
||||||
|
{
|
||||||
|
return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<EdmProperty> GetComplexProperties(ComplexType type)
|
||||||
|
{
|
||||||
|
return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<EdmProperty> GetPropertiesWithDefaultValues(EntityType type)
|
||||||
|
{
|
||||||
|
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<EdmProperty> GetPropertiesWithDefaultValues(ComplexType type)
|
||||||
|
{
|
||||||
|
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<NavigationProperty> GetNavigationProperties(EntityType type)
|
||||||
|
{
|
||||||
|
return type.NavigationProperties.Where(np => np.DeclaringType == type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<NavigationProperty> GetCollectionNavigationProperties(EntityType type)
|
||||||
|
{
|
||||||
|
return type.NavigationProperties.Where(np => np.DeclaringType == type && np.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FunctionParameter GetReturnParameter(EdmFunction edmFunction)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(edmFunction, "edmFunction");
|
||||||
|
|
||||||
|
var returnParamsProperty = edmFunction.GetType().GetProperty("ReturnParameters");
|
||||||
|
return returnParamsProperty == null
|
||||||
|
? edmFunction.ReturnParameter
|
||||||
|
: ((IEnumerable<FunctionParameter>)returnParamsProperty.GetValue(edmFunction, null)).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsComposable(EdmFunction edmFunction)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(edmFunction, "edmFunction");
|
||||||
|
|
||||||
|
var isComposableProperty = edmFunction.GetType().GetProperty("IsComposableAttribute");
|
||||||
|
return isComposableProperty != null && (bool)isComposableProperty.GetValue(edmFunction, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<FunctionImportParameter> GetParameters(EdmFunction edmFunction)
|
||||||
|
{
|
||||||
|
return FunctionImportParameter.Create(edmFunction.Parameters, _code, _ef);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TypeUsage GetReturnType(EdmFunction edmFunction)
|
||||||
|
{
|
||||||
|
var returnParam = GetReturnParameter(edmFunction);
|
||||||
|
return returnParam == null ? null : _ef.GetElementType(returnParam.TypeUsage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GenerateMergeOptionFunction(EdmFunction edmFunction, bool includeMergeOption)
|
||||||
|
{
|
||||||
|
var returnType = GetReturnType(edmFunction);
|
||||||
|
return !includeMergeOption && returnType != null && returnType.EdmType.BuiltInTypeKind == BuiltInTypeKind.EntityType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EdmMetadataLoader
|
||||||
|
{
|
||||||
|
private readonly IDynamicHost _host;
|
||||||
|
private readonly System.Collections.IList _errors;
|
||||||
|
|
||||||
|
public EdmMetadataLoader(IDynamicHost host, System.Collections.IList errors)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(host, "host");
|
||||||
|
ArgumentNotNull(errors, "errors");
|
||||||
|
|
||||||
|
_host = host;
|
||||||
|
_errors = errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<GlobalItem> CreateEdmItemCollection(string sourcePath)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(sourcePath, "sourcePath");
|
||||||
|
|
||||||
|
if (!ValidateInputPath(sourcePath))
|
||||||
|
{
|
||||||
|
return new EdmItemCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
var schemaElement = LoadRootElement(_host.ResolvePath(sourcePath));
|
||||||
|
if (schemaElement != null)
|
||||||
|
{
|
||||||
|
using (var reader = schemaElement.CreateReader())
|
||||||
|
{
|
||||||
|
IList<EdmSchemaError> errors;
|
||||||
|
var itemCollection = MetadataItemCollectionFactory.CreateEdmItemCollection(new[] { reader }, out errors);
|
||||||
|
|
||||||
|
ProcessErrors(errors, sourcePath);
|
||||||
|
|
||||||
|
return itemCollection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new EdmItemCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetModelNamespace(string sourcePath)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(sourcePath, "sourcePath");
|
||||||
|
|
||||||
|
if (!ValidateInputPath(sourcePath))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
var model = LoadRootElement(_host.ResolvePath(sourcePath));
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
var attribute = model.Attribute("Namespace");
|
||||||
|
return attribute != null ? attribute.Value : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool ValidateInputPath(string sourcePath)
|
||||||
|
{
|
||||||
|
if (sourcePath == "$" + "edmxInputFile" + "$")
|
||||||
|
{
|
||||||
|
_errors.Add(
|
||||||
|
new CompilerError(_host.TemplateFile ?? sourcePath, 0, 0, string.Empty,
|
||||||
|
GetResourceString("Template_ReplaceVsItemTemplateToken")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public XElement LoadRootElement(string sourcePath)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(sourcePath, "sourcePath");
|
||||||
|
|
||||||
|
var root = XElement.Load(sourcePath, LoadOptions.SetBaseUri | LoadOptions.SetLineInfo);
|
||||||
|
return root.Elements()
|
||||||
|
.Where(e => e.Name.LocalName == "Runtime")
|
||||||
|
.Elements()
|
||||||
|
.Where(e => e.Name.LocalName == "ConceptualModels")
|
||||||
|
.Elements()
|
||||||
|
.Where(e => e.Name.LocalName == "Schema")
|
||||||
|
.FirstOrDefault()
|
||||||
|
?? root;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ProcessErrors(IEnumerable<EdmSchemaError> errors, string sourceFilePath)
|
||||||
|
{
|
||||||
|
foreach (var error in errors)
|
||||||
|
{
|
||||||
|
_errors.Add(
|
||||||
|
new CompilerError(
|
||||||
|
error.SchemaLocation ?? sourceFilePath,
|
||||||
|
error.Line,
|
||||||
|
error.Column,
|
||||||
|
error.ErrorCode.ToString(CultureInfo.InvariantCulture),
|
||||||
|
error.Message)
|
||||||
|
{
|
||||||
|
IsWarning = error.Severity == EdmSchemaErrorSeverity.Warning
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsLazyLoadingEnabled(EntityContainer container)
|
||||||
|
{
|
||||||
|
string lazyLoadingAttributeValue;
|
||||||
|
var lazyLoadingAttributeName = MetadataConstants.EDM_ANNOTATION_09_02 + ":LazyLoadingEnabled";
|
||||||
|
bool isLazyLoading;
|
||||||
|
return !MetadataTools.TryGetStringMetadataPropertySetting(container, lazyLoadingAttributeName, out lazyLoadingAttributeValue)
|
||||||
|
|| !bool.TryParse(lazyLoadingAttributeValue, out isLazyLoading)
|
||||||
|
|| isLazyLoading;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ArgumentNotNull<T>(T arg, string name) where T : class
|
||||||
|
{
|
||||||
|
if (arg == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly Lazy<System.Resources.ResourceManager> ResourceManager =
|
||||||
|
new Lazy<System.Resources.ResourceManager>(
|
||||||
|
() => new System.Resources.ResourceManager("System.Data.Entity.Design", typeof(MetadataItemCollectionFactory).Assembly), isThreadSafe: true);
|
||||||
|
|
||||||
|
public static string GetResourceString(string resourceName)
|
||||||
|
{
|
||||||
|
ArgumentNotNull(resourceName, "resourceName");
|
||||||
|
|
||||||
|
return ResourceManager.Value.GetString(resourceName, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
#>
|
21
musicschoolapp/Pages/CourseEditingPage.xaml
Normal file
21
musicschoolapp/Pages/CourseEditingPage.xaml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<Page x:Class="musicschoolapp.Pages.CourseEditingPage"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:local="clr-namespace:musicschoolapp.Pages"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
d:DesignHeight="450" d:DesignWidth="800"
|
||||||
|
Title="CourseEditingPage">
|
||||||
|
|
||||||
|
<Grid>
|
||||||
|
<DataGrid x:Name="dGridStudent" AutoGenerateColumns="False" SelectionChanged="dGridStudent_SelectionChanged" MouseDoubleClick="dGridStudent_MouseDoubleClick">
|
||||||
|
<DataGrid.Columns>
|
||||||
|
<DataGridTextColumn Header="Имя" Binding="{Binding Name}"></DataGridTextColumn>
|
||||||
|
<DataGridTextColumn Header="Описание" Binding="{Binding Description}"></DataGridTextColumn>
|
||||||
|
<DataGridTextColumn Header="Продолжительность" Binding="{Binding Duration}"></DataGridTextColumn>
|
||||||
|
<DataGridTextColumn Header="Цена" Binding="{Binding Price}"></DataGridTextColumn>
|
||||||
|
</DataGrid.Columns>
|
||||||
|
</DataGrid>
|
||||||
|
</Grid>
|
||||||
|
</Page>
|
163
musicschoolapp/Pages/CourseEditingPage.xaml.cs
Normal file
163
musicschoolapp/Pages/CourseEditingPage.xaml.cs
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
using Microsoft.Win32;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Data.Entity;
|
||||||
|
using System.Data.Entity.Infrastructure;
|
||||||
|
using System.Data.Entity.Migrations;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Data.SqlTypes;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.Remoting.Contexts;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
using System.IO;
|
||||||
|
using System.Data.Entity.Validation;
|
||||||
|
|
||||||
|
namespace musicschoolapp.Pages
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Логика взаимодействия для StudentEditingPage.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class CourseEditingPage : Page
|
||||||
|
{
|
||||||
|
musicschoolEntities1 mse = new musicschoolEntities1();
|
||||||
|
DbSet<Student> dbContext_;
|
||||||
|
List<Course> students1;
|
||||||
|
bool adding = false;
|
||||||
|
public CourseEditingPage(bool editing)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
students1 = mse.Course.ToList();
|
||||||
|
dGridStudent.ItemsSource = students1;
|
||||||
|
if(editing)
|
||||||
|
{
|
||||||
|
dGridStudent.IsReadOnly = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dGridStudent.IsReadOnly = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int updateDB()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (var student in students1)
|
||||||
|
{
|
||||||
|
var original = mse.Course.Find(student.CourseID);
|
||||||
|
|
||||||
|
if (original != null)
|
||||||
|
{
|
||||||
|
mse.Entry(original).CurrentValues.SetValues(student);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mse.Course.Add(student);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int saveresult = mse.SaveChanges();
|
||||||
|
students1 = mse.Course.ToList();
|
||||||
|
dGridStudent.ItemsSource=students1;
|
||||||
|
return saveresult;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
students1 = mse.Course.ToList();
|
||||||
|
dGridStudent.ItemsSource = students1;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void dGridStudent_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
var grid = (DataGrid)sender;
|
||||||
|
var cellInfo = grid.SelectedCells[grid.CurrentCell.Column.DisplayIndex];
|
||||||
|
|
||||||
|
if (cellInfo.Column.Header.ToString() == "Фото")
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Вы дважды кликнули по столбцу 'Фото'. Изменить?", "Вопрос", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||||
|
{
|
||||||
|
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||||||
|
openFileDialog.ShowDialog();
|
||||||
|
if (mse.Course.Find((grid.SelectedItem as Course).CourseID) == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект не создан.");
|
||||||
|
grid.SelectedItem = -1;
|
||||||
|
mse.Course.Add(dGridStudent.SelectedItem as Course);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mse.SaveChanges();
|
||||||
|
}
|
||||||
|
catch (DbEntityValidationException ex)
|
||||||
|
{
|
||||||
|
foreach (var entityValidationErrors in ex.EntityValidationErrors)
|
||||||
|
{
|
||||||
|
foreach (var validationError in entityValidationErrors.ValidationErrors)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Свойство: " + validationError.PropertyName + " Ошибка: " + validationError.ErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show("добавил");
|
||||||
|
int index = grid.SelectedIndex;
|
||||||
|
grid.SelectedIndex = -1;
|
||||||
|
grid.SelectedIndex = index;
|
||||||
|
dGridStudent_SelectionChanged(sender, new SelectionChangedEventArgs(DataGrid.SelectionChangedEvent, new Collection<object> { }, new Collection<object> { dGridStudent.SelectedItem }));
|
||||||
|
}
|
||||||
|
mse.SaveChanges();
|
||||||
|
dGridStudent.ItemsSource = mse.Course.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void dGridStudent_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.AddedItems != null && e.AddedItems.Count > 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (e.RemovedItems != null && e.RemovedItems.Count > 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
Course selectedStudent = (e.RemovedItems[0] as Course);
|
||||||
|
if (selectedStudent != null)
|
||||||
|
{
|
||||||
|
Course studentInDb = mse.Course.Find(selectedStudent.CourseID);
|
||||||
|
if (studentInDb != null)
|
||||||
|
{
|
||||||
|
mse.Course.Remove(studentInDb);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mse.SaveChanges();
|
||||||
|
}
|
||||||
|
catch (DbUpdateException ex)
|
||||||
|
{
|
||||||
|
|
||||||
|
MessageBox.Show("Запись, похоже, удалить нельзя.\n\n" + ex.InnerException);
|
||||||
|
students1 = mse.Course.ToList();
|
||||||
|
mse.Entry(studentInDb).State = System.Data.EntityState.Unchanged;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
students1.Remove(dGridStudent.SelectedItem as Course);
|
||||||
|
dGridStudent.SelectedIndex = -1;
|
||||||
|
MessageBox.Show("Удалено");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
musicschoolapp/Pages/EnrollmentEditingPage.xaml
Normal file
28
musicschoolapp/Pages/EnrollmentEditingPage.xaml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<Page x:Class="musicschoolapp.Pages.EnrollmentEditingPage"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:local="clr-namespace:musicschoolapp.Pages"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
d:DesignHeight="450" d:DesignWidth="800"
|
||||||
|
Title="EnrollmentEditingPage">
|
||||||
|
|
||||||
|
<Grid>
|
||||||
|
<DataGrid Margin="0,20,0,0" x:Name="dGridStudent" AutoGenerateColumns="False" SelectionChanged="dGridStudent_SelectionChanged" MouseDoubleClick="dGridStudent_MouseDoubleClick">
|
||||||
|
<DataGrid.Columns>
|
||||||
|
<DataGridTextColumn IsReadOnly="True" Header="ID зачисления" Binding="{Binding EnrollmentID}"></DataGridTextColumn>
|
||||||
|
<DataGridTextColumn Header="Имя студента" Binding="{Binding Student.FirstName}"></DataGridTextColumn>
|
||||||
|
<DataGridTextColumn Header="Фамилия студента" Binding="{Binding Student.LastName}"></DataGridTextColumn>
|
||||||
|
<DataGridTextColumn Header="ID курса" Binding="{Binding Course.Name}"></DataGridTextColumn>
|
||||||
|
<DataGridTextColumn Header="Дата зачисления" Binding="{Binding EnrollmentDate}"></DataGridTextColumn>
|
||||||
|
<DataGridTextColumn Header="Проходной балл" Binding="{Binding Grade}"></DataGridTextColumn>
|
||||||
|
</DataGrid.Columns>
|
||||||
|
</DataGrid>
|
||||||
|
<Button Content="Экспорт в Excel" HorizontalAlignment="Left" Margin="67,0,0,0" VerticalAlignment="Top" Click="ToExcelButton_OnClick"/>
|
||||||
|
<ComboBox x:Name="combobox_courses" HorizontalAlignment="Left" Margin="270,-2,0,0" VerticalAlignment="Top" Width="117" Height="22" SelectionChanged="combobox_courses_SelectionChanged"/>
|
||||||
|
<TextBox x:Name="textbox_search" HorizontalAlignment="Left" Margin="482,1,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" TextChanged="TextBox_TextChanged"/>
|
||||||
|
<Label Content="Фильтр:" HorizontalAlignment="Left" Margin="212,-4,0,0" VerticalAlignment="Top"/>
|
||||||
|
<Label Content="Поиск:" HorizontalAlignment="Left" Margin="424,-4,0,0" VerticalAlignment="Top"/>
|
||||||
|
</Grid>
|
||||||
|
</Page>
|
288
musicschoolapp/Pages/EnrollmentEditingPage.xaml.cs
Normal file
288
musicschoolapp/Pages/EnrollmentEditingPage.xaml.cs
Normal file
@ -0,0 +1,288 @@
|
|||||||
|
using Microsoft.Win32;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Data.Entity;
|
||||||
|
using System.Data.Entity.Infrastructure;
|
||||||
|
using System.Data.Entity.Migrations;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Data.SqlTypes;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.Remoting.Contexts;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
using System.IO;
|
||||||
|
using System.Data.Entity.Validation;
|
||||||
|
using System.Data.OleDb;
|
||||||
|
using System.Data;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace musicschoolapp.Pages
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Логика взаимодействия для StudentEditingPage.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class EnrollmentEditingPage : Page
|
||||||
|
{
|
||||||
|
musicschoolEntities1 mse = new musicschoolEntities1();
|
||||||
|
DbSet<Enrollment> dbContext_;
|
||||||
|
bool isadmin_;
|
||||||
|
List<Enrollment> students1;
|
||||||
|
bool adding = false;
|
||||||
|
public EnrollmentEditingPage(bool isadmin)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
this.isadmin_ = isadmin;
|
||||||
|
if(isadmin)
|
||||||
|
{
|
||||||
|
dGridStudent.IsReadOnly = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isadmin_ = false;
|
||||||
|
dGridStudent.IsReadOnly = true;
|
||||||
|
}
|
||||||
|
combobox_courses.ItemsSource = mse.Course.ToList();
|
||||||
|
students1 = mse.Enrollment.ToList();
|
||||||
|
dGridStudent.ItemsSource = students1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int updateDB()
|
||||||
|
{
|
||||||
|
combobox_courses.SelectedIndex = -1;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (var student in students1)
|
||||||
|
{
|
||||||
|
var original = mse.Enrollment.Find(student.EnrollmentID);
|
||||||
|
|
||||||
|
if (original != null)
|
||||||
|
{
|
||||||
|
mse.Entry(original).CurrentValues.SetValues(student);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mse.Enrollment.Add(student);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int saveresult = mse.SaveChanges();
|
||||||
|
students1 = mse.Enrollment.ToList();
|
||||||
|
dGridStudent.ItemsSource = students1;
|
||||||
|
return saveresult;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.InnerException.ToString());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void dGridStudent_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
var grid = (DataGrid)sender;
|
||||||
|
var cellInfo = grid.SelectedCells[grid.CurrentCell.Column.DisplayIndex];
|
||||||
|
|
||||||
|
if (cellInfo.Column.Header.ToString() == "Фото")
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Вы дважды кликнули по столбцу 'Фото'. Изменить?", "Вопрос", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||||
|
{
|
||||||
|
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||||||
|
openFileDialog.ShowDialog();
|
||||||
|
if (mse.Student.Find((grid.SelectedItem as Enrollment).EnrollmentID) == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект не создан.");
|
||||||
|
grid.SelectedItem = -1;
|
||||||
|
mse.Enrollment.Add(dGridStudent.SelectedItem as Enrollment);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mse.SaveChanges();
|
||||||
|
}
|
||||||
|
catch (DbEntityValidationException ex)
|
||||||
|
{
|
||||||
|
foreach (var entityValidationErrors in ex.EntityValidationErrors)
|
||||||
|
{
|
||||||
|
foreach (var validationError in entityValidationErrors.ValidationErrors)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Свойство: " + validationError.PropertyName + " Ошибка: " + validationError.ErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show("добавил");
|
||||||
|
int index = grid.SelectedIndex;
|
||||||
|
grid.SelectedIndex = -1;
|
||||||
|
grid.SelectedIndex = index;
|
||||||
|
dGridStudent_SelectionChanged(sender, new SelectionChangedEventArgs(DataGrid.SelectionChangedEvent, new Collection<object> { }, new Collection<object> { dGridStudent.SelectedItem }));
|
||||||
|
}
|
||||||
|
mse.SaveChanges();
|
||||||
|
dGridStudent.ItemsSource = mse.Enrollment.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void dGridStudent_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.AddedItems != null && e.AddedItems.Count > 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (e.RemovedItems != null && e.RemovedItems.Count > 0)
|
||||||
|
{
|
||||||
|
Enrollment selectedStudent = (e.RemovedItems[0] as Enrollment);
|
||||||
|
if (selectedStudent != null)
|
||||||
|
{
|
||||||
|
Enrollment studentInDb = mse.Enrollment.Find(selectedStudent.EnrollmentID);
|
||||||
|
if (studentInDb != null && (e.RemovedItems[0] as Enrollment).Student != null && (e.RemovedItems[0] as Enrollment).Course != null && isadmin_)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (MessageBox.Show("Удалить " + (e.RemovedItems[0] as Enrollment).Student.LastName + " (" + (e.RemovedItems[0] as Enrollment).Course.Name + ")", "Внимание",MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||||
|
{
|
||||||
|
mse.Enrollment.Remove(studentInDb);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mse.SaveChanges();
|
||||||
|
}
|
||||||
|
catch (DbUpdateException ex)
|
||||||
|
{
|
||||||
|
|
||||||
|
MessageBox.Show("Запись, похоже, удалить нельзя.\n\n" + ex.InnerException);
|
||||||
|
MessageBox.Show("запись была удалена только из таблицы, но сохранена в базе данных, перезапустите окно и продолжайте работать.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
students1.Remove(dGridStudent.SelectedItem as Enrollment);
|
||||||
|
dGridStudent.SelectedIndex = -1;
|
||||||
|
if ((e.RemovedItems[0] as Enrollment).Student != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Удалено: " + (e.RemovedItems[0] as Enrollment).Student.LastName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Удалена 1 запись.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BtnEdit_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ToExcelButton_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var d = dGridStudent.ItemsSource.Cast<Enrollment>();
|
||||||
|
var data = ToDataTable(d.ToList());
|
||||||
|
var dialog = new SaveFileDialog();
|
||||||
|
dialog.DefaultExt = ".xlsx";
|
||||||
|
dialog.Filter = "Excel файл |*.xlsx";
|
||||||
|
dialog.ShowDialog();
|
||||||
|
if (dialog.FileName != String.Empty)
|
||||||
|
{
|
||||||
|
ToExcelFile(data, dialog.FileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DataTable ToDataTable<T>(List<T> items)
|
||||||
|
{
|
||||||
|
var dataTable = new DataTable(typeof(T).Name);
|
||||||
|
|
||||||
|
var properties = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||||
|
foreach (var prop in properties)
|
||||||
|
{
|
||||||
|
var type = (prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>) ? Nullable.GetUnderlyingType(prop.PropertyType) : prop.PropertyType);
|
||||||
|
dataTable.Columns.Add(prop.Name, type);
|
||||||
|
}
|
||||||
|
foreach (var item in items)
|
||||||
|
{
|
||||||
|
var values = new object[properties.Length];
|
||||||
|
for (var i = 0; i < properties.Length; i++)
|
||||||
|
{
|
||||||
|
values[i] = properties[i].GetValue(item, null);
|
||||||
|
}
|
||||||
|
dataTable.Rows.Add(values);
|
||||||
|
}
|
||||||
|
return dataTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ToExcelFile(DataTable dataTable, string filePath, bool overwriteFile = true)
|
||||||
|
{
|
||||||
|
if (File.Exists(filePath) && overwriteFile)
|
||||||
|
File.Delete(filePath);
|
||||||
|
|
||||||
|
using (var connection = new OleDbConnection())
|
||||||
|
{
|
||||||
|
connection.ConnectionString = $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={filePath};" +
|
||||||
|
"Extended Properties='Excel 12.0 Xml;HDR=YES;'";
|
||||||
|
connection.Open();
|
||||||
|
using (var command = new OleDbCommand())
|
||||||
|
{
|
||||||
|
command.Connection = connection;
|
||||||
|
var columnNames = (from DataColumn dataColumn in dataTable.Columns select dataColumn.ColumnName).ToList();
|
||||||
|
var tableName = !string.IsNullOrWhiteSpace(dataTable.TableName) ? dataTable.TableName : Guid.NewGuid().ToString();
|
||||||
|
command.CommandText = $"CREATE TABLE [{tableName}] ({string.Join(",", columnNames.Select(c => $"[{c}] VARCHAR").ToArray())});";
|
||||||
|
command.ExecuteNonQuery();
|
||||||
|
foreach (DataRow row in dataTable.Rows)
|
||||||
|
{
|
||||||
|
var rowValues = (from DataColumn column in dataTable.Columns select (row[column] != null && row[column] != DBNull.Value) ? row[column].ToString() : string.Empty).ToList();
|
||||||
|
command.CommandText = $"INSERT INTO [{tableName}]({string.Join(",", columnNames.Select(c => $"[{c}]"))}) VALUES ({string.Join(",", rowValues.Select(r => $"'{r}'").ToArray())});";
|
||||||
|
command.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
connection.Close();
|
||||||
|
}
|
||||||
|
MessageBox.Show("Файл успешно сохранён в "+filePath);
|
||||||
|
}
|
||||||
|
private void Button_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void combobox_courses_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
dGridStudent.SelectedIndex = 0;
|
||||||
|
|
||||||
|
if (combobox_courses.SelectedItem != null)
|
||||||
|
{
|
||||||
|
dGridStudent.ItemsSource = students1.Where(x => x.CourseID == (combobox_courses.SelectedItem as Course).CourseID).ToList();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dGridStudent.ItemsSource = students1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
|
||||||
|
{
|
||||||
|
dGridStudent.SelectedIndex = -1;
|
||||||
|
if (textbox_search.Text != String.Empty && dGridStudent.SelectedItem == null)
|
||||||
|
{
|
||||||
|
if(combobox_courses.SelectedItem != null)
|
||||||
|
{
|
||||||
|
dGridStudent.ItemsSource = students1.Where(x => x.Student.LastName.Contains(textbox_search.Text) && x.Course == combobox_courses.SelectedItem as Course).ToList();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
dGridStudent.ItemsSource = students1.Where(x => x.Student.LastName.Contains(textbox_search.Text)).ToList();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dGridStudent.ItemsSource = students1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
21
musicschoolapp/Pages/Instr.xaml
Normal file
21
musicschoolapp/Pages/Instr.xaml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<Page x:Class="musicschoolapp.Pages.Instr"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:local="clr-namespace:musicschoolapp.Pages"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
d:DesignHeight="450" d:DesignWidth="800"
|
||||||
|
Title="Instr">
|
||||||
|
|
||||||
|
<Grid>
|
||||||
|
<DataGrid x:Name="dGridStudent" AutoGenerateColumns="False" SelectionChanged="dGridStudent_SelectionChanged" MouseDoubleClick="dGridStudent_MouseDoubleClick">
|
||||||
|
<DataGrid.Columns>
|
||||||
|
<DataGridTextColumn Header="ID" Binding="{Binding Id_instrument}"></DataGridTextColumn>
|
||||||
|
<DataGridTextColumn Header="Название" Binding="{Binding Name_instrument}"></DataGridTextColumn>
|
||||||
|
<DataGridTextColumn Header="Дата приобретения" Binding="{Binding Date_receiving}"></DataGridTextColumn>
|
||||||
|
<DataGridCheckBoxColumn Header="Личный?" Binding="{Binding isPersonal}"></DataGridCheckBoxColumn>
|
||||||
|
</DataGrid.Columns>
|
||||||
|
</DataGrid>
|
||||||
|
</Grid>
|
||||||
|
</Page>
|
168
musicschoolapp/Pages/Instr.xaml.cs
Normal file
168
musicschoolapp/Pages/Instr.xaml.cs
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
using Microsoft.Win32;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Data.Entity;
|
||||||
|
using System.Data.Entity.Infrastructure;
|
||||||
|
using System.Data.Entity.Migrations;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Data.SqlTypes;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.Remoting.Contexts;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
using System.IO;
|
||||||
|
using System.Data.Entity.Validation;
|
||||||
|
|
||||||
|
namespace musicschoolapp.Pages
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Логика взаимодействия для StudentEditingPage.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class Instr : Page
|
||||||
|
{
|
||||||
|
musicschoolEntities1 mse = new musicschoolEntities1();
|
||||||
|
DbSet<Student> dbContext_;
|
||||||
|
List<Instruments> students1;
|
||||||
|
bool adding = false;
|
||||||
|
public Instr()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
//dbContext_ = dbContext;
|
||||||
|
students1 = mse.Instruments.ToList();
|
||||||
|
dGridStudent.ItemsSource = students1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int updateDB()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (var student in students1)
|
||||||
|
{
|
||||||
|
var original = mse.Instruments.Find(student.Id_instrument);
|
||||||
|
|
||||||
|
if (original != null)
|
||||||
|
{
|
||||||
|
// Обновить запись в базе данных
|
||||||
|
mse.Entry(original).CurrentValues.SetValues(student);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mse.Instruments.Add(student);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
students1 = mse.Instruments.ToList();
|
||||||
|
dGridStudent.ItemsSource = students1;
|
||||||
|
int saveresult = mse.SaveChanges();
|
||||||
|
|
||||||
|
return saveresult;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void dGridStudent_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
var grid = (DataGrid)sender;
|
||||||
|
var cellInfo = grid.SelectedCells[grid.CurrentCell.Column.DisplayIndex];
|
||||||
|
|
||||||
|
if (cellInfo.Column.Header.ToString() == "Фото")
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Вы дважды кликнули по столбцу 'Фото'. Изменить?", "Вопрос", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||||
|
{
|
||||||
|
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||||||
|
openFileDialog.ShowDialog();
|
||||||
|
if (mse.Instruments.Find((grid.SelectedItem as Instruments).Id_instrument) == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект не создан.");
|
||||||
|
grid.SelectedItem = -1;
|
||||||
|
//return;
|
||||||
|
mse.Instruments.Add(dGridStudent.SelectedItem as Instruments);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mse.SaveChanges();
|
||||||
|
}
|
||||||
|
catch (DbEntityValidationException ex)
|
||||||
|
{
|
||||||
|
foreach (var entityValidationErrors in ex.EntityValidationErrors)
|
||||||
|
{
|
||||||
|
foreach (var validationError in entityValidationErrors.ValidationErrors)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Свойство: " + validationError.PropertyName + " Ошибка: " + validationError.ErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show("добавил");
|
||||||
|
int index = grid.SelectedIndex;
|
||||||
|
grid.SelectedIndex = -1;
|
||||||
|
grid.SelectedIndex = index;
|
||||||
|
//dGridStudent.RaiseEvent();
|
||||||
|
dGridStudent_SelectionChanged(sender, new SelectionChangedEventArgs(DataGrid.SelectionChangedEvent, new Collection<object> { }, new Collection<object> { dGridStudent.SelectedItem }));
|
||||||
|
}
|
||||||
|
mse.SaveChanges();
|
||||||
|
dGridStudent.ItemsSource = mse.Instruments.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
private void dGridStudent_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.AddedItems != null && e.AddedItems.Count > 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (e.RemovedItems != null && e.RemovedItems.Count > 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
Instruments selectedStudent = (e.RemovedItems[0] as Instruments);
|
||||||
|
if (selectedStudent != null)
|
||||||
|
{
|
||||||
|
Instruments studentInDb = mse.Instruments.Find(selectedStudent.Id_instrument);
|
||||||
|
if (studentInDb != null)
|
||||||
|
{
|
||||||
|
mse.Instruments.Remove(studentInDb);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mse.SaveChanges();
|
||||||
|
}
|
||||||
|
catch (DbUpdateException ex)
|
||||||
|
{
|
||||||
|
|
||||||
|
MessageBox.Show("Запись, похоже, удалить нельзя.\n\n" + ex.InnerException);
|
||||||
|
students1 = mse.Instruments.ToList();
|
||||||
|
mse.Entry(studentInDb).State = System.Data.EntityState.Unchanged;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
students1.Remove(dGridStudent.SelectedItem as Instruments);
|
||||||
|
dGridStudent.SelectedIndex = -1;
|
||||||
|
//students1 = mse.Student.ToList();
|
||||||
|
MessageBox.Show("Удалено");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BtnEdit_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
musicschoolapp/Pages/MenuPage.xaml
Normal file
30
musicschoolapp/Pages/MenuPage.xaml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<Page x:Class="musicschoolapp.Pages.MenuPage"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:local="clr-namespace:musicschoolapp.Pages"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
d:DesignHeight="450" d:DesignWidth="800"
|
||||||
|
Title="MenuPage">
|
||||||
|
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="115*"></RowDefinition>
|
||||||
|
<RowDefinition Height="38*"></RowDefinition>
|
||||||
|
<RowDefinition Height="74*"></RowDefinition>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="*"></ColumnDefinition>
|
||||||
|
<ColumnDefinition Width="*"></ColumnDefinition>
|
||||||
|
<ColumnDefinition Width="*"></ColumnDefinition>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<TextBlock Grid.Column="1" Text="Выберите режим работы" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="22" Height="30" Width="254"/>
|
||||||
|
<Button x:Name="courseButton" IsEnabled="False" Grid.Column="0" Grid.Row="1" Content="Курс" Margin="10,10,10,10" FontSize="16" Click="courseButton_Click"></Button>
|
||||||
|
<Button x:Name="enrollmentButton" IsEnabled="False" Grid.Column="1" Grid.Row="1" Content="Зачисление" Margin="10,10,10,10" FontSize="16" Click="enrollmentButton_Click"></Button>
|
||||||
|
<Button x:Name="studentButton" IsEnabled="False" Grid.Column="2" Grid.Row="1" Content="Студент" Margin="10,10,10,10" FontSize="16" Click="studentButton_Click"></Button>
|
||||||
|
<Button x:Name="adminButton" IsEnabled="False" Grid.Row="2" Content="Пользователи" FontSize="16" Margin="0,10,0,0" Grid.Column="1" HorizontalAlignment="Center" Width="266" Height="52" VerticalAlignment="Top" Click="adminButton_Click"/>
|
||||||
|
<Button x:Name="quickEnrollButton" Content="Быстрое зачисление" HorizontalAlignment="Left" Margin="15,12,0,0" Grid.Row="2" VerticalAlignment="Top" Height="50" Width="240" Click="quickEnrollButton_Click" FontSize="16"/>
|
||||||
|
<Button x:Name="instrButton" Grid.Column="2" Content="Инструменты" HorizontalAlignment="Right" Margin="0,10,10,0" Grid.Row="2" VerticalAlignment="Top" Height="52" Width="247" FontSize="16" IsEnabled="False" Click="instrButton_Click"/>
|
||||||
|
</Grid>
|
||||||
|
</Page>
|
68
musicschoolapp/Pages/MenuPage.xaml.cs
Normal file
68
musicschoolapp/Pages/MenuPage.xaml.cs
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data.Entity;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
|
namespace musicschoolapp.Pages
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Логика взаимодействия для MenuPage.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class MenuPage : Page
|
||||||
|
{
|
||||||
|
StudentEditingPage studentEditingPage;
|
||||||
|
CourseEditingPage courseEditingPage;
|
||||||
|
public EnrollmentEditingPage enrollmentEditingPage;
|
||||||
|
Instr instr = new Instr();
|
||||||
|
public MenuPage(StudentEditingPage s, CourseEditingPage c, EnrollmentEditingPage e, Instr i)
|
||||||
|
{
|
||||||
|
enrollmentEditingPage = e;
|
||||||
|
courseEditingPage = c;
|
||||||
|
studentEditingPage = s;
|
||||||
|
instr = i;
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void courseButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
NavigationService.Navigate(courseEditingPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void studentButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
NavigationService.Navigate(studentEditingPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enrollmentButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
NavigationService.Navigate(enrollmentEditingPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void quickEnrollButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
NavigationService.Navigate(new QuickEnroll());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void instrButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
NavigationService.Navigate(instr);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void adminButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Process.Start("AdminEditingApp\\admin\\etc\\bin\\Debug\\etc.exe");
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
musicschoolapp/Pages/QuickEnroll.xaml
Normal file
27
musicschoolapp/Pages/QuickEnroll.xaml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<Page x:Class="musicschoolapp.Pages.QuickEnroll"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:local="clr-namespace:musicschoolapp.Pages"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
d:DesignHeight="450" d:DesignWidth="800"
|
||||||
|
Title="QuickEnroll">
|
||||||
|
|
||||||
|
<Grid>
|
||||||
|
<Grid>
|
||||||
|
<DataGrid IsEnabled="False" CanUserAddRows="False" Margin="0,25,0,0" x:Name="dGridStudent" AutoGenerateColumns="False" SelectionChanged="dGridStudent_SelectionChanged">
|
||||||
|
<DataGrid.Columns>
|
||||||
|
<DataGridTextColumn Header="ID студента" IsReadOnly="True" Binding="{Binding StudentID}"></DataGridTextColumn>
|
||||||
|
<DataGridTextColumn Header="Имя студента" IsReadOnly="True" Binding="{Binding FirstName}"></DataGridTextColumn>
|
||||||
|
<DataGridTextColumn Header="Фамилия студента" IsReadOnly="True" Binding="{Binding LastName}"></DataGridTextColumn>
|
||||||
|
<DataGridTextColumn Header="Проходной балл" Binding="{Binding grade}"></DataGridTextColumn>
|
||||||
|
<DataGridCheckBoxColumn x:Name="checkEnroll" Header="Зачислить?" Binding="{Binding toEnroll}">
|
||||||
|
</DataGridCheckBoxColumn>
|
||||||
|
</DataGrid.Columns>
|
||||||
|
</DataGrid>
|
||||||
|
<Button x:Name="buttonStart" Content="Выполнить" HorizontalAlignment="Left" Margin="205,0,0,0" VerticalAlignment="Top" Width="68" Click="buttonStart_Click" IsCancel="True"/>
|
||||||
|
</Grid>
|
||||||
|
<ComboBox x:Name="comboboxCourse" HorizontalAlignment="Left" Margin="75,0,0,0" VerticalAlignment="Top" Width="120" SelectionChanged="comboboxCourse_SelectionChanged"/>
|
||||||
|
</Grid>
|
||||||
|
</Page>
|
76
musicschoolapp/Pages/QuickEnroll.xaml.cs
Normal file
76
musicschoolapp/Pages/QuickEnroll.xaml.cs
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
|
namespace musicschoolapp.Pages
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Логика взаимодействия для QuickEnroll.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class QuickEnroll : Page
|
||||||
|
{
|
||||||
|
musicschoolEntities1 mse = new musicschoolEntities1();
|
||||||
|
public QuickEnroll()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
comboboxCourse.ItemsSource = mse.Course.ToList();
|
||||||
|
comboboxCourse.DisplayMemberPath = "Name";
|
||||||
|
dGridStudent.ItemsSource = mse.Student.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dGridStudent_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (dGridStudent.SelectedCells[3] != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
foreach (var student in dGridStudent.ItemsSource)
|
||||||
|
{
|
||||||
|
var student_ = student as Student;
|
||||||
|
if (true)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (student_.toEnroll)
|
||||||
|
{
|
||||||
|
Enrollment enrollment = new Enrollment();
|
||||||
|
enrollment.StudentID = student_.StudentID;
|
||||||
|
enrollment.CourseID = (comboboxCourse.SelectedItem as Course).CourseID;
|
||||||
|
enrollment.EnrollmentDate = DateTime.Now;
|
||||||
|
enrollment.Grade = student_.grade;
|
||||||
|
mse.Enrollment.Add(enrollment);
|
||||||
|
student_.toEnroll = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonStart_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Добавлено: " + mse.SaveChanges());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void comboboxCourse_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
dGridStudent.IsEnabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
48
musicschoolapp/Pages/StudentEditingPage.xaml
Normal file
48
musicschoolapp/Pages/StudentEditingPage.xaml
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<Page x:Class="musicschoolapp.Pages.StudentEditingPage"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:local="clr-namespace:musicschoolapp.Pages"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
d:DesignHeight="450" d:DesignWidth="800"
|
||||||
|
Title="StudentEditingPage">
|
||||||
|
|
||||||
|
<Grid>
|
||||||
|
<DataGrid x:Name="dGridStudent" AutoGenerateColumns="False" SelectionChanged="dGridStudent_SelectionChanged" MouseDoubleClick="dGridStudent_MouseDoubleClick">
|
||||||
|
<DataGrid.Columns>
|
||||||
|
<DataGridTextColumn Header="ID" Binding="{Binding StudentID}"></DataGridTextColumn>
|
||||||
|
<DataGridTextColumn Header="Имя" Binding="{Binding FirstName}"></DataGridTextColumn>
|
||||||
|
<DataGridTextColumn Header="Фамилия" Binding="{Binding LastName}"></DataGridTextColumn>
|
||||||
|
<DataGridTemplateColumn x:Name="dcolumn" Header="Дата рождения" Width="130">
|
||||||
|
<DataGridTemplateColumn.CellTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<DatePicker SelectedDate="{Binding BirthDate}"></DatePicker>
|
||||||
|
</DataTemplate>
|
||||||
|
</DataGridTemplateColumn.CellTemplate>
|
||||||
|
</DataGridTemplateColumn>
|
||||||
|
<!--<DataGridTextColumn Header="Дата рождения" Binding="{Binding BirthDate}"></DataGridTextColumn>-->
|
||||||
|
<DataGridTextColumn Header="Номер телефона" Binding="{Binding Phone}"></DataGridTextColumn>
|
||||||
|
<DataGridTextColumn Header="Почта" Binding="{Binding Email}"></DataGridTextColumn>
|
||||||
|
<DataGridTextColumn Header="ID инструмента" Binding="{Binding Id_instrument}"></DataGridTextColumn>
|
||||||
|
<DataGridTextColumn IsReadOnly="True" Header="Название инструмента" Binding="{Binding Instruments}"></DataGridTextColumn>
|
||||||
|
<DataGridTemplateColumn x:Name="PhotoColumn" Header="Фото" Width="130">
|
||||||
|
<DataGridTemplateColumn.CellTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<Image Height="80" Width="80" VerticalAlignment="Center"
|
||||||
|
Source="{Binding photo}"></Image>
|
||||||
|
</DataTemplate>
|
||||||
|
</DataGridTemplateColumn.CellTemplate>
|
||||||
|
</DataGridTemplateColumn>
|
||||||
|
<DataGridTemplateColumn Width="auto">
|
||||||
|
<DataGridTemplateColumn.CellTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<Button Width="80" Height="40" Content="Редактировать"
|
||||||
|
Name="BtnEdit" Click="BtnEdit_Click"></Button>
|
||||||
|
</DataTemplate>
|
||||||
|
</DataGridTemplateColumn.CellTemplate>
|
||||||
|
</DataGridTemplateColumn>
|
||||||
|
</DataGrid.Columns>
|
||||||
|
</DataGrid>
|
||||||
|
</Grid>
|
||||||
|
</Page>
|
170
musicschoolapp/Pages/StudentEditingPage.xaml.cs
Normal file
170
musicschoolapp/Pages/StudentEditingPage.xaml.cs
Normal file
@ -0,0 +1,170 @@
|
|||||||
|
using Microsoft.Win32;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Data.Entity;
|
||||||
|
using System.Data.Entity.Infrastructure;
|
||||||
|
using System.Data.Entity.Migrations;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Data.SqlTypes;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.Remoting.Contexts;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
using System.IO;
|
||||||
|
using System.Data.Entity.Validation;
|
||||||
|
|
||||||
|
namespace musicschoolapp.Pages
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Логика взаимодействия для StudentEditingPage.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class StudentEditingPage : Page
|
||||||
|
{
|
||||||
|
musicschoolEntities1 mse = new musicschoolEntities1();
|
||||||
|
DbSet<Student> dbContext_;
|
||||||
|
List<Student> students1;
|
||||||
|
bool adding = false;
|
||||||
|
public StudentEditingPage()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
//dbContext_ = dbContext;
|
||||||
|
students1= mse.Student.ToList();
|
||||||
|
dGridStudent.ItemsSource = students1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int updateDB()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (var student in students1)
|
||||||
|
{
|
||||||
|
var original = mse.Student.Find(student.StudentID);
|
||||||
|
|
||||||
|
if (original != null)
|
||||||
|
{
|
||||||
|
// Обновить запись в базе данных
|
||||||
|
mse.Entry(original).CurrentValues.SetValues(student);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mse.Student.Add(student);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int saveresult = mse.SaveChanges();
|
||||||
|
students1 = mse.Student.ToList();
|
||||||
|
dGridStudent.ItemsSource = students1;
|
||||||
|
return saveresult;
|
||||||
|
} catch(Exception ex)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void dGridStudent_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
var grid = (DataGrid)sender;
|
||||||
|
if(grid.CurrentCell.Column != null)
|
||||||
|
{
|
||||||
|
var cellInfo = grid.SelectedCells[grid.CurrentCell.Column.DisplayIndex];
|
||||||
|
|
||||||
|
if (cellInfo.Column.Header.ToString() == "Фото")
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Вы дважды кликнули по столбцу 'Фото'. Изменить?", "Вопрос", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||||
|
{
|
||||||
|
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||||||
|
openFileDialog.ShowDialog();
|
||||||
|
if (mse.Student.Find((grid.SelectedItem as Student).StudentID) == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект не создан.");
|
||||||
|
grid.SelectedItem = -1;
|
||||||
|
//return;
|
||||||
|
mse.Student.Add(dGridStudent.SelectedItem as Student);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mse.SaveChanges();
|
||||||
|
}
|
||||||
|
catch (DbEntityValidationException ex)
|
||||||
|
{
|
||||||
|
foreach (var entityValidationErrors in ex.EntityValidationErrors)
|
||||||
|
{
|
||||||
|
foreach (var validationError in entityValidationErrors.ValidationErrors)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Свойство: " + validationError.PropertyName + " Ошибка: " + validationError.ErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show("добавил");
|
||||||
|
int index = grid.SelectedIndex;
|
||||||
|
grid.SelectedIndex = -1;
|
||||||
|
grid.SelectedIndex = index;
|
||||||
|
dGridStudent_SelectionChanged(sender, new SelectionChangedEventArgs(DataGrid.SelectionChangedEvent, new Collection<object> { }, new Collection<object> { dGridStudent.SelectedItem }));
|
||||||
|
}
|
||||||
|
mse.Student.Find((grid.SelectedItem as Student).StudentID).photo = File.ReadAllBytes(openFileDialog.FileName);
|
||||||
|
mse.SaveChanges();
|
||||||
|
dGridStudent.ItemsSource = mse.Student.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
private void dGridStudent_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.AddedItems != null && e.AddedItems.Count > 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (e.RemovedItems != null && e.RemovedItems.Count > 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
Student selectedStudent = (e.RemovedItems[0] as Student);
|
||||||
|
if (selectedStudent != null)
|
||||||
|
{
|
||||||
|
Student studentInDb = mse.Student.Find(selectedStudent.StudentID);
|
||||||
|
if (studentInDb != null)
|
||||||
|
{
|
||||||
|
mse.Student.Remove(studentInDb);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mse.SaveChanges();
|
||||||
|
}
|
||||||
|
catch (DbUpdateException ex)
|
||||||
|
{
|
||||||
|
|
||||||
|
MessageBox.Show("Запись, похоже, удалить нельзя.\n\n" + ex.InnerException);
|
||||||
|
students1 = mse.Student.ToList();
|
||||||
|
mse.Entry(studentInDb).State = System.Data.EntityState.Unchanged;
|
||||||
|
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
students1.Remove(dGridStudent.SelectedItem as Student);
|
||||||
|
dGridStudent.SelectedIndex = -1;
|
||||||
|
MessageBox.Show("Удалено");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BtnEdit_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
55
musicschoolapp/Properties/AssemblyInfo.cs
Normal file
55
musicschoolapp/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Resources;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
// Общие сведения об этой сборке предоставляются следующим набором
|
||||||
|
// набор атрибутов. Измените значения этих атрибутов, чтобы изменить сведения,
|
||||||
|
// связанные со сборкой.
|
||||||
|
[assembly: AssemblyTitle("musicschoolapp")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("musicschoolapp")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2024")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми
|
||||||
|
// для компонентов COM. Если необходимо обратиться к типу в этой сборке через
|
||||||
|
// из модели COM, установите атрибут ComVisible для этого типа в значение true.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
//Чтобы начать создание локализуемых приложений, задайте
|
||||||
|
//<UICulture>CultureYouAreCodingWith</UICulture> в файле .csproj
|
||||||
|
//в <PropertyGroup>. Например, при использовании английского (США)
|
||||||
|
//в своих исходных файлах установите <UICulture> в en-US. Затем отмените преобразование в комментарий
|
||||||
|
//атрибута NeutralResourceLanguage ниже. Обновите "en-US" в
|
||||||
|
//строка внизу для обеспечения соответствия настройки UICulture в файле проекта.
|
||||||
|
|
||||||
|
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
|
||||||
|
|
||||||
|
|
||||||
|
[assembly: ThemeInfo(
|
||||||
|
ResourceDictionaryLocation.None, //где расположены словари ресурсов по конкретным тематикам
|
||||||
|
//(используется, если ресурс не найден на странице,
|
||||||
|
// или в словарях ресурсов приложения)
|
||||||
|
ResourceDictionaryLocation.SourceAssembly //где расположен словарь универсальных ресурсов
|
||||||
|
//(используется, если ресурс не найден на странице,
|
||||||
|
// в приложении или в каких-либо словарях ресурсов для конкретной темы)
|
||||||
|
)]
|
||||||
|
|
||||||
|
|
||||||
|
// Сведения о версии для сборки включают четыре следующих значения:
|
||||||
|
//
|
||||||
|
// Основной номер версии
|
||||||
|
// Дополнительный номер версии
|
||||||
|
// Номер сборки
|
||||||
|
// Номер редакции
|
||||||
|
//
|
||||||
|
// Можно задать все значения или принять номера сборки и редакции по умолчанию
|
||||||
|
// используя "*", как показано ниже:
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
71
musicschoolapp/Properties/Resources.Designer.cs
generated
Normal file
71
musicschoolapp/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// Этот код был создан программным средством.
|
||||||
|
// Версия среды выполнения: 4.0.30319.42000
|
||||||
|
//
|
||||||
|
// Изменения в этом файле могут привести к неправильному поведению и будут утрачены, если
|
||||||
|
// код создан повторно.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace musicschoolapp.Properties
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс ресурсов со строгим типом для поиска локализованных строк и пр.
|
||||||
|
/// </summary>
|
||||||
|
// Этот класс был автоматически создан при помощи StronglyTypedResourceBuilder
|
||||||
|
// класс с помощью таких средств, как ResGen или Visual Studio.
|
||||||
|
// Для добавления или удаления члена измените файл .ResX, а затем перезапустите ResGen
|
||||||
|
// с параметром /str или заново постройте свой VS-проект.
|
||||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
|
internal class Resources
|
||||||
|
{
|
||||||
|
|
||||||
|
private static global::System.Resources.ResourceManager resourceMan;
|
||||||
|
|
||||||
|
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||||
|
|
||||||
|
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||||
|
internal Resources()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возврат кэшированного экземпляра ResourceManager, используемого этим классом.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Resources.ResourceManager ResourceManager
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if ((resourceMan == null))
|
||||||
|
{
|
||||||
|
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("musicschoolapp.Properties.Resources", typeof(Resources).Assembly);
|
||||||
|
resourceMan = temp;
|
||||||
|
}
|
||||||
|
return resourceMan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Переопределяет свойство CurrentUICulture текущего потока для всех
|
||||||
|
/// подстановки ресурсов с помощью этого класса ресурсов со строгим типом.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Globalization.CultureInfo Culture
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return resourceCulture;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
resourceCulture = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
117
musicschoolapp/Properties/Resources.resx
Normal file
117
musicschoolapp/Properties/Resources.resx
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
30
musicschoolapp/Properties/Settings.Designer.cs
generated
Normal file
30
musicschoolapp/Properties/Settings.Designer.cs
generated
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// This code was generated by a tool.
|
||||||
|
// Runtime Version:4.0.30319.42000
|
||||||
|
//
|
||||||
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
|
// the code is regenerated.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace musicschoolapp.Properties
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
|
||||||
|
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
||||||
|
{
|
||||||
|
|
||||||
|
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||||
|
|
||||||
|
public static Settings Default
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return defaultInstance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
7
musicschoolapp/Properties/Settings.settings
Normal file
7
musicschoolapp/Properties/Settings.settings
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
|
||||||
|
<Profiles>
|
||||||
|
<Profile Name="(Default)" />
|
||||||
|
</Profiles>
|
||||||
|
<Settings />
|
||||||
|
</SettingsFile>
|
36
musicschoolapp/Student.cs
Normal file
36
musicschoolapp/Student.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// Этот код был создан из шаблона.
|
||||||
|
//
|
||||||
|
// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения.
|
||||||
|
// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace musicschoolapp
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
public partial class Student
|
||||||
|
{
|
||||||
|
public Student()
|
||||||
|
{
|
||||||
|
this.Enrollment = new HashSet<Enrollment>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int StudentID { get; set; }
|
||||||
|
public string FirstName { get; set; }
|
||||||
|
public string LastName { get; set; }
|
||||||
|
public System.DateTime BirthDate { get; set; }
|
||||||
|
public string Phone { get; set; }
|
||||||
|
public string Email { get; set; }
|
||||||
|
public byte[] photo { get; set; }
|
||||||
|
public bool toEnroll { get; set; }
|
||||||
|
public int grade { get; set; }
|
||||||
|
public Nullable<int> Id_instrument { get; set; }
|
||||||
|
|
||||||
|
public virtual ICollection<Enrollment> Enrollment { get; set; }
|
||||||
|
public virtual Instruments Instruments { get; set; }
|
||||||
|
}
|
||||||
|
}
|
22
musicschoolapp/User.cs
Normal file
22
musicschoolapp/User.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// Этот код был создан из шаблона.
|
||||||
|
//
|
||||||
|
// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения.
|
||||||
|
// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace musicschoolapp
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
public partial class User
|
||||||
|
{
|
||||||
|
public int UserID { get; set; }
|
||||||
|
public string username { get; set; }
|
||||||
|
public string password { get; set; }
|
||||||
|
public int permission_level { get; set; }
|
||||||
|
}
|
||||||
|
}
|
24
musicschoolapp/WorkingWindow.xaml
Normal file
24
musicschoolapp/WorkingWindow.xaml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<Window x:Class="musicschoolapp.WorkingWindow"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:musicschoolapp"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="Основное окно программы" Height="450" Width="800">
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="75"></RowDefinition>
|
||||||
|
<RowDefinition Height="30"/>
|
||||||
|
<RowDefinition Height="*"></RowDefinition>
|
||||||
|
<RowDefinition Height="30"></RowDefinition>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<TextBlock Text="Приложение музыкальной школы" FontSize="30" HorizontalAlignment="Center"
|
||||||
|
VerticalAlignment="Center" FontFamily="Tahoma"></TextBlock>
|
||||||
|
<Grid Background="CornflowerBlue" Panel.ZIndex="-2" ></Grid>
|
||||||
|
<Grid Grid.Row="2" Background="#FFE1E4FF"></Grid>
|
||||||
|
<TextBlock x:Name="identifier" Grid.Row="1" Text="Вы вошли как: " HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="14"></TextBlock>
|
||||||
|
<Frame Grid.Row="2" Name="MainFrame"></Frame>
|
||||||
|
<Button x:Name="buttonUpdate" Content="Обновить" HorizontalAlignment="Center" Grid.Row="3" VerticalAlignment="Center" Width="96" Click="buttonUpdate_Click"/>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
89
musicschoolapp/WorkingWindow.xaml.cs
Normal file
89
musicschoolapp/WorkingWindow.xaml.cs
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
using musicschoolapp.Pages;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.Eventing.Reader;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
|
namespace musicschoolapp
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Логика взаимодействия для WorkingWindow.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class WorkingWindow : Window
|
||||||
|
{
|
||||||
|
StudentEditingPage studentEditingPage;
|
||||||
|
CourseEditingPage c;
|
||||||
|
EnrollmentEditingPage s;
|
||||||
|
QuickEnroll qe;
|
||||||
|
Instr instr;
|
||||||
|
public WorkingWindow(User user)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
studentEditingPage = new StudentEditingPage();
|
||||||
|
qe = new QuickEnroll();
|
||||||
|
c = new CourseEditingPage(true);
|
||||||
|
s = new EnrollmentEditingPage(true);
|
||||||
|
instr = new Instr();
|
||||||
|
|
||||||
|
MenuPage menuPage = new MenuPage(studentEditingPage, c, s, instr);
|
||||||
|
if(user.permission_level >=2)
|
||||||
|
{
|
||||||
|
s = new EnrollmentEditingPage(true);
|
||||||
|
menuPage.courseButton.IsEnabled = true;
|
||||||
|
menuPage.studentButton.IsEnabled = true;
|
||||||
|
menuPage.enrollmentButton.IsEnabled = true;
|
||||||
|
menuPage.adminButton.IsEnabled = true;
|
||||||
|
menuPage.instrButton.IsEnabled = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(user.permission_level >= 1)
|
||||||
|
{
|
||||||
|
s = new EnrollmentEditingPage(true);
|
||||||
|
//menuPage.courseButton.IsEnabled = true;
|
||||||
|
//menuPage.studentButton.IsEnabled = true;
|
||||||
|
menuPage.enrollmentButton.IsEnabled = true;
|
||||||
|
menuPage.studentButton.IsEnabled = true;
|
||||||
|
menuPage.instrButton.IsEnabled = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
menuPage.enrollmentButton.IsEnabled = true;
|
||||||
|
menuPage.quickEnrollButton.IsEnabled = false;
|
||||||
|
s = new EnrollmentEditingPage(false);
|
||||||
|
}
|
||||||
|
menuPage.enrollmentEditingPage = s;
|
||||||
|
identifier.Text = "Вы вошли как " + user.username + " с уровнем доступа " + user.permission_level;
|
||||||
|
MainFrame.Navigate(menuPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonUpdate_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (MainFrame.NavigationService.Content == studentEditingPage)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Обновлена ли база данных:" + studentEditingPage.updateDB().ToString());
|
||||||
|
}
|
||||||
|
else if (MainFrame.NavigationService.Content == c)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Обновлена ли база данных Курсов:" + c.updateDB().ToString());
|
||||||
|
}
|
||||||
|
else if(MainFrame.NavigationService.Content == s)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Обновлена ли база данных Зачисления:" + s.updateDB().ToString());
|
||||||
|
}
|
||||||
|
else if (MainFrame.NavigationService.Content == instr)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Обновлена ли база данных Инструментов:" + instr.updateDB().ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
254
musicschoolapp/musicschoolapp.csproj
Normal file
254
musicschoolapp/musicschoolapp.csproj
Normal file
@ -0,0 +1,254 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{CD4C9F97-7E80-4EDB-879E-9CFF6FC040D6}</ProjectGuid>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<RootNamespace>musicschoolapp</RootNamespace>
|
||||||
|
<AssemblyName>musicschoolapp</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<Deterministic>true</Deterministic>
|
||||||
|
<PublishUrl>publish\</PublishUrl>
|
||||||
|
<Install>true</Install>
|
||||||
|
<InstallFrom>Disk</InstallFrom>
|
||||||
|
<UpdateEnabled>false</UpdateEnabled>
|
||||||
|
<UpdateMode>Foreground</UpdateMode>
|
||||||
|
<UpdateInterval>7</UpdateInterval>
|
||||||
|
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||||
|
<UpdatePeriodically>false</UpdatePeriodically>
|
||||||
|
<UpdateRequired>false</UpdateRequired>
|
||||||
|
<MapFileExtensions>true</MapFileExtensions>
|
||||||
|
<ApplicationRevision>0</ApplicationRevision>
|
||||||
|
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||||
|
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||||
|
<UseApplicationTrust>false</UseApplicationTrust>
|
||||||
|
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\EntityFramework.5.0.0\lib\net40\EntityFramework.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop, Version=1.0.168.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Data.Entity" />
|
||||||
|
<Reference Include="System.IO, Version=2.6.8.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Microsoft.Bcl.1.1.8\lib\net40\System.IO.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Net" />
|
||||||
|
<Reference Include="System.Runtime, Version=2.6.8.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Microsoft.Bcl.1.1.8\lib\net40\System.Runtime.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Runtime.Caching" />
|
||||||
|
<Reference Include="System.Runtime.Serialization" />
|
||||||
|
<Reference Include="System.Security" />
|
||||||
|
<Reference Include="System.Threading.Tasks, Version=2.6.8.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Microsoft.Bcl.1.1.8\lib\net40\System.Threading.Tasks.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="System.Xaml">
|
||||||
|
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="WindowsBase" />
|
||||||
|
<Reference Include="PresentationCore" />
|
||||||
|
<Reference Include="PresentationFramework" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ApplicationDefinition Include="App.xaml">
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</ApplicationDefinition>
|
||||||
|
<Compile Include="Class1.cs" />
|
||||||
|
<Compile Include="Course.cs">
|
||||||
|
<DependentUpon>Model1.tt</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Enrollment.cs">
|
||||||
|
<DependentUpon>Model1.tt</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Instruments.cs">
|
||||||
|
<DependentUpon>Model1.tt</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Model1.cs">
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
<DependentUpon>Model1.tt</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Pages\CourseEditingPage.xaml.cs">
|
||||||
|
<DependentUpon>CourseEditingPage.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Pages\EnrollmentEditingPage.xaml.cs">
|
||||||
|
<DependentUpon>EnrollmentEditingPage.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Pages\Instr.xaml.cs">
|
||||||
|
<DependentUpon>Instr.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Pages\MenuPage.xaml.cs">
|
||||||
|
<DependentUpon>MenuPage.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Pages\QuickEnroll.xaml.cs">
|
||||||
|
<DependentUpon>QuickEnroll.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Pages\StudentEditingPage.xaml.cs">
|
||||||
|
<DependentUpon>StudentEditingPage.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Student.cs">
|
||||||
|
<DependentUpon>Model1.tt</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="User.cs">
|
||||||
|
<DependentUpon>Model1.tt</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="WorkingWindow.xaml.cs">
|
||||||
|
<DependentUpon>WorkingWindow.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Page Include="MainWindow.xaml">
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</Page>
|
||||||
|
<Compile Include="App.xaml.cs">
|
||||||
|
<DependentUpon>App.xaml</DependentUpon>
|
||||||
|
<SubType>Code</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="MainWindow.xaml.cs">
|
||||||
|
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||||
|
<SubType>Code</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Page Include="Pages\CourseEditingPage.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
|
<Page Include="Pages\EnrollmentEditingPage.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
|
<Page Include="Pages\Instr.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
|
<Page Include="Pages\MenuPage.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
|
<Page Include="Pages\QuickEnroll.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
|
<Page Include="Pages\StudentEditingPage.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
|
<Page Include="WorkingWindow.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Model1.Context.cs">
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
<DependentUpon>Model1.Context.tt</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Model1.Designer.cs">
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
<DependentUpon>Model1.edmx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs">
|
||||||
|
<SubType>Code</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Properties\Resources.Designer.cs">
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Properties\Settings.Designer.cs">
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DependentUpon>Settings.settings</DependentUpon>
|
||||||
|
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||||
|
</Compile>
|
||||||
|
<EmbeddedResource Include="Properties\Resources.resx">
|
||||||
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||||
|
</EmbeddedResource>
|
||||||
|
<None Include="App.Config" />
|
||||||
|
<EntityDeploy Include="Model1.edmx">
|
||||||
|
<Generator>EntityModelCodeGenerator</Generator>
|
||||||
|
<LastGenOutput>Model1.Designer.cs</LastGenOutput>
|
||||||
|
</EntityDeploy>
|
||||||
|
<None Include="Model1.edmx.diagram">
|
||||||
|
<DependentUpon>Model1.edmx</DependentUpon>
|
||||||
|
</None>
|
||||||
|
<None Include="packages.config" />
|
||||||
|
<None Include="Properties\Settings.settings">
|
||||||
|
<Generator>SettingsSingleFileGenerator</Generator>
|
||||||
|
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Model1.Context.tt">
|
||||||
|
<Generator>TextTemplatingFileGenerator</Generator>
|
||||||
|
<DependentUpon>Model1.edmx</DependentUpon>
|
||||||
|
<LastGenOutput>Model1.Context.cs</LastGenOutput>
|
||||||
|
</Content>
|
||||||
|
<Content Include="Model1.tt">
|
||||||
|
<Generator>TextTemplatingFileGenerator</Generator>
|
||||||
|
<DependentUpon>Model1.edmx</DependentUpon>
|
||||||
|
<LastGenOutput>Model1.cs</LastGenOutput>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||||
|
<Visible>False</Visible>
|
||||||
|
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||||
|
<Install>false</Install>
|
||||||
|
</BootstrapperPackage>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="AdminEditingApp\" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
|
||||||
|
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
|
||||||
|
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
|
||||||
|
<Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
|
||||||
|
</Target>
|
||||||
|
</Project>
|
8
musicschoolapp/packages.config
Normal file
8
musicschoolapp/packages.config
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="EntityFramework" version="5.0.0" targetFramework="net40" />
|
||||||
|
<package id="EntityFramework.ru" version="5.0.0" targetFramework="net40" />
|
||||||
|
<package id="Microsoft.Bcl" version="1.1.8" targetFramework="net40" />
|
||||||
|
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net40" />
|
||||||
|
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net40" />
|
||||||
|
</packages>
|
Loading…
Reference in New Issue
Block a user