Guest User

Untitled

a guest
Dec 16th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. namespace PlanillaFvh
  6. {
  7. public class ClaseInsertar
  8. {
  9. public int IdAsignacionRegimenMaestro { get; set; }
  10. public int IdDia { get; set; }
  11. public DateTime Entrada1 { get; set; }
  12. public DateTime? Salida1 { get; set; }
  13. public DateTime? Entrada2 { get; set; }
  14. public DateTime Salida2 { get; set; }
  15. public int EditarHorario()
  16. {
  17. using (var fvhDb = new FvhContext.FvhDataContext())
  18. {
  19. var esIngresado = (from horario in fvhDb.Horarios
  20. where horario.IdAsignacionRegimenMaestro == IdAsignacionRegimenMaestro
  21. && horario.IdDia == IdDia
  22. select horario).FirstOrDefault();
  23.  
  24. if (esIngresado==null)
  25. {
  26. InsertarHorarioDia();
  27. return 1;
  28. }
  29. else
  30. {
  31. esIngresado.Entrada1 = Entrada1;
  32. esIngresado.Salida1 = Salida1;
  33. esIngresado.Entrada2 = Entrada2;
  34. esIngresado.Salida2 = Salida2;
  35. fvhDb.SubmitChanges();
  36. return 1;
  37. }
  38.  
  39.  
  40. }
  41.  
  42. }
  43. public int BorrarHorario()
  44. {
  45. using (var fvhDb = new FvhContext.FvhDataContext())
  46. {
  47. var delHor = (from horario in fvhDb.Horarios
  48. where
  49. horario.IdAsignacionRegimenMaestro == IdAsignacionRegimenMaestro &&
  50. horario.IdDia == IdDia
  51. select horario).FirstOrDefault();
  52. if(delHor!=null)
  53. fvhDb.Horarios.DeleteOnSubmit(delHor);
  54. return 1;
  55. }
  56.  
  57. }
  58.  
  59. public int InsertarHorarioDia()
  60. {
  61. using (var fvhDb = new FvhContext.FvhDataContext())
  62. {
  63. var esIngresado = from horario in fvhDb.Horarios
  64. where horario.IdAsignacionRegimenMaestro == IdAsignacionRegimenMaestro
  65. && horario.IdDia == IdDia
  66. select horario;
  67.  
  68. if (esIngresado.Count() != 0) return 0;
  69.  
  70. var nuevoHorario = new FvhEntity.Horario()
  71. {
  72. IdAsignacionRegimenMaestro = IdAsignacionRegimenMaestro,
  73. IdDia = IdDia,
  74. Entrada1 = Entrada1,
  75. Salida1 = Salida1,
  76. Entrada2 = Entrada2,
  77. Salida2 = Salida2
  78. };
  79. fvhDb.Horarios.InsertOnSubmit(nuevoHorario);
  80. fvhDb.SubmitChanges();
  81. return 1;
  82.  
  83. }
  84. }
  85. }
  86. public class Validacion: ClaseInsertar
  87. {
  88. public string TextEntrada1 { get; set; }
  89. public string TextSalida1 { get; set; }
  90. public string TextEntrada2 { get; set; }
  91. public string TextSalida2 { get; set; }
  92.  
  93. public int EditarValidar()
  94. {
  95. try
  96. {
  97. Entrada1 = Convert.ToDateTime(TextEntrada1);
  98. if (!string.IsNullOrEmpty(TextSalida1))
  99. {
  100. Salida1 = Convert.ToDateTime(TextSalida1);
  101. }
  102. else
  103. {
  104. Salida1 = null;
  105. }
  106. if (!string.IsNullOrEmpty((TextEntrada2)))
  107. {
  108. Entrada2 = Convert.ToDateTime(TextEntrada2);
  109.  
  110. }
  111. else
  112. {
  113. Entrada2 = null;
  114. }
  115. Salida2 = Convert.ToDateTime(TextSalida2);
  116. }
  117. catch (Exception)
  118. {
  119.  
  120. throw;
  121. }
  122. if (!string.IsNullOrEmpty(TextEntrada1) & !string.IsNullOrEmpty(TextSalida2))
  123. {
  124. if ((!string.IsNullOrEmpty(TextEntrada2) & (!string.IsNullOrEmpty(TextSalida1))))
  125. {
  126. return EditarHorario();
  127. }
  128. else
  129. {
  130. if (string.IsNullOrEmpty(TextEntrada2) & (string.IsNullOrEmpty(TextSalida1)))
  131. {
  132. return EditarHorario();
  133. }
  134. }
  135. }
  136. else
  137. {
  138. BorrarHorario();
  139. }
  140. return 0;
  141.  
  142. }
  143.  
  144. public int InsertarValidar()
  145. {
  146. try
  147. {
  148. if (!string.IsNullOrEmpty(TextEntrada1))
  149. Entrada1 = Convert.ToDateTime(TextEntrada1);
  150. if (!string.IsNullOrEmpty(TextSalida1))
  151. {
  152. Salida1 = Convert.ToDateTime(TextSalida1);
  153. }
  154. else
  155. {
  156. Salida1 = null;
  157. }
  158. if (!string.IsNullOrEmpty((TextEntrada2)))
  159. {
  160. Entrada2 = Convert.ToDateTime(TextEntrada2);
  161.  
  162. }
  163. else
  164. {
  165. Entrada2 = null;
  166. }
  167. if(!string.IsNullOrEmpty(TextSalida2))
  168. Salida2 = Convert.ToDateTime(TextSalida2);
  169. }
  170. catch (Exception)
  171. {
  172.  
  173. throw;
  174. }
  175. if (!string.IsNullOrEmpty(TextEntrada1) & !string.IsNullOrEmpty(TextSalida2))
  176. {
  177. if ((!string.IsNullOrEmpty(TextEntrada2)&(!string.IsNullOrEmpty(TextSalida1))))
  178. {
  179. return InsertarHorarioDia();
  180. }
  181. else
  182. {
  183. if (string.IsNullOrEmpty(TextEntrada2) & (string.IsNullOrEmpty(TextSalida1)))
  184. {
  185. return InsertarHorarioDia();
  186. }
  187. }
  188. }
  189. return 0;
  190. }
  191. }
  192. }
Add Comment
Please, Sign In to add comment