■ iBatis를 사용해 SQLite 데이터베이스 파일을 액세스하는 방법을 보여준다.
▶ providers.config
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
<?xml version="1.0" encoding="utf-8"?> <providers xmlns="http://ibatis.apache.org/providers" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <clear /> <provider name="Odbc1.1" description="Odbc, provider V1.0.5000.0 in framework .NET V1.1" assemblyName="System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" connectionClass="System.Data.Odbc.OdbcConnection" commandClass="System.Data.Odbc.OdbcCommand" parameterClass="System.Data.Odbc.OdbcParameter" parameterDbTypeClass="System.Data.Odbc.OdbcType" parameterDbTypeProperty="OdbcType" dataAdapterClass="System.Data.Odbc.OdbcDataAdapter" commandBuilderClass="System.Data.Odbc.OdbcCommandBuilder" usePositionalParameters="true" useParameterPrefixInSql="false" useParameterPrefixInParameter="false" parameterPrefix="@" allowMARS="false" enabled="false" /> <provider name="Odbc2.0" description="Odbc, provider V2.0.0.0 in framework .NET V2" assemblyName="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" connectionClass="System.Data.Odbc.OdbcConnection" commandClass="System.Data.Odbc.OdbcCommand" parameterClass="System.Data.Odbc.OdbcParameter" parameterDbTypeClass="System.Data.Odbc.OdbcType" parameterDbTypeProperty="OdbcType" dataAdapterClass="System.Data.Odbc.OdbcDataAdapter" commandBuilderClass="System.Data.Odbc.OdbcCommandBuilder" usePositionalParameters="true" useParameterPrefixInSql="false" useParameterPrefixInParameter="false" parameterPrefix="@" allowMARS="false" enabled="false" /> <provider name="OleDb1.1" description="OleDb, provider V1.0.5000.0 in framework .NET V1.1" assemblyName="System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" connectionClass="System.Data.OleDb.OleDbConnection" commandClass="System.Data.OleDb.OleDbCommand" parameterClass="System.Data.OleDb.OleDbParameter" parameterDbTypeClass="System.Data.OleDb.OleDbType" parameterDbTypeProperty="OleDbType" dataAdapterClass="System.Data.OleDb.OleDbDataAdapter" commandBuilderClass="System.Data.OleDb.OleDbCommandBuilder" usePositionalParameters="true" useParameterPrefixInSql="false" useParameterPrefixInParameter="false" parameterPrefix="" allowMARS="false" enabled="false" /> <provider name="OleDb2.0" description="OleDb, provider V2.0.0.0 in framework .NET V2" assemblyName="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" connectionClass="System.Data.OleDb.OleDbConnection" commandClass="System.Data.OleDb.OleDbCommand" parameterClass="System.Data.OleDb.OleDbParameter" parameterDbTypeClass="System.Data.OleDb.OleDbType" parameterDbTypeProperty="OleDbType" dataAdapterClass="System.Data.OleDb.OleDbDataAdapter" commandBuilderClass="System.Data.OleDb.OleDbCommandBuilder" usePositionalParameters="true" useParameterPrefixInSql="false" useParameterPrefixInParameter="false" parameterPrefix="" allowMARS="false" enabled="false" /> <provider name="sqlServer1.0" description="Microsoft SQL Server, provider V1.0.3300.0 in framework .NET V1.0" assemblyName="System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" connectionClass="System.Data.SqlClient.SqlConnection" commandClass="System.Data.SqlClient.SqlCommand" parameterClass="System.Data.SqlClient.SqlParameter" parameterDbTypeClass="System.Data.SqlDbType" parameterDbTypeProperty="SqlDbType" dataAdapterClass="System.Data.SqlClient.SqlDataAdapter" commandBuilderClass="System.Data.SqlClient.SqlCommandBuilder" usePositionalParameters="false" useParameterPrefixInSql="true" useParameterPrefixInParameter="true" parameterPrefix="@" allowMARS="false" enabled="false" /> <provider name="sqlServer1.1" description="Microsoft SQL Server, provider V1.0.5000.0 in framework .NET V1.1" assemblyName="System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" connectionClass="System.Data.SqlClient.SqlConnection" commandClass="System.Data.SqlClient.SqlCommand" parameterClass="System.Data.SqlClient.SqlParameter" parameterDbTypeClass="System.Data.SqlDbType" parameterDbTypeProperty="SqlDbType" dataAdapterClass="System.Data.SqlClient.SqlDataAdapter" commandBuilderClass="System.Data.SqlClient.SqlCommandBuilder" usePositionalParameters="false" useParameterPrefixInSql="true" useParameterPrefixInParameter="true" parameterPrefix="@" allowMARS="false" enabled="false" /> <provider name="sqlServer2.0" description="Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0" enabled="false" assemblyName="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" connectionClass="System.Data.SqlClient.SqlConnection" commandClass="System.Data.SqlClient.SqlCommand" parameterClass="System.Data.SqlClient.SqlParameter" parameterDbTypeClass="System.Data.SqlDbType" parameterDbTypeProperty="SqlDbType" dataAdapterClass="System.Data.SqlClient.SqlDataAdapter" commandBuilderClass=" System.Data.SqlClient.SqlCommandBuilder" usePositionalParameters = "false" useParameterPrefixInSql = "true" useParameterPrefixInParameter = "true" parameterPrefix="@" allowMARS="false" /> <provider name="sqlServer4.0" description="Microsoft SQL Server, provider V4.0.0.0 in framework .NET V4.0" assemblyName="System.Data, Version=4.0.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089" connectionClass="System.Data.SqlClient.SqlConnection" commandClass="System.Data.SqlClient.SqlCommand" parameterClass="System.Data.SqlClient.SqlParameter" parameterDbTypeClass="System.Data.SqlDbType" parameterDbTypeProperty="SqlDbType" dataAdapterClass="System.Data.SqlClient.SqlDataAdapter" commandBuilderClass=" System.Data.SqlClient.SqlCommandBuilder" usePositionalParameters = "false" useParameterPrefixInSql = "true" useParameterPrefixInParameter = "true" parameterPrefix="@" allowMARS="false" enabled="false" /> <provider name="sqlServer2005" description="Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0" assemblyName="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" connectionClass="System.Data.SqlClient.SqlConnection" commandClass="System.Data.SqlClient.SqlCommand" parameterClass="System.Data.SqlClient.SqlParameter" parameterDbTypeClass="System.Data.SqlDbType" parameterDbTypeProperty="SqlDbType" dataAdapterClass="System.Data.SqlClient.SqlDataAdapter" commandBuilderClass=" System.Data.SqlClient.SqlCommandBuilder" usePositionalParameters = "false" useParameterPrefixInSql = "true" useParameterPrefixInParameter = "true" parameterPrefix="@" allowMARS="true" enabled="false" /> <provider name="oracle9.2" description="Oracle, Oracle provider V9.2.0.401" assemblyName="Oracle.DataAccess, Version=9.2.0.401, Culture=neutral, PublicKeyToken=89b483f429c47342" connectionClass="Oracle.DataAccess.Client.OracleConnection" commandClass="Oracle.DataAccess.Client.OracleCommand" parameterClass="Oracle.DataAccess.Client.OracleParameter" parameterDbTypeClass="Oracle.DataAccess.Client.OracleDbType" parameterDbTypeProperty="OracleDbType" dataAdapterClass="Oracle.DataAccess.Client.OracleDataAdapter" commandBuilderClass="Oracle.DataAccess.Client.OracleCommandBuilder" usePositionalParameters="false" useParameterPrefixInSql="true" useParameterPrefixInParameter="false" parameterPrefix=":" useDeriveParameters="false" allowMARS="false" enabled="false" /> <provider name="oracle10.1" description="Oracle, oracle provider V10.1.0.301" assemblyName="Oracle.DataAccess, Version=10.1.0.301, Culture=neutral, PublicKeyToken=89b483f429c47342" connectionClass="Oracle.DataAccess.Client.OracleConnection" commandClass="Oracle.DataAccess.Client.OracleCommand" parameterClass="Oracle.DataAccess.Client.OracleParameter" parameterDbTypeClass="Oracle.DataAccess.Client.OracleDbType" parameterDbTypeProperty="OracleDbType" dataAdapterClass="Oracle.DataAccess.Client.OracleDataAdapter" commandBuilderClass="Oracle.DataAccess.Client.OracleCommandBuilder" usePositionalParameters="true" useParameterPrefixInSql="true" useParameterPrefixInParameter="true" parameterPrefix=":" useDeriveParameters="false" allowMARS="false" enabled="false" /> <provider name="oracleClient1.0" description="Oracle, Microsoft provider V1.0.5000.0" assemblyName="System.Data.OracleClient, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" connectionClass="System.Data.OracleClient.OracleConnection" commandClass="System.Data.OracleClient.OracleCommand" parameterClass="System.Data.OracleClient.OracleParameter" parameterDbTypeClass="System.Data.OracleClient.OracleType" parameterDbTypeProperty="OracleType" dataAdapterClass="System.Data.OracleClient.OracleDataAdapter" commandBuilderClass="System.Data.OracleClient.OracleCommandBuilder" usePositionalParameters="false" useParameterPrefixInSql="true" useParameterPrefixInParameter="false" parameterPrefix=":" allowMARS="false" enabled="false" /> <provider name="PostgreSql0.99.1.0" description="PostgreSql, Npgsql provider V0.99.1.0" assemblyName="Npgsql, Version=0.99.1.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" connectionClass="Npgsql.NpgsqlConnection" commandClass="Npgsql.NpgsqlCommand" parameterClass="Npgsql.NpgsqlParameter" parameterDbTypeClass="NpgsqlTypes.NpgsqlDbType" parameterDbTypeProperty="NpgsqlDbType" dataAdapterClass="Npgsql.NpgsqlDataAdapter" commandBuilderClass="Npgsql.NpgsqlCommandBuilder" usePositionalParameters="false" useParameterPrefixInSql="true" useParameterPrefixInParameter="true" parameterPrefix=":" allowMARS="true" enabled="false" /> <provider name="MySql" description="MySQL, MySQL provider 1.0.7.30072" assemblyName="MySql.Data, Version=1.0.7.30072, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionClass="MySql.Data.MySqlClient.MySqlConnection" commandClass="MySql.Data.MySqlClient.MySqlCommand" parameterClass="MySql.Data.MySqlClient.MySqlParameter" parameterDbTypeClass="MySql.Data.MySqlClient.MySqlDbType" parameterDbTypeProperty="MySqlDbType" dataAdapterClass="MySql.Data.MySqlClient.MySqlDataAdapter" commandBuilderClass="MySql.Data.MySqlClient.MySqlCommandBuilder" usePositionalParameters="false" useParameterPrefixInSql="true" useParameterPrefixInParameter="true" parameterPrefix="?" allowMARS="false" enabled="false" /> <provider name="ByteFx" description="MySQL, ByteFx provider V0.7.6.15073" assemblyName="ByteFX.MySqlClient, Version=0.7.6.15073, Culture=neutral, PublicKeyToken=f2fef6fed1732fc1" connectionClass="ByteFX.Data.MySqlClient.MySqlConnection" commandClass="ByteFX.Data.MySqlClient.MySqlCommand" parameterClass="ByteFX.Data.MySqlClient.MySqlParameter" parameterDbTypeClass="ByteFX.Data.MySqlClient.MySqlDbType" parameterDbTypeProperty="MySqlDbType" dataAdapterClass="ByteFX.Data.MySqlClient.MySqlDataAdapter" commandBuilderClass="ByteFX.Data.MySqlClient.MySqlCommandBuilder" usePositionalParameters="false" useParameterPrefixInSql="true" useParameterPrefixInParameter="true" parameterPrefix="@" allowMARS="false" enabled="false" /> <provider name="iDb2.10" description="IBM DB2 Provider, V 10.0" assemblyName="IBM.Data.DB2.iSeries, Version=10.0.0.0,Culture=neutral, PublicKeyToken=9cdb2ebfb1f93a26, Custom=null" connectionClass="IBM.Data.DB2.iSeries.iDB2Connection" commandClass="IBM.Data.DB2.iSeries.iDB2Command" parameterClass="IBM.Data.DB2.iSeries.iDB2Parameter" parameterDbTypeClass="IBM.Data.DB2.iSeries.iDB2DbType" parameterDbTypeProperty="iDB2DbType" dataAdapterClass="IBM.Data.DB2.iSeries.iDB2DataAdapter" commandBuilderClass="IBM.Data.DB2.iSeries.iDB2CommandBuilder" usePositionalParameters="true" useParameterPrefixInSql="false" useParameterPrefixInParameter="false" parameterPrefix="" allowMARS="false" enabled="false" /> <provider name="Informix" description="Informix NET Provider, 2.81.0.0" assemblyName="IBM.Data.Informix, Version=2.81.0.0, Culture=neutral, PublicKeyToken=7c307b91aa13d208" connectionClass="IBM.Data.Informix.IfxConnection" commandClass="IBM.Data.Informix.IfxCommand" parameterClass="IBM.Data.Informix.IfxParameter" parameterDbTypeClass="IBM.Data.Informix.IfxType" parameterDbTypeProperty="IfxType" dataAdapterClass="IBM.Data.Informix.IfxDataAdapter" commandBuilderClass="IBM.Data.Informix.IfxCommandBuilder" usePositionalParameters = "true" useParameterPrefixInSql = "false" useParameterPrefixInParameter = "false" useDeriveParameters="false" allowMARS="false" enabled="false" /> <provider name="SQLite3" description="SQLite, SQLite.NET provider V1.0.105.1" assemblyName="System.Data.SQLite, Version=1.0.105.1, Culture=neutral, PublicKeyToken=db937bc2d44ff139" connectionClass="System.Data.SQLite.SQLiteConnection" commandClass="System.Data.SQLite.SQLiteCommand" parameterClass="System.Data.SQLite.SQLiteParameter" parameterDbTypeClass="System.Data.SQLite.SQLiteType" parameterDbTypeProperty="DbType" dataAdapterClass="System.Data.SQLite.SQLiteDataAdapter" commandBuilderClass="System.Data.SQLite.SQLiteCommandBuilder" usePositionalParameters="false" useParameterPrefixInSql="true" useParameterPrefixInParameter="true" parameterPrefix="@" setDbParameterPrecision="false" setDbParameterScale="false" allowMARS="false" enabled="true" /> <provider name="SQLite3 Finisar" description="SQLite, SQLite.NET provider V0.21.1869.3794" assemblyName="SQLite.NET, Version=0.21.1869.3794, Culture=neutral, PublicKeyToken=c273bd375e695f9c" connectionClass="Finisar.SQLite.SQLiteConnection" commandClass="Finisar.SQLite.SQLiteCommand" parameterClass="Finisar.SQLite.SQLiteParameter" parameterDbTypeClass="System.Data.DbType, System.Data" parameterDbTypeProperty="DbType" dataAdapterClass="Finisar.SQLite.SQLiteDataAdapter" commandBuilderClass="Finisar.SQLite.SQLiteCommandBuilder" usePositionalParameters="false" useParameterPrefixInSql="true" useParameterPrefixInParameter="true" parameterPrefix="@" setDbParameterPrecision="false" setDbParameterScale="false" allowMARS="false" enabled="false" /> <provider name="Firebird1.7" description="Firebird, Firebird SQL .NET provider V1.7.0.33200" assemblyName="FirebirdSql.Data.Firebird, Version=1.7.0.33200, Culture=neutral, PublicKeyToken=fa843d180294369d" connectionClass="FirebirdSql.Data.Firebird.FbConnection" commandClass="FirebirdSql.Data.Firebird.FbCommand" parameterClass="FirebirdSql.Data.Firebird.FbParameter" parameterDbTypeClass="FirebirdSql.Data.Firebird.FbDbType" parameterDbTypeProperty="FbDbType" dataAdapterClass="FirebirdSql.Data.Firebird.FbDataAdapter" commandBuilderClass="FirebirdSql.Data.Firebird.FbCommandBuilder" usePositionalParameters="false" useParameterPrefixInSql="true" useParameterPrefixInParameter="true" parameterPrefix="@" allowMARS="false" enabled="false" /> </providers> |
▶ sql.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<?xml version="1.0" encoding="utf-8" ?> <sqlMap namespace="iBatis" xmlns="http://ibatis.apache.org/mapping" xmlns:xls="http://www.w3.org/2001/XMLSchema-instance"> <statements> <select id="SampleDAO.GetSampleList" resultClass="TestProject.SampleModel"> SELECT * FROM Result </select> <insert id ="SampleDAO.InsertSample" parameterClass="TestProject.SampleModel"> INSERT INTO Result ( CREATE_TIME ,VALUE1 ,VALUE2 ) VALUES ( #CREATE_TIME# ,#VALUE1# ,#VALUE2# ) </insert> <update id ="SampleDAO.UpdateSample" parameterClass="TestProject.SampleModel"> UPDATE Result SET VALUE1 = #VALUE1# WHERE ID = #ID# </update> <delete id ="SampleDAO.DeleteSample" parameterClass="TestProject.SampleModel"> DELETE FROM Result WHERE ID = #ID# </delete> </statements> </sqlMap> |
▶ SqlMap.config
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?xml version="1.0" encoding="utf-8" ?> <sqlMapConfig xmlns="http://ibatis.apache.org/dataMapper" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <settings> <setting useStatementNamespaces="false" /> </settings> <providers resource="Providers.config" /> <database> <provider name="SQLite3" /> <dataSource name="TestDB" connectionString="Data Source = sample.db3;Version = 3" /> </database> <sqlMaps> <sqlMap resource="sql.xml" /> </sqlMaps> </sqlMapConfig> |
▶ SampleModel.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
using System; namespace TestProject { /// <summary> /// 샘플 모델 /// </summary> public class SampleModel { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public int ID { get; set; } #endregion #region 생성 시간 - CREATE_TIME /// <summary> /// 생성 시간 /// </summary> public DateTime CREATE_TIME { get; set; } #endregion #region 값 1 - VALUE1 /// <summary> /// 값 1 /// </summary> public double VALUE1 { get; set; } #endregion #region 값 2 - VALUE2 /// <summary> /// 값 2 /// </summary> public double VALUE2 { get; set; } #endregion } } |
▶ SampleDAO.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
using System; using System.Collections.Generic; using IBatisNet.DataMapper; using IBatisNet.DataMapper.Configuration; namespace TestProject { /// <summary> /// 샘플 DAO /// </summary> public class SampleDAO { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 매퍼 구하기 - GetMapper() /// <summary> /// 매퍼 구하기 /// </summary> /// <returns>SQL 매퍼 인터페이스</returns> public ISqlMapper GetMapper() { DomSqlMapBuilder builder = new DomSqlMapBuilder(); ISqlMapper mapper = builder.Configure("SqlMap.config"); return mapper; } #endregion #region 샘플 리스트 구하기 - GetSampleList() /// <summary> /// 샘플 리스트 구하기 /// </summary> /// <returns>샘플 리스트</returns> public IList<SampleModel> GetSampleList() { ISqlMapper mapper = Mapper.Instance(); IList<SampleModel> list = mapper.QueryForList<SampleModel>("SampleDAO.GetSampleList", null); return list; } #endregion #region 샘플 삽입하기 - InsertSample(createTime, value1, value2) /// <summary> /// 샘플 삽입하기 /// </summary> /// <param name="createTime">생성 시간</param> /// <param name="value1">값 1</param> /// <param name="value2">값 2</param> public void InsertSample(DateTime createTime, double value1, double value2) { SampleModel sample = new SampleModel(); sample.CREATE_TIME = createTime; sample.VALUE1 = value1; sample.VALUE2 = value2; GetMapper().Insert("SampleDAO.InsertSample", sample); } #endregion #region 샘플 수정하기 - UpdateSample(id, value1) /// <summary> /// 샘플 수정하기 /// </summary> /// <param name="id">ID</param> /// <param name="value1">값 1</param> /// <returns>샘플 수정 결과</returns> public bool UpdateSample(int id, double value1) { SampleModel sample = new SampleModel(); sample.ID = id; sample.VALUE1 = value1; return GetMapper().Update("SampleDAO.UpdateSample", sample) > 0 ? true : false; } #endregion #region 샘플 삭제하기 - DeleteSample(id) /// <summary> /// 샘플 삭제하기 /// </summary> /// <param name="id">ID</param> /// <returns>샘플 삭제 결과</returns> public bool DeleteSample(int id) { SampleModel sample = new SampleModel(); sample.ID = id; return GetMapper().Delete("SampleDAO.DeleteSample", sample) > 0 ? true : false; } #endregion } } |
▶ MainForm.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
using System; using System.Collections.Generic; using System.Windows.Forms; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 샘플 DAO /// </summary> private SampleDAO dao = new SampleDAO(); #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); this.selectButton.Click += selectButton_Click; this.insertButton.Click += insertButton_Click; this.updateButton.Click += updateButton_Click; this.deleteButton.Click += deleteButton_Click; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region Select 버튼 클릭시 처리하기 - selectButton_Click(sender, e) /// <summary> /// Select 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void selectButton_Click(object sender, EventArgs e) { IList<SampleModel> list = this.dao.GetSampleList(); MessageBox.Show(list.Count.ToString()); } #endregion #region Insert 버튼 클릭시 처리하기 - insertButton_Click(sender, e) /// <summary> /// Insert 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void insertButton_Click(object sender, EventArgs e) { this.dao.InsertSample(DateTime.Now, 9.99999, 1.11111); } #endregion #region Update 버튼 클릭시 처리하기 - updateButton_Click(sender, e) /// <summary> /// Update 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void updateButton_Click(object sender, EventArgs e) { this.dao.UpdateSample(1, 8.88888); } #endregion #region Delete 버튼 클릭시 처리하기 - deleteButton_Click(sender, e) /// <summary> /// Delete 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void deleteButton_Click(object sender, EventArgs e) { this.dao.DeleteSample(1); } #endregion } } |