protected void gridCamiones_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_ID = Convert.ToInt32(gridCamiones.DataKeys[e.RowIndex].Value);

            using (bonisoftEntities context = new bonisoftEntities())
            {
                camion obj = context.camiones.First(x => x.Camion_ID == camion_ID);
                context.camiones.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 camión", obj.GetType().Name + ": " + obj.Camion_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
 public CamionViewModel(camion entity)
 {
     this.id          = entity.Id;
     this.title       = entity.title;
     this.detail      = entity.detail;
     this.price       = entity.price;
     this.date        = entity.date;
     this.customer_id = entity.customer_id;
     this.category_Id = entity.category_Id;
     this.resources   = entity.resources;
     this.marca       = entity.marca;
     this.anio        = entity.anio;
     this.kilometraje = entity.kilometraje;
     this.vin         = entity.vin;
     this.condicion   = entity.condicion;
     this.articleType = entity.GetType().BaseType.Name;
 }
        protected void gridCamiones_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            #region Updatepanel triggers

            ScriptManager ScriptManager1 = ScriptManager.GetCurrent(this.Page);
            if (ScriptManager1 != null)
            {
                LinkButton lnk = null;
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    lnk = e.Row.FindControl("lnkEdit") as LinkButton;
                    if (lnk != null)
                    {
                        ScriptManager1.RegisterAsyncPostBackControl(lnk);
                    }

                    lnk = e.Row.FindControl("lnkDelete") as LinkButton;
                    if (lnk != null)
                    {
                        ScriptManager1.RegisterAsyncPostBackControl(lnk);
                    }

                    lnk = e.Row.FindControl("lnkInsert") as LinkButton;
                    if (lnk != null)
                    {
                        ScriptManager1.RegisterAsyncPostBackControl(lnk);
                    }

                    lnk = e.Row.FindControl("lnkCancel") as LinkButton;
                    if (lnk != null)
                    {
                        ScriptManager1.RegisterAsyncPostBackControl(lnk);
                    }
                }
            }

            #endregion

            #region DDL Options

            DropDownList ddl = null;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ddl = e.Row.FindControl("ddlEjes1") as DropDownList;
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                ddl = e.Row.FindControl("ddlEjes2") as DropDownList;
            }
            if (ddl != null)
            {
                using (bonisoftEntities context = new bonisoftEntities())
                {
                    DataTable dt1 = new DataTable();
                    dt1 = Extras.ToDataTable(context.camion_ejes.ToList());

                    ddl.DataSource     = dt1;
                    ddl.DataTextField  = "Ejes";
                    ddl.DataValueField = "Camion_ejes_ID";
                    ddl.DataBind();
                    ddl.Items.Insert(0, new ListItem("Elegir", "0"));
                }
            }

            #endregion

            #region DDL Default values

            // Ejes ----------------------------------------------------
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                LinkButton lbl = e.Row.FindControl("lbl3") as LinkButton;
                if (lbl != null)
                {
                    using (bonisoftEntities context = new bonisoftEntities())
                    {
                        camion camion = (camion)(e.Row.DataItem);
                        if (camion != null)
                        {
                            int         id          = camion.Ejes_ID;
                            camion_ejes camion_ejes = (camion_ejes)context.camion_ejes.FirstOrDefault(c => c.Camion_ejes_ID == id);
                            if (camion_ejes != null)
                            {
                                string nombre = camion_ejes.Ejes;
                                lbl.Text            = nombre;
                                lbl.CommandArgument = "ejes," + nombre;
                            }
                        }
                    }
                }
            }

            #endregion DDL Default values
        }
        protected void gridCamiones_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      = gridCamiones.Rows[e.RowIndex];
            TextBox      txb1     = row.FindControl("txb1") as TextBox;
            TextBox      txb2     = row.FindControl("txb2") as TextBox;
            TextBox      txb6     = row.FindControl("txb6") as TextBox;
            TextBox      txb7     = row.FindControl("txb7") as TextBox;
            TextBox      txb9     = row.FindControl("txb9") as TextBox;
            DropDownList ddlEjes2 = row.FindControl("ddlEjes1") as DropDownList;

            if (txb1 != null && txb2 != null && txb6 != null && txb7 != null && txb9 != null && ddlEjes2 != null)
            {
                using (bonisoftEntities context = new bonisoftEntities())
                {
                    int    camion_ID = Convert.ToInt32(gridCamiones.DataKeys[e.RowIndex].Value);
                    camion obj       = context.camiones.First(x => x.Camion_ID == camion_ID);
                    obj.Matricula_camion = txb1.Text;
                    obj.Matricula_zorra  = txb2.Text;
                    obj.Marca            = txb6.Text;
                    obj.Comentarios      = txb9.Text;

                    decimal value = obj.Tara;
                    if (!decimal.TryParse(txb7.Text, out value))
                    {
                        value = obj.Tara;
                    }
                    obj.Tara = value;

                    #region DDL logic

                    int ddl1 = obj.Ejes_ID;
                    if (!int.TryParse(ddlEjes2.SelectedValue, out ddl1))
                    {
                        ddl1 = obj.Ejes_ID;
                    }
                    obj.Ejes_ID = ddl1;

                    #endregion

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

                    lblMessage.Text        = "Guardado correctamente.";
                    gridCamiones.EditIndex = -1;
                    BindGrid();
                }
            }
        }
        protected void gridCamiones_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      = gridCamiones.FooterRow;
                TextBox      txb1     = row.FindControl("txbNew1") as TextBox;
                TextBox      txb2     = row.FindControl("txbNew2") as TextBox;
                TextBox      txb6     = row.FindControl("txbNew6") as TextBox;
                TextBox      txb7     = row.FindControl("txbNew7") as TextBox;
                TextBox      txb9     = row.FindControl("txbNew9") as TextBox;
                DropDownList ddlEjes2 = row.FindControl("ddlEjes2") as DropDownList;
                if (txb1 != null && txb2 != null && txb6 != null && txb7 != null && txb9 != null && ddlEjes2 != null)
                {
                    using (bonisoftEntities context = new bonisoftEntities())
                    {
                        camion obj = new camion();
                        obj.Matricula_camion = txb1.Text;
                        obj.Matricula_zorra  = txb2.Text;
                        obj.Marca            = txb6.Text;
                        obj.Comentarios      = txb9.Text;

                        decimal value = 0;
                        if (!decimal.TryParse(txb7.Text, out value))
                        {
                            value = 0;
                        }
                        obj.Tara = value;

                        #region DDL logic

                        int ddl1 = 0;
                        if (!int.TryParse(ddlEjes2.SelectedValue, out ddl1))
                        {
                            ddl1 = 0;
                        }
                        obj.Ejes_ID = ddl1;

                        #endregion

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

                        #region Guardar log
                        try
                        {
                            int    id      = 1;
                            camion camion1 = (camion)context.camiones.OrderByDescending(p => p.Camion_ID).FirstOrDefault();
                            if (camion1 != null)
                            {
                                id = camion1.Camion_ID;
                            }

                            string userID1  = HttpContext.Current.Session["UserID"].ToString();
                            string username = HttpContext.Current.Session["UserName"].ToString();
                            Global_Objects.Logs.AddUserLog("Agrega camión", camion1.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 if (e.CommandName == "View")
            {
                string[] values = e.CommandArgument.ToString().Split(new char[] { ',' });
                if (values.Length > 1)
                {
                    string tabla = values[0];
                    string dato  = values[1];
                    if (!string.IsNullOrWhiteSpace(tabla) && !string.IsNullOrWhiteSpace(dato))
                    {
                        Response.Redirect("Listados.aspx?tabla=" + tabla + "&dato=" + dato);
                    }
                }
            }
        }