protected void gridTipos_RowDeleting(object sender, GridViewDeleteEventArgs e) { // Logger variables System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(true); System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame(); string className = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name; string methodName = stackFrame.GetMethod().Name; int lena_tipo_ID = Convert.ToInt32(gridTipos.DataKeys[e.RowIndex].Value); using (bonisoftEntities context = new bonisoftEntities()) { lena_tipo obj = context.lena_tipo.First(x => x.Lena_tipo_ID == lena_tipo_ID); context.lena_tipo.Remove(obj); context.SaveChanges(); #region Guardar log try { string userID1 = HttpContext.Current.Session["UserID"].ToString(); string username = HttpContext.Current.Session["UserName"].ToString(); Global_Objects.Logs.AddUserLog("Borra tipo de leña", obj.GetType().Name + ": " + obj.Lena_tipo_ID, userID1, username); } catch (Exception ex) { Global_Objects.Logs.AddErrorLog("Excepcion. Guardando log. ERROR:", className, methodName, ex.Message); } #endregion BindGrid(); lblMessage.Text = "Borrado correctamente."; } }
protected void gridTipos_RowCommand(object sender, GridViewCommandEventArgs e) { // Logger variables System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(true); System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame(); string className = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name; string methodName = stackFrame.GetMethod().Name; if (e.CommandName == "InsertNew") { GridViewRow row = gridTipos.FooterRow; TextBox txb1 = row.FindControl("txbNew1") as TextBox; TextBox txb2 = row.FindControl("txbNew2") as TextBox; if (txb1 != null && txb2 != null) { using (bonisoftEntities context = new bonisoftEntities()) { lena_tipo obj = new lena_tipo(); obj.Tipo = txb1.Text; obj.Comentarios = txb2.Text; context.lena_tipo.Add(obj); context.SaveChanges(); #region Guardar log try { int id = 1; lena_tipo lena_tipo1 = (lena_tipo)context.lena_tipo.OrderByDescending(p => p.Lena_tipo_ID).FirstOrDefault(); if (lena_tipo1 != null) { id = lena_tipo1.Lena_tipo_ID; } string userID1 = HttpContext.Current.Session["UserID"].ToString(); string username = HttpContext.Current.Session["UserName"].ToString(); Global_Objects.Logs.AddUserLog("Agrega tipo de leña", lena_tipo1.GetType().Name + ": " + id, userID1, username); } catch (Exception ex) { Global_Objects.Logs.AddErrorLog("Excepcion. Guardando log. ERROR:", className, methodName, ex.Message); } #endregion lblMessage.Text = "Agregado correctamente."; BindGrid(); } } } }
protected void gridTipos_RowUpdating(object sender, GridViewUpdateEventArgs e) { // Logger variables System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(true); System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame(); string className = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name; string methodName = stackFrame.GetMethod().Name; GridViewRow row = gridTipos.Rows[e.RowIndex]; TextBox txb1 = row.FindControl("txb1") as TextBox; TextBox txb2 = row.FindControl("txb2") as TextBox; if (txb1 != null && txb2 != null) { using (bonisoftEntities context = new bonisoftEntities()) { int lena_tipo_ID = Convert.ToInt32(gridTipos.DataKeys[e.RowIndex].Value); lena_tipo obj = context.lena_tipo.First(x => x.Lena_tipo_ID == lena_tipo_ID); obj.Tipo = txb1.Text; obj.Comentarios = txb2.Text; context.SaveChanges(); #region Guardar log try { string userID1 = HttpContext.Current.Session["UserID"].ToString(); string username = HttpContext.Current.Session["UserName"].ToString(); Global_Objects.Logs.AddUserLog("Modifica tipo de leña", obj.GetType().Name + ": " + obj.Lena_tipo_ID, userID1, username); } catch (Exception ex) { Global_Objects.Logs.AddErrorLog("Excepcion. Guardando log. ERROR:", className, methodName, ex.Message); } #endregion lblMessage.Text = "Guardado correctamente."; gridTipos.EditIndex = -1; BindGrid(); } } }