示例#1
0
        protected void gridUsuarios_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 Usuario_ID = Convert.ToInt32(gridUsuarios.DataKeys[e.RowIndex].Value);

            using (bonisoftEntities context = new bonisoftEntities())
            {
                usuario obj = context.usuarios.First(x => x.Usuario_ID == Usuario_ID);
                context.usuarios.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 usuario", obj.GetType().Name + ": " + obj.Usuario_ID, userID1, username);
                }
                catch (Exception ex)
                {
                    Global_Objects.Logs.AddErrorLog("Excepcion. Guardando log. ERROR:", className, methodName, ex.Message);
                }
                #endregion

                BindGrid();
                lblMessage.Text = "Borrado correctamente.";
            }
        }
示例#2
0
        protected void gridUsuarios_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  = gridUsuarios.FooterRow;
                TextBox     txb1 = row.FindControl("txbNew1") as TextBox;
                TextBox     txb2 = row.FindControl("txbNew2") as TextBox;
                CheckBox    chk  = row.FindControl("chkNew") as CheckBox;
                if (txb1 != null && txb2 != null && chk != null)
                {
                    using (bonisoftEntities context = new bonisoftEntities())
                    {
                        usuario obj = new usuario();
                        obj.Usuario1 = txb1.Text;
                        obj.Clave    = txb2.Text;
                        obj.EsAdmin  = chk.Checked;

                        context.usuarios.Add(obj);
                        context.SaveChanges();

                        #region Guardar log
                        try
                        {
                            int     id       = 1;
                            usuario usuario1 = (usuario)context.usuarios.OrderByDescending(p => p.Usuario_ID).FirstOrDefault();
                            if (usuario1 != null)
                            {
                                id = usuario1.Usuario_ID;
                            }

                            string userID1  = HttpContext.Current.Session["UserID"].ToString();
                            string username = HttpContext.Current.Session["UserName"].ToString();
                            Global_Objects.Logs.AddUserLog("Agrega variedad", usuario1.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();
                    }
                }
            }
        }
示例#3
0
        protected void gridUsuarios_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  = gridUsuarios.Rows[e.RowIndex];
            TextBox     txb1 = row.FindControl("txb1") as TextBox;
            TextBox     txb2 = row.FindControl("txb2") as TextBox;
            CheckBox    chk  = row.FindControl("chk1") as CheckBox;

            if (txb1 != null && txb2 != null && chk != null)
            {
                using (bonisoftEntities context = new bonisoftEntities())
                {
                    int     Usuario_ID = Convert.ToInt32(gridUsuarios.DataKeys[e.RowIndex].Value);
                    usuario obj        = context.usuarios.First(x => x.Usuario_ID == Usuario_ID);
                    obj.Usuario1 = txb1.Text;
                    obj.Clave    = txb2.Text;
                    obj.EsAdmin  = chk.Checked;

                    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 usuario", obj.GetType().Name + ": " + obj.Usuario_ID, userID1, username);
                    }
                    catch (Exception ex)
                    {
                        Global_Objects.Logs.AddErrorLog("Excepcion. Guardando log. ERROR:", className, methodName, ex.Message);
                    }
                    #endregion

                    lblMessage.Text        = "Guardado correctamente.";
                    gridUsuarios.EditIndex = -1;
                    BindGrid();
                }
            }
        }