From fcc6256535c423f48506ffb2a057a3d8f2cd37ff Mon Sep 17 00:00:00 2001 From: syneffort Date: Tue, 19 Jul 2022 01:45:59 +0900 Subject: [PATCH] entity framework base setting --- TinyPOS/DbGen/App.config | 6 ++ TinyPOS/DbGen/DbGen.csproj | 52 +++++++++++++ TinyPOS/DbGen/Program.cs | 15 ++++ TinyPOS/DbGen/Properties/AssemblyInfo.cs | 36 +++++++++ TinyPOS/TinyPOS.sln | 19 ++++- TinyPOS/TinyPosDBGen/App.config | 15 ++++ TinyPOS/TinyPosDBGen/Program.cs | 38 +++++++++ .../TinyPosDBGen/Properties/AssemblyInfo.cs | 36 +++++++++ TinyPOS/TinyPosDBGen/TinyPosDBGen.csproj | 77 +++++++++++++++++++ TinyPOS/TinyPosDBGen/packages.config | 4 + TinyPOS/TinyPosEntity/App.config | 12 +++ TinyPOS/TinyPosEntity/EntityContext.cs | 30 ++++++++ TinyPOS/TinyPosEntity/EntityController.cs | 75 ++++++++++++++++++ .../TinyPosEntity/Properties/AssemblyInfo.cs | 36 +++++++++ TinyPOS/TinyPosEntity/Standard.cs | 16 ++++ TinyPOS/TinyPosEntity/Student.cs | 20 +++++ TinyPOS/TinyPosEntity/TinyPosEntity.csproj | 73 ++++++++++++++++++ TinyPOS/TinyPosEntity/packages.config | 4 + 18 files changed, 562 insertions(+), 2 deletions(-) create mode 100644 TinyPOS/DbGen/App.config create mode 100644 TinyPOS/DbGen/DbGen.csproj create mode 100644 TinyPOS/DbGen/Program.cs create mode 100644 TinyPOS/DbGen/Properties/AssemblyInfo.cs create mode 100644 TinyPOS/TinyPosDBGen/App.config create mode 100644 TinyPOS/TinyPosDBGen/Program.cs create mode 100644 TinyPOS/TinyPosDBGen/Properties/AssemblyInfo.cs create mode 100644 TinyPOS/TinyPosDBGen/TinyPosDBGen.csproj create mode 100644 TinyPOS/TinyPosDBGen/packages.config create mode 100644 TinyPOS/TinyPosEntity/App.config create mode 100644 TinyPOS/TinyPosEntity/EntityContext.cs create mode 100644 TinyPOS/TinyPosEntity/EntityController.cs create mode 100644 TinyPOS/TinyPosEntity/Properties/AssemblyInfo.cs create mode 100644 TinyPOS/TinyPosEntity/Standard.cs create mode 100644 TinyPOS/TinyPosEntity/Student.cs create mode 100644 TinyPOS/TinyPosEntity/TinyPosEntity.csproj create mode 100644 TinyPOS/TinyPosEntity/packages.config diff --git a/TinyPOS/DbGen/App.config b/TinyPOS/DbGen/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/TinyPOS/DbGen/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/TinyPOS/DbGen/DbGen.csproj b/TinyPOS/DbGen/DbGen.csproj new file mode 100644 index 0000000..df3ab26 --- /dev/null +++ b/TinyPOS/DbGen/DbGen.csproj @@ -0,0 +1,52 @@ + + + + + Debug + AnyCPU + {7947D982-5B7F-4ED1-A55A-0F67B69C3790} + Exe + DbGen + DbGen + v4.5 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TinyPOS/DbGen/Program.cs b/TinyPOS/DbGen/Program.cs new file mode 100644 index 0000000..5c4a054 --- /dev/null +++ b/TinyPOS/DbGen/Program.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DbGen +{ + class Program + { + static void Main(string[] args) + { + } + } +} diff --git a/TinyPOS/DbGen/Properties/AssemblyInfo.cs b/TinyPOS/DbGen/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..51e93bf --- /dev/null +++ b/TinyPOS/DbGen/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("DbGen")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("DbGen")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("7947d982-5b7f-4ed1-a55a-0f67b69c3790")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를 +// 기본값으로 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TinyPOS/TinyPOS.sln b/TinyPOS/TinyPOS.sln index 4e980bb..948627e 100644 --- a/TinyPOS/TinyPOS.sln +++ b/TinyPOS/TinyPOS.sln @@ -1,10 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.32510.428 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TinyPOS", "TinyPOS\TinyPOS.csproj", "{90A68652-78DF-44D2-8ED4-308BB2117A6B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TinyPosDBGen", "TinyPosDBGen\TinyPosDBGen.csproj", "{18503F9B-7E99-4851-A03B-7EB2CA85C324}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TinyPosEntity", "TinyPosEntity\TinyPosEntity.csproj", "{90DDC5FF-216C-4C46-8BC6-D8DDAB4442B3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,8 +19,19 @@ Global {90A68652-78DF-44D2-8ED4-308BB2117A6B}.Debug|Any CPU.Build.0 = Debug|Any CPU {90A68652-78DF-44D2-8ED4-308BB2117A6B}.Release|Any CPU.ActiveCfg = Release|Any CPU {90A68652-78DF-44D2-8ED4-308BB2117A6B}.Release|Any CPU.Build.0 = Release|Any CPU + {18503F9B-7E99-4851-A03B-7EB2CA85C324}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {18503F9B-7E99-4851-A03B-7EB2CA85C324}.Debug|Any CPU.Build.0 = Debug|Any CPU + {18503F9B-7E99-4851-A03B-7EB2CA85C324}.Release|Any CPU.ActiveCfg = Release|Any CPU + {18503F9B-7E99-4851-A03B-7EB2CA85C324}.Release|Any CPU.Build.0 = Release|Any CPU + {90DDC5FF-216C-4C46-8BC6-D8DDAB4442B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {90DDC5FF-216C-4C46-8BC6-D8DDAB4442B3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {90DDC5FF-216C-4C46-8BC6-D8DDAB4442B3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {90DDC5FF-216C-4C46-8BC6-D8DDAB4442B3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {99A6E94A-8DC5-4CFB-B197-A53FBC71CDBF} + EndGlobalSection EndGlobal diff --git a/TinyPOS/TinyPosDBGen/App.config b/TinyPOS/TinyPosDBGen/App.config new file mode 100644 index 0000000..83020bf --- /dev/null +++ b/TinyPOS/TinyPosDBGen/App.config @@ -0,0 +1,15 @@ + + + + +
+ + + + + + + + + + \ No newline at end of file diff --git a/TinyPOS/TinyPosDBGen/Program.cs b/TinyPOS/TinyPosDBGen/Program.cs new file mode 100644 index 0000000..8e6512d --- /dev/null +++ b/TinyPOS/TinyPosDBGen/Program.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Data.SqlClient; +using TinyPosEntity; + +namespace TinyPosDBGen +{ + class Program + { + static string connString = "data source=localhost;initial catalog=SchoolDBDB;user id=sa;password=92070983;"; + + static void Main(string[] args) + { + EntityController.ConnectionString = connString; + EntityController.GetInstance().Initialize(); + + Student student = new Student() + { + StudentName = "테스트용", + Height = 180 + }; + + //EntityController.GetInstance().AddStudent(student); + + List students = EntityController.GetInstance().FindStudent("테스트용"); + if (students.Count > 0) + { + foreach (Student item in students) + { + EntityController.GetInstance().RemoveStudent(student); + } + } + } + } +} diff --git a/TinyPOS/TinyPosDBGen/Properties/AssemblyInfo.cs b/TinyPOS/TinyPosDBGen/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..65cab12 --- /dev/null +++ b/TinyPOS/TinyPosDBGen/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("TinyPosDBGen")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TinyPosDBGen")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("18503f9b-7e99-4851-a03b-7eb2ca85c324")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를 +// 기본값으로 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TinyPOS/TinyPosDBGen/TinyPosDBGen.csproj b/TinyPOS/TinyPosDBGen/TinyPosDBGen.csproj new file mode 100644 index 0000000..34a7d66 --- /dev/null +++ b/TinyPOS/TinyPosDBGen/TinyPosDBGen.csproj @@ -0,0 +1,77 @@ + + + + + + Debug + AnyCPU + {18503F9B-7E99-4851-A03B-7EB2CA85C324} + Exe + TinyPosDBGen + TinyPosDBGen + v4.5 + 512 + true + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll + + + ..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll + + + + + + + + + + + + + + + + + + + + + + {90ddc5ff-216c-4c46-8bc6-d8ddab4442b3} + TinyPosEntity + + + + + + 이 프로젝트는 이 컴퓨터에 없는 NuGet 패키지를 참조합니다. 해당 패키지를 다운로드하려면 NuGet 패키지 복원을 사용하십시오. 자세한 내용은 http://go.microsoft.com/fwlink/?LinkID=322105를 참조하십시오. 누락된 파일은 {0}입니다. + + + + + + \ No newline at end of file diff --git a/TinyPOS/TinyPosDBGen/packages.config b/TinyPOS/TinyPosDBGen/packages.config new file mode 100644 index 0000000..3d8e5d3 --- /dev/null +++ b/TinyPOS/TinyPosDBGen/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/TinyPOS/TinyPosEntity/App.config b/TinyPOS/TinyPosEntity/App.config new file mode 100644 index 0000000..2af6916 --- /dev/null +++ b/TinyPOS/TinyPosEntity/App.config @@ -0,0 +1,12 @@ + + + + +
+ + + + + + + \ No newline at end of file diff --git a/TinyPOS/TinyPosEntity/EntityContext.cs b/TinyPOS/TinyPosEntity/EntityContext.cs new file mode 100644 index 0000000..22e81e4 --- /dev/null +++ b/TinyPOS/TinyPosEntity/EntityContext.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Data.Entity; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TinyPosEntity +{ + public class EntityContext : DbContext + { + public static string ConnectionString { get; set; } + + public EntityContext() : base(ConnectionString) + { + + } + + public DbSet Students { get; set; } + public DbSet Standards { get; set; } + } + + public class EntityInitializer : DropCreateDatabaseIfModelChanges + { + protected override void Seed(EntityContext context) + { + base.Seed(context); + } + } +} diff --git a/TinyPOS/TinyPosEntity/EntityController.cs b/TinyPOS/TinyPosEntity/EntityController.cs new file mode 100644 index 0000000..7aa76f3 --- /dev/null +++ b/TinyPOS/TinyPosEntity/EntityController.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Data.Entity; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TinyPosEntity +{ + public class EntityController + { + public static string ConnectionString { get; set; } + + private static EntityController instance; + + private EntityController(string connectionString) + { + EntityContext.ConnectionString = connectionString; + } + + public static EntityController GetInstance() + { + if (string.IsNullOrEmpty(ConnectionString)) + throw new Exception("ConnectionString 값이 필요합니다."); + + if (instance == null) + instance = new EntityController(ConnectionString); + + return instance; + } + + public void Initialize() + { + Database.SetInitializer(new EntityInitializer()); + + using (EntityContext context = new EntityContext()) + { + context.Database.CreateIfNotExists(); + } + } + + public void AddStudent(Student student) + { + using (EntityContext context = new EntityContext()) + { + context.Students.Add(student); + context.SaveChanges(); + } + } + + public List FindStudent(string name) + { + List result = null; + using (EntityContext context = new EntityContext()) + { + var student = from s in context.Students + where s.StudentName.Equals(name) + select s; + + if (student.Count() > 0) + result = student.ToList(); + } + + return result; + } + + public void RemoveStudent(Student student) + { + using (EntityContext context = new EntityContext()) + { + context.Database.ExecuteSqlCommand("DELETE FROM dbo.Students WHERE StudentName = {0}", student.StudentName); + } + } + } +} diff --git a/TinyPOS/TinyPosEntity/Properties/AssemblyInfo.cs b/TinyPOS/TinyPosEntity/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..aff9cfc --- /dev/null +++ b/TinyPOS/TinyPosEntity/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("TinyPosEntity")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TinyPosEntity")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("90ddc5ff-216c-4c46-8bc6-d8ddab4442b3")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를 +// 기본값으로 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TinyPOS/TinyPosEntity/Standard.cs b/TinyPOS/TinyPosEntity/Standard.cs new file mode 100644 index 0000000..cc66afe --- /dev/null +++ b/TinyPOS/TinyPosEntity/Standard.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TinyPosEntity +{ + public class Standard + { + public int StandardId { get; set; } + public string StandardName { get; set; } + + public List Students { get; set; } + } +} diff --git a/TinyPOS/TinyPosEntity/Student.cs b/TinyPOS/TinyPosEntity/Student.cs new file mode 100644 index 0000000..bb51cce --- /dev/null +++ b/TinyPOS/TinyPosEntity/Student.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TinyPosEntity +{ + public class Student + { + public int StudentId { get; set; } + public string StudentName { get; set; } + public DateTime? DateOfBirth { get; set; } + public byte[] Photo { get; set; } + public float Height { get; set; } + public float Weight { get; set; } + + public Standard Standard { get; set; } + } +} diff --git a/TinyPOS/TinyPosEntity/TinyPosEntity.csproj b/TinyPOS/TinyPosEntity/TinyPosEntity.csproj new file mode 100644 index 0000000..fa9f9ef --- /dev/null +++ b/TinyPOS/TinyPosEntity/TinyPosEntity.csproj @@ -0,0 +1,73 @@ + + + + + + Debug + AnyCPU + {90DDC5FF-216C-4C46-8BC6-D8DDAB4442B3} + Library + Properties + TinyPosEntity + TinyPosEntity + v4.5 + 512 + true + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll + + + ..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll + + + + + + + + + + + + + + + + + + + + + + + + + + 이 프로젝트는 이 컴퓨터에 없는 NuGet 패키지를 참조합니다. 해당 패키지를 다운로드하려면 NuGet 패키지 복원을 사용하십시오. 자세한 내용은 http://go.microsoft.com/fwlink/?LinkID=322105를 참조하십시오. 누락된 파일은 {0}입니다. + + + + + + \ No newline at end of file diff --git a/TinyPOS/TinyPosEntity/packages.config b/TinyPOS/TinyPosEntity/packages.config new file mode 100644 index 0000000..3d8e5d3 --- /dev/null +++ b/TinyPOS/TinyPosEntity/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file