PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/development/Source/Modules/Blog/Data/SqlServer2000/Blog_Categories.cs

#
C# | 446 lines | 276 code | 48 blank | 122 comment | 28 complexity | 48b276067931012d4d8cebe4a74b9f21 MD5 | raw file
  1. #region Copyright © 2004, Nicholas Berardi
  2. /*
  3. * ManagedFusion (www.ManagedFusion.net) Copyright © 2004, Nicholas Berardi
  4. * All rights reserved.
  5. *
  6. * This code is protected under the Common Public License Version 1.0
  7. * The license in its entirety at <http://opensource.org/licenses/cpl.php>
  8. *
  9. * ManagedFusion is freely available from <http://www.ManagedFusion.net/>
  10. */
  11. #endregion
  12. ///////////////////////////////////////////////////////////////////////////
  13. // Description: Data Access class for the table 'Blog_Categories'
  14. // Generated by LLBLGen v1.21.2003.712 Final on: Wednesday, January 26, 2005, 4:47:11 PM
  15. // Because the Base Class already implements IDispose, this class doesn't.
  16. ///////////////////////////////////////////////////////////////////////////
  17. using System;
  18. using System.Data;
  19. using System.Data.SqlTypes;
  20. using System.Data.SqlClient;
  21. namespace OmniPortal.Modules.Blog.Data.SqlServer
  22. {
  23. /// <summary>
  24. /// Purpose: Data Access class for the table 'Blog_Categories'.
  25. /// </summary>
  26. public class Blog_Categories : DBInteractionBase
  27. {
  28. #region Class Member Declarations
  29. private SqlInt32 _iD;
  30. private SqlString _name;
  31. #endregion
  32. /// <summary>
  33. /// Purpose: Class constructor.
  34. /// </summary>
  35. public Blog_Categories()
  36. {
  37. // Nothing for now.
  38. }
  39. /// <summary>
  40. /// Purpose: Insert method. This method will insert one new row into the database.
  41. /// </summary>
  42. /// <returns>True if succeeded, otherwise an Exception is thrown. </returns>
  43. /// <remarks>
  44. /// Properties needed for this method:
  45. /// <UL>
  46. /// <LI>Name</LI>
  47. /// </UL>
  48. /// Properties set after a succesful call of this method:
  49. /// <UL>
  50. /// <LI>Identity</LI>
  51. /// <LI>ErrorCode</LI>
  52. /// </UL>
  53. /// </remarks>
  54. public override bool Insert()
  55. {
  56. SqlCommand cmdToExecute = new SqlCommand();
  57. cmdToExecute.CommandText = "dbo.[Blog_Categories_Insert]";
  58. cmdToExecute.CommandType = CommandType.StoredProcedure;
  59. // Use base class' connection object
  60. cmdToExecute.Connection = _mainConnection;
  61. try
  62. {
  63. cmdToExecute.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 64, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _name));
  64. cmdToExecute.Parameters.Add(new SqlParameter("@Identity", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, _iD));
  65. cmdToExecute.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, _errorCode));
  66. if(_mainConnectionIsCreatedLocal)
  67. {
  68. // Open connection.
  69. _mainConnection.Open();
  70. }
  71. else
  72. {
  73. if(_mainConnectionProvider.IsTransactionPending)
  74. {
  75. cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
  76. }
  77. }
  78. // Execute query.
  79. _rowsAffected = cmdToExecute.ExecuteNonQuery();
  80. _iD = (Int32)cmdToExecute.Parameters["@Identity"].Value;
  81. _errorCode = (Int32)cmdToExecute.Parameters["@ErrorCode"].Value;
  82. if(_errorCode != (int)LLBLError.AllOk)
  83. {
  84. // Throw error.
  85. throw new Exception("Stored Procedure 'Blog_Categories_Insert' reported the ErrorCode: " + _errorCode);
  86. }
  87. return true;
  88. }
  89. catch(Exception ex)
  90. {
  91. // some error occured. Bubble it to caller and encapsulate Exception object
  92. throw new Exception("Blog_Categories::Insert::Error occured.", ex);
  93. }
  94. finally
  95. {
  96. if(_mainConnectionIsCreatedLocal)
  97. {
  98. // Close connection.
  99. _mainConnection.Close();
  100. }
  101. cmdToExecute.Dispose();
  102. }
  103. }
  104. /// <summary>
  105. /// Purpose: Update method. This method will Update one existing row in the database.
  106. /// </summary>
  107. /// <returns>True if succeeded, otherwise an Exception is thrown. </returns>
  108. /// <remarks>
  109. /// Properties needed for this method:
  110. /// <UL>
  111. /// <LI>Identity</LI>
  112. /// <LI>Name</LI>
  113. /// </UL>
  114. /// Properties set after a succesful call of this method:
  115. /// <UL>
  116. /// <LI>ErrorCode</LI>
  117. /// </UL>
  118. /// </remarks>
  119. public override bool Update()
  120. {
  121. SqlCommand cmdToExecute = new SqlCommand();
  122. cmdToExecute.CommandText = "dbo.[Blog_Categories_Update]";
  123. cmdToExecute.CommandType = CommandType.StoredProcedure;
  124. // Use base class' connection object
  125. cmdToExecute.Connection = _mainConnection;
  126. try
  127. {
  128. cmdToExecute.Parameters.Add(new SqlParameter("@Identity", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _iD));
  129. cmdToExecute.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 64, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _name));
  130. cmdToExecute.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, _errorCode));
  131. if(_mainConnectionIsCreatedLocal)
  132. {
  133. // Open connection.
  134. _mainConnection.Open();
  135. }
  136. else
  137. {
  138. if(_mainConnectionProvider.IsTransactionPending)
  139. {
  140. cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
  141. }
  142. }
  143. // Execute query.
  144. _rowsAffected = cmdToExecute.ExecuteNonQuery();
  145. _errorCode = (Int32)cmdToExecute.Parameters["@ErrorCode"].Value;
  146. if(_errorCode != (int)LLBLError.AllOk)
  147. {
  148. // Throw error.
  149. throw new Exception("Stored Procedure 'Blog_Categories_Update' reported the ErrorCode: " + _errorCode);
  150. }
  151. return true;
  152. }
  153. catch(Exception ex)
  154. {
  155. // some error occured. Bubble it to caller and encapsulate Exception object
  156. throw new Exception("Blog_Categories::Update::Error occured.", ex);
  157. }
  158. finally
  159. {
  160. if(_mainConnectionIsCreatedLocal)
  161. {
  162. // Close connection.
  163. _mainConnection.Close();
  164. }
  165. cmdToExecute.Dispose();
  166. }
  167. }
  168. /// <summary>
  169. /// Purpose: Delete method. This method will Delete one existing row in the database, based on the Primary Key.
  170. /// </summary>
  171. /// <returns>True if succeeded, otherwise an Exception is thrown. </returns>
  172. /// <remarks>
  173. /// Properties needed for this method:
  174. /// <UL>
  175. /// <LI>Identity</LI>
  176. /// </UL>
  177. /// Properties set after a succesful call of this method:
  178. /// <UL>
  179. /// <LI>ErrorCode</LI>
  180. /// </UL>
  181. /// </remarks>
  182. public override bool Delete()
  183. {
  184. SqlCommand cmdToExecute = new SqlCommand();
  185. cmdToExecute.CommandText = "dbo.[Blog_Categories_Delete]";
  186. cmdToExecute.CommandType = CommandType.StoredProcedure;
  187. // Use base class' connection object
  188. cmdToExecute.Connection = _mainConnection;
  189. try
  190. {
  191. cmdToExecute.Parameters.Add(new SqlParameter("@Identity", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _iD));
  192. cmdToExecute.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, _errorCode));
  193. if(_mainConnectionIsCreatedLocal)
  194. {
  195. // Open connection.
  196. _mainConnection.Open();
  197. }
  198. else
  199. {
  200. if(_mainConnectionProvider.IsTransactionPending)
  201. {
  202. cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
  203. }
  204. }
  205. // Execute query.
  206. _rowsAffected = cmdToExecute.ExecuteNonQuery();
  207. _errorCode = (Int32)cmdToExecute.Parameters["@ErrorCode"].Value;
  208. if(_errorCode != (int)LLBLError.AllOk)
  209. {
  210. // Throw error.
  211. throw new Exception("Stored Procedure 'Blog_Categories_Delete' reported the ErrorCode: " + _errorCode);
  212. }
  213. return true;
  214. }
  215. catch(Exception ex)
  216. {
  217. // some error occured. Bubble it to caller and encapsulate Exception object
  218. throw new Exception("Blog_Categories::Delete::Error occured.", ex);
  219. }
  220. finally
  221. {
  222. if(_mainConnectionIsCreatedLocal)
  223. {
  224. // Close connection.
  225. _mainConnection.Close();
  226. }
  227. cmdToExecute.Dispose();
  228. }
  229. }
  230. /// <summary>
  231. /// Purpose: Select method. This method will Select one existing row from the database, based on the Primary Key.
  232. /// </summary>
  233. /// <returns>DataTable object if succeeded, otherwise an Exception is thrown. </returns>
  234. /// <remarks>
  235. /// Properties needed for this method:
  236. /// <UL>
  237. /// <LI>Identity</LI>
  238. /// </UL>
  239. /// Properties set after a succesful call of this method:
  240. /// <UL>
  241. /// <LI>ErrorCode</LI>
  242. /// <LI>Identity</LI>
  243. /// <LI>Name</LI>
  244. /// </UL>
  245. /// Will fill all properties corresponding with a field in the table with the value of the row selected.
  246. /// </remarks>
  247. public override DataTable SelectOne()
  248. {
  249. SqlCommand cmdToExecute = new SqlCommand();
  250. cmdToExecute.CommandText = "dbo.[Blog_Categories_SelectOne]";
  251. cmdToExecute.CommandType = CommandType.StoredProcedure;
  252. DataTable toReturn = new DataTable("Blog_Categories");
  253. SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);
  254. // Use base class' connection object
  255. cmdToExecute.Connection = _mainConnection;
  256. try
  257. {
  258. cmdToExecute.Parameters.Add(new SqlParameter("@Identity", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _iD));
  259. cmdToExecute.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, _errorCode));
  260. if(_mainConnectionIsCreatedLocal)
  261. {
  262. // Open connection.
  263. _mainConnection.Open();
  264. }
  265. else
  266. {
  267. if(_mainConnectionProvider.IsTransactionPending)
  268. {
  269. cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
  270. }
  271. }
  272. // Execute query.
  273. adapter.Fill(toReturn);
  274. _errorCode = (Int32)cmdToExecute.Parameters["@ErrorCode"].Value;
  275. if(_errorCode != (int)LLBLError.AllOk)
  276. {
  277. // Throw error.
  278. throw new Exception("Stored Procedure 'Blog_Categories_SelectOne' reported the ErrorCode: " + _errorCode);
  279. }
  280. if(toReturn.Rows.Count > 0)
  281. {
  282. _iD = (Int32)toReturn.Rows[0]["Identity"];
  283. _name = (string)toReturn.Rows[0]["Name"];
  284. }
  285. return toReturn;
  286. }
  287. catch(Exception ex)
  288. {
  289. // some error occured. Bubble it to caller and encapsulate Exception object
  290. throw new Exception("Blog_Categories::SelectOne::Error occured.", ex);
  291. }
  292. finally
  293. {
  294. if(_mainConnectionIsCreatedLocal)
  295. {
  296. // Close connection.
  297. _mainConnection.Close();
  298. }
  299. cmdToExecute.Dispose();
  300. adapter.Dispose();
  301. }
  302. }
  303. /// <summary>
  304. /// Purpose: SelectAll method. This method will Select all rows from the table.
  305. /// </summary>
  306. /// <returns>DataTable object if succeeded, otherwise an Exception is thrown. </returns>
  307. /// <remarks>
  308. /// Properties set after a succesful call of this method:
  309. /// <UL>
  310. /// <LI>ErrorCode</LI>
  311. /// </UL>
  312. /// </remarks>
  313. public override DataTable SelectAll()
  314. {
  315. SqlCommand cmdToExecute = new SqlCommand();
  316. cmdToExecute.CommandText = "dbo.[Blog_Categories_SelectAll]";
  317. cmdToExecute.CommandType = CommandType.StoredProcedure;
  318. DataTable toReturn = new DataTable("Blog_Categories");
  319. SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);
  320. // Use base class' connection object
  321. cmdToExecute.Connection = _mainConnection;
  322. try
  323. {
  324. cmdToExecute.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, _errorCode));
  325. if(_mainConnectionIsCreatedLocal)
  326. {
  327. // Open connection.
  328. _mainConnection.Open();
  329. }
  330. else
  331. {
  332. if(_mainConnectionProvider.IsTransactionPending)
  333. {
  334. cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
  335. }
  336. }
  337. // Execute query.
  338. adapter.Fill(toReturn);
  339. _errorCode = (Int32)cmdToExecute.Parameters["@ErrorCode"].Value;
  340. if(_errorCode != (int)LLBLError.AllOk)
  341. {
  342. // Throw error.
  343. throw new Exception("Stored Procedure 'Blog_Categories_SelectAll' reported the ErrorCode: " + _errorCode);
  344. }
  345. return toReturn;
  346. }
  347. catch(Exception ex)
  348. {
  349. // some error occured. Bubble it to caller and encapsulate Exception object
  350. throw new Exception("Blog_Categories::SelectAll::Error occured.", ex);
  351. }
  352. finally
  353. {
  354. if(_mainConnectionIsCreatedLocal)
  355. {
  356. // Close connection.
  357. _mainConnection.Close();
  358. }
  359. cmdToExecute.Dispose();
  360. adapter.Dispose();
  361. }
  362. }
  363. #region Class Property Declarations
  364. public SqlInt32 ID
  365. {
  366. get
  367. {
  368. return _iD;
  369. }
  370. set
  371. {
  372. SqlInt32 iDTmp = (SqlInt32)value;
  373. if(iDTmp.IsNull)
  374. {
  375. throw new ArgumentOutOfRangeException("Identity", "Identity can't be NULL");
  376. }
  377. _iD = value;
  378. }
  379. }
  380. public SqlString Name
  381. {
  382. get
  383. {
  384. return _name;
  385. }
  386. set
  387. {
  388. SqlString nameTmp = (SqlString)value;
  389. if(nameTmp.IsNull)
  390. {
  391. throw new ArgumentOutOfRangeException("Name", "Name can't be NULL");
  392. }
  393. _name = value;
  394. }
  395. }
  396. #endregion
  397. }
  398. }