개정판 8164f84e
issue #0000
- controller 추가
- db연결 테스트
- repository 샘플 추가
Change-Id: Ib25b053bd779d2e1f874e87284b47e071c8ff485
ID2.Manager/ID2.Manager.Controller/Controllers/BaseController.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 | ||
7 |
using System.Configuration; |
|
8 | ||
9 |
namespace ID2.Manager.Controller.Controllers |
|
10 |
{ |
|
11 |
public class BaseController |
|
12 |
{ |
|
13 |
public string _DbConnectionStr = string.Empty; |
|
14 | ||
15 |
public BaseController() |
|
16 |
{ |
|
17 |
this._DbConnectionStr = ConfigurationManager.ConnectionStrings["ID2Manager"].ToString(); |
|
18 |
} |
|
19 |
} |
|
20 |
} |
ID2.Manager/ID2.Manager.Controller/Controllers/UserController.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 | ||
7 |
using ID2.Manager.Data.Models; |
|
8 |
using ID2.Manager.Dapper.Repository; |
|
9 | ||
10 |
namespace ID2.Manager.Controller.Controllers |
|
11 |
{ |
|
12 |
public class UserController : BaseController |
|
13 |
{ |
|
14 |
public UserInfo GetUserInfo(string userId, string userPW) |
|
15 |
{ |
|
16 |
using (UserRepository rep = new UserRepository(this._DbConnectionStr)) |
|
17 |
{ |
|
18 |
return rep.GetUserInfo(userId, userPW); |
|
19 |
} |
|
20 |
} |
|
21 |
} |
|
22 |
} |
ID2.Manager/ID2.Manager.Controller/ID2.Manager.Controller.csproj | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|
3 |
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
|
4 |
<PropertyGroup> |
|
5 |
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|
6 |
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|
7 |
<ProjectGuid>{83DACC10-43B1-4E38-ABEF-E5EF9492A82D}</ProjectGuid> |
|
8 |
<OutputType>Library</OutputType> |
|
9 |
<AppDesignerFolder>Properties</AppDesignerFolder> |
|
10 |
<RootNamespace>ID2.Manager.Controller</RootNamespace> |
|
11 |
<AssemblyName>ID2.Manager.Controller</AssemblyName> |
|
12 |
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion> |
|
13 |
<FileAlignment>512</FileAlignment> |
|
14 |
<Deterministic>true</Deterministic> |
|
15 |
</PropertyGroup> |
|
16 |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|
17 |
<DebugSymbols>true</DebugSymbols> |
|
18 |
<DebugType>full</DebugType> |
|
19 |
<Optimize>false</Optimize> |
|
20 |
<OutputPath>bin\Debug\</OutputPath> |
|
21 |
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|
22 |
<ErrorReport>prompt</ErrorReport> |
|
23 |
<WarningLevel>4</WarningLevel> |
|
24 |
</PropertyGroup> |
|
25 |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|
26 |
<DebugType>pdbonly</DebugType> |
|
27 |
<Optimize>true</Optimize> |
|
28 |
<OutputPath>bin\Release\</OutputPath> |
|
29 |
<DefineConstants>TRACE</DefineConstants> |
|
30 |
<ErrorReport>prompt</ErrorReport> |
|
31 |
<WarningLevel>4</WarningLevel> |
|
32 |
</PropertyGroup> |
|
33 |
<ItemGroup> |
|
34 |
<Reference Include="System" /> |
|
35 |
<Reference Include="System.Configuration" /> |
|
36 |
<Reference Include="System.Core" /> |
|
37 |
<Reference Include="System.Xml.Linq" /> |
|
38 |
<Reference Include="System.Data.DataSetExtensions" /> |
|
39 |
<Reference Include="Microsoft.CSharp" /> |
|
40 |
<Reference Include="System.Data" /> |
|
41 |
<Reference Include="System.Net.Http" /> |
|
42 |
<Reference Include="System.Xml" /> |
|
43 |
</ItemGroup> |
|
44 |
<ItemGroup> |
|
45 |
<Compile Include="Controllers\BaseController.cs" /> |
|
46 |
<Compile Include="Controllers\UserController.cs" /> |
|
47 |
<Compile Include="Properties\AssemblyInfo.cs" /> |
|
48 |
</ItemGroup> |
|
49 |
<ItemGroup> |
|
50 |
<ProjectReference Include="..\ID2.Manager.Dapper\ID2.Manager.Dapper.csproj"> |
|
51 |
<Project>{6d22aaa8-d584-43f4-b71c-b32c5c9288ed}</Project> |
|
52 |
<Name>ID2.Manager.Dapper</Name> |
|
53 |
</ProjectReference> |
|
54 |
<ProjectReference Include="..\ID2.Manager.Data\ID2.Manager.Data.csproj"> |
|
55 |
<Project>{b17c0800-40f4-40e2-b5a6-d366d9c2e0f6}</Project> |
|
56 |
<Name>ID2.Manager.Data</Name> |
|
57 |
</ProjectReference> |
|
58 |
</ItemGroup> |
|
59 |
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
|
60 |
</Project> |
ID2.Manager/ID2.Manager.Controller/Properties/AssemblyInfo.cs | ||
---|---|---|
1 |
using System.Reflection; |
|
2 |
using System.Runtime.CompilerServices; |
|
3 |
using System.Runtime.InteropServices; |
|
4 | ||
5 |
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 |
|
6 |
// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 |
|
7 |
// 이러한 특성 값을 변경하세요. |
|
8 |
[assembly: AssemblyTitle("ID2.Manager.Controller")] |
|
9 |
[assembly: AssemblyDescription("")] |
|
10 |
[assembly: AssemblyConfiguration("")] |
|
11 |
[assembly: AssemblyCompany("")] |
|
12 |
[assembly: AssemblyProduct("ID2.Manager.Controller")] |
|
13 |
[assembly: AssemblyCopyright("Copyright © 2023")] |
|
14 |
[assembly: AssemblyTrademark("")] |
|
15 |
[assembly: AssemblyCulture("")] |
|
16 | ||
17 |
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 |
|
18 |
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 |
|
19 |
// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. |
|
20 |
[assembly: ComVisible(false)] |
|
21 | ||
22 |
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. |
|
23 |
[assembly: Guid("83dacc10-43b1-4e38-abef-e5ef9492a82d")] |
|
24 | ||
25 |
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. |
|
26 |
// |
|
27 |
// 주 버전 |
|
28 |
// 부 버전 |
|
29 |
// 빌드 번호 |
|
30 |
// 수정 버전 |
|
31 |
// |
|
32 |
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를 |
|
33 |
// 기본값으로 할 수 있습니다. |
|
34 |
// [assembly: AssemblyVersion("1.0.*")] |
|
35 |
[assembly: AssemblyVersion("1.0.0.0")] |
|
36 |
[assembly: AssemblyFileVersion("1.0.0.0")] |
ID2.Manager/ID2.Manager.Dapper/IBaseRepository.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 | ||
7 |
using System.Data.SqlClient; |
|
8 | ||
9 |
namespace ID2.Manager.Dapper |
|
10 |
{ |
|
11 |
public interface IBaseRepository : IDisposable |
|
12 |
{ |
|
13 |
SqlConnection DBConnection(string connectionStr); |
|
14 |
} |
|
15 |
} |
ID2.Manager/ID2.Manager.Dapper/ID2.Manager.Dapper.csproj | ||
---|---|---|
33 | 33 |
</PropertyGroup> |
34 | 34 |
<ItemGroup> |
35 | 35 |
<Reference Include="System" /> |
36 |
<Reference Include="System.ComponentModel.DataAnnotations" /> |
|
36 | 37 |
<Reference Include="System.Core" /> |
37 | 38 |
<Reference Include="System.Xml.Linq" /> |
38 | 39 |
<Reference Include="System.Data.DataSetExtensions" /> |
... | ... | |
42 | 43 |
<Reference Include="System.Xml" /> |
43 | 44 |
</ItemGroup> |
44 | 45 |
<ItemGroup> |
46 |
<Compile Include="IBaseRepository.cs" /> |
|
45 | 47 |
<Compile Include="Properties\AssemblyInfo.cs" /> |
48 |
<Compile Include="Repository\BaseRepository.cs" /> |
|
49 |
<Compile Include="Repository\UserRepository.cs" /> |
|
46 | 50 |
</ItemGroup> |
47 |
<ItemGroup> |
|
48 |
<Folder Include="Controllers\" /> |
|
49 |
</ItemGroup> |
|
51 |
<ItemGroup /> |
|
50 | 52 |
<ItemGroup> |
51 | 53 |
<PackageReference Include="Dapper"> |
52 | 54 |
<Version>2.0.90</Version> |
... | ... | |
55 | 57 |
<Version>13.0.3</Version> |
56 | 58 |
</PackageReference> |
57 | 59 |
</ItemGroup> |
60 |
<ItemGroup> |
|
61 |
<ProjectReference Include="..\ID2.Manager.Data\ID2.Manager.Data.csproj"> |
|
62 |
<Project>{b17c0800-40f4-40e2-b5a6-d366d9c2e0f6}</Project> |
|
63 |
<Name>ID2.Manager.Data</Name> |
|
64 |
</ProjectReference> |
|
65 |
</ItemGroup> |
|
58 | 66 |
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
59 | 67 |
</Project> |
ID2.Manager/ID2.Manager.Dapper/Repository/BaseRepository.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 | ||
7 |
using System.Data; |
|
8 |
using System.Data.SqlClient; |
|
9 |
using System.ComponentModel.DataAnnotations.Schema; |
|
10 | ||
11 |
using Dapper; |
|
12 | ||
13 |
namespace ID2.Manager.Dapper.Repository |
|
14 |
{ |
|
15 |
public abstract class BaseRepository : IBaseRepository |
|
16 |
{ |
|
17 |
private readonly IDbConnection _DbConnection;//readonly 삭제해야하는지 확인 |
|
18 | ||
19 |
public SqlConnection DBConnection(string connectionStr) |
|
20 |
{ |
|
21 |
return new SqlConnection(connectionStr); |
|
22 |
} |
|
23 | ||
24 |
public void Dispose() |
|
25 |
{ |
|
26 |
if (this._DbConnection != null) |
|
27 |
{ |
|
28 |
this._DbConnection.Close(); |
|
29 |
} |
|
30 |
} |
|
31 | ||
32 |
protected BaseRepository(string connectionStr) |
|
33 |
{ |
|
34 |
this._DbConnection = this.DBConnection(connectionStr); |
|
35 | ||
36 |
SqlMapper.TypeMapProvider = type => |
|
37 |
{ |
|
38 |
// create fallback default type map |
|
39 |
var fallback = new DefaultTypeMap(type); |
|
40 |
return new CustomPropertyTypeMap(type, (t, column) => |
|
41 |
{ |
|
42 |
var property = t.GetProperties().FirstOrDefault(prop => |
|
43 |
prop.GetCustomAttributes(typeof(ColumnAttribute), true) |
|
44 |
.Cast<ColumnAttribute>() |
|
45 |
.Any(attr => attr.Name == column)); |
|
46 | ||
47 |
// if no property matched - fall back to default type map |
|
48 |
if (property == null) |
|
49 |
{ |
|
50 |
property = fallback.GetMember(column)?.Property; |
|
51 |
} |
|
52 | ||
53 |
return property; |
|
54 |
}); |
|
55 |
}; |
|
56 |
} |
|
57 | ||
58 |
public IEnumerable<T> Query<T>(string sql) |
|
59 |
{ |
|
60 |
if (this._DbConnection.State != ConnectionState.Open) |
|
61 |
{ |
|
62 |
this._DbConnection.Open(); |
|
63 |
} |
|
64 | ||
65 |
return this._DbConnection.Query<T>(sql); |
|
66 |
} |
|
67 | ||
68 |
public IEnumerable<T> Query<T>(string sql, object param) |
|
69 |
{ |
|
70 |
if (this._DbConnection.State != ConnectionState.Open) |
|
71 |
{ |
|
72 |
this._DbConnection.Open(); |
|
73 |
} |
|
74 | ||
75 |
return this._DbConnection.Query<T>(sql, param); |
|
76 |
} |
|
77 | ||
78 |
public async Task<IEnumerable<T>> QueryAsync<T>(string sql) |
|
79 |
{ |
|
80 |
if (this._DbConnection.State != ConnectionState.Open) |
|
81 |
{ |
|
82 |
this._DbConnection.Open(); |
|
83 |
} |
|
84 | ||
85 |
return await this._DbConnection.QueryAsync<T>(sql); |
|
86 |
} |
|
87 | ||
88 |
public async Task<IEnumerable<T>> QueryAsync<T>(string sql, object param) |
|
89 |
{ |
|
90 |
if (this._DbConnection.State != ConnectionState.Open) |
|
91 |
{ |
|
92 |
this._DbConnection.Open(); |
|
93 |
} |
|
94 | ||
95 |
return await this._DbConnection.QueryAsync<T>(sql, param); |
|
96 |
} |
|
97 | ||
98 |
public int Execute(string query, object param, IDbTransaction dbTran) |
|
99 |
{ |
|
100 |
if (this._DbConnection.State != ConnectionState.Open) |
|
101 |
{ |
|
102 |
this._DbConnection.Open(); |
|
103 |
} |
|
104 | ||
105 |
return this._DbConnection.Execute(query, param, dbTran); |
|
106 |
} |
|
107 | ||
108 |
public async Task<int> ExecuteAsync(string query, object param, IDbTransaction dbTran) |
|
109 |
{ |
|
110 |
if (this._DbConnection.State != ConnectionState.Open) |
|
111 |
{ |
|
112 |
this._DbConnection.Open(); |
|
113 |
} |
|
114 | ||
115 |
return await this._DbConnection.ExecuteAsync(query, param, dbTran); |
|
116 |
} |
|
117 |
} |
|
118 |
} |
ID2.Manager/ID2.Manager.Dapper/Repository/UserRepository.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 | ||
7 |
using ID2.Manager.Data.Models; |
|
8 | ||
9 |
namespace ID2.Manager.Dapper.Repository |
|
10 |
{ |
|
11 |
public class UserRepository : BaseRepository |
|
12 |
{ |
|
13 |
public UserRepository(string connectionStr) : base(connectionStr) {} |
|
14 | ||
15 |
public UserInfo GetUserInfo(string userId, string userPW) |
|
16 |
{ |
|
17 |
string query = $@" |
|
18 |
select * from dbo.Users"; |
|
19 | ||
20 |
return Query<UserInfo>(query, new { userId, userPW }).FirstOrDefault(); |
|
21 |
} |
|
22 |
} |
|
23 |
} |
ID2.Manager/ID2.Manager.sln | ||
---|---|---|
11 | 11 |
EndProject |
12 | 12 |
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ID2.Manager.Data", "ID2.Manager.Data\ID2.Manager.Data.csproj", "{B17C0800-40F4-40E2-B5A6-D366D9C2E0F6}" |
13 | 13 |
EndProject |
14 |
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ID2.Manager.Controller", "ID2.Manager.Controller\ID2.Manager.Controller.csproj", "{83DACC10-43B1-4E38-ABEF-E5EF9492A82D}" |
|
15 |
EndProject |
|
14 | 16 |
Global |
15 | 17 |
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
16 | 18 |
Debug|Any CPU = Debug|Any CPU |
... | ... | |
33 | 35 |
{B17C0800-40F4-40E2-B5A6-D366D9C2E0F6}.Debug|Any CPU.Build.0 = Debug|Any CPU |
34 | 36 |
{B17C0800-40F4-40E2-B5A6-D366D9C2E0F6}.Release|Any CPU.ActiveCfg = Release|Any CPU |
35 | 37 |
{B17C0800-40F4-40E2-B5A6-D366D9C2E0F6}.Release|Any CPU.Build.0 = Release|Any CPU |
38 |
{83DACC10-43B1-4E38-ABEF-E5EF9492A82D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|
39 |
{83DACC10-43B1-4E38-ABEF-E5EF9492A82D}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|
40 |
{83DACC10-43B1-4E38-ABEF-E5EF9492A82D}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|
41 |
{83DACC10-43B1-4E38-ABEF-E5EF9492A82D}.Release|Any CPU.Build.0 = Release|Any CPU |
|
36 | 42 |
EndGlobalSection |
37 | 43 |
GlobalSection(SolutionProperties) = preSolution |
38 | 44 |
HideSolutionNode = FALSE |
ID2.Manager/ID2.Manager/App.config | ||
---|---|---|
3 | 3 |
<startup> |
4 | 4 |
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /> |
5 | 5 |
</startup> |
6 |
<connectionStrings> |
|
7 |
<add name="ID2Manager" providerName="System.Data.SqlClient" connectionString="data source=192.168.0.67;initial catalog=ARS;persist security info=True;user id=sa;password=dof1073#;multipleactiveresultsets=True"/> |
|
8 |
</connectionStrings> |
|
6 | 9 |
</configuration> |
ID2.Manager/ID2.Manager/Forms/Login.cs | ||
---|---|---|
10 | 10 | |
11 | 11 |
using ID2.Manager.Common; |
12 | 12 |
using ID2.Manager.Data.Models; |
13 |
using ID2.Manager.Controller.Controllers; |
|
13 | 14 | |
14 | 15 |
using Telerik.WinControls; |
15 | 16 | |
... | ... | |
29 | 30 |
if (!IsValidatioin()) return; |
30 | 31 | |
31 | 32 |
//DB연결해서 체크로직추가 |
33 |
UserController userService = new UserController(); |
|
34 |
UserInfo info = userService.GetUserInfo(this.radTextBoxID.Text, this.radTextBoxPW.Text); |
|
32 | 35 | |
33 | 36 |
//체크완료 시 로그인 |
34 | 37 |
informations.ActiveUser = new UserInfo() |
ID2.Manager/ID2.Manager/ID2.Manager.csproj | ||
---|---|---|
102 | 102 |
<Project>{d5abdf40-ca97-4b5a-a08c-63d7d53bca3a}</Project> |
103 | 103 |
<Name>ID2.Manager.Common</Name> |
104 | 104 |
</ProjectReference> |
105 |
<ProjectReference Include="..\ID2.Manager.Controller\ID2.Manager.Controller.csproj"> |
|
106 |
<Project>{83dacc10-43b1-4e38-abef-e5ef9492a82d}</Project> |
|
107 |
<Name>ID2.Manager.Controller</Name> |
|
108 |
</ProjectReference> |
|
105 | 109 |
<ProjectReference Include="..\ID2.Manager.Dapper\ID2.Manager.Dapper.csproj"> |
106 | 110 |
<Project>{6d22aaa8-d584-43f4-b71c-b32c5c9288ed}</Project> |
107 | 111 |
<Name>ID2.Manager.Dapper</Name> |
내보내기 Unified diff