Пример #1
0
        protected void gridCargadores_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 cargador_ID = Convert.ToInt32(gridCargadores.DataKeys[e.RowIndex].Value);

            using (bonisoftEntities context = new bonisoftEntities())
            {
                cargador obj = context.cargadores.First(x => x.Cargador_ID == cargador_ID);
                context.cargadores.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 cargador", obj.GetType().Name + ": " + obj.Cargador_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 gridCargadores_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  = gridCargadores.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;
                if (txb1 != null && txb2 != null && txb3 != null && txb4 != null)
                {
                    using (bonisoftEntities context = new bonisoftEntities())
                    {
                        cargador obj = new cargador();
                        obj.Nombre      = txb1.Text;
                        obj.Comentarios = txb2.Text;
                        obj.Direccion   = txb3.Text;
                        obj.Telefono    = txb4.Text;

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

                        #region Guardar log
                        try
                        {
                            int      id       = 1;
                            cargador cargador = (cargador)context.cargadores.OrderByDescending(p => p.Cargador_ID).FirstOrDefault();
                            if (cargador != null)
                            {
                                id = cargador.Cargador_ID;
                            }

                            string userID1  = HttpContext.Current.Session["UserID"].ToString();
                            string username = HttpContext.Current.Session["UserName"].ToString();
                            Global_Objects.Logs.AddUserLog("Agrega cargador", cargador.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();
            }
        }
Пример #3
0
        protected void gridCargadores_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  = gridCargadores.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;

            if (txb1 != null && txb2 != null && txb3 != null && txb4 != null)
            {
                using (bonisoftEntities context = new bonisoftEntities())
                {
                    int      cargador_ID = Convert.ToInt32(gridCargadores.DataKeys[e.RowIndex].Value);
                    cargador obj         = context.cargadores.First(x => x.Cargador_ID == cargador_ID);
                    obj.Nombre      = txb1.Text;
                    obj.Comentarios = txb2.Text;
                    obj.Direccion   = txb3.Text;
                    obj.Telefono    = txb4.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 cargador", obj.GetType().Name + ": " + obj.Cargador_ID, userID1, username);
                    }
                    catch (Exception ex)
                    {
                        Global_Objects.Logs.AddErrorLog("Excepcion. Guardando log. ERROR:", className, methodName, ex.Message);
                    }
                    #endregion

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