From b8aa8c44b2e48bbcf6d652b6c8a235e1b431ae18 Mon Sep 17 00:00:00 2001 From: oreshki Date: Tue, 7 Apr 2026 16:58:06 +0500 Subject: [PATCH] Model added --- Labaratory/Labaratory.sln | 25 + Labaratory/Labaratory/Analyzer.cs | 32 + Labaratory/Labaratory/Analyzer_Logs.cs | 27 + Labaratory/Labaratory/App.config | 18 + Labaratory/Labaratory/App.xaml | 15 + Labaratory/Labaratory/App.xaml.cs | 17 + Labaratory/Labaratory/BaseViewModel.cs | 19 + Labaratory/Labaratory/Insurance_Companies.cs | 36 + Labaratory/Labaratory/Invoice.cs | 29 + Labaratory/Labaratory/Labaratory.csproj | 223 ++++ Labaratory/Labaratory/LoginViewModel.cs | 35 + Labaratory/Labaratory/MainWindow.xaml | 74 ++ Labaratory/Labaratory/MainWindow.xaml.cs | 77 ++ Labaratory/Labaratory/Model1.Context.cs | 43 + Labaratory/Labaratory/Model1.Context.tt | 636 ++++++++++ Labaratory/Labaratory/Model1.Designer.cs | 10 + Labaratory/Labaratory/Model1.cs | 9 + Labaratory/Labaratory/Model1.edmx | 1111 +++++++++++++++++ Labaratory/Labaratory/Model1.edmx.diagram | 42 + Labaratory/Labaratory/Model1.tt | 733 +++++++++++ Labaratory/Labaratory/Order.cs | 37 + Labaratory/Labaratory/Order_Items.cs | 34 + Labaratory/Labaratory/Order_Statuses.cs | 29 + Labaratory/Labaratory/Patient.cs | 41 + Labaratory/Labaratory/Policy_Types.cs | 29 + .../Labaratory/Properties/AssemblyInfo.cs | 52 + .../Properties/Resources.Designer.cs | 71 ++ .../Labaratory/Properties/Resources.resx | 117 ++ .../Properties/Settings.Designer.cs | 30 + .../Labaratory/Properties/Settings.settings | 7 + Labaratory/Labaratory/Rendered_Services.cs | 35 + Labaratory/Labaratory/Role.cs | 29 + Labaratory/Labaratory/Service.cs | 36 + Labaratory/Labaratory/Service_Statuses.cs | 29 + Labaratory/Labaratory/SessionManager.cs | 15 + Labaratory/Labaratory/User.cs | 43 + Labaratory/Labaratory/packages.config | 12 + 37 files changed, 3857 insertions(+) create mode 100644 Labaratory/Labaratory.sln create mode 100644 Labaratory/Labaratory/Analyzer.cs create mode 100644 Labaratory/Labaratory/Analyzer_Logs.cs create mode 100644 Labaratory/Labaratory/App.config create mode 100644 Labaratory/Labaratory/App.xaml create mode 100644 Labaratory/Labaratory/App.xaml.cs create mode 100644 Labaratory/Labaratory/BaseViewModel.cs create mode 100644 Labaratory/Labaratory/Insurance_Companies.cs create mode 100644 Labaratory/Labaratory/Invoice.cs create mode 100644 Labaratory/Labaratory/Labaratory.csproj create mode 100644 Labaratory/Labaratory/LoginViewModel.cs create mode 100644 Labaratory/Labaratory/MainWindow.xaml create mode 100644 Labaratory/Labaratory/MainWindow.xaml.cs create mode 100644 Labaratory/Labaratory/Model1.Context.cs create mode 100644 Labaratory/Labaratory/Model1.Context.tt create mode 100644 Labaratory/Labaratory/Model1.Designer.cs create mode 100644 Labaratory/Labaratory/Model1.cs create mode 100644 Labaratory/Labaratory/Model1.edmx create mode 100644 Labaratory/Labaratory/Model1.edmx.diagram create mode 100644 Labaratory/Labaratory/Model1.tt create mode 100644 Labaratory/Labaratory/Order.cs create mode 100644 Labaratory/Labaratory/Order_Items.cs create mode 100644 Labaratory/Labaratory/Order_Statuses.cs create mode 100644 Labaratory/Labaratory/Patient.cs create mode 100644 Labaratory/Labaratory/Policy_Types.cs create mode 100644 Labaratory/Labaratory/Properties/AssemblyInfo.cs create mode 100644 Labaratory/Labaratory/Properties/Resources.Designer.cs create mode 100644 Labaratory/Labaratory/Properties/Resources.resx create mode 100644 Labaratory/Labaratory/Properties/Settings.Designer.cs create mode 100644 Labaratory/Labaratory/Properties/Settings.settings create mode 100644 Labaratory/Labaratory/Rendered_Services.cs create mode 100644 Labaratory/Labaratory/Role.cs create mode 100644 Labaratory/Labaratory/Service.cs create mode 100644 Labaratory/Labaratory/Service_Statuses.cs create mode 100644 Labaratory/Labaratory/SessionManager.cs create mode 100644 Labaratory/Labaratory/User.cs create mode 100644 Labaratory/Labaratory/packages.config diff --git a/Labaratory/Labaratory.sln b/Labaratory/Labaratory.sln new file mode 100644 index 0000000..cec51cd --- /dev/null +++ b/Labaratory/Labaratory.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.13.35919.96 d17.13 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Labaratory", "Labaratory\Labaratory.csproj", "{F0FF7740-16D4-4CA7-9CE0-8F86B4F36F71}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F0FF7740-16D4-4CA7-9CE0-8F86B4F36F71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F0FF7740-16D4-4CA7-9CE0-8F86B4F36F71}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F0FF7740-16D4-4CA7-9CE0-8F86B4F36F71}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F0FF7740-16D4-4CA7-9CE0-8F86B4F36F71}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D2088D7B-B202-4B62-8D56-EC8E3D220390} + EndGlobalSection +EndGlobal diff --git a/Labaratory/Labaratory/Analyzer.cs b/Labaratory/Labaratory/Analyzer.cs new file mode 100644 index 0000000..6c9f195 --- /dev/null +++ b/Labaratory/Labaratory/Analyzer.cs @@ -0,0 +1,32 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан по шаблону. +// +// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения. +// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода. +// +//------------------------------------------------------------------------------ + +namespace Labaratory +{ + using System; + using System.Collections.Generic; + + public partial class Analyzer + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + public Analyzer() + { + this.Analyzer_Logs = new HashSet(); + this.Rendered_Services = new HashSet(); + } + + public int ID_Analyzer { get; set; } + public string AnalyzerName { get; set; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Analyzer_Logs { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Rendered_Services { get; set; } + } +} diff --git a/Labaratory/Labaratory/Analyzer_Logs.cs b/Labaratory/Labaratory/Analyzer_Logs.cs new file mode 100644 index 0000000..60bb550 --- /dev/null +++ b/Labaratory/Labaratory/Analyzer_Logs.cs @@ -0,0 +1,27 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан по шаблону. +// +// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения. +// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода. +// +//------------------------------------------------------------------------------ + +namespace Labaratory +{ + using System; + using System.Collections.Generic; + + public partial class Analyzer_Logs + { + public int ID_Log { get; set; } + public Nullable Analyzer { get; set; } + public Nullable Rendered { get; set; } + public Nullable StartTime { get; set; } + public Nullable CompletionDateTime { get; set; } + public Nullable WorkTimeSeconds { get; set; } + + public virtual Analyzer Analyzer1 { get; set; } + public virtual Rendered_Services Rendered_Services { get; set; } + } +} diff --git a/Labaratory/Labaratory/App.config b/Labaratory/Labaratory/App.config new file mode 100644 index 0000000..5679481 --- /dev/null +++ b/Labaratory/Labaratory/App.config @@ -0,0 +1,18 @@ + + + + +
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/Labaratory/Labaratory/App.xaml b/Labaratory/Labaratory/App.xaml new file mode 100644 index 0000000..8e969db --- /dev/null +++ b/Labaratory/Labaratory/App.xaml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/Labaratory/Labaratory/App.xaml.cs b/Labaratory/Labaratory/App.xaml.cs new file mode 100644 index 0000000..8535705 --- /dev/null +++ b/Labaratory/Labaratory/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace Labaratory +{ + /// + /// Логика взаимодействия для App.xaml + /// + public partial class App : Application + { + } +} diff --git a/Labaratory/Labaratory/BaseViewModel.cs b/Labaratory/Labaratory/BaseViewModel.cs new file mode 100644 index 0000000..0b57116 --- /dev/null +++ b/Labaratory/Labaratory/BaseViewModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel; +using System.Runtime.CompilerServices; + +namespace Labaratory +{ + public class BaseViewModel : INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + protected void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/Labaratory/Labaratory/Insurance_Companies.cs b/Labaratory/Labaratory/Insurance_Companies.cs new file mode 100644 index 0000000..deb8e09 --- /dev/null +++ b/Labaratory/Labaratory/Insurance_Companies.cs @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан по шаблону. +// +// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения. +// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода. +// +//------------------------------------------------------------------------------ + +namespace Labaratory +{ + using System; + using System.Collections.Generic; + + public partial class Insurance_Companies + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + public Insurance_Companies() + { + this.Invoices = new HashSet(); + this.Patients = new HashSet(); + } + + public int ID_Company { get; set; } + public string CompanyName { get; set; } + public string Address { get; set; } + public string INN { get; set; } + public string SettlementAccount { get; set; } + public string BIK { get; set; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Invoices { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Patients { get; set; } + } +} diff --git a/Labaratory/Labaratory/Invoice.cs b/Labaratory/Labaratory/Invoice.cs new file mode 100644 index 0000000..0957f87 --- /dev/null +++ b/Labaratory/Labaratory/Invoice.cs @@ -0,0 +1,29 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан по шаблону. +// +// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения. +// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода. +// +//------------------------------------------------------------------------------ + +namespace Labaratory +{ + using System; + using System.Collections.Generic; + + public partial class Invoice + { + public int ID_Invoice { get; set; } + public string InvoiceNumber { get; set; } + public Nullable Accountant { get; set; } + public Nullable Company { get; set; } + public Nullable OrderRef { get; set; } + public Nullable Amount { get; set; } + public Nullable IssueDate { get; set; } + + public virtual Insurance_Companies Insurance_Companies { get; set; } + public virtual User User { get; set; } + public virtual Order Order { get; set; } + } +} diff --git a/Labaratory/Labaratory/Labaratory.csproj b/Labaratory/Labaratory/Labaratory.csproj new file mode 100644 index 0000000..e4cf16a --- /dev/null +++ b/Labaratory/Labaratory/Labaratory.csproj @@ -0,0 +1,223 @@ + + + + + + Debug + AnyCPU + {F0FF7740-16D4-4CA7-9CE0-8F86B4F36F71} + WinExe + Labaratory + Labaratory + v4.7.2 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + true + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\EasyCaptcha.Wpf.0.9.0.3\lib\net45\EasyCaptcha.Wpf.dll + + + ..\packages\EntityFramework.6.5.1\lib\net45\EntityFramework.dll + + + ..\packages\EntityFramework.6.5.1\lib\net45\EntityFramework.SqlServer.dll + + + + ..\packages\System.Buffers.4.6.1\lib\net462\System.Buffers.dll + + + + + ..\packages\System.Memory.4.6.3\lib\net462\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.6.1\lib\net462\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.6.1.2\lib\net462\System.Runtime.CompilerServices.Unsafe.dll + + + + + + + + + + + 4.0 + + + + + + ..\packages\WPF-UI.4.2.0\lib\net472\Wpf.Ui.dll + + + ..\packages\WPF-UI.Abstractions.4.2.0\lib\net462\Wpf.Ui.Abstractions.dll + + + + + MSBuild:Compile + Designer + + + Model1.tt + + + Model1.tt + + + + Model1.tt + + + Model1.tt + + + + True + True + Model1.Context.tt + + + True + True + Model1.tt + + + True + True + Model1.edmx + + + Model1.tt + + + Model1.tt + + + Model1.tt + + + Model1.tt + + + Model1.tt + + + Model1.tt + + + Model1.tt + + + Model1.tt + + + Model1.tt + + + + Model1.tt + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + EntityModelCodeGenerator + Model1.Designer.cs + + + Model1.edmx + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + TextTemplatingFileGenerator + Model1.Context.cs + Model1.edmx + + + TextTemplatingFileGenerator + Model1.edmx + Model1.cs + + + + + + + + + Данный проект ссылается на пакеты NuGet, отсутствующие на этом компьютере. Используйте восстановление пакетов NuGet, чтобы скачать их. Дополнительную информацию см. по адресу: http://go.microsoft.com/fwlink/?LinkID=322105. Отсутствует следующий файл: {0}. + + + + + + \ No newline at end of file diff --git a/Labaratory/Labaratory/LoginViewModel.cs b/Labaratory/Labaratory/LoginViewModel.cs new file mode 100644 index 0000000..16a6ef9 --- /dev/null +++ b/Labaratory/Labaratory/LoginViewModel.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace Labaratory +{ + public class LoginViewModel : BaseViewModel + { + private string _login; + private string _captchaText; + private bool _isCaptchaVisible; + + public string Login + { + get => _login; + set { _login = value; OnPropertyChanged(); } + } + + public bool IsCaptchaVisible + { + get => _isCaptchaVisible; + set { _isCaptchaVisible = value; OnPropertyChanged(); } + } + + public ICommand LoginCommand { get; } + + public LoginViewModel() + { + // Инициализация команд и капчи + } + } +} diff --git a/Labaratory/Labaratory/MainWindow.xaml b/Labaratory/Labaratory/MainWindow.xaml new file mode 100644 index 0000000..f2c359c --- /dev/null +++ b/Labaratory/Labaratory/MainWindow.xaml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Labaratory/Labaratory/MainWindow.xaml.cs b/Labaratory/Labaratory/MainWindow.xaml.cs new file mode 100644 index 0000000..f64c193 --- /dev/null +++ b/Labaratory/Labaratory/MainWindow.xaml.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +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; + +namespace Labaratory +{ + /// + /// Логика взаимодействия для MainWindow.xaml + /// + public partial class MainWindow : Window + { + private string _activeCaptcha; + + public MainWindow() + { + LaboratoryDBEntities db = new LaboratoryDBEntities(); + InitializeComponent(); + DataContext = new LoginViewModel(); + } + + private void GenerateCaptcha() + { + const string chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"; + Random rand = new Random(); + _activeCaptcha = new string(Enumerable.Repeat(chars, 5) + .Select(s => s[rand.Next(s.Length)]).ToArray()); + + CaptchaVisual.Text = _activeCaptcha; + CaptchaInput.Clear(); + } + + private void RefreshCaptcha_Click(object sender, RoutedEventArgs e) + { + GenerateCaptcha(); + } + + + private void LoginButton_Click(object sender, RoutedEventArgs e) + { + if (CaptchaInput.Visibility == Visibility.Visible) + { + Login(); + } + else + { + MessageBox.Show("Неверная капча!"); + GenerateCaptcha(); + } + + if (CaptchaInput.Visibility != Visibility.Visible) + { + + } + else + { + MessageBox.Show("Неверная капча!"); + GenerateCaptcha(); + } + } + private bool Login() + { + + } + + } +} diff --git a/Labaratory/Labaratory/Model1.Context.cs b/Labaratory/Labaratory/Model1.Context.cs new file mode 100644 index 0000000..374e494 --- /dev/null +++ b/Labaratory/Labaratory/Model1.Context.cs @@ -0,0 +1,43 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан по шаблону. +// +// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения. +// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода. +// +//------------------------------------------------------------------------------ + +namespace Labaratory +{ + using System; + using System.Data.Entity; + using System.Data.Entity.Infrastructure; + + public partial class LaboratoryDBEntities : DbContext + { + public LaboratoryDBEntities() + : base("name=LaboratoryDBEntities") + { + } + + protected override void OnModelCreating(DbModelBuilder modelBuilder) + { + throw new UnintentionalCodeFirstException(); + } + + public virtual DbSet Analyzer_Logs { get; set; } + public virtual DbSet Analyzers { get; set; } + public virtual DbSet Insurance_Companies { get; set; } + public virtual DbSet Invoices { get; set; } + public virtual DbSet Order_Items { get; set; } + public virtual DbSet Order_Statuses { get; set; } + public virtual DbSet Orders { get; set; } + public virtual DbSet Patients { get; set; } + public virtual DbSet Policy_Types { get; set; } + public virtual DbSet Rendered_Services { get; set; } + public virtual DbSet Roles { get; set; } + public virtual DbSet Service_Statuses { get; set; } + public virtual DbSet Services { get; set; } + public virtual DbSet Users { get; set; } + } +} diff --git a/Labaratory/Labaratory/Model1.Context.tt b/Labaratory/Labaratory/Model1.Context.tt new file mode 100644 index 0000000..7b8920f --- /dev/null +++ b/Labaratory/Labaratory/Model1.Context.tt @@ -0,0 +1,636 @@ +<#@ template language="C#" debug="false" hostspecific="true"#> +<#@ include file="EF6.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().FirstOrDefault(); +if (container == null) +{ + return string.Empty; +} +#> +//------------------------------------------------------------------------------ +// +// <#=CodeGenerationTools.GetResourceString("Template_GeneratedCodeCommentLine1")#> +// +// <#=CodeGenerationTools.GetResourceString("Template_GeneratedCodeCommentLine2")#> +// <#=CodeGenerationTools.GetResourceString("Template_GeneratedCodeCommentLine3")#> +// +//------------------------------------------------------------------------------ + +<# + +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.Entity.Core.Objects; +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; +<# +} + +foreach (var entitySet in container.BaseEntitySets.OfType()) +{ + // Note: the DbSet members are defined below such that the getter and + // setter always have the same accessibility as the DbSet definition + if (Accessibility.ForReadOnlyProperty(entitySet) != "public") + { +#> + <#=codeStringGenerator.DbSetInitializer(entitySet)#> +<# + } +} +#> + } + + protected override void OnModelCreating(DbModelBuilder modelBuilder) + { + throw new UnintentionalCodeFirstException(); + } + +<# + foreach (var entitySet in container.BaseEntitySets.OfType()) + { +#> + <#=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)) + { +#> + + [DbFunction("<#=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_EF6"; + +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 navProp) + { + var endType = _typeMapper.GetTypeName(navProp.ToEndMember.GetEntityType()); + return string.Format( + CultureInfo.InvariantCulture, + "{0} {1} {2} {{ {3}get; {4}set; }}", + AccessibilityAndVirtual(Accessibility.ForNavigationProperty(navProp)), + navProp.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many ? ("ICollection<" + endType + ">") : endType, + _code.Escape(navProp), + _code.SpaceAfter(Accessibility.ForGetter(navProp)), + _code.SpaceAfter(Accessibility.ForSetter(navProp))); + } + + 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 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(" + TypeMapper.FixNamespaces(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 => TypeMapper.FixNamespaces(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 => TypeMapper.FixNamespaces(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} virtual DbSet<{1}> {2} {{ get; set; }}", + Accessibility.ForReadOnlyProperty(entitySet), + _typeMapper.GetTypeName(entitySet.ElementType), + _code.Escape(entitySet)); + } + + public string DbSetInitializer(EntitySet entitySet) + { + return string.Format( + CultureInfo.InvariantCulture, + "{0} = Set<{1}>();", + _code.Escape(entitySet), + _typeMapper.GetTypeName(entitySet.ElementType)); + } + + 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 static string FixNamespaces(string typeName) + { + return typeName.Replace("System.Data.Spatial.", "System.Data.Entity.Spatial."); + } + + 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); + } + + typeName = FixNamespaces(typeName); + + 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(); + } + + 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 types, string sourceFile) + { + ArgumentNotNull(types, "types"); + ArgumentNotNull(sourceFile, "sourceFile"); + + var hash = new HashSet(StringComparer.InvariantCultureIgnoreCase); + if (types.Any(item => !hash.Add(item))) + { + _errors.Add( + new CompilerError(sourceFile, -1, -1, "6023", + String.Format(CultureInfo.CurrentCulture, CodeGenerationTools.GetResourceString("Template_CaseInsensitiveTypeConflict")))); + return false; + } + return true; + } + + public IEnumerable GetEnumItemsToGenerate(IEnumerable itemCollection) + { + return GetItemsToGenerate(itemCollection) + .Where(e => IsEnumType(e)); + } + + public IEnumerable GetItemsToGenerate(IEnumerable itemCollection) where T: EdmType + { + return itemCollection + .OfType() + .Where(i => !i.MetadataProperties.Any(p => p.Name == ExternalTypeNameAttributeName)) + .OrderBy(i => i.Name); + } + + public IEnumerable GetAllGlobalItems(IEnumerable 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 GetSimpleProperties(EntityType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type); + } + + public IEnumerable GetSimpleProperties(ComplexType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type); + } + + public IEnumerable GetComplexProperties(EntityType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type); + } + + public IEnumerable GetComplexProperties(ComplexType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type); + } + + public IEnumerable GetPropertiesWithDefaultValues(EntityType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null); + } + + public IEnumerable GetPropertiesWithDefaultValues(ComplexType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null); + } + + public IEnumerable GetNavigationProperties(EntityType type) + { + return type.NavigationProperties.Where(np => np.DeclaringType == type); + } + + public IEnumerable 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)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 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 static void ArgumentNotNull(T arg, string name) where T : class +{ + if (arg == null) + { + throw new ArgumentNullException(name); + } +} +#> \ No newline at end of file diff --git a/Labaratory/Labaratory/Model1.Designer.cs b/Labaratory/Labaratory/Model1.Designer.cs new file mode 100644 index 0000000..501daac --- /dev/null +++ b/Labaratory/Labaratory/Model1.Designer.cs @@ -0,0 +1,10 @@ +// Создание кода T4 для модели "C:\Users\usersql\source\repos\UP01TASK3\Labaratory\Labaratory\Model1.edmx" включено. +// Чтобы включить формирование кода прежних версий, измените значение свойства "Стратегия создания кода" конструктора +// на "Legacy ObjectContext". Это свойство доступно в окне "Свойства", если модель +// открыта в конструкторе. + +// Если не сформированы контекст и классы сущности, возможная причина в том, что вы создали пустую модель, но +// еще не выбрали версию Entity Framework для использования. Чтобы сформировать класс контекста и классы сущностей +// для своей модели, откройте модель в конструкторе, щелкните правой кнопкой область конструктора и +// выберите "Обновить модель из базы данных", "Сформировать базу данных из модели" или "Добавить элемент формирования +// кода...". \ No newline at end of file diff --git a/Labaratory/Labaratory/Model1.cs b/Labaratory/Labaratory/Model1.cs new file mode 100644 index 0000000..a8fe9a9 --- /dev/null +++ b/Labaratory/Labaratory/Model1.cs @@ -0,0 +1,9 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан по шаблону. +// +// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения. +// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода. +// +//------------------------------------------------------------------------------ + diff --git a/Labaratory/Labaratory/Model1.edmx b/Labaratory/Labaratory/Model1.edmx new file mode 100644 index 0000000..2ba6fbc --- /dev/null +++ b/Labaratory/Labaratory/Model1.edmx @@ -0,0 +1,1111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Labaratory/Labaratory/Model1.edmx.diagram b/Labaratory/Labaratory/Model1.edmx.diagram new file mode 100644 index 0000000..0f82470 --- /dev/null +++ b/Labaratory/Labaratory/Model1.edmx.diagram @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Labaratory/Labaratory/Model1.tt b/Labaratory/Labaratory/Model1.tt new file mode 100644 index 0000000..b0e43c7 --- /dev/null +++ b/Labaratory/Labaratory/Model1.tt @@ -0,0 +1,733 @@ +<#@ template language="C#" debug="false" hostspecific="true"#> +<#@ include file="EF6.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(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()) + { +#> + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + 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) + { + if (navigationProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many) + { +#> + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] +<# + } +#> + <#=codeStringGenerator.NavigationProperty(navigationProperty)#> +<# + } + } +#> +} +<# + EndNamespace(code); +} + +foreach (var complex in typeMapper.GetItemsToGenerate(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(); +#> +//------------------------------------------------------------------------------ +// +// <#=CodeGenerationTools.GetResourceString("Template_GeneratedCodeCommentLine1")#> +// +// <#=CodeGenerationTools.GetResourceString("Template_GeneratedCodeCommentLine2")#> +// <#=CodeGenerationTools.GetResourceString("Template_GeneratedCodeCommentLine3")#> +// +//------------------------------------------------------------------------------ +<#=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_EF6"; + +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 navProp) + { + var endType = _typeMapper.GetTypeName(navProp.ToEndMember.GetEntityType()); + return string.Format( + CultureInfo.InvariantCulture, + "{0} {1} {2} {{ {3}get; {4}set; }}", + AccessibilityAndVirtual(Accessibility.ForNavigationProperty(navProp)), + navProp.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many ? ("ICollection<" + endType + ">") : endType, + _code.Escape(navProp), + _code.SpaceAfter(Accessibility.ForGetter(navProp)), + _code.SpaceAfter(Accessibility.ForSetter(navProp))); + } + + 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 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(" + TypeMapper.FixNamespaces(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 => TypeMapper.FixNamespaces(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 => TypeMapper.FixNamespaces(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} virtual 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 static string FixNamespaces(string typeName) + { + return typeName.Replace("System.Data.Spatial.", "System.Data.Entity.Spatial."); + } + + 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); + } + + typeName = FixNamespaces(typeName); + + 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(); + } + + 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 types, string sourceFile) + { + ArgumentNotNull(types, "types"); + ArgumentNotNull(sourceFile, "sourceFile"); + + var hash = new HashSet(StringComparer.InvariantCultureIgnoreCase); + if (types.Any(item => !hash.Add(item))) + { + _errors.Add( + new CompilerError(sourceFile, -1, -1, "6023", + String.Format(CultureInfo.CurrentCulture, CodeGenerationTools.GetResourceString("Template_CaseInsensitiveTypeConflict")))); + return false; + } + return true; + } + + public IEnumerable GetEnumItemsToGenerate(IEnumerable itemCollection) + { + return GetItemsToGenerate(itemCollection) + .Where(e => IsEnumType(e)); + } + + public IEnumerable GetItemsToGenerate(IEnumerable itemCollection) where T: EdmType + { + return itemCollection + .OfType() + .Where(i => !i.MetadataProperties.Any(p => p.Name == ExternalTypeNameAttributeName)) + .OrderBy(i => i.Name); + } + + public IEnumerable GetAllGlobalItems(IEnumerable 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 GetSimpleProperties(EntityType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type); + } + + public IEnumerable GetSimpleProperties(ComplexType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type); + } + + public IEnumerable GetComplexProperties(EntityType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type); + } + + public IEnumerable GetComplexProperties(ComplexType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type); + } + + public IEnumerable GetPropertiesWithDefaultValues(EntityType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null); + } + + public IEnumerable GetPropertiesWithDefaultValues(ComplexType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null); + } + + public IEnumerable GetNavigationProperties(EntityType type) + { + return type.NavigationProperties.Where(np => np.DeclaringType == type); + } + + public IEnumerable 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)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 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 static void ArgumentNotNull(T arg, string name) where T : class +{ + if (arg == null) + { + throw new ArgumentNullException(name); + } +} +#> \ No newline at end of file diff --git a/Labaratory/Labaratory/Order.cs b/Labaratory/Labaratory/Order.cs new file mode 100644 index 0000000..51565e5 --- /dev/null +++ b/Labaratory/Labaratory/Order.cs @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан по шаблону. +// +// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения. +// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода. +// +//------------------------------------------------------------------------------ + +namespace Labaratory +{ + using System; + using System.Collections.Generic; + + public partial class Order + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + public Order() + { + this.Invoices = new HashSet(); + this.Order_Items = new HashSet(); + } + + public int ID_Order { get; set; } + public Nullable OrderDate { get; set; } + public Nullable Patient { get; set; } + public Nullable Status { get; set; } + public Nullable TotalExecutionDays { get; set; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Invoices { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Order_Items { get; set; } + public virtual Order_Statuses Order_Statuses { get; set; } + public virtual Patient Patient1 { get; set; } + } +} diff --git a/Labaratory/Labaratory/Order_Items.cs b/Labaratory/Labaratory/Order_Items.cs new file mode 100644 index 0000000..e73a73c --- /dev/null +++ b/Labaratory/Labaratory/Order_Items.cs @@ -0,0 +1,34 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан по шаблону. +// +// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения. +// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода. +// +//------------------------------------------------------------------------------ + +namespace Labaratory +{ + using System; + using System.Collections.Generic; + + public partial class Order_Items + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + public Order_Items() + { + this.Rendered_Services = new HashSet(); + } + + public int ID_OrderItem { get; set; } + public Nullable Order { get; set; } + public Nullable Service { get; set; } + public Nullable ServiceStatus { get; set; } + + public virtual Order Order1 { get; set; } + public virtual Service Service1 { get; set; } + public virtual Service_Statuses Service_Statuses { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Rendered_Services { get; set; } + } +} diff --git a/Labaratory/Labaratory/Order_Statuses.cs b/Labaratory/Labaratory/Order_Statuses.cs new file mode 100644 index 0000000..aae936a --- /dev/null +++ b/Labaratory/Labaratory/Order_Statuses.cs @@ -0,0 +1,29 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан по шаблону. +// +// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения. +// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода. +// +//------------------------------------------------------------------------------ + +namespace Labaratory +{ + using System; + using System.Collections.Generic; + + public partial class Order_Statuses + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + public Order_Statuses() + { + this.Orders = new HashSet(); + } + + public int ID_Status { get; set; } + public string StatusName { get; set; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Orders { get; set; } + } +} diff --git a/Labaratory/Labaratory/Patient.cs b/Labaratory/Labaratory/Patient.cs new file mode 100644 index 0000000..775a27c --- /dev/null +++ b/Labaratory/Labaratory/Patient.cs @@ -0,0 +1,41 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан по шаблону. +// +// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения. +// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода. +// +//------------------------------------------------------------------------------ + +namespace Labaratory +{ + using System; + using System.Collections.Generic; + + public partial class Patient + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + public Patient() + { + this.Orders = new HashSet(); + } + + public int ID_Patient { get; set; } + public string Surname { get; set; } + public string FirstName { get; set; } + public string Patronymic { get; set; } + public Nullable BirthDate { get; set; } + public string PassportSeries { get; set; } + public string PassportNumber { get; set; } + public string Phone { get; set; } + public string Email { get; set; } + public string InsuranceNumber { get; set; } + public Nullable PolicyType { get; set; } + public Nullable Company { get; set; } + + public virtual Insurance_Companies Insurance_Companies { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Orders { get; set; } + public virtual Policy_Types Policy_Types { get; set; } + } +} diff --git a/Labaratory/Labaratory/Policy_Types.cs b/Labaratory/Labaratory/Policy_Types.cs new file mode 100644 index 0000000..91987d7 --- /dev/null +++ b/Labaratory/Labaratory/Policy_Types.cs @@ -0,0 +1,29 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан по шаблону. +// +// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения. +// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода. +// +//------------------------------------------------------------------------------ + +namespace Labaratory +{ + using System; + using System.Collections.Generic; + + public partial class Policy_Types + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + public Policy_Types() + { + this.Patients = new HashSet(); + } + + public int ID_PolicyType { get; set; } + public string TypeName { get; set; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Patients { get; set; } + } +} diff --git a/Labaratory/Labaratory/Properties/AssemblyInfo.cs b/Labaratory/Labaratory/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..06b204e --- /dev/null +++ b/Labaratory/Labaratory/Properties/AssemblyInfo.cs @@ -0,0 +1,52 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// Общие сведения об этой сборке предоставляются следующим набором +// набор атрибутов. Измените значения этих атрибутов, чтобы изменить сведения, +// связанные со сборкой. +[assembly: AssemblyTitle("Labaratory")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("HP Inc.")] +[assembly: AssemblyProduct("Labaratory")] +[assembly: AssemblyCopyright("Copyright © HP Inc. 2026")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми +// для компонентов COM. Если необходимо обратиться к типу в этой сборке через +// из модели COM, установите атрибут ComVisible для этого типа в значение true. +[assembly: ComVisible(false)] + +//Чтобы начать создание локализуемых приложений, задайте +//CultureYouAreCodingWith в файле .csproj +//в . Например, при использовании английского (США) +//в своих исходных файлах установите в en-US. Затем отмените преобразование в комментарий +//атрибута NeutralResourceLanguage ниже. Обновите "en-US" в +//строка внизу для обеспечения соответствия настройки UICulture в файле проекта. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //где расположены словари ресурсов по конкретным тематикам + //(используется, если ресурс не найден на странице, + // или в словарях ресурсов приложения) + ResourceDictionaryLocation.SourceAssembly //где расположен словарь универсальных ресурсов + //(используется, если ресурс не найден на странице, + // в приложении или в каких-либо словарях ресурсов для конкретной темы) +)] + + +// Сведения о версии для сборки включают четыре следующих значения: +// +// Основной номер версии +// Дополнительный номер версии +// Номер сборки +// Номер редакции +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Labaratory/Labaratory/Properties/Resources.Designer.cs b/Labaratory/Labaratory/Properties/Resources.Designer.cs new file mode 100644 index 0000000..d364e69 --- /dev/null +++ b/Labaratory/Labaratory/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// Этот код был создан программным средством. +// Версия среды выполнения: 4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильному поведению и будут утрачены, если +// код создан повторно. +// +//------------------------------------------------------------------------------ + +namespace Labaratory.Properties +{ + + + /// + /// Класс ресурсов со строгим типом для поиска локализованных строк и пр. + /// + // Этот класс был автоматически создан при помощи 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() + { + } + + /// + /// Возврат кэшированного экземпляра ResourceManager, используемого этим классом. + /// + [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("Labaratory.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Переопределяет свойство CurrentUICulture текущего потока для всех + /// подстановки ресурсов с помощью этого класса ресурсов со строгим типом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Labaratory/Labaratory/Properties/Resources.resx b/Labaratory/Labaratory/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Labaratory/Labaratory/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Labaratory/Labaratory/Properties/Settings.Designer.cs b/Labaratory/Labaratory/Properties/Settings.Designer.cs new file mode 100644 index 0000000..b5cc3b4 --- /dev/null +++ b/Labaratory/Labaratory/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// 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. +// +//------------------------------------------------------------------------------ + +namespace Labaratory.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; + } + } + } +} diff --git a/Labaratory/Labaratory/Properties/Settings.settings b/Labaratory/Labaratory/Properties/Settings.settings new file mode 100644 index 0000000..033d7a5 --- /dev/null +++ b/Labaratory/Labaratory/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Labaratory/Labaratory/Rendered_Services.cs b/Labaratory/Labaratory/Rendered_Services.cs new file mode 100644 index 0000000..f8d36fc --- /dev/null +++ b/Labaratory/Labaratory/Rendered_Services.cs @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан по шаблону. +// +// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения. +// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода. +// +//------------------------------------------------------------------------------ + +namespace Labaratory +{ + using System; + using System.Collections.Generic; + + public partial class Rendered_Services + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + public Rendered_Services() + { + this.Analyzer_Logs = new HashSet(); + } + + public int ID_Rendered { get; set; } + public Nullable OrderItem { get; set; } + public Nullable Laborant { get; set; } + public Nullable Analyzer { get; set; } + public Nullable ExecutionDate { get; set; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Analyzer_Logs { get; set; } + public virtual Analyzer Analyzer1 { get; set; } + public virtual Order_Items Order_Items { get; set; } + public virtual User User { get; set; } + } +} diff --git a/Labaratory/Labaratory/Role.cs b/Labaratory/Labaratory/Role.cs new file mode 100644 index 0000000..3f7d315 --- /dev/null +++ b/Labaratory/Labaratory/Role.cs @@ -0,0 +1,29 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан по шаблону. +// +// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения. +// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода. +// +//------------------------------------------------------------------------------ + +namespace Labaratory +{ + using System; + using System.Collections.Generic; + + public partial class Role + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + public Role() + { + this.Users = new HashSet(); + } + + public int ID_Role { get; set; } + public string RoleName { get; set; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Users { get; set; } + } +} diff --git a/Labaratory/Labaratory/Service.cs b/Labaratory/Labaratory/Service.cs new file mode 100644 index 0000000..0fe68e5 --- /dev/null +++ b/Labaratory/Labaratory/Service.cs @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан по шаблону. +// +// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения. +// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода. +// +//------------------------------------------------------------------------------ + +namespace Labaratory +{ + using System; + using System.Collections.Generic; + + public partial class Service + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + public Service() + { + this.Order_Items = new HashSet(); + this.Users = new HashSet(); + } + + public int ID_Service { get; set; } + public string ServiceCode { get; set; } + public string ServiceName { get; set; } + public decimal Price { get; set; } + public Nullable ExecutionTime { get; set; } + public Nullable AverageDeviation { get; set; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Order_Items { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Users { get; set; } + } +} diff --git a/Labaratory/Labaratory/Service_Statuses.cs b/Labaratory/Labaratory/Service_Statuses.cs new file mode 100644 index 0000000..6fd5935 --- /dev/null +++ b/Labaratory/Labaratory/Service_Statuses.cs @@ -0,0 +1,29 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан по шаблону. +// +// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения. +// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода. +// +//------------------------------------------------------------------------------ + +namespace Labaratory +{ + using System; + using System.Collections.Generic; + + public partial class Service_Statuses + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + public Service_Statuses() + { + this.Order_Items = new HashSet(); + } + + public int ID_ServiceStatus { get; set; } + public string StatusName { get; set; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Order_Items { get; set; } + } +} diff --git a/Labaratory/Labaratory/SessionManager.cs b/Labaratory/Labaratory/SessionManager.cs new file mode 100644 index 0000000..4604573 --- /dev/null +++ b/Labaratory/Labaratory/SessionManager.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Labaratory +{ + public static class SessionManager + { + public static string CurrentRole { get; set; } + public static DateTime? BlockUntil { get; set; } + public static bool NeedsCaptcha { get; set; } + } +} diff --git a/Labaratory/Labaratory/User.cs b/Labaratory/Labaratory/User.cs new file mode 100644 index 0000000..100514d --- /dev/null +++ b/Labaratory/Labaratory/User.cs @@ -0,0 +1,43 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан по шаблону. +// +// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения. +// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода. +// +//------------------------------------------------------------------------------ + +namespace Labaratory +{ + using System; + using System.Collections.Generic; + + public partial class User + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + public User() + { + this.Invoices = new HashSet(); + this.Rendered_Services = new HashSet(); + this.Services = new HashSet(); + } + + public int ID_User { get; set; } + public Nullable Role { get; set; } + public string Surname { get; set; } + public string FirstName { get; set; } + public string Patronymic { get; set; } + public string Login { get; set; } + public string Password { get; set; } + public Nullable LastLogin { get; set; } + public string IP { get; set; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Invoices { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Rendered_Services { get; set; } + public virtual Role Role1 { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Services { get; set; } + } +} diff --git a/Labaratory/Labaratory/packages.config b/Labaratory/Labaratory/packages.config new file mode 100644 index 0000000..c99e7e3 --- /dev/null +++ b/Labaratory/Labaratory/packages.config @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file