protected void gridProveedores_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 proveedor_ID = Convert.ToInt32(gridProveedores.DataKeys[e.RowIndex].Value); using (bonisoftEntities context = new bonisoftEntities()) { proveedor obj = context.proveedores.First(x => x.Proveedor_ID == proveedor_ID); context.proveedores.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 proveedor", obj.GetType().Name + ": " + obj.Proveedor_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 gridProveedores_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 = gridProveedores.Rows[e.RowIndex]; TextBox txb1 = row.FindControl("txb1") as TextBox; TextBox txb2 = row.FindControl("txb2") as TextBox; TextBox txb3 = row.FindControl("txb3") as TextBox; TextBox txb4 = row.FindControl("txb4") as TextBox; TextBox txb5 = row.FindControl("txb5") as TextBox; TextBox txb10 = row.FindControl("txb10") as TextBox; TextBox txb23 = row.FindControl("txb23") as TextBox; TextBox txb24 = row.FindControl("txb24") as TextBox; TextBox txb20 = row.FindControl("txb20") as TextBox; if (txb1 != null && txb2 != null && txb3 != null && txb4 != null && txb5 != null && txb10 != null && txb23 != null && txb24 != null && txb20 != null) { using (bonisoftEntities context = new bonisoftEntities()) { int proveedor_ID = Convert.ToInt32(gridProveedores.DataKeys[e.RowIndex].Value); proveedor obj = context.proveedores.First(x => x.Proveedor_ID == proveedor_ID); obj.Nombre = txb1.Text; obj.Razon_social = txb2.Text; obj.RUT = txb3.Text; obj.Direccion = txb4.Text; obj.Telefono = txb5.Text; obj.Comentarios = txb10.Text; obj.Email = txb23.Text; obj.Nro_cuenta = txb24.Text; obj.Depto = txb20.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 proveedor", obj.GetType().Name + ": " + obj.GetType().Name + ": " + obj.Proveedor_ID, userID1, username); } catch (Exception ex) { Global_Objects.Logs.AddErrorLog("Excepcion. Guardando log. ERROR:", className, methodName, ex.Message); } #endregion lblMessage.Text = "Guardado correctamente."; gridProveedores.EditIndex = -1; BindGrid(); } } }
protected void gridProveedores_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 = gridProveedores.FooterRow; TextBox txb1 = row.FindControl("txbNew1") as TextBox; TextBox txb2 = row.FindControl("txbNew2") as TextBox; TextBox txb3 = row.FindControl("txbNew3") as TextBox; TextBox txb4 = row.FindControl("txbNew4") as TextBox; TextBox txb5 = row.FindControl("txbNew5") as TextBox; TextBox txb10 = row.FindControl("txbNew10") as TextBox; TextBox txb23 = row.FindControl("txbNew23") as TextBox; TextBox txb24 = row.FindControl("txbNew24") as TextBox; TextBox txb20 = row.FindControl("txbNew20") as TextBox; if (txb1 != null && txb2 != null && txb3 != null && txb4 != null && txb5 != null && txb10 != null && txb23 != null && txb24 != null && txb20 != null) { using (bonisoftEntities context = new bonisoftEntities()) { proveedor obj = new proveedor(); obj.Nombre = txb1.Text; obj.Razon_social = txb2.Text; obj.RUT = txb3.Text; obj.Direccion = txb4.Text; obj.Telefono = txb5.Text; obj.Comentarios = txb10.Text; obj.Email = txb23.Text; obj.Nro_cuenta = txb24.Text; obj.Depto = txb20.Text; context.proveedores.Add(obj); context.SaveChanges(); #region Guardar log try { int id = 1; proveedor proveedor = (proveedor)context.proveedores.OrderByDescending(p => p.Proveedor_ID).FirstOrDefault(); if (proveedor != null) { id = proveedor.Proveedor_ID; } string userID1 = HttpContext.Current.Session["UserID"].ToString(); string username = HttpContext.Current.Session["UserName"].ToString(); Global_Objects.Logs.AddUserLog("Agrega proveedor", proveedor.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(); } } } else { //BindGrid(); } }