/Docs/07-Implementacion/Source/trunk/EDUAR_actual/EDUAR/EDUAR_BusinessLogic/Common/BLFeriadosYFechasEspeciales.cs

http://blpm.googlecode.com/ · C# · 236 lines · 187 code · 21 blank · 28 comment · 19 complexity · 8ad122b6c0d78e7eddc021659fb23393 MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EDUAR_DataAccess.Common;
  6. using EDUAR_Entities;
  7. using EDUAR_BusinessLogic.Shared;
  8. using EDUAR_Entities.Shared;
  9. using EDUAR_Utility.Excepciones;
  10. using EDUAR_Utility.Enumeraciones;
  11. using EDUAR_DataAccess.Shared;
  12. namespace EDUAR_BusinessLogic.Common
  13. {
  14. public class BLFeriadosYFechasEspeciales : BusinessLogicBase<FeriadosYFechasEspeciales, DAFeriadosYFechasEspeciales>
  15. {
  16. #region --[Constante]--
  17. private const string ClassName = "BLFeriadosYFechasEspeciales";
  18. #endregion
  19. #region --[Constructores]--
  20. /// <summary>
  21. /// Constructor con DTO como parámetro.
  22. /// </summary>
  23. public BLFeriadosYFechasEspeciales(DTBase objFeriadosYFechasEspeciales)
  24. {
  25. Data = (FeriadosYFechasEspeciales)objFeriadosYFechasEspeciales;
  26. }
  27. /// <summary>
  28. /// Constructor vacio
  29. /// </summary>
  30. public BLFeriadosYFechasEspeciales()
  31. {
  32. Data = new FeriadosYFechasEspeciales();
  33. }
  34. #endregion
  35. #region --[Propiedades Override]--
  36. protected override sealed DAFeriadosYFechasEspeciales DataAcces
  37. {
  38. get { return dataAcces; }
  39. set { dataAcces = value; }
  40. }
  41. public override sealed FeriadosYFechasEspeciales Data
  42. {
  43. get { return data; }
  44. set { data = value; }
  45. }
  46. public override string FieldId
  47. {
  48. get { return DataAcces.FieldID; }
  49. }
  50. public override string FieldDescription
  51. {
  52. get { return DataAcces.FieldDescription; }
  53. }
  54. /// <summary>
  55. /// Gets the by id.
  56. /// </summary>
  57. public override void GetById()
  58. {
  59. try
  60. {
  61. Data = DataAcces.GetById(Data);
  62. }
  63. catch (CustomizedException ex)
  64. {
  65. throw ex;
  66. }
  67. catch (Exception ex)
  68. {
  69. throw new CustomizedException(string.Format("Fallo en {0} - GetById", ClassName), ex,
  70. enuExceptionType.BusinessLogicException);
  71. }
  72. }
  73. /// <summary>
  74. /// Método que guarda el registro actualmente cargado en memoria. No importa si se trata de una alta o modificación.
  75. /// </summary>
  76. public override void Save()
  77. {
  78. try
  79. {
  80. //Abre la transaccion que se va a utilizar
  81. DataAcces.Transaction.OpenTransaction();
  82. int idFeriadosYFechasEspeciales = 0;
  83. if (Data.idFeriado == 0)
  84. DataAcces.Create(Data, out idFeriadosYFechasEspeciales);
  85. else
  86. DataAcces.Update(Data);
  87. //Se da el OK para la transaccion.
  88. DataAcces.Transaction.CommitTransaction();
  89. }
  90. catch (CustomizedException ex)
  91. {
  92. if (DataAcces != null && DataAcces.Transaction != null)
  93. DataAcces.Transaction.RollbackTransaction();
  94. throw ex;
  95. }
  96. catch (Exception ex)
  97. {
  98. if (DataAcces != null && DataAcces.Transaction != null)
  99. DataAcces.Transaction.RollbackTransaction();
  100. throw new CustomizedException(string.Format("Fallo en {0} - Save()", ClassName), ex,
  101. enuExceptionType.BusinessLogicException);
  102. }
  103. }
  104. /// <summary>
  105. /// Método que guarda el registro actualmente cargado en memoria. No importa si se trata de una alta o modificación.
  106. /// </summary>
  107. public override void Save(DATransaction objDATransaction)
  108. {
  109. try
  110. {
  111. //Si no viene el Id es porque se esta creando la entidad
  112. DataAcces = new DAFeriadosYFechasEspeciales(objDATransaction);
  113. if (Data.idFeriado == 0)
  114. DataAcces.Create(Data);
  115. else
  116. {
  117. DataAcces.Update(Data);
  118. }
  119. }
  120. catch (CustomizedException ex)
  121. {
  122. throw ex;
  123. }
  124. catch (Exception ex)
  125. {
  126. throw new CustomizedException(string.Format("Fallo en {0} - Save()", ClassName), ex,
  127. enuExceptionType.BusinessLogicException);
  128. }
  129. }
  130. public override void Delete()
  131. {
  132. throw new NotImplementedException();
  133. }
  134. public override void Delete(DATransaction objDATransaction)
  135. {
  136. try
  137. {
  138. DataAcces = new DAFeriadosYFechasEspeciales(objDATransaction);
  139. DataAcces.Delete(Data);
  140. }
  141. catch (CustomizedException ex)
  142. {
  143. throw ex;
  144. }
  145. catch (Exception ex)
  146. {
  147. throw new CustomizedException(string.Format("Fallo en {0} - Delete()", ClassName), ex,
  148. enuExceptionType.BusinessLogicException);
  149. }
  150. }
  151. #endregion
  152. #region --[Métodos publicos]--
  153. /// <summary>
  154. /// Validars the fecha.
  155. /// </summary>
  156. /// <param name="fecha">The fecha.</param>
  157. /// <returns></returns>
  158. public bool ValidarFecha(DateTime fecha)
  159. {
  160. try
  161. {
  162. bool diaDisponible = DataAcces.ValidarFecha(fecha);
  163. if (!diaDisponible
  164. || (fecha.Date.DayOfWeek == DayOfWeek.Sunday || fecha.Date.DayOfWeek == DayOfWeek.Saturday))
  165. throw new CustomizedException(string.Format("La fecha seleccionada corresponde a un día feriado/no laborable", ClassName), null,
  166. enuExceptionType.ValidationException);
  167. return diaDisponible;
  168. }
  169. catch (CustomizedException ex)
  170. {
  171. throw ex;
  172. }
  173. catch (Exception ex)
  174. {
  175. throw new CustomizedException(string.Format("Fallo en {0} - GetFeriadosYFechasEspecialess", ClassName), ex,
  176. enuExceptionType.BusinessLogicException);
  177. }
  178. }
  179. /// <summary>
  180. /// Validars the hora (que sea en horario de funcionamiento del establecimiento educativo).
  181. /// </summary>
  182. /// <param name="hora">hora.</param>
  183. /// <returns></returns>
  184. public bool ValidarHora(DateTime hora)
  185. {
  186. bool retValue = false;
  187. DateTime horaDesde, horaHasta;
  188. try
  189. {
  190. horaDesde = DataAcces.getHorarioInicio();
  191. horaHasta = DataAcces.getHorarioFinalizacion();
  192. if (hora <= horaDesde || hora > horaHasta)
  193. {
  194. throw new CustomizedException(string.Format("El horario debe ser dentro de la franja horaria laborable desde las: " + horaDesde.Hour + ":" + horaDesde.Minute + "hs hasta las " + horaHasta.Hour + ":" + horaHasta.Minute + "hs.", ClassName), null,
  195. enuExceptionType.ValidationException);
  196. }
  197. else
  198. {
  199. retValue = true;
  200. }
  201. }
  202. catch (CustomizedException ex)
  203. {
  204. throw ex;
  205. }
  206. catch (Exception ex)
  207. {
  208. throw new CustomizedException(string.Format("Fallo en {0} - GetFeriadosYFechasEspecialess", ClassName), ex,
  209. enuExceptionType.BusinessLogicException);
  210. }
  211. return (retValue);
  212. }
  213. #endregion
  214. }
  215. }