Ejemplo n.º 1
0
 /// <summary>  Inicializa el registro con las horas a null, en el caso que no este inicializado</summary>
 private void inicializarRegistro()
 {
     using (var db = new ContextoBBDD())
     {
         fichaje = db.Fichar.Where(x => x.UserID == UserLoginCache.Id && x.dia == DateTime.Today).FirstOrDefault();
         if (fichaje == null)
         {
             fichaje           = new FicharModel();
             fichaje.UserID    = UserLoginCache.Id;
             fichaje.horarioID = 1;
             fichaje.dia       = DateTime.Today;
             fichaje.warning   = 1;
             db.Fichar.Add(fichaje);
             db.SaveChanges();
             btn_entrar.IsEnabled  = true;
             btn_salir.IsEnabled   = false;
             btn_entrar.Background = Brushes.LightGreen;
             btn_salir.Background  = Brushes.Red;
         }
         else
         {
             if (fichaje.entrada1.TotalMilliseconds == 0)
             {
                 btn_entrar.IsEnabled  = true;
                 btn_salir.IsEnabled   = false;
                 btn_entrar.Background = Brushes.LightGreen;
                 btn_salir.Background  = Brushes.Red;
             }
             else if (fichaje.salida1.TotalMilliseconds == 0)
             {
                 btn_entrar.IsEnabled  = true;
                 btn_salir.IsEnabled   = false;
                 btn_entrar.Background = Brushes.LightGreen;
                 btn_salir.Background  = Brushes.Red;
             }
             else if (fichaje.entrada2.TotalMilliseconds == 0)
             {
                 btn_entrar.IsEnabled  = true;
                 btn_salir.IsEnabled   = false;
                 btn_entrar.Background = Brushes.LightGreen;
                 btn_salir.Background  = Brushes.Red;
             }
             else if (fichaje.salida2.TotalMilliseconds == 0)
             {
                 btn_entrar.IsEnabled  = true;
                 btn_salir.IsEnabled   = false;
                 btn_entrar.Background = Brushes.LightGreen;
                 btn_salir.Background  = Brushes.Red;
             }
             else
             {
                 btn_entrar.IsEnabled  = false;
                 btn_salir.IsEnabled   = false;
                 btn_entrar.Background = Brushes.Red;
                 btn_salir.Background  = Brushes.Red;
             }
         }
         horario = db.Horarios.Where(x => x.ID == fichaje.horarioID).FirstOrDefault();
     }
 }
Ejemplo n.º 2
0
        private void llenarHorarios()
        {
            HorariosModel HorariosBD = new HorariosModel();
            var           lista      = HorariosBD.Filtrar();

            foreach (Horarios horario in lista)
            {
                listBoxHorarios.Items.Add(horario);
            }

            listBoxHorarios.DisplayMember = "Horario";
            listBoxHorarios.ValueMember   = "Id";
            listBoxHorarios.SelectedIndex = 0;
        }
Ejemplo n.º 3
0
        private void btn_anadirHorario_Click(object sender, RoutedEventArgs e)
        {
            HorariosModel h = new HorariosModel();

            try
            {
                h = db.Horarios.Where(x => x.nombre == txt_nombre.Text).FirstOrDefault();
                if (h != null)
                {
                    txt_nombre.Background = Brushes.Red;
                    return;
                }
                h        = new HorariosModel();
                h.nombre = txt_nombre.Text;

                h.lunes     = cb_lunes.IsChecked.Value;
                h.martes    = cb_martes.IsChecked.Value;
                h.miercoles = cb_miercoles.IsChecked.Value;
                h.jueves    = cb_jueves.IsChecked.Value;
                h.viernes   = cb_viernes.IsChecked.Value;
                h.sabado    = cb_sabado.IsChecked.Value;
                h.domingo   = cb_domingo.IsChecked.Value;

                h.entrada1 = stringAHora(txt_entrada1.Text);
                h.salida1  = stringAHora(txt_salida1.Text);
                h.entrada2 = stringAHora(txt_entrada2.Text);
                h.salida2  = stringAHora(txt_salida2.Text);

                if ((h.salida1 - h.entrada1) + (h.salida2 - h.entrada2) >= stringAHora("08:00"))
                {
                    h.jornadaCompleta = true;
                }

                db.Horarios.Add(h);
                db.SaveChanges();
                //Una vez registrado limpiamos los textboxes
                txt_nombre.Text        = "";
                cb_lunes.IsChecked     = false;
                cb_martes.IsChecked    = false;
                cb_miercoles.IsChecked = false;
                cb_jueves.IsChecked    = false;
                cb_viernes.IsChecked   = false;
                cb_sabado.IsChecked    = false;
                cb_domingo.IsChecked   = false;
                txt_entrada1.Text      = "";
                txt_salida1.Text       = "";
                txt_entrada2.Text      = "";
                txt_salida2.Text       = "";
            }
            catch
            {
                if (h.entrada1 == null)
                {
                    txt_entrada1.Background = Brushes.Red;
                }
                else if (h.salida1 == null)
                {
                    txt_salida1.Background = Brushes.Red;
                }
                else if (h.entrada2 == null)
                {
                    txt_entrada2.Background = Brushes.Red;
                }
                else if (h.salida2 == null)
                {
                    txt_salida2.Background = Brushes.Red;
                }
            }
        }
Ejemplo n.º 4
0
 public frmHorarios()
 {
     InitializeComponent();
     HorariosBD   = new HorariosModel();
     NuevoHorario = new Horarios();
 }