Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace PlanillaFvh
- {
- public class ClaseInsertar
- {
- public int IdAsignacionRegimenMaestro { get; set; }
- public int IdDia { get; set; }
- public DateTime Entrada1 { get; set; }
- public DateTime? Salida1 { get; set; }
- public DateTime? Entrada2 { get; set; }
- public DateTime Salida2 { get; set; }
- public int EditarHorario()
- {
- using (var fvhDb = new FvhContext.FvhDataContext())
- {
- var esIngresado = (from horario in fvhDb.Horarios
- where horario.IdAsignacionRegimenMaestro == IdAsignacionRegimenMaestro
- && horario.IdDia == IdDia
- select horario).FirstOrDefault();
- if (esIngresado==null)
- {
- InsertarHorarioDia();
- return 1;
- }
- else
- {
- esIngresado.Entrada1 = Entrada1;
- esIngresado.Salida1 = Salida1;
- esIngresado.Entrada2 = Entrada2;
- esIngresado.Salida2 = Salida2;
- fvhDb.SubmitChanges();
- return 1;
- }
- }
- }
- public int BorrarHorario()
- {
- using (var fvhDb = new FvhContext.FvhDataContext())
- {
- var delHor = (from horario in fvhDb.Horarios
- where
- horario.IdAsignacionRegimenMaestro == IdAsignacionRegimenMaestro &&
- horario.IdDia == IdDia
- select horario).FirstOrDefault();
- if(delHor!=null)
- fvhDb.Horarios.DeleteOnSubmit(delHor);
- return 1;
- }
- }
- public int InsertarHorarioDia()
- {
- using (var fvhDb = new FvhContext.FvhDataContext())
- {
- var esIngresado = from horario in fvhDb.Horarios
- where horario.IdAsignacionRegimenMaestro == IdAsignacionRegimenMaestro
- && horario.IdDia == IdDia
- select horario;
- if (esIngresado.Count() != 0) return 0;
- var nuevoHorario = new FvhEntity.Horario()
- {
- IdAsignacionRegimenMaestro = IdAsignacionRegimenMaestro,
- IdDia = IdDia,
- Entrada1 = Entrada1,
- Salida1 = Salida1,
- Entrada2 = Entrada2,
- Salida2 = Salida2
- };
- fvhDb.Horarios.InsertOnSubmit(nuevoHorario);
- fvhDb.SubmitChanges();
- return 1;
- }
- }
- }
- public class Validacion: ClaseInsertar
- {
- public string TextEntrada1 { get; set; }
- public string TextSalida1 { get; set; }
- public string TextEntrada2 { get; set; }
- public string TextSalida2 { get; set; }
- public int EditarValidar()
- {
- try
- {
- Entrada1 = Convert.ToDateTime(TextEntrada1);
- if (!string.IsNullOrEmpty(TextSalida1))
- {
- Salida1 = Convert.ToDateTime(TextSalida1);
- }
- else
- {
- Salida1 = null;
- }
- if (!string.IsNullOrEmpty((TextEntrada2)))
- {
- Entrada2 = Convert.ToDateTime(TextEntrada2);
- }
- else
- {
- Entrada2 = null;
- }
- Salida2 = Convert.ToDateTime(TextSalida2);
- }
- catch (Exception)
- {
- throw;
- }
- if (!string.IsNullOrEmpty(TextEntrada1) & !string.IsNullOrEmpty(TextSalida2))
- {
- if ((!string.IsNullOrEmpty(TextEntrada2) & (!string.IsNullOrEmpty(TextSalida1))))
- {
- return EditarHorario();
- }
- else
- {
- if (string.IsNullOrEmpty(TextEntrada2) & (string.IsNullOrEmpty(TextSalida1)))
- {
- return EditarHorario();
- }
- }
- }
- else
- {
- BorrarHorario();
- }
- return 0;
- }
- public int InsertarValidar()
- {
- try
- {
- if (!string.IsNullOrEmpty(TextEntrada1))
- Entrada1 = Convert.ToDateTime(TextEntrada1);
- if (!string.IsNullOrEmpty(TextSalida1))
- {
- Salida1 = Convert.ToDateTime(TextSalida1);
- }
- else
- {
- Salida1 = null;
- }
- if (!string.IsNullOrEmpty((TextEntrada2)))
- {
- Entrada2 = Convert.ToDateTime(TextEntrada2);
- }
- else
- {
- Entrada2 = null;
- }
- if(!string.IsNullOrEmpty(TextSalida2))
- Salida2 = Convert.ToDateTime(TextSalida2);
- }
- catch (Exception)
- {
- throw;
- }
- if (!string.IsNullOrEmpty(TextEntrada1) & !string.IsNullOrEmpty(TextSalida2))
- {
- if ((!string.IsNullOrEmpty(TextEntrada2)&(!string.IsNullOrEmpty(TextSalida1))))
- {
- return InsertarHorarioDia();
- }
- else
- {
- if (string.IsNullOrEmpty(TextEntrada2) & (string.IsNullOrEmpty(TextSalida1)))
- {
- return InsertarHorarioDia();
- }
- }
- }
- return 0;
- }
- }
- }
Add Comment
Please, Sign In to add comment