/Docs/07-Implementacion/Source/trunk/EDUAR_Regular/EDUAR/EDUAR_DataAccess/Common/DAEventoInstitucional.cs

http://blpm.googlecode.com/ · C# · 272 lines · 244 code · 28 blank · 0 comment · 26 complexity · bf46ad966059a1f9138858883a07a455 MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EDUAR_Entities;
  6. using EDUAR_DataAccess.Shared;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using EDUAR_Utility.Excepciones;
  10. using EDUAR_Utility.Enumeraciones;
  11. using EDUAR_Utility.Constantes;
  12. namespace EDUAR_DataAccess.Common
  13. {
  14. public class DAEventoInstitucional : DataAccesBase<EventoInstitucional>
  15. {
  16. #region --[Atributos]--
  17. private const string ClassName = "DAEventoInstitucional";
  18. #endregion
  19. #region --[Constructor]--
  20. public DAEventoInstitucional()
  21. {
  22. }
  23. public DAEventoInstitucional(DATransaction objDATransaction)
  24. : base(objDATransaction)
  25. {
  26. }
  27. #endregion
  28. #region --[Implementación métodos heredados]--
  29. public override string FieldID
  30. {
  31. get { throw new NotImplementedException(); }
  32. }
  33. public override string FieldDescription
  34. {
  35. get { throw new NotImplementedException(); }
  36. }
  37. public override EventoInstitucional GetById(EventoInstitucional entidad)
  38. {
  39. try
  40. {
  41. Transaction.DBcomand = Transaction.DataBase.GetStoredProcCommand("EventoInstitucional_Select");
  42. if (entidad.idEventoInstitucional > 0)
  43. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "idEventoInstitucional", DbType.Int32, entidad.idEventoInstitucional);
  44. IDataReader reader = Transaction.DataBase.ExecuteReader(Transaction.DBcomand);
  45. EventoInstitucional objEvento = new EventoInstitucional();
  46. while (reader.Read())
  47. {
  48. objEvento.idEventoInstitucional = Convert.ToInt32(reader["idEventoInstitucional"]);
  49. objEvento.fecha = Convert.ToDateTime(reader["fecha"].ToString());
  50. objEvento.hora = Convert.ToDateTime(reader["hora"].ToString());
  51. objEvento.lugar = reader["lugar"].ToString();
  52. objEvento.tipoEventoInstitucional = new TipoEventoInstitucional() { idTipoEventoInstitucional = Convert.ToInt32((reader["idTipoEvento"])), descripcion = reader["tipoEvento"].ToString() };
  53. objEvento.organizador = new Persona() { idPersona = Convert.ToInt32(reader["idPersona"]), nombre = reader["nombreOrganizador"].ToString(), apellido = reader["apellidoOrganizador"].ToString() };
  54. objEvento.titulo = reader["titulo"].ToString();
  55. objEvento.detalle = reader["detalle"].ToString();
  56. objEvento.activo = (bool)(reader["activo"]);
  57. }
  58. return objEvento;
  59. }
  60. catch (SqlException ex)
  61. {
  62. throw new CustomizedException(string.Format("Fallo en {0} - GetEventoInstitucional()", ClassName),
  63. ex, enuExceptionType.SqlException);
  64. }
  65. catch (Exception ex)
  66. {
  67. throw new CustomizedException(string.Format("Fallo en {0} - GetEventoInstitucional()", ClassName),
  68. ex, enuExceptionType.DataAccesException);
  69. }
  70. }
  71. public override void Create(EventoInstitucional entidad)
  72. {
  73. try
  74. {
  75. Transaction.DBcomand = Transaction.DataBase.GetStoredProcCommand("EventoInstitucional_Insert");
  76. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@idEventoInstitucional", DbType.Int32, 0);
  77. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@idTipoEvento", DbType.Int32, entidad.tipoEventoInstitucional.idTipoEventoInstitucional);
  78. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@idPersona", DbType.Int32, entidad.organizador.idPersona);
  79. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@fecha", DbType.Date, entidad.fecha);
  80. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@hora", DbType.Time, Convert.ToDateTime(entidad.hora).ToShortTimeString());
  81. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@lugar", DbType.String, entidad.lugar);
  82. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@titulo", DbType.String, entidad.titulo);
  83. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@detalle", DbType.String, entidad.detalle);
  84. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@activo", DbType.String, entidad.activo);
  85. if (Transaction.Transaction != null)
  86. Transaction.DataBase.ExecuteNonQuery(Transaction.DBcomand, Transaction.Transaction);
  87. else
  88. Transaction.DataBase.ExecuteNonQuery(Transaction.DBcomand);
  89. }
  90. catch (SqlException ex)
  91. {
  92. throw new CustomizedException(string.Format("Fallo en {0} - Create()", ClassName),
  93. ex, enuExceptionType.SqlException);
  94. }
  95. catch (Exception ex)
  96. {
  97. throw new CustomizedException(string.Format("Fallo en {0} - Create()", ClassName),
  98. ex, enuExceptionType.DataAccesException);
  99. }
  100. }
  101. public override void Create(EventoInstitucional entidad, out int identificador)
  102. {
  103. try
  104. {
  105. Transaction.DBcomand = Transaction.DataBase.GetStoredProcCommand("EventoInstitucional_Insert");
  106. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@idEventoInstitucional", DbType.Int32,0);
  107. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@idTipoEvento", DbType.Int32, entidad.tipoEventoInstitucional.idTipoEventoInstitucional);
  108. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@username", DbType.String, entidad.organizador.username);
  109. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@fecha", DbType.Date, entidad.fecha);
  110. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@hora", DbType.Time, Convert.ToDateTime(entidad.hora).ToShortTimeString());
  111. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@lugar", DbType.String, entidad.lugar);
  112. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@titulo", DbType.String, entidad.titulo);
  113. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@detalle", DbType.String, entidad.detalle);
  114. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@activo", DbType.String, entidad.activo);
  115. if (Transaction.Transaction != null)
  116. Transaction.DataBase.ExecuteNonQuery(Transaction.DBcomand, Transaction.Transaction);
  117. else
  118. Transaction.DataBase.ExecuteNonQuery(Transaction.DBcomand);
  119. identificador = Int32.Parse(Transaction.DBcomand.Parameters["@idEventoInstitucional"].Value.ToString());
  120. }
  121. catch (SqlException ex)
  122. {
  123. throw new CustomizedException(string.Format("Fallo en {0} - Create()", ClassName),
  124. ex, enuExceptionType.SqlException);
  125. }
  126. catch (Exception ex)
  127. {
  128. throw new CustomizedException(string.Format("Fallo en {0} - Create()", ClassName),
  129. ex, enuExceptionType.DataAccesException);
  130. }
  131. }
  132. public override void Update(EventoInstitucional entidad)
  133. {
  134. try
  135. {
  136. Transaction.DBcomand = Transaction.DataBase.GetStoredProcCommand("EventoInstitucional_Update");
  137. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@idEventoInstitucional", DbType.Int32, entidad.idEventoInstitucional);
  138. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@idTipoEvento", DbType.Int32, entidad.tipoEventoInstitucional.idTipoEventoInstitucional);
  139. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@username", DbType.String, entidad.organizador.username);
  140. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@fecha", DbType.Date, entidad.fecha);
  141. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@hora", DbType.Time, Convert.ToDateTime(entidad.hora).ToShortTimeString());
  142. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@lugar", DbType.String, entidad.lugar);
  143. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@titulo", DbType.String, entidad.titulo);
  144. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@detalle", DbType.String, entidad.detalle);
  145. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@activo", DbType.String, entidad.activo);
  146. if (Transaction.Transaction != null)
  147. Transaction.DataBase.ExecuteNonQuery(Transaction.DBcomand, Transaction.Transaction);
  148. else
  149. Transaction.DataBase.ExecuteNonQuery(Transaction.DBcomand);
  150. }
  151. catch (SqlException ex)
  152. {
  153. if (ex.Number == BLConstantesGenerales.ConcurrencyErrorNumber)
  154. throw new CustomizedException(string.Format(
  155. "No se puede modificar el Evento {0}, debido a que otro usuario lo ha modificado.",
  156. entidad.titulo), ex, enuExceptionType.ConcurrencyException);
  157. throw new CustomizedException(string.Format("Fallo en {0} - Update()", ClassName),
  158. ex, enuExceptionType.SqlException);
  159. }
  160. catch (Exception ex)
  161. {
  162. throw new CustomizedException(string.Format("Fallo en {0} - Update()", ClassName),
  163. ex, enuExceptionType.DataAccesException);
  164. }
  165. }
  166. public override void Delete(EventoInstitucional entidad)
  167. {
  168. throw new NotImplementedException();
  169. }
  170. #endregion
  171. #region --[Métodos Públicos]--
  172. public List<EventoInstitucional> GetEventoInstitucional(EventoInstitucional entidad)
  173. {
  174. try
  175. {
  176. Transaction.DBcomand = Transaction.DataBase.GetStoredProcCommand("EventoInstitucional_Select");
  177. if (entidad != null)
  178. {
  179. if (entidad.idEventoInstitucional > 0)
  180. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@idEventoInstitucional", DbType.Int32, entidad.idEventoInstitucional);
  181. if (entidad.tipoEventoInstitucional.idTipoEventoInstitucional > 0)
  182. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@idTipoEvento", DbType.Int32, entidad.tipoEventoInstitucional.idTipoEventoInstitucional);
  183. if (entidad.organizador.Equals(null))
  184. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@idPersona", DbType.String, entidad.organizador.idPersona);
  185. if (ValidarFechaSQL(entidad.fecha))
  186. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@fecha", DbType.Date, entidad.fecha.ToShortDateString());
  187. if (ValidarFechaSQL(entidad.fechaDesde))
  188. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@fechaDesde", DbType.Date, entidad.fechaDesde.ToShortDateString());
  189. if (ValidarFechaSQL(entidad.fechaHasta))
  190. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@fechaHasta", DbType.Date, entidad.fechaHasta.ToShortDateString());
  191. if (entidad.hora != null)
  192. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@hora", DbType.Time, Convert.ToDateTime(String.Format("{0:HH:mm}",entidad.hora)).ToShortTimeString());
  193. if (!string.IsNullOrEmpty(entidad.lugar))
  194. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@lugar", DbType.String, entidad.lugar);
  195. if (!string.IsNullOrEmpty(entidad.titulo))
  196. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@titulo", DbType.String, entidad.titulo);
  197. if (!string.IsNullOrEmpty(entidad.detalle))
  198. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@detalle", DbType.String, entidad.detalle);
  199. if (entidad.activo)
  200. Transaction.DataBase.AddInParameter(Transaction.DBcomand, "@activo", DbType.String, entidad.activo);
  201. }
  202. IDataReader reader = Transaction.DataBase.ExecuteReader(Transaction.DBcomand);
  203. List<EventoInstitucional> listEventoInstitucional = new List<EventoInstitucional>();
  204. EventoInstitucional objEvento;
  205. while (reader.Read())
  206. {
  207. objEvento = new EventoInstitucional();
  208. objEvento.idEventoInstitucional = Convert.ToInt32(reader["idEventoInstitucional"]);
  209. objEvento.fecha = Convert.ToDateTime(reader["fecha"].ToString());
  210. if (!string.IsNullOrEmpty(reader["hora"].ToString()))
  211. objEvento.hora = Convert.ToDateTime(reader["hora"].ToString());
  212. objEvento.lugar = reader["lugar"].ToString();
  213. objEvento.tipoEventoInstitucional = new TipoEventoInstitucional();
  214. {
  215. objEvento.tipoEventoInstitucional.idTipoEventoInstitucional = Convert.ToInt32(reader["idTipoEvento"]);
  216. objEvento.tipoEventoInstitucional.descripcion = reader["tipoEvento"].ToString();
  217. }
  218. objEvento.organizador = new Persona();
  219. {
  220. objEvento.organizador.idPersona = Convert.ToInt32(reader["idPersona"]);
  221. objEvento.organizador.nombre = reader["nombreOrganizador"].ToString();
  222. objEvento.organizador.apellido = reader["apellidoOrganizador"].ToString();
  223. }
  224. objEvento.titulo = reader["titulo"].ToString();
  225. objEvento.detalle = reader["detalle"].ToString();
  226. objEvento.activo = (bool)(reader["activo"]);
  227. listEventoInstitucional.Add(objEvento);
  228. }
  229. return listEventoInstitucional;
  230. }
  231. catch (SqlException ex)
  232. {
  233. throw new CustomizedException(string.Format("Fallo en {0} - GetEventoInstitucional()", ClassName),
  234. ex, enuExceptionType.SqlException);
  235. }
  236. catch (Exception ex)
  237. {
  238. throw new CustomizedException(string.Format("Fallo en {0} - GetEventoInstitucional()", ClassName),
  239. ex, enuExceptionType.DataAccesException);
  240. }
  241. }
  242. #endregion
  243. }
  244. }