diff --git a/PR14/.vs/PR14/v17/.suo b/PR14/.vs/PR14/v17/.suo
index 3080cac..78efb26 100644
Binary files a/PR14/.vs/PR14/v17/.suo and b/PR14/.vs/PR14/v17/.suo differ
diff --git a/PR14/.vs/PR14/v17/DocumentLayout.json b/PR14/.vs/PR14/v17/DocumentLayout.json
index 2ec0e4b..86a2369 100644
--- a/PR14/.vs/PR14/v17/DocumentLayout.json
+++ b/PR14/.vs/PR14/v17/DocumentLayout.json
@@ -9,6 +9,10 @@
{
"AbsoluteMoniker": "D:0:0:{68BE38C1-9A3E-4D01-81ED-9DC821B2AE98}|PR14\\PR14.csproj|C:\\Users\\usersql\\Source\\Repos\\MDK0101\\PR14\\pr14\\mainwindow.xaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{68BE38C1-9A3E-4D01-81ED-9DC821B2AE98}|PR14\\PR14.csproj|solutionrelative:pr14\\mainwindow.xaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
+ },
+ {
+ "AbsoluteMoniker": "D:0:0:{68BE38C1-9A3E-4D01-81ED-9DC821B2AE98}|PR14\\PR14.csproj|c:\\users\\usersql\\source\\repos\\mdk0101\\pr14\\pr14\\models\\model1.edmx||{C99AEA30-8E36-4515-B76F-496F5A48A6AA}|",
+ "RelativeMoniker": "D:0:0:{68BE38C1-9A3E-4D01-81ED-9DC821B2AE98}|PR14\\PR14.csproj|solutionrelative:pr14\\models\\model1.edmx||{C99AEA30-8E36-4515-B76F-496F5A48A6AA}|"
}
],
"DocumentGroupContainers": [
@@ -18,7 +22,7 @@
"DocumentGroups": [
{
"DockedWidth": 200,
- "SelectedChildIndex": 14,
+ "SelectedChildIndex": 16,
"Children": [
{
"$type": "Bookmark",
@@ -76,14 +80,30 @@
"$type": "Bookmark",
"Name": "ST:0:0:{aa2115a1-9712-457b-9047-dbb71ca2cdd2}"
},
+ {
+ "$type": "Bookmark",
+ "Name": "ST:0:0:{1c4feeaa-4718-4aa9-859d-94ce25d182ba}"
+ },
+ {
+ "$type": "Document",
+ "DocumentIndex": 2,
+ "Title": "Model1.edmx [Diagram1]",
+ "DocumentMoniker": "C:\\Users\\usersql\\Source\\Repos\\MDK0101\\PR14\\PR14\\Models\\Model1.edmx",
+ "RelativeDocumentMoniker": "PR14\\Models\\Model1.edmx",
+ "ToolTip": "C:\\Users\\usersql\\Source\\Repos\\MDK0101\\PR14\\PR14\\Models\\Model1.edmx [Diagram1]",
+ "RelativeToolTip": "PR14\\Models\\Model1.edmx [Diagram1]",
+ "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.001116|",
+ "WhenOpened": "2026-04-20T12:26:58.918Z",
+ "EditorCaption": " [Diagram1]"
+ },
{
"$type": "Document",
"DocumentIndex": 0,
"Title": "MainWindow.xaml",
"DocumentMoniker": "C:\\Users\\usersql\\Source\\Repos\\MDK0101\\PR14\\PR14\\MainWindow.xaml",
"RelativeDocumentMoniker": "PR14\\MainWindow.xaml",
- "ToolTip": "C:\\Users\\usersql\\Source\\Repos\\MDK0101\\PR14\\PR14\\MainWindow.xaml*",
- "RelativeToolTip": "PR14\\MainWindow.xaml*",
+ "ToolTip": "C:\\Users\\usersql\\Source\\Repos\\MDK0101\\PR14\\PR14\\MainWindow.xaml",
+ "RelativeToolTip": "PR14\\MainWindow.xaml",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.003549|",
"WhenOpened": "2026-04-20T10:44:32.389Z",
"EditorCaption": ""
@@ -94,8 +114,9 @@
"Title": "MainWindow.xaml.cs",
"DocumentMoniker": "C:\\Users\\usersql\\Source\\Repos\\MDK0101\\PR14\\PR14\\MainWindow.xaml.cs",
"RelativeDocumentMoniker": "PR14\\MainWindow.xaml.cs",
- "ToolTip": "C:\\Users\\usersql\\Source\\Repos\\MDK0101\\PR14\\PR14\\MainWindow.xaml.cs",
- "RelativeToolTip": "PR14\\MainWindow.xaml.cs",
+ "ToolTip": "C:\\Users\\usersql\\Source\\Repos\\MDK0101\\PR14\\PR14\\MainWindow.xaml.cs*",
+ "RelativeToolTip": "PR14\\MainWindow.xaml.cs*",
+ "ViewState": "AQIAAFQAAAAAAAAAAAAgwG0AAAANAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2026-04-20T10:44:31.757Z",
"EditorCaption": ""
diff --git a/PR14/PR14/App.config b/PR14/PR14/App.config
index 56efbc7..8b53a17 100644
--- a/PR14/PR14/App.config
+++ b/PR14/PR14/App.config
@@ -1,6 +1,18 @@
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/PR14/PR14/AppointmentWindow.xaml b/PR14/PR14/AppointmentWindow.xaml
new file mode 100644
index 0000000..d3f840c
--- /dev/null
+++ b/PR14/PR14/AppointmentWindow.xaml
@@ -0,0 +1,59 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/PR14/PR14/AppointmentWindow.xaml.cs b/PR14/PR14/AppointmentWindow.xaml.cs
new file mode 100644
index 0000000..d7c6477
--- /dev/null
+++ b/PR14/PR14/AppointmentWindow.xaml.cs
@@ -0,0 +1,99 @@
+using PR14.Models;
+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.Shapes;
+using static System.Data.Entity.Infrastructure.Design.Executor;
+
+namespace PR14
+{
+ ///
+ /// Логика взаимодействия для AppointmentWindow.xaml
+ ///
+ public partial class AppointmentWindow : Window
+ {
+ DBPR14Entities db = new DBPR14Entities();
+ Patient currentPatient;
+ public AppointmentWindow()
+ {
+ InitializeComponent();
+ }
+ public AppointmentWindow(Patient patient)
+ {
+ InitializeComponent();
+ currentPatient = patient;
+ tbPatientName.Text = $"{patient.middle_name} {patient.first_name[0]}.{patient.last_name[0]}.";
+
+ // Загружаем специальности в ComboBox
+ cbSpeciality.ItemsSource = db.Specialities.ToList();
+ }
+
+ // Фильтрация врачей при выборе специальности
+ private void cbSpeciality_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ if (cbSpeciality.SelectedItem is Speciality spec)
+ {
+ // Показываем только врачей этой специальности
+ cbDoctor.ItemsSource = db.Doctors.Where(d => d.speciality_id == spec.id).ToList();
+ }
+ }
+
+ private void BtnSaveAppointment_Click(object sender, RoutedEventArgs e)
+ {
+ try
+ {
+ var record = new Record // Ваша таблица записей
+ {
+ id_patient = currentPatient.id_patient,
+ id_doctor = (cbDoctor.SelectedItem as Doctor).id,
+ appointment_date = dpDate.SelectedDate.Value,
+ appointment_time = Convert.ToDateTime(cbTime.Text)
+ };
+
+ db.Records.Add(record);
+ db.SaveChanges();
+
+ MessageBox.Show("Запись успешно создана!");
+ this.Close(); // Возврат на главную форму
+ }
+ catch (Exception ex) { MessageBox.Show("Ошибка: " + ex.Message); }
+ }
+ private void BtnSave_Click(object sender, RoutedEventArgs e)
+ {
+ try
+ {
+ if (cbDoctor.SelectedItem == null || dpDate.SelectedDate == null || cbTime.SelectedItem == null)
+ {
+ throw new Exception("Заполните все поля записи!");
+ }
+
+ var newAppointment = new Record
+ {
+ id_patient = currentPatient.id_patient,
+ id_doctor = (cbDoctor.SelectedItem as Doctor).id_doctor,
+ appointment_date = dpDate.SelectedDate.Value,
+ appointment_time = TimeSpan.Parse(cbTime.Text)
+ };
+
+ db.Records.Add(newAppointment);
+ db.SaveChanges();
+
+ MessageBox.Show("Пациент успешно записан!");
+ this.Close();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Ошибка записи: " + ex.Message);
+ }
+ }
+ }
+}
diff --git a/PR14/PR14/MainWindow.xaml b/PR14/PR14/MainWindow.xaml
index 2ab3b79..52896c1 100644
--- a/PR14/PR14/MainWindow.xaml
+++ b/PR14/PR14/MainWindow.xaml
@@ -18,38 +18,45 @@
Text="Список пациентов:"
Margin="10,10,10,0"
/>
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
@@ -59,7 +66,7 @@
-
+
diff --git a/PR14/PR14/MainWindow.xaml.cs b/PR14/PR14/MainWindow.xaml.cs
index 914c1a3..a2251dc 100644
--- a/PR14/PR14/MainWindow.xaml.cs
+++ b/PR14/PR14/MainWindow.xaml.cs
@@ -1,4 +1,5 @@
-using System;
+using PR14.Models;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -20,9 +21,123 @@ namespace PR14
///
public partial class MainWindow : Window
{
+ DBPR14Entities db = new DBPR14Entities();
public MainWindow()
{
InitializeComponent();
+ LoadData();
+ }
+ private void BtnAdd_Click(object sender, RoutedEventArgs e)
+ {
+ try
+ {
+ if (string.IsNullOrWhiteSpace(tbSurname.Text) ||
+ string.IsNullOrWhiteSpace(tbName.Text) ||
+ string.IsNullOrWhiteSpace(tbAddress.Text) ||
+ dpBirthday.SelectedDate == null)
+ {
+ throw new Exception("Заполните все обязательные поля!");
+ }
+
+ if (dpBirthday.SelectedDate >= DateTime.Now)
+ {
+ throw new Exception("Дата рождения не может быть в будущем!");
+ }
+
+ string polis = tbPolis.Text.Trim();
+ if (polis.Length != 16 || !polis.All(char.IsDigit))
+ {
+ throw new Exception("Полис должен содержать 16 цифр!");
+ }
+
+ string phone = tbPhone.Text.Trim();
+ if (phone.Length != 11 || !phone.All(char.IsDigit))
+ {
+ throw new Exception("Номер телефона должен содержать 11 цифр!");
+ }
+
+ if (db.Patients.Any(p => p.policy_number == polis))
+ {
+ throw new Exception("Пациент с таким номером полиса уже существует в базе!");
+ }
+
+ if (db.Patients.Any(p => p.phone_number == phone))
+ {
+ throw new Exception("Пациент с таким номером телефона уже существует в базе!");
+ }
+ var newPatient = new Patient
+ {
+ middle_name = tbSurname.Text,
+ first_name = tbName.Text,
+ last_name = tbPatronymic.Text,
+ gender = rbMale.IsChecked == true ? "М" : "Ж",
+ birth_date = dpBirthday.SelectedDate.Value,
+ address = tbAddress.Text,
+ policy_number = polis,
+ phone_number = phone
+ };
+
+ db.Patients.Add(newPatient);
+ db.SaveChanges();
+
+ MessageBox.Show("Пациент успешно добавлен!");
+ LoadData();
+ }
+ catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
+ {
+ string fullError = "Ошибка валидации данных:\n";
+ foreach (var validationErrors in dbEx.EntityValidationErrors)
+ {
+ foreach (var validationError in validationErrors.ValidationErrors)
+ {
+ fullError += $"- Поле: {validationError.PropertyName}, Ошибка: {validationError.ErrorMessage}\n";
+ }
+ }
+ MessageBox.Show(fullError, "Ошибка модели");
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message);
+ }
+ }
+ private void LoadData()
+ {
+ lvPatients.ItemsSource = db.Patients.ToList();
+ }
+ private void lvPatients_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ if (lvPatients.SelectedItem is Patient selected)
+ {
+ tbSurname.Text = selected.middle_name;
+ tbName.Text = selected.first_name;
+ tbPatronymic.Text = selected.last_name;
+ dpBirthday.SelectedDate = selected.birth_date;
+ tbAddress.Text = selected.address;
+ tbPolis.Text = selected.policy_number;
+ tbPhone.Text = selected.phone_number;
+
+ if (selected.gender == "М") rbMale.IsChecked = true;
+ else rbFemale.IsChecked = true;
+
+ tbSurname.IsReadOnly = true;
+ tbName.IsReadOnly = true;
+ tbPatronymic.IsReadOnly = true;
+ tbPolis.IsReadOnly = true;
+ dpBirthday.IsEnabled = false;
+
+ tbAddress.IsReadOnly = false;
+ tbPhone.IsReadOnly = false;
+ }
+ }
+ private void BtnRecord_Click(object sender, RoutedEventArgs e)
+ {
+ if (lvPatients.SelectedItem is Patient selected)
+ {
+ // Передаем выбранного пациента в конструктор нового окна
+ AppointmentWindow appointWin = new AppointmentWindow(selected);
+ appointWin.ShowDialog();
+ }
+ else { MessageBox.Show("Выберите пациента!"); }
}
}
}
diff --git a/PR14/PR14/Models/Doctor.cs b/PR14/PR14/Models/Doctor.cs
new file mode 100644
index 0000000..6c6e893
--- /dev/null
+++ b/PR14/PR14/Models/Doctor.cs
@@ -0,0 +1,33 @@
+//------------------------------------------------------------------------------
+//
+// Этот код создан по шаблону.
+//
+// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения.
+// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода.
+//
+//------------------------------------------------------------------------------
+
+namespace PR14.Models
+{
+ using System;
+ using System.Collections.Generic;
+
+ public partial class Doctor
+ {
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
+ public Doctor()
+ {
+ this.Records = new HashSet();
+ }
+
+ public int id_doctor { get; set; }
+ public string last_name { get; set; }
+ public string first_name { get; set; }
+ public string middle_name { get; set; }
+ public int id_speciality { get; set; }
+
+ public virtual Speciality Speciality { get; set; }
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
+ public virtual ICollection Records { get; set; }
+ }
+}
diff --git a/PR14/PR14/Models/Model1.Context.cs b/PR14/PR14/Models/Model1.Context.cs
new file mode 100644
index 0000000..d82da38
--- /dev/null
+++ b/PR14/PR14/Models/Model1.Context.cs
@@ -0,0 +1,33 @@
+//------------------------------------------------------------------------------
+//
+// Этот код создан по шаблону.
+//
+// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения.
+// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода.
+//
+//------------------------------------------------------------------------------
+
+namespace PR14.Models
+{
+ using System;
+ using System.Data.Entity;
+ using System.Data.Entity.Infrastructure;
+
+ public partial class DBPR14Entities : DbContext
+ {
+ public DBPR14Entities()
+ : base("name=DBPR14Entities")
+ {
+ }
+
+ protected override void OnModelCreating(DbModelBuilder modelBuilder)
+ {
+ throw new UnintentionalCodeFirstException();
+ }
+
+ public virtual DbSet Doctors { get; set; }
+ public virtual DbSet Patients { get; set; }
+ public virtual DbSet Records { get; set; }
+ public virtual DbSet Specialities { get; set; }
+ }
+}
diff --git a/PR14/PR14/Models/Model1.Context.tt b/PR14/PR14/Models/Model1.Context.tt
new file mode 100644
index 0000000..7b8920f
--- /dev/null
+++ b/PR14/PR14/Models/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/PR14/PR14/Models/Model1.Designer.cs b/PR14/PR14/Models/Model1.Designer.cs
new file mode 100644
index 0000000..45205e5
--- /dev/null
+++ b/PR14/PR14/Models/Model1.Designer.cs
@@ -0,0 +1,10 @@
+// Создание кода T4 для модели "C:\Users\usersql\Source\Repos\MDK0101\PR14\PR14\Models\Model1.edmx" включено.
+// Чтобы включить формирование кода прежних версий, измените значение свойства "Стратегия создания кода" конструктора
+// на "Legacy ObjectContext". Это свойство доступно в окне "Свойства", если модель
+// открыта в конструкторе.
+
+// Если не сформированы контекст и классы сущности, возможная причина в том, что вы создали пустую модель, но
+// еще не выбрали версию Entity Framework для использования. Чтобы сформировать класс контекста и классы сущностей
+// для своей модели, откройте модель в конструкторе, щелкните правой кнопкой область конструктора и
+// выберите "Обновить модель из базы данных", "Сформировать базу данных из модели" или "Добавить элемент формирования
+// кода...".
\ No newline at end of file
diff --git a/PR14/PR14/Models/Model1.cs b/PR14/PR14/Models/Model1.cs
new file mode 100644
index 0000000..a8fe9a9
--- /dev/null
+++ b/PR14/PR14/Models/Model1.cs
@@ -0,0 +1,9 @@
+//------------------------------------------------------------------------------
+//
+// Этот код создан по шаблону.
+//
+// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения.
+// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода.
+//
+//------------------------------------------------------------------------------
+
diff --git a/PR14/PR14/Models/Model1.edmx b/PR14/PR14/Models/Model1.edmx
new file mode 100644
index 0000000..090d19c
--- /dev/null
+++ b/PR14/PR14/Models/Model1.edmx
@@ -0,0 +1,282 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/PR14/PR14/Models/Model1.edmx.diagram b/PR14/PR14/Models/Model1.edmx.diagram
new file mode 100644
index 0000000..42b0d4d
--- /dev/null
+++ b/PR14/PR14/Models/Model1.edmx.diagram
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/PR14/PR14/Models/Model1.tt b/PR14/PR14/Models/Model1.tt
new file mode 100644
index 0000000..b0e43c7
--- /dev/null
+++ b/PR14/PR14/Models/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/PR14/PR14/Models/Patient.cs b/PR14/PR14/Models/Patient.cs
new file mode 100644
index 0000000..8483f05
--- /dev/null
+++ b/PR14/PR14/Models/Patient.cs
@@ -0,0 +1,36 @@
+//------------------------------------------------------------------------------
+//
+// Этот код создан по шаблону.
+//
+// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения.
+// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода.
+//
+//------------------------------------------------------------------------------
+
+namespace PR14.Models
+{
+ using System;
+ using System.Collections.Generic;
+
+ public partial class Patient
+ {
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
+ public Patient()
+ {
+ this.Records = new HashSet();
+ }
+
+ public int id_patient { get; set; }
+ public string last_name { get; set; }
+ public string first_name { get; set; }
+ public string middle_name { get; set; }
+ public string gender { get; set; }
+ public Nullable birth_date { get; set; }
+ public string address { get; set; }
+ public string policy_number { get; set; }
+ public string phone_number { get; set; }
+
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
+ public virtual ICollection Records { get; set; }
+ }
+}
diff --git a/PR14/PR14/Models/Record.cs b/PR14/PR14/Models/Record.cs
new file mode 100644
index 0000000..8da60b1
--- /dev/null
+++ b/PR14/PR14/Models/Record.cs
@@ -0,0 +1,26 @@
+//------------------------------------------------------------------------------
+//
+// Этот код создан по шаблону.
+//
+// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения.
+// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода.
+//
+//------------------------------------------------------------------------------
+
+namespace PR14.Models
+{
+ using System;
+ using System.Collections.Generic;
+
+ public partial class Record
+ {
+ public int id_appointment { get; set; }
+ public int id_patient { get; set; }
+ public int id_doctor { get; set; }
+ public System.DateTime appointment_date { get; set; }
+ public System.TimeSpan appointment_time { get; set; }
+
+ public virtual Doctor Doctor { get; set; }
+ public virtual Patient Patient { get; set; }
+ }
+}
diff --git a/PR14/PR14/Models/Speciality.cs b/PR14/PR14/Models/Speciality.cs
new file mode 100644
index 0000000..1130f7e
--- /dev/null
+++ b/PR14/PR14/Models/Speciality.cs
@@ -0,0 +1,29 @@
+//------------------------------------------------------------------------------
+//
+// Этот код создан по шаблону.
+//
+// Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения.
+// Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода.
+//
+//------------------------------------------------------------------------------
+
+namespace PR14.Models
+{
+ using System;
+ using System.Collections.Generic;
+
+ public partial class Speciality
+ {
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
+ public Speciality()
+ {
+ this.Doctors = new HashSet();
+ }
+
+ public int id_speciality { get; set; }
+ public string name_speciality { get; set; }
+
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
+ public virtual ICollection Doctors { get; set; }
+ }
+}
diff --git a/PR14/PR14/PR14.csproj b/PR14/PR14/PR14.csproj
index 8cba9b0..dcb3175 100644
--- a/PR14/PR14/PR14.csproj
+++ b/PR14/PR14/PR14.csproj
@@ -1,5 +1,6 @@
+
Debug
@@ -14,6 +15,8 @@
4
true
true
+
+
AnyCPU
@@ -35,8 +38,17 @@
4
+
+ ..\packages\EntityFramework.6.5.1\lib\net45\EntityFramework.dll
+
+
+ ..\packages\EntityFramework.6.5.1\lib\net45\EntityFramework.SqlServer.dll
+
+
+
+
@@ -70,6 +82,10 @@
MSBuild:Compile
Designer
+
+ Designer
+ MSBuild:Compile
+
MSBuild:Compile
Designer
@@ -78,12 +94,42 @@
App.xaml
Code
+
+ AppointmentWindow.xaml
+
MainWindow.xaml
Code
+
+ Model1.tt
+
+
+ True
+ True
+ Model1.Context.tt
+
+
+ True
+ True
+ Model1.tt
+
+
+ True
+ True
+ Model1.edmx
+
+
+ Model1.tt
+
+
+ Model1.tt
+
+
+ Model1.tt
+
Code
@@ -101,6 +147,13 @@
ResXFileCodeGenerator
Resources.Designer.cs
+
+ EntityModelCodeGenerator
+ Model1.Designer.cs
+
+
+ Model1.edmx
+
SettingsSingleFileGenerator
@@ -110,5 +163,29 @@
+
+
+
+ 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/PR14/PR14/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/PR14/PR14/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
index f3b8abb..1b50774 100644
Binary files a/PR14/PR14/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/PR14/PR14/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ
diff --git a/PR14/PR14/obj/Debug/MainWindow.g.cs b/PR14/PR14/obj/Debug/MainWindow.g.cs
index 6db6f65..ad8c6a9 100644
--- a/PR14/PR14/obj/Debug/MainWindow.g.cs
+++ b/PR14/PR14/obj/Debug/MainWindow.g.cs
@@ -1,4 +1,4 @@
-#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "F9FCE631641E7289F19E694FBE5CD8539BF472CDAFF29FED1E7329E99B4BF64A"
+#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "0C7DAB16E7F78393B4927CAAE8AFA28B449B4DC4D4F03AC006B0BB730D29D630"
//------------------------------------------------------------------------------
//
// Этот код создан программой.
@@ -40,6 +40,86 @@ namespace PR14 {
///
public partial class MainWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector {
+
+ #line 21 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.ListView lvPatients;
+
+ #line default
+ #line hidden
+
+
+ #line 35 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.TextBox tbSurname;
+
+ #line default
+ #line hidden
+
+
+ #line 38 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.TextBox tbName;
+
+ #line default
+ #line hidden
+
+
+ #line 41 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.TextBox tbPatronymic;
+
+ #line default
+ #line hidden
+
+
+ #line 45 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.RadioButton rbMale;
+
+ #line default
+ #line hidden
+
+
+ #line 46 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.RadioButton rbFemale;
+
+ #line default
+ #line hidden
+
+
+ #line 50 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.DatePicker dpBirthday;
+
+ #line default
+ #line hidden
+
+
+ #line 53 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.TextBox tbAddress;
+
+ #line default
+ #line hidden
+
+
+ #line 56 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.TextBox tbPolis;
+
+ #line default
+ #line hidden
+
+
+ #line 59 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.TextBox tbPhone;
+
+ #line default
+ #line hidden
+
private bool _contentLoaded;
///
@@ -68,6 +148,53 @@ namespace PR14 {
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
+ switch (connectionId)
+ {
+ case 1:
+ this.lvPatients = ((System.Windows.Controls.ListView)(target));
+
+ #line 21 "..\..\MainWindow.xaml"
+ this.lvPatients.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.lvPatients_SelectionChanged);
+
+ #line default
+ #line hidden
+ return;
+ case 2:
+ this.tbSurname = ((System.Windows.Controls.TextBox)(target));
+ return;
+ case 3:
+ this.tbName = ((System.Windows.Controls.TextBox)(target));
+ return;
+ case 4:
+ this.tbPatronymic = ((System.Windows.Controls.TextBox)(target));
+ return;
+ case 5:
+ this.rbMale = ((System.Windows.Controls.RadioButton)(target));
+ return;
+ case 6:
+ this.rbFemale = ((System.Windows.Controls.RadioButton)(target));
+ return;
+ case 7:
+ this.dpBirthday = ((System.Windows.Controls.DatePicker)(target));
+ return;
+ case 8:
+ this.tbAddress = ((System.Windows.Controls.TextBox)(target));
+ return;
+ case 9:
+ this.tbPolis = ((System.Windows.Controls.TextBox)(target));
+ return;
+ case 10:
+ this.tbPhone = ((System.Windows.Controls.TextBox)(target));
+ return;
+ case 11:
+
+ #line 69 "..\..\MainWindow.xaml"
+ ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.BtnAdd_Click);
+
+ #line default
+ #line hidden
+ return;
+ }
this._contentLoaded = true;
}
}
diff --git a/PR14/PR14/obj/Debug/MainWindow.g.i.cs b/PR14/PR14/obj/Debug/MainWindow.g.i.cs
index 9f5cba8..ad8c6a9 100644
--- a/PR14/PR14/obj/Debug/MainWindow.g.i.cs
+++ b/PR14/PR14/obj/Debug/MainWindow.g.i.cs
@@ -1,5 +1,4 @@
-// Updated by XamlIntelliSenseFileGenerator 20.04.2026 16:57:45
-#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "F9FCE631641E7289F19E694FBE5CD8539BF472CDAFF29FED1E7329E99B4BF64A"
+#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "0C7DAB16E7F78393B4927CAAE8AFA28B449B4DC4D4F03AC006B0BB730D29D630"
//------------------------------------------------------------------------------
//
// Этот код создан программой.
@@ -33,57 +32,171 @@ using System.Windows.Shapes;
using System.Windows.Shell;
-namespace PR14
-{
-
-
+namespace PR14 {
+
+
///
/// MainWindow
///
- public partial class MainWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector
- {
-
+ public partial class MainWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector {
+
+
+ #line 21 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.ListView lvPatients;
+
+ #line default
+ #line hidden
+
+
+ #line 35 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.TextBox tbSurname;
+
+ #line default
+ #line hidden
+
+
+ #line 38 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.TextBox tbName;
+
+ #line default
+ #line hidden
+
+
+ #line 41 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.TextBox tbPatronymic;
+
+ #line default
+ #line hidden
+
+
+ #line 45 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.RadioButton rbMale;
+
+ #line default
+ #line hidden
+
+
+ #line 46 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.RadioButton rbFemale;
+
+ #line default
+ #line hidden
+
+
+ #line 50 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.DatePicker dpBirthday;
+
+ #line default
+ #line hidden
+
+
+ #line 53 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.TextBox tbAddress;
+
+ #line default
+ #line hidden
+
+
+ #line 56 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.TextBox tbPolis;
+
+ #line default
+ #line hidden
+
+
+ #line 59 "..\..\MainWindow.xaml"
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+ internal System.Windows.Controls.TextBox tbPhone;
+
+ #line default
+ #line hidden
+
private bool _contentLoaded;
-
+
///
/// InitializeComponent
///
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
- public void InitializeComponent()
- {
- if (_contentLoaded)
- {
+ public void InitializeComponent() {
+ if (_contentLoaded) {
return;
}
_contentLoaded = true;
System.Uri resourceLocater = new System.Uri("/PR14;component/mainwindow.xaml", System.UriKind.Relative);
-
-#line 1 "..\..\MainWindow.xaml"
+
+ #line 1 "..\..\MainWindow.xaml"
System.Windows.Application.LoadComponent(this, resourceLocater);
-
-#line default
-#line hidden
+
+ #line default
+ #line hidden
}
-
+
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
- void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
- {
+ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
+ switch (connectionId)
+ {
+ case 1:
+ this.lvPatients = ((System.Windows.Controls.ListView)(target));
+
+ #line 21 "..\..\MainWindow.xaml"
+ this.lvPatients.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.lvPatients_SelectionChanged);
+
+ #line default
+ #line hidden
+ return;
+ case 2:
+ this.tbSurname = ((System.Windows.Controls.TextBox)(target));
+ return;
+ case 3:
+ this.tbName = ((System.Windows.Controls.TextBox)(target));
+ return;
+ case 4:
+ this.tbPatronymic = ((System.Windows.Controls.TextBox)(target));
+ return;
+ case 5:
+ this.rbMale = ((System.Windows.Controls.RadioButton)(target));
+ return;
+ case 6:
+ this.rbFemale = ((System.Windows.Controls.RadioButton)(target));
+ return;
+ case 7:
+ this.dpBirthday = ((System.Windows.Controls.DatePicker)(target));
+ return;
+ case 8:
+ this.tbAddress = ((System.Windows.Controls.TextBox)(target));
+ return;
+ case 9:
+ this.tbPolis = ((System.Windows.Controls.TextBox)(target));
+ return;
+ case 10:
+ this.tbPhone = ((System.Windows.Controls.TextBox)(target));
+ return;
+ case 11:
+
+ #line 69 "..\..\MainWindow.xaml"
+ ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.BtnAdd_Click);
+
+ #line default
+ #line hidden
+ return;
+ }
this._contentLoaded = true;
}
-
- internal System.Windows.Controls.DatePicker dpBirthday;
- internal System.Windows.Controls.TextBlock tbSurname;
- internal System.Windows.Controls.TextBlock tbName;
- internal System.Windows.Controls.TextBlock tbPatronymic;
- internal System.Windows.Controls.TextBlock tbAdress;
- internal System.Windows.Controls.TextBlock tbPolis;
- internal System.Windows.Controls.TextBlock tbPhone;
}
}
diff --git a/PR14/PR14/obj/Debug/PR14.csproj.AssemblyReference.cache b/PR14/PR14/obj/Debug/PR14.csproj.AssemblyReference.cache
index f243590..c00041c 100644
Binary files a/PR14/PR14/obj/Debug/PR14.csproj.AssemblyReference.cache and b/PR14/PR14/obj/Debug/PR14.csproj.AssemblyReference.cache differ
diff --git a/PR14/PR14/obj/Debug/PR14_MarkupCompile.cache b/PR14/PR14/obj/Debug/PR14_MarkupCompile.cache
index 6b31404..de3cfd3 100644
--- a/PR14/PR14/obj/Debug/PR14_MarkupCompile.cache
+++ b/PR14/PR14/obj/Debug/PR14_MarkupCompile.cache
@@ -11,9 +11,9 @@ false
DEBUG;TRACE
C:\Users\usersql\Source\Repos\MDK0101\PR14\PR14\App.xaml
1219584333
-
-51579654133
-18790512828
+2-1223955081
+12-8670233
+23-924788474
MainWindow.xaml;
False
diff --git a/PR14/PR14/packages.config b/PR14/PR14/packages.config
index c999a65..2fef370 100644
--- a/PR14/PR14/packages.config
+++ b/PR14/PR14/packages.config
@@ -1,4 +1,6 @@
+
+
\ No newline at end of file