protected void gridChoferes_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 chofer_ID = Convert.ToInt32(gridChoferes.DataKeys[e.RowIndex].Value); using (bonisoftEntities context = new bonisoftEntities()) { chofer obj = context.choferes.First(x => x.Chofer_ID == chofer_ID); context.choferes.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 chofer", obj.GetType().Name + ": " + obj.Chofer_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 gridChoferes_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 = gridChoferes.Rows[e.RowIndex]; TextBox txb1 = row.FindControl("txb1") as TextBox; TextBox txb2 = row.FindControl("txb2") as TextBox; TextBox txb4 = row.FindControl("txb4") as TextBox; TextBox txb5 = row.FindControl("txb5") as TextBox; TextBox txb20 = row.FindControl("txb20") as TextBox; if (txb1 != null && txb2 != null && txb4 != null && txb5 != null && txb20 != null) { using (bonisoftEntities context = new bonisoftEntities()) { int chofer_ID = Convert.ToInt32(gridChoferes.DataKeys[e.RowIndex].Value); chofer obj = context.choferes.First(x => x.Chofer_ID == chofer_ID); obj.Nombre_completo = txb1.Text; obj.Telefono = txb5.Text; obj.Empresa = txb2.Text; obj.Comentarios = txb4.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 chofer", obj.GetType().Name + ": " + obj.Chofer_ID, userID1, username); } catch (Exception ex) { Global_Objects.Logs.AddErrorLog("Excepcion. Guardando log. ERROR:", className, methodName, ex.Message); } #endregion lblMessage.Text = "Guardado correctamente."; gridChoferes.EditIndex = -1; BindGrid(); } } }
public static void editarchofer() { try { editarchofer: Console.Clear(); Console.WriteLine("Introduzca el numero telefónico del chofer:"); long cellphn = Convert.ToInt64(Console.ReadLine()); chofer editchofer = new chofer(); foreach (chofer k in choferes) { if (cellphn == k.telefono) { choferes.Remove(k); Console.Write("Nombre del nuevo chofer: "); editchofer.nombre = Console.ReadLine(); Console.Write("Apellido del nuevo chofer: "); editchofer.apellido = Console.ReadLine(); Console.Write("Telefono del nuevo chofer: "); editchofer.telefono = Convert.ToInt64(Console.ReadLine()); choferes.Add(editchofer); mainmenu(); } else { Console.WriteLine("El número de Telefono es incorrecto. Toque Enter para volver a introducirla"); Console.ReadKey(); goto editarchofer; } } } catch (Exception mistake) { Console.WriteLine("ERROR. " + mistake.Message); Console.ReadKey(); mainmenu(); } }
//Metodos para el mantenimiento de choferes public static void agregarchofer() { try { Console.Clear(); chofer adddriver = new chofer(); Console.Clear(); Console.Write("Nombre del chofer: "); adddriver.nombre = Console.ReadLine(); Console.Write("Apellido del chofer: "); adddriver.apellido = Console.ReadLine(); Console.Write("Teléfono del chofer: "); adddriver.telefono = Convert.ToInt64(Console.ReadLine()); choferes.Add(adddriver); mainmenu(); } catch (Exception mistake) { Console.WriteLine(mistake.Message); Console.ReadKey(); mainmenu(); } }
protected void gridChoferes_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 = gridChoferes.FooterRow; TextBox txb1 = row.FindControl("txbNew1") as TextBox; TextBox txb2 = row.FindControl("txbNew2") as TextBox; TextBox txb4 = row.FindControl("txbNew4") as TextBox; TextBox txb5 = row.FindControl("txbNew5") as TextBox; TextBox txb20 = row.FindControl("txbNew20") as TextBox; if (txb1 != null && txb2 != null && txb4 != null && txb5 != null && txb20 != null) { using (bonisoftEntities context = new bonisoftEntities()) { chofer obj = new chofer(); obj.Nombre_completo = txb1.Text; obj.Telefono = txb5.Text; obj.Empresa = txb2.Text; obj.Comentarios = txb4.Text; obj.Depto = txb20.Text; context.choferes.Add(obj); context.SaveChanges(); #region Guardar log try { int id = 1; chofer chofer = (chofer)context.choferes.OrderByDescending(p => p.Chofer_ID).FirstOrDefault(); if (chofer != null) { id = chofer.Chofer_ID; } string userID1 = HttpContext.Current.Session["UserID"].ToString(); string username = HttpContext.Current.Session["UserName"].ToString(); Global_Objects.Logs.AddUserLog("Agrega chofer", chofer.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(); } }
public void AddChofer(chofer cho) { dc.chofers.InsertOnSubmit(cho); }