protected void gridFormas_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 forma_de_pago_ID = Convert.ToInt32(gridFormas.DataKeys[e.RowIndex].Value); using (bonisoftEntities context = new bonisoftEntities()) { forma_de_pago obj = context.forma_de_pago.First(x => x.Forma_de_pago_ID == forma_de_pago_ID); context.forma_de_pago.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 formas de pago", obj.GetType().Name + ": " + obj.Forma_de_pago_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 gridFormas_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 = gridFormas.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()) { forma_de_pago obj = new forma_de_pago(); obj.Forma = txb1.Text; obj.Comentarios = txb2.Text; context.forma_de_pago.Add(obj); context.SaveChanges(); #region Guardar log try { int id = 1; forma_de_pago forma_de_pago1 = (forma_de_pago)context.forma_de_pago.OrderByDescending(p => p.Forma_de_pago_ID).FirstOrDefault(); if (forma_de_pago1 != null) { id = forma_de_pago1.Forma_de_pago_ID; } string userID1 = HttpContext.Current.Session["UserID"].ToString(); string username = HttpContext.Current.Session["UserName"].ToString(); Global_Objects.Logs.AddUserLog("Agrega forma de pago", obj.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 gridFormas_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 = gridFormas.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 forma_de_pago_ID = Convert.ToInt32(gridFormas.DataKeys[e.RowIndex].Value); forma_de_pago obj = context.forma_de_pago.First(x => x.Forma_de_pago_ID == forma_de_pago_ID); obj.Forma = 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 formas de pago", obj.GetType().Name + ": " + obj.Forma_de_pago_ID, userID1, username); } catch (Exception ex) { Global_Objects.Logs.AddErrorLog("Excepcion. Guardando log. ERROR:", className, methodName, ex.Message); } #endregion lblMessage.Text = "Guardado correctamente."; gridFormas.EditIndex = -1; BindGrid(); } } }