protected void gridEjes_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 camion_ejes_ID = Convert.ToInt32(gridEjes.DataKeys[e.RowIndex].Value); using (bonisoftEntities context = new bonisoftEntities()) { camion_ejes obj = context.camion_ejes.First(x => x.Camion_ejes_ID == camion_ejes_ID); context.camion_ejes.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 ejes de camión", obj.GetType().Name + ": " + obj.Camion_ejes_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 gridEjes_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 = gridEjes.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()) { camion_ejes obj = new camion_ejes(); obj.Ejes = txb1.Text; obj.Comentarios = txb2.Text; context.camion_ejes.Add(obj); context.SaveChanges(); #region Guardar log try { int id = 1; camion_ejes camion_ejes1 = (camion_ejes)context.camion_ejes.OrderByDescending(p => p.Camion_ejes_ID).FirstOrDefault(); if (camion_ejes1 != null) { id = camion_ejes1.Camion_ejes_ID; } string userID1 = HttpContext.Current.Session["UserID"].ToString(); string username = HttpContext.Current.Session["UserName"].ToString(); Global_Objects.Logs.AddUserLog("Agrega ejes de camión", camion_ejes1.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 gridEjes_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 = gridEjes.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 camion_ejes_ID = Convert.ToInt32(gridEjes.DataKeys[e.RowIndex].Value); camion_ejes obj = context.camion_ejes.First(x => x.Camion_ejes_ID == camion_ejes_ID); obj.Ejes = 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 ejes de camión", obj.GetType().Name + ": " + obj.Camion_ejes_ID, userID1, username); } catch (Exception ex) { Global_Objects.Logs.AddErrorLog("Excepcion. Guardando log. ERROR:", className, methodName, ex.Message); } #endregion lblMessage.Text = "Guardado correctamente."; gridEjes.EditIndex = -1; BindGrid(); } } }