public static void AddUserLog(string message, string object_ID, string userID_str, string username) { // 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; using (bonisoftEntities context = new bonisoftEntities()) { log new_log = new log(); new_log.Fecha = DateTime.Now; new_log.Usuario = username; new_log.Descripcion = message; new_log.Dato = object_ID; int userID = 0; if (!int.TryParse(userID_str, out userID)) { userID = 0; AddErrorLog("Excepcion. Convirtiendo int. ERROR:", className, methodName, userID_str); } new_log.Usuario_ID = userID; context.logs.Add(new_log); context.SaveChanges(); } }
protected void gridTipos_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 lena_tipo_ID = Convert.ToInt32(gridTipos.DataKeys[e.RowIndex].Value); using (bonisoftEntities context = new bonisoftEntities()) { lena_tipo obj = context.lena_tipo.First(x => x.Lena_tipo_ID == lena_tipo_ID); context.lena_tipo.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 tipo de leña", obj.GetType().Name + ": " + obj.Lena_tipo_ID, userID1, username); } catch (Exception ex) { Global_Objects.Logs.AddErrorLog("Excepcion. Guardando log. ERROR:", className, methodName, ex.Message); } #endregion BindGrid(); lblMessage.Text = "Borrado correctamente."; } }
private void BindGrid() { using (bonisoftEntities context = new bonisoftEntities()) { hdnTiposCount.Value = context.lena_tipo.Count().ToString(); if (context.lena_tipo.Count() > 0) { gridTipos.DataSource = context.lena_tipo.ToList(); gridTipos.DataBind(); } else { var obj = new List <lena_tipo>(); obj.Add(new lena_tipo()); // Bind the DataTable which contain a blank row to the GridView gridTipos.DataSource = obj; gridTipos.DataBind(); int columnsCount = gridTipos.Columns.Count; gridTipos.Rows[0].Cells.Clear(); // clear all the cells in the row gridTipos.Rows[0].Cells.Add(new TableCell()); //add a new blank cell gridTipos.Rows[0].Cells[0].ColumnSpan = columnsCount; //set the column span to the new added cell //You can set the styles here gridTipos.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center; gridTipos.Rows[0].Cells[0].ForeColor = System.Drawing.Color.Red; gridTipos.Rows[0].Cells[0].Font.Bold = true; //set No Results found to the new added cell gridTipos.Rows[0].Cells[0].Text = "No hay registros"; } ScriptManager.RegisterStartupScript(this, typeof(Page), "updateCounts", "updateCounts();", true); } }
public static bool CheckUserAdmin(string userID_str) { // 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; bool isAdmin = false; using (bonisoftEntities context = new bonisoftEntities()) { if (!string.IsNullOrWhiteSpace(userID_str)) { int userID = 0; if (!int.TryParse(userID_str, out userID)) { userID = 0; Global_Objects.Logs.AddErrorLog("Excepcion. Convirtiendo int. ERROR:", className, methodName, userID_str); //Global_Objects.ErrorLog.AddErrorLog("Excepcion. Convirtiendo int. ERROR:", className, methodName, e.Message); } if (userID > 0) { usuario usuario = (usuario)context.usuarios.FirstOrDefault(v => v.Usuario_ID == userID); if (usuario != null) { isAdmin = usuario.EsAdmin; } } } } return(isAdmin); }
protected void gridProcesadores_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 = gridProcesadores.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()) { procesador obj = new procesador(); obj.Nombre = txb1.Text; obj.Comentarios = txb2.Text; obj.Direccion = txb3.Text; obj.Telefono = txb4.Text; context.procesadores.Add(obj); context.SaveChanges(); #region Guardar log try { int id = 1; procesador procesador = (procesador)context.procesadores.OrderByDescending(p => p.Procesador_ID).FirstOrDefault(); if (procesador != null) { id = procesador.Procesador_ID; } string userID1 = HttpContext.Current.Session["UserID"].ToString(); string username = HttpContext.Current.Session["UserName"].ToString(); Global_Objects.Logs.AddUserLog("Agrega procesador", procesador.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(); } }
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 gridClientes_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandArgument != null) { if (!string.IsNullOrWhiteSpace(e.CommandArgument.ToString()) && !string.IsNullOrWhiteSpace(e.CommandName)) { using (bonisoftEntities context = new bonisoftEntities()) { } } } }
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(); } } } }
private void Perform_login(string username, string password, bool isPasswordInput_hashed = false) { // 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; string exception_message = string.Empty; int resultado = 0; if (!string.IsNullOrWhiteSpace(username) || !string.IsNullOrWhiteSpace(password)) { using (bonisoftEntities context = new bonisoftEntities()) { try { context.Database.Connection.Open(); usuario usuario = (usuario)context.usuarios.FirstOrDefault(v => v.Usuario1 == username && v.Clave == password); if (usuario != null) { Session["UserID"] = usuario.Usuario_ID; Session["UserName"] = username; Response.Redirect("Pages/Viajes", false); } else { resultado = 2; } } catch (Exception ex) { Logs.AddErrorLog("Excepcion. Haciendo login. ERROR:", className, methodName, ex.Message); exception_message = ex.Message; resultado = 3; } } } else { resultado = 1; } ScriptManager.RegisterStartupScript(this, typeof(Page), "ShowErrorMessage", "ShowErrorMessage('" + resultado + "', '" + exception_message + "');", true); }
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(); } } }
private void BindGrid() { using (bonisoftEntities context = new bonisoftEntities()) { var elements = context.clientes.OrderBy(e => e.Nombre).ToList(); if (elements.Count() > 0) { gridClientes.DataSource = elements; gridClientes.DataBind(); lblGridClientesCount.Text = "Resultados: " + elements.Count(); } else { var obj = new List <cliente>(); obj.Add(new cliente()); /* Grid Viajes */ // Bind the DataTable which contain a blank row to the GridView gridClientes.DataSource = obj; gridClientes.DataBind(); int columnsCount = gridClientes.Columns.Count; gridClientes.Rows[0].Cells.Clear(); // clear all the cells in the row gridClientes.Rows[0].Cells.Add(new TableCell()); //add a new blank cell gridClientes.Rows[0].Cells[0].ColumnSpan = columnsCount; //set the column span to the new added cell //You can set the styles here gridClientes.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center; gridClientes.Rows[0].Cells[0].ForeColor = System.Drawing.Color.Red; gridClientes.Rows[0].Cells[0].Font.Bold = true; //set No Results found to the new added cell gridClientes.Rows[0].Cells[0].Text = "No hay registros"; } } }
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); } } } }
private void BindGridLogs(string date_start = "", string date_end = "") { using (bonisoftEntities context = new bonisoftEntities()) { // 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; bool isResult = false; if (!string.IsNullOrWhiteSpace(date_start) && !string.IsNullOrWhiteSpace(date_end)) { DateTime date1 = DateTime.Now; if (!DateTime.TryParseExact(date_start, GlobalVariables.ShortDateTime_format, CultureInfo.InvariantCulture, DateTimeStyles.None, out date1)) { date1 = DateTime.Now; Logs.AddErrorLog("Excepcion. Convirtiendo datetime. ERROR:", className, methodName, date_start); } DateTime date2 = DateTime.Now; if (!DateTime.TryParseExact(date_end, GlobalVariables.ShortDateTime_format, CultureInfo.InvariantCulture, DateTimeStyles.None, out date2)) { date2 = DateTime.Now; Logs.AddErrorLog("Excepcion. Convirtiendo datetime. ERROR:", className, methodName, date_end); } var elements = context.logs.Where(e => e.Fecha >= date1 && e.Fecha <= date2).OrderByDescending(e => e.Fecha).ToList(); if (elements.Count() > 0) { gridLogs.DataSource = elements; gridLogs.DataBind(); isResult = true; } } else { var elements = context.logs.OrderByDescending(e => e.Fecha).ToList(); if (elements.Count() > 0) { gridLogs.DataSource = elements; gridLogs.DataBind(); isResult = true; } } if (!isResult) { var obj = new List <log>(); obj.Add(new log()); /* Grid Viajes */ // Bind the DataTable which contain a blank row to the GridView gridLogs.DataSource = obj; gridLogs.DataBind(); int columnsCount = gridLogs.Columns.Count; gridLogs.Rows[0].Cells.Clear(); // clear all the cells in the row gridLogs.Rows[0].Cells.Add(new TableCell()); //add a new blank cell gridLogs.Rows[0].Cells[0].ColumnSpan = columnsCount; //set the column span to the new added cell //You can set the styles here gridLogs.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center; gridLogs.Rows[0].Cells[0].ForeColor = System.Drawing.Color.Red; gridLogs.Rows[0].Cells[0].Font.Bold = true; //set No Results found to the new added cell gridLogs.Rows[0].Cells[0].Text = "No hay registros"; } gridLogs.UseAccessibleHeader = true; gridLogs.HeaderRow.TableSection = TableRowSection.TableHeader; } }
protected void gridClientes_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 = gridClientes.FooterRow; TextBox txb1 = row.FindControl("txbNew1") as TextBox; TextBox txb3 = row.FindControl("txbNew3") as TextBox; TextBox txb5 = row.FindControl("txbNew5") as TextBox; TextBox txb7 = row.FindControl("txbNew7") as TextBox; TextBox txb13 = row.FindControl("txbNew13") as TextBox; TextBox txb14 = row.FindControl("txbNew14") as TextBox; TextBox txb15 = row.FindControl("txbNew15") as TextBox; TextBox txb16 = row.FindControl("txbNew16") as TextBox; TextBox txb17 = row.FindControl("txbNew17") as TextBox; TextBox txb22 = row.FindControl("txbNew22") 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 && txb3 != null && txb5 != null && txb13 != null && txb14 != null && txb15 != null && txb16 != null && txb17 != null && txb22 != null && txb23 != null && txb24 != null && txb20 != null) { using (bonisoftEntities context = new bonisoftEntities()) { cliente obj = new cliente(); obj.Dueno_nombre = txb1.Text; obj.Encargado_lena_nombre = txb3.Text; obj.Encargado_pagos_nombre = txb5.Text; //obj.Supervisor_lena_nombre = txb7.Text; obj.Supervisor_lena_nombre = string.Empty; obj.Nombre = txb13.Text; obj.Razon_social = txb14.Text; obj.RUT = txb15.Text; obj.Direccion = txb16.Text; obj.Telefono = txb17.Text; obj.Comentarios = txb22.Text; obj.Email = txb23.Text; obj.Nro_cuenta = txb24.Text; obj.Depto = txb20.Text; // obj.Forma_de_pago_ID = 0; obj.Dueno_contacto = string.Empty; obj.Encargado_lena_contacto = string.Empty; obj.Encargado_pagos_contacto = string.Empty; obj.Supervisor_lena_contacto = string.Empty; obj.Periodos_liquidacion = string.Empty; obj.Fechas_pago = string.Empty; // obj.EsBarraca = false; context.clientes.Add(obj); context.SaveChanges(); #region Guardar log try { int id = 1; cliente cliente = (cliente)context.clientes.OrderByDescending(p => p.cliente_ID).FirstOrDefault(); if (cliente != null) { id = cliente.cliente_ID; } string userID1 = HttpContext.Current.Session["UserID"].ToString(); string username = HttpContext.Current.Session["UserName"].ToString(); Global_Objects.Logs.AddUserLog("Agrega cliente", cliente.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); } } } else { //BindGrid(); } }