/CoreSESeguridad/Querys/TieneRestriccionAcceso/TieneRestriccionAccesoQryMd.cs

https://bitbucket.org/rjulietagarcia/estadisticas · C# · 245 lines · 240 code · 3 blank · 2 comment · 10 complexity · 48f3978e0a6c14c03de565b6d1280054 MD5 · raw file

  1. using System;
  2. using System.Text;
  3. using System.Globalization;
  4. using System.Data;
  5. using System.Data.Common;
  6. using System.Collections;
  7. using System.Runtime.InteropServices;
  8. using Mx.Com.Cimar.Supports.DataBases;
  9. using Mx.Gob.Nl.Educacion.Model;
  10. namespace Mx.Gob.Nl.Educacion.Querys
  11. {
  12. internal class TieneRestriccionAccesoQryMD
  13. {
  14. private TieneRestriccionAccesoQryDP tieneRestriccionAccesoQry = null;
  15. public TieneRestriccionAccesoQryMD(TieneRestriccionAccesoQryDP tieneRestriccionAccesoQry)
  16. {
  17. this.tieneRestriccionAccesoQry = tieneRestriccionAccesoQry;
  18. }
  19. protected static TieneRestriccionAccesoQryDP ReadRow(DbDataReader dr)
  20. {
  21. #region Read Row
  22. TieneRestriccionAccesoQryDP tieneRestriccionAccesoQry = new TieneRestriccionAccesoQryDP();
  23. tieneRestriccionAccesoQry.NiveleducacionId = dr.IsDBNull(0) ? 0 : dr.GetInt32(0);
  24. tieneRestriccionAccesoQry.Niveltrabajo = dr.IsDBNull(1) ? 0 : dr.GetInt32(1);
  25. tieneRestriccionAccesoQry.SostenimientoId = dr.IsDBNull(2) ? 0 : dr.GetInt32(2);
  26. tieneRestriccionAccesoQry.FechaInicio = dr.IsDBNull(3) ? "" : dr.GetDateTime(3).ToShortDateString();;
  27. tieneRestriccionAccesoQry.FechaFin = dr.IsDBNull(4) ? "" : dr.GetDateTime(4).ToShortDateString();;
  28. return tieneRestriccionAccesoQry;
  29. #endregion
  30. }
  31. public static Int64 Count(DbConnection con, DbTransaction tran)
  32. {
  33. Int64 resultado = 0;
  34. #region SQL Count TieneRestriccionAccesoQry
  35. DbCommand com = con.CreateCommand();
  36. String countTieneRestriccionAccesoQry = String.Format(CultureInfo.CurrentCulture,TieneRestriccionAcceso.TieneRestriccionAccesoQry.TieneRestriccionAccesoQryCount,"");
  37. com.CommandText = countTieneRestriccionAccesoQry;
  38. #endregion
  39. if (tran != null)
  40. {
  41. com.Transaction = tran;
  42. }
  43. try
  44. {
  45. resultado = Convert.ToInt64(com.ExecuteScalar().ToString());
  46. }
  47. catch (DbException ex)
  48. {
  49. LimpiaConsulta.LimpiaConsultas(con, com, tran, ex);
  50. #region Error Count TieneRestriccionAccesoQry
  51. System.Diagnostics.Debug.WriteLine(ex.Message);
  52. String errorCountTieneRestriccionAccesoQry = String.Format(CultureInfo.CurrentCulture,TieneRestriccionAcceso.TieneRestriccionAccesoQry.TieneRestriccionAccesoQryCount, "" );
  53. System.Diagnostics.Debug.WriteLine(errorCountTieneRestriccionAccesoQry);
  54. #endregion
  55. }
  56. return resultado;
  57. }
  58. public static TieneRestriccionAccesoQryDP[] List(DbConnection con, DbTransaction tran,
  59. Int64 startRowIndex, Int64 maximumRows)
  60. {
  61. #region SQL List TieneRestriccionAccesoQry
  62. ArrayList lista = new ArrayList();
  63. DbCommand com = con.CreateCommand();
  64. String listTieneRestriccionAccesoQry = String.Format(CultureInfo.CurrentCulture, TieneRestriccionAcceso.TieneRestriccionAccesoQry.TieneRestriccionAccesoQrySelect, "", ConstantesGlobales.IncluyeRows);
  65. listTieneRestriccionAccesoQry = listTieneRestriccionAccesoQry.Substring(6);
  66. String filtraList = String.Format(CultureInfo.CurrentCulture, ConstantesGlobales.TraeUnosRegistros,
  67. ConstantesGlobales.ParameterPrefix,
  68. listTieneRestriccionAccesoQry, "",
  69. (startRowIndex + maximumRows).ToString(),
  70. startRowIndex,
  71. maximumRows,
  72. "" // DISTINCT si es que aplica.
  73. );
  74. com.CommandText = filtraList;
  75. DbDataReader dr;
  76. #endregion
  77. #region Parametros Load TieneRestriccionAccesoQry
  78. Common.CreateParameter(com, String.Format("{0}RegPagina", ConstantesGlobales.ParameterPrefix), DbType.Int64, 0, ParameterDirection.Input, maximumRows);
  79. Common.CreateParameter(com, String.Format("{0}startRowIndex", ConstantesGlobales.ParameterPrefix), DbType.Int64, 0, ParameterDirection.Input, startRowIndex);
  80. #endregion
  81. if (tran != null)
  82. {
  83. com.Transaction = tran;
  84. }
  85. try
  86. {
  87. #region Lee la lista TieneRestriccionAccesoQry
  88. dr = com.ExecuteReader(CommandBehavior.Default);
  89. try
  90. {
  91. while (dr.Read())
  92. {
  93. lista.Add(ReadRow(dr));
  94. }
  95. }
  96. finally
  97. {
  98. dr.Close();
  99. }
  100. #endregion
  101. }
  102. catch (DbException ex)
  103. {
  104. LimpiaConsulta.LimpiaConsultas(con, com, tran, ex);
  105. #region Error Load Lista TieneRestriccionAccesoQry
  106. System.Diagnostics.Debug.WriteLine(ex.Message);
  107. String errorLoadListaTieneRestriccionAccesoQry = String.Format(CultureInfo.CurrentCulture,TieneRestriccionAcceso.TieneRestriccionAccesoQry.TieneRestriccionAccesoQrySelect, "" );
  108. System.Diagnostics.Debug.WriteLine(errorLoadListaTieneRestriccionAccesoQry);
  109. #endregion
  110. }
  111. return (TieneRestriccionAccesoQryDP[])lista.ToArray(typeof(TieneRestriccionAccesoQryDP));
  112. }
  113. public static Int64 CountForRestriccion(DbConnection con, DbTransaction tran, String aIdNiveleducacion, Int32 aNiveltrabajo, String aIdSostenimiento, String aFechaInicio, String aFechaFin)
  114. {
  115. Int64 resultado = 0;
  116. #region SQL CountForRestriccion TieneRestriccionAccesoQry
  117. DbCommand com = con.CreateCommand();
  118. String countTieneRestriccionAccesoQryForRestriccion = String.Format(CultureInfo.CurrentCulture,TieneRestriccionAcceso.TieneRestriccionAccesoQry.TieneRestriccionAccesoQryCount,"");
  119. countTieneRestriccionAccesoQryForRestriccion += " WHERE \n";
  120. String delimitador = "";
  121. countTieneRestriccionAccesoQryForRestriccion += String.Format(" {1} Id_NivelEducacion in ("+aIdNiveleducacion+ ")\n", Model.ConstantesGlobales.ParameterPrefix,
  122. delimitador);
  123. delimitador = " AND ";
  124. countTieneRestriccionAccesoQryForRestriccion += String.Format(" {1} NivelTrabajo = {0}Niveltrabajo\n", Model.ConstantesGlobales.ParameterPrefix,
  125. delimitador);
  126. delimitador = " AND ";
  127. countTieneRestriccionAccesoQryForRestriccion += String.Format(" {1} id_Sostenimiento in ("+aIdSostenimiento+")\n", Model.ConstantesGlobales.ParameterPrefix,
  128. delimitador);
  129. delimitador = " AND ";
  130. countTieneRestriccionAccesoQryForRestriccion += String.Format(" {1} Fecha_Inicio >= {0}FechaInicio\n", Model.ConstantesGlobales.ParameterPrefix,
  131. delimitador);
  132. delimitador = " AND ";
  133. countTieneRestriccionAccesoQryForRestriccion += String.Format(" {1} Fecha_Fin <= {0}FechaFin\n", Model.ConstantesGlobales.ParameterPrefix,
  134. delimitador);
  135. delimitador = " AND ";
  136. com.CommandText = countTieneRestriccionAccesoQryForRestriccion;
  137. #endregion
  138. #region Parametros countTieneRestriccionAccesoQryForRestriccion
  139. // Common.CreateParameter(com, String.Format(CultureInfo.CurrentCulture,"{0}IdNiveleducacion",ConstantesGlobales.ParameterPrefix), DbType.Int32, 0, ParameterDirection.Input, aIdNiveleducacion);
  140. Common.CreateParameter(com, String.Format(CultureInfo.CurrentCulture,"{0}Niveltrabajo",ConstantesGlobales.ParameterPrefix), DbType.Int32, 0, ParameterDirection.Input, aNiveltrabajo);
  141. // Common.CreateParameter(com, String.Format(CultureInfo.CurrentCulture,"{0}IdSostenimiento",ConstantesGlobales.ParameterPrefix), DbType.Int32, 0, ParameterDirection.Input, aIdSostenimiento);
  142. Common.CreateParameter(com, String.Format(CultureInfo.CurrentCulture,"{0}FechaInicio",ConstantesGlobales.ParameterPrefix), DbType.DateTime, 0, ParameterDirection.Input, Convert.ToDateTime(DateTime.Now.ToShortDateString()));
  143. Common.CreateParameter(com, String.Format(CultureInfo.CurrentCulture, "{0}FechaFin", ConstantesGlobales.ParameterPrefix), DbType.DateTime, 0, ParameterDirection.Input, Convert.ToDateTime(DateTime.Now.ToShortDateString()));
  144. #endregion
  145. if (tran != null)
  146. {
  147. com.Transaction = tran;
  148. }
  149. try
  150. {
  151. resultado = Convert.ToInt64(com.ExecuteScalar().ToString());
  152. }
  153. catch (DbException ex)
  154. {
  155. LimpiaConsulta.LimpiaConsultas(con, com, tran, ex);
  156. #region Error CountForRestriccion TieneRestriccionAccesoQry
  157. System.Diagnostics.Debug.WriteLine(ex.Message);
  158. String errorCountTieneRestriccionAccesoQryForRestriccion = String.Format(CultureInfo.CurrentCulture,TieneRestriccionAcceso.TieneRestriccionAccesoQry.TieneRestriccionAccesoQryCount, "" );
  159. System.Diagnostics.Debug.WriteLine(errorCountTieneRestriccionAccesoQryForRestriccion);
  160. #endregion
  161. }
  162. return resultado;
  163. }
  164. public static TieneRestriccionAccesoQryDP[] ListForRestriccion(DbConnection con, DbTransaction tran,
  165. Int64 startRowIndex, Int64 maximumRows, Int32 aIdNiveleducacion, Int32 aNiveltrabajo, Int32 aIdSostenimiento, String aFechaInicio, String aFechaFin)
  166. {
  167. #region SQL List TieneRestriccionAccesoQry
  168. ArrayList lista = new ArrayList();
  169. DbCommand com = con.CreateCommand();
  170. String listTieneRestriccionAccesoQryForRestriccion = String.Format(CultureInfo.CurrentCulture, TieneRestriccionAcceso.TieneRestriccionAccesoQry.TieneRestriccionAccesoQrySelect, "", ConstantesGlobales.IncluyeRows);
  171. listTieneRestriccionAccesoQryForRestriccion = listTieneRestriccionAccesoQryForRestriccion.Substring(6);
  172. listTieneRestriccionAccesoQryForRestriccion += " WHERE \n";
  173. String delimitador = "";
  174. listTieneRestriccionAccesoQryForRestriccion += String.Format(" {1} Id_NivelEducacion = {0}IdNiveleducacion\n", Model.ConstantesGlobales.ParameterPrefix,
  175. delimitador);
  176. delimitador = " AND ";
  177. listTieneRestriccionAccesoQryForRestriccion += String.Format(" {1} NivelTrabajo = {0}Niveltrabajo\n", Model.ConstantesGlobales.ParameterPrefix,
  178. delimitador);
  179. delimitador = " AND ";
  180. listTieneRestriccionAccesoQryForRestriccion += String.Format(" {1} id_Sostenimiento = {0}IdSostenimiento\n", Model.ConstantesGlobales.ParameterPrefix,
  181. delimitador);
  182. delimitador = " AND ";
  183. listTieneRestriccionAccesoQryForRestriccion += String.Format(" {1} Fecha_Inicio = {0}FechaInicio\n", Model.ConstantesGlobales.ParameterPrefix,
  184. delimitador);
  185. delimitador = " AND ";
  186. listTieneRestriccionAccesoQryForRestriccion += String.Format(" {1} Fecha_Fin = {0}FechaFin\n", Model.ConstantesGlobales.ParameterPrefix,
  187. delimitador);
  188. delimitador = " AND ";
  189. String filtraList = String.Format(CultureInfo.CurrentCulture, ConstantesGlobales.TraeUnosRegistros,
  190. ConstantesGlobales.ParameterPrefix,
  191. listTieneRestriccionAccesoQryForRestriccion, "",
  192. (startRowIndex + maximumRows).ToString(),
  193. startRowIndex,
  194. maximumRows,
  195. "" // DISTINCT si es que aplica.
  196. );
  197. com.CommandText = filtraList;
  198. DbDataReader dr;
  199. #endregion
  200. #region Parametros Load TieneRestriccionAccesoQry
  201. Common.CreateParameter(com, String.Format("{0}RegPagina", ConstantesGlobales.ParameterPrefix), DbType.Int64, 0, ParameterDirection.Input, maximumRows);
  202. Common.CreateParameter(com, String.Format("{0}startRowIndex", ConstantesGlobales.ParameterPrefix), DbType.Int64, 0, ParameterDirection.Input, startRowIndex);
  203. Common.CreateParameter(com, String.Format(CultureInfo.CurrentCulture,"{0}IdNiveleducacion",ConstantesGlobales.ParameterPrefix), DbType.Int32, 0, ParameterDirection.Input, aIdNiveleducacion);
  204. Common.CreateParameter(com, String.Format(CultureInfo.CurrentCulture,"{0}Niveltrabajo",ConstantesGlobales.ParameterPrefix), DbType.Int32, 0, ParameterDirection.Input, aNiveltrabajo);
  205. Common.CreateParameter(com, String.Format(CultureInfo.CurrentCulture,"{0}IdSostenimiento",ConstantesGlobales.ParameterPrefix), DbType.Int32, 0, ParameterDirection.Input, aIdSostenimiento);
  206. Common.CreateParameter(com, String.Format(CultureInfo.CurrentCulture,"{0}FechaInicio",ConstantesGlobales.ParameterPrefix), DbType.DateTime, 0, ParameterDirection.Input, DateTime.Parse(aFechaInicio,CultureInfo.CurrentCulture));
  207. Common.CreateParameter(com, String.Format(CultureInfo.CurrentCulture,"{0}FechaFin",ConstantesGlobales.ParameterPrefix), DbType.DateTime, 0, ParameterDirection.Input, DateTime.Parse(aFechaFin,CultureInfo.CurrentCulture));
  208. #endregion
  209. if (tran != null)
  210. {
  211. com.Transaction = tran;
  212. }
  213. try
  214. {
  215. #region Lee la lista TieneRestriccionAccesoQry
  216. dr = com.ExecuteReader(CommandBehavior.Default);
  217. try
  218. {
  219. while (dr.Read())
  220. {
  221. lista.Add(ReadRow(dr));
  222. }
  223. }
  224. finally
  225. {
  226. dr.Close();
  227. }
  228. #endregion
  229. }
  230. catch (DbException ex)
  231. {
  232. LimpiaConsulta.LimpiaConsultas(con, com, tran, ex);
  233. #region Error Load Lista TieneRestriccionAccesoQry
  234. System.Diagnostics.Debug.WriteLine(ex.Message);
  235. String errorLoadListaTieneRestriccionAccesoQry = String.Format(CultureInfo.CurrentCulture,TieneRestriccionAcceso.TieneRestriccionAccesoQry.TieneRestriccionAccesoQrySelect, "" );
  236. System.Diagnostics.Debug.WriteLine(errorLoadListaTieneRestriccionAccesoQry);
  237. #endregion
  238. }
  239. return (TieneRestriccionAccesoQryDP[])lista.ToArray(typeof(TieneRestriccionAccesoQryDP));
  240. }
  241. }
  242. }