//Metodo para grebar en bd el tiempo de ocio y de Anti Procrastine public void SetTime(int OcioTime, int APTime) { try { using (Model.AntiProcrastineEntities db = new Model.AntiProcrastineEntities()) { Model.AntiP AP = db.AntiP.First(); AP.OcioTime = OcioTime; AP.APTime = APTime; db.Entry(AP).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); var e = new AjusteEventArgs(); e.OcioTime = OcioTime; e.APTime = APTime; ChangePreset(this, e); } } //cath para saber sobre error en Entity Framework catch (DbEntityValidationException ex) { StringBuilder sb = new StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } throw new DbEntityValidationException( "Entity Validation Failed - errors follow:\n" + sb.ToString(), ex ); // Add the original exception as the innerException } catch (Exception ex) { string Error = ex.Message; } }
//Evento que se ejecuta cuando se cambian los valores del preset private void Ajuste_ChangePreset(object sender, Admin.AjusteEventArgs e) { NumOcio.Value = e.OcioTime; NumAP.Value = e.APTime; }