Guest User

Untitled

a guest
Dec 16th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Windows.Forms;
  8.  
  9.  
  10.  
  11. namespace PlanillaFvh
  12. {
  13. public partial class WebFormaIngresoHorarios : System.Web.UI.Page
  14. {
  15. public Boolean EsEdicion = false;
  16. protected void Page_Load(object sender, EventArgs e)
  17. {
  18. if (IsPostBack) return;
  19. LimpiarBloquearTextos();
  20. using (var fvhDb = new FvhContext.FvhDataContext())
  21. {
  22. MaestrosCombo.DataSource = fvhDb.Maestros;
  23. MaestrosCombo.DataTextField = @"Nombre";
  24. MaestrosCombo.DataValueField = @"IdMaestro";
  25. MaestrosCombo.DataBind();
  26. }
  27.  
  28.  
  29. }
  30.  
  31. protected void MaestrosComboSelectedIndexChanged(object sender, EventArgs e)
  32. {
  33.  
  34. using (var fvhDb = new FvhContext.FvhDataContext())
  35. {
  36. var listadosPorMaestro = from maestro in fvhDb.Maestros
  37. join asignacion in fvhDb.AsignacionRegimenMaestros on maestro.IdMaestro equals
  38. asignacion.IdMaestro
  39. where maestro.IdMaestro == Convert.ToInt32(MaestrosCombo.SelectedValue)
  40. join regimen in fvhDb.Regimens on asignacion.IdRegimen equals regimen.IdRegimen
  41. select new
  42. {
  43. asignacion.IdAsignacionRegimenMaestro,
  44. regimen.NombreRegimen,
  45. regimen.DiasDeRegimen,
  46. regimen.JornadasDeRegimen
  47. };
  48. //RegimenCombo.Items.Clear();
  49. RegimenCombo.DataSource = listadosPorMaestro;
  50. RegimenCombo.DataTextField = "NombreRegimen";
  51. RegimenCombo.DataValueField = "IdAsignacionRegimenMaestro";
  52. RegimenCombo.DataBind();
  53. }
  54.  
  55. }
  56.  
  57. public void LimpiarBloquearTextos()
  58. {
  59. LunesEn1.Text = "";
  60. LunesEn1.Enabled = false;
  61. LunesEn2.Text = "";
  62. LunesEn2.Enabled = false;
  63. LunesSa1.Text = "";
  64. LunesSa1.Enabled = false;
  65. LunesSa2.Text = "";
  66. LunesSa2.Enabled = false;
  67. MartesEn1.Text = "";
  68. MartesEn1.Enabled = false;
  69. MartesEn2.Text = "";
  70. MartesEn2.Enabled = false;
  71. MartesSa1.Text = "";
  72. MartesSa1.Enabled = false;
  73. MartesSa2.Text = "";
  74. MartesSa2.Enabled = false;
  75. MiercolesEn1.Text = "";
  76. MiercolesEn1.Enabled = false;
  77. MiercolesEn2.Text = "";
  78. MiercolesEn2.Enabled = false;
  79. MiercolesSa1.Text = "";
  80. MiercolesSa1.Enabled = false;
  81. MiercolesSa2.Text = "";
  82. MiercolesSa2.Enabled = false;
  83. JuevesEn1.Text = "";
  84. JuevesEn1.Enabled = false;
  85. JuevesEn2.Text = "";
  86. JuevesEn2.Enabled = false;
  87. JuevesSa1.Text = "";
  88. JuevesSa1.Enabled = false;
  89. JuevesSa2.Text = "";
  90. JuevesSa2.Enabled = false;
  91. ViernesEn1.Text = "";
  92. ViernesEn1.Enabled = false;
  93. ViernesEn2.Text = "";
  94. ViernesEn2.Enabled = false;
  95. ViernesSa1.Text = "";
  96. ViernesSa1.Enabled = false;
  97. ViernesSa2.Text = "";
  98. ViernesSa2.Enabled = false;
  99. SabadoEn1.Text = "";
  100. SabadoEn1.Enabled = false;
  101. SabadoEn2.Text = "";
  102. SabadoEn2.Enabled = false;
  103. SabadoSa1.Text = "";
  104. SabadoSa1.Enabled = false;
  105. SabadoSa2.Text = "";
  106. SabadoSa2.Enabled = false;
  107. GuardarBoton.Enabled = false;
  108.  
  109. }
  110.  
  111. public void HabilitarTextos()
  112. {
  113.  
  114. LunesEn1.Enabled = true;
  115. LunesEn2.Enabled = true;
  116. LunesSa1.Enabled = true;
  117. LunesSa2.Enabled = true;
  118. MartesEn1.Enabled = true;
  119. MartesEn2.Enabled = true;
  120. MartesSa1.Enabled = true;
  121. MartesSa2.Enabled = true;
  122. MiercolesEn1.Enabled = true;
  123. MiercolesEn2.Enabled = true;
  124. MiercolesSa1.Enabled = true;
  125. MiercolesSa2.Enabled = true;
  126. JuevesEn1.Enabled = true;
  127. JuevesEn2.Enabled = true;
  128. JuevesSa1.Enabled = true;
  129. JuevesSa2.Enabled = true;
  130. ViernesEn1.Enabled = true;
  131. ViernesEn2.Enabled = true;
  132. ViernesSa1.Enabled = true;
  133. ViernesSa2.Enabled = true;
  134. SabadoEn1.Enabled = true;
  135. SabadoEn2.Enabled = true;
  136. SabadoSa1.Enabled = true;
  137. SabadoSa2.Enabled = true;
  138. }
  139.  
  140. public void DeshabilitarTextos()
  141. {
  142. LunesEn1.Enabled = false;
  143. LunesEn2.Enabled = false;
  144. LunesSa1.Enabled = false;
  145. LunesSa2.Enabled = false;
  146. MartesEn1.Enabled = false;
  147. MartesEn2.Enabled = false;
  148. MartesSa1.Enabled = false;
  149. MartesSa2.Enabled = false;
  150. MiercolesEn1.Enabled = false;
  151. MiercolesEn2.Enabled = false;
  152. MiercolesSa1.Enabled = false;
  153. MiercolesSa2.Enabled = false;
  154. JuevesEn1.Enabled = false;
  155. JuevesEn2.Enabled = false;
  156. JuevesSa1.Enabled = false;
  157. JuevesSa2.Enabled = false;
  158. ViernesEn1.Enabled = false;
  159. ViernesEn2.Enabled = false;
  160. ViernesSa1.Enabled = false;
  161. ViernesSa2.Enabled = false;
  162. SabadoEn1.Enabled = false;
  163. SabadoEn2.Enabled = false;
  164. SabadoSa1.Enabled = false;
  165. SabadoSa2.Enabled = false;
  166. }
  167.  
  168. protected void BuscarBotonClick(object sender, EventArgs e)
  169. {
  170. if (Page.IsValid)
  171. {
  172. var abuscar =Convert.ToInt32(RegimenCombo.SelectedValue);
  173. using (var fvhDb = new FvhContext.FvhDataContext())
  174. {
  175. var horarios = from horario in fvhDb.Horarios
  176. join asignacion in fvhDb.AsignacionRegimenMaestros on horario.IdAsignacionRegimenMaestro
  177. equals asignacion.IdAsignacionRegimenMaestro
  178. join dia in fvhDb.Dias on horario.IdDia equals dia.IdDia
  179. where asignacion.IdAsignacionRegimenMaestro == abuscar
  180. select new
  181. {
  182. horario.Entrada1,
  183. horario.Salida1,
  184. horario.Entrada2,
  185. horario.Salida2,
  186. dia.NombreDia
  187. };
  188. if (horarios.Count() > 0)
  189. {
  190. EsEdicion = true;
  191. LimpiarBloquearTextos();
  192. var formato = "{0:D2}:{1:D2}";
  193. foreach (var horario in horarios)
  194. {
  195. if (string.Compare(horario.NombreDia.ToUpper(), @"LUNES") == 0)
  196. {
  197.  
  198. LunesEn1.Text = string.Format(formato,horario.Entrada1.Hour,horario.Entrada1.Minute);
  199. if (horario.Salida1.HasValue)
  200. LunesSa1.Text = string.Format(formato,horario.Salida1.Value.Hour,horario.Salida1.Value.Minute);
  201. if (horario.Entrada2.HasValue)
  202. LunesEn2.Text = string.Format(formato, horario.Entrada2.Value.Hour,
  203. horario.Entrada2.Value.Minute);
  204. LunesSa2.Text = string.Format(formato,horario.Salida2.Hour,horario.Salida2.Minute);
  205.  
  206. }
  207. if (string.Compare(horario.NombreDia.ToUpper(), @"MARTES") == 0)
  208. {
  209. MartesEn1.Text = string.Format(formato,horario.Entrada1.Hour,horario.Entrada1.Minute);
  210. if (horario.Salida1.HasValue)
  211. MartesSa1.Text = string.Format(formato,horario.Salida1.Value.Hour,horario.Salida1.Value.Minute);
  212. if (horario.Entrada2.HasValue)
  213. MartesEn2.Text = string.Format(formato, horario.Entrada2.Value.Hour,
  214. horario.Entrada2.Value.Minute);
  215. MartesSa2.Text = string.Format(formato,horario.Salida2.Hour,horario.Salida2.Minute);
  216. }
  217. if (string.Compare(horario.NombreDia.ToUpper(), @"MIERCOLES") == 0)
  218. {
  219. MiercolesEn1.Text = string.Format(formato,horario.Entrada1.Hour,horario.Entrada1.Minute);
  220. if (horario.Salida1.HasValue)
  221. MiercolesSa1.Text = string.Format(formato,horario.Salida1.Value.Hour,horario.Salida1.Value.Minute);
  222. if (horario.Entrada2.HasValue)
  223. MiercolesEn2.Text = string.Format(formato,horario.Entrada2.Value.Hour,horario.Entrada2.Value.Minute);
  224. MiercolesSa2.Text = string.Format(formato,horario.Salida2.Hour,horario.Salida2.Minute);
  225.  
  226. }
  227. if (string.Compare(horario.NombreDia.ToUpper(), @"JUEVES") == 0)
  228. {
  229. JuevesEn1.Text = string.Format(formato,horario.Entrada1.Hour,horario.Entrada1.Minute);
  230. if (horario.Salida1.HasValue)
  231. JuevesSa1.Text = string.Format(formato,horario.Salida1.Value.Hour,horario.Salida1.Value.Minute);
  232. if (horario.Entrada2.HasValue)
  233. JuevesEn2.Text = string.Format(formato, horario.Entrada2.Value.Hour,
  234. horario.Entrada2.Value.Minute);
  235. JuevesSa2.Text = string.Format(formato,horario.Salida2.Hour,horario.Salida2.Minute);
  236.  
  237. }
  238. if (string.Compare(horario.NombreDia.ToUpper(), @"VIERNES") == 0)
  239. {
  240. ViernesEn1.Text = string.Format(formato,horario.Entrada1.Hour,horario.Entrada1.Minute);
  241. if (horario.Salida1.HasValue)
  242. ViernesSa1.Text = string.Format(formato,horario.Salida1.Value.Hour,horario.Salida1.Value.Minute);
  243. if (horario.Entrada2.HasValue)
  244. ViernesEn2.Text = string.Format(formato, horario.Entrada2.Value.Hour,
  245. horario.Entrada2.Value.Minute);
  246. ViernesSa2.Text = string.Format(formato,horario.Salida2.Hour,horario.Salida2.Minute);
  247.  
  248. }
  249. if (string.Compare(horario.NombreDia.ToUpper(), @"SABADO") == 0)
  250. {
  251. SabadoEn1.Text = string.Format(formato,horario.Entrada1.Hour,horario.Entrada1.Minute);
  252. if (horario.Salida1.HasValue)
  253. SabadoSa1.Text = string.Format(formato,horario.Salida1.Value.Hour,horario.Salida1.Value.Minute);
  254. if (horario.Entrada2.HasValue)
  255. SabadoEn2.Text = string.Format(formato, horario.Entrada2.Value.Hour,
  256. horario.Entrada2.Value.Minute);
  257. SabadoSa2.Text = string.Format(formato,horario.Salida2.Hour,horario.Salida2.Minute);
  258.  
  259. }
  260. }
  261. //aqui va el messagebox
  262. if(MessageBox.Show("Este horario ya existe, \n ¿desea editarlo?","Planilla Fvh",MessageBoxButtons.YesNo)==DialogResult.Yes)
  263. {
  264. GuardarBoton.Enabled = true;
  265. EsEdicion = true;
  266. HabilitarTextos();
  267. }
  268.  
  269. }
  270. else
  271. {
  272. EsEdicion = false;
  273. GuardarBoton.Enabled = true;
  274. HabilitarTextos();
  275. }
  276. }
  277. }
  278. }
  279.  
  280. protected void GuardarBotonClick(object sender, EventArgs e)
  281. {
  282. var nuevoHorario = new Validacion();
  283. nuevoHorario.IdAsignacionRegimenMaestro = Convert.ToInt32(RegimenCombo.SelectedValue);
  284. var validos = 0;
  285. if (!Page.IsValid) return;
  286. //dia lunes!
  287. nuevoHorario.IdDia = 1;
  288. nuevoHorario.TextEntrada1 = LunesEn1.Text;
  289. nuevoHorario.TextSalida1 = LunesSa1.Text;
  290. nuevoHorario.TextEntrada2 = LunesEn2.Text;
  291. nuevoHorario.TextSalida2 = LunesSa2.Text;
  292. if (EsEdicion)
  293. {
  294. validos = validos + nuevoHorario.EditarValidar();
  295. }
  296. else
  297. {
  298. validos = validos + nuevoHorario.InsertarValidar();
  299. }
  300. //dia martes!
  301. nuevoHorario.IdDia = 2;
  302. nuevoHorario.TextEntrada1 = MartesEn1.Text;
  303. nuevoHorario.TextSalida1 = MartesSa1.Text;
  304. nuevoHorario.TextEntrada2 = MartesEn2.Text;
  305. nuevoHorario.TextSalida2 = MartesSa2.Text;
  306. if (EsEdicion)
  307. {
  308. validos = validos + nuevoHorario.EditarValidar();
  309. }
  310. else
  311. {
  312. validos = validos + nuevoHorario.InsertarValidar();
  313. }
  314. //dia Miercoles!
  315. nuevoHorario.IdDia = 3;
  316. nuevoHorario.TextEntrada1 = MiercolesEn1.Text;
  317. nuevoHorario.TextSalida1 = MiercolesSa1.Text;
  318. nuevoHorario.TextEntrada2 = MiercolesEn2.Text;
  319. nuevoHorario.TextSalida2 = MiercolesSa2.Text;
  320. if (EsEdicion)
  321. {
  322. validos = validos + nuevoHorario.EditarValidar();
  323. }
  324. else
  325. {
  326. validos = validos + nuevoHorario.InsertarValidar();
  327. }
  328.  
  329. //dia Jueves!
  330. nuevoHorario.IdDia = 4;
  331. nuevoHorario.TextEntrada1 = JuevesEn1.Text;
  332. nuevoHorario.TextSalida1 = JuevesSa1.Text;
  333. nuevoHorario.TextEntrada2 = JuevesEn2.Text;
  334. nuevoHorario.TextSalida2 = JuevesSa2.Text;
  335. if (EsEdicion)
  336. {
  337. validos = validos + nuevoHorario.EditarValidar();
  338. }
  339. else
  340. {
  341. validos = validos + nuevoHorario.InsertarValidar();
  342. }
  343. //dia Viernes!
  344. nuevoHorario.IdDia = 5;
  345. nuevoHorario.TextEntrada1 = ViernesEn1.Text;
  346. nuevoHorario.TextSalida1 = ViernesSa1.Text;
  347. nuevoHorario.TextEntrada2 = ViernesEn2.Text;
  348. nuevoHorario.TextSalida2 = ViernesSa2.Text;
  349. if (EsEdicion)
  350. {
  351. validos = validos + nuevoHorario.EditarValidar();
  352. }
  353. else
  354. {
  355. validos = validos + nuevoHorario.InsertarValidar();
  356. }
  357. //dia Sabado!
  358. nuevoHorario.IdDia = 2;
  359. nuevoHorario.TextEntrada1 = SabadoEn1.Text;
  360. nuevoHorario.TextSalida1 = SabadoSa1.Text;
  361. nuevoHorario.TextEntrada2 = SabadoEn2.Text;
  362. nuevoHorario.TextSalida2 = SabadoSa2.Text;
  363. if (EsEdicion)
  364. {
  365. validos = validos + nuevoHorario.EditarValidar();
  366. }
  367. else
  368. {
  369. validos = validos + nuevoHorario.InsertarValidar();
  370. }
  371.  
  372.  
  373.  
  374. if (validos > 0)
  375. {
  376. MessageBox.Show("Se han ingresado correctamente " + validos.ToString() + " dias a su horario",
  377. "Sistema de Planilla");
  378.  
  379. }
  380. else
  381. {
  382. MessageBox.Show("No se ha podido ingresar ningun horario", "Sistema de Planillas");
  383. }
  384. }
  385.  
  386.  
  387. protected void RegimenComboSelectedIndexChanged(object sender, EventArgs e)
  388. {
  389. using (var fvhDb = new FvhContext.FvhDataContext())
  390. {
  391. var listadosPorMaestro = from maestro in fvhDb.Maestros
  392. join asignacion in fvhDb.AsignacionRegimenMaestros on maestro.IdMaestro equals
  393. asignacion.IdMaestro
  394. where maestro.IdMaestro == Convert.ToInt32(MaestrosCombo.SelectedValue)
  395. join regimen in fvhDb.Regimens on asignacion.IdRegimen equals regimen.IdRegimen
  396. select new
  397. {
  398. asignacion.IdAsignacionRegimenMaestro,
  399. regimen.NombreRegimen,
  400. regimen.DiasDeRegimen,
  401. regimen.JornadasDeRegimen
  402. };
  403. RegimenCombo.DataSource = listadosPorMaestro;
  404. RegimenCombo.DataTextField = "NombreRegimen";
  405. RegimenCombo.DataValueField = "IdAsignacionRegimenMaestro";
  406. RegimenCombo.DataBind();
  407. }
  408. }
  409. }
  410. }
Add Comment
Please, Sign In to add comment