/// <summary> /// Se cargan todos los departamentos existentes en el catalogo /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { DepartamentoLN departamentoLN = new DepartamentoLN(); DataTable dt = departamentoLN.ObtenerDepartamento(); for (int i = 0; i < dt.Rows.Count; i++) { int fil = i + 1; int id = Convert.ToInt32(dt.Rows[i]["id_departamento"]); tabla_departamento.Rows.Add(new TableRow()); tabla_departamento.Rows[fil].Cells.Add(new TableCell()); tabla_departamento.Rows[fil].Cells.Add(new TableCell()); if ((fil % 2) == 0) { tabla_departamento.Rows[fil].BackColor = Color.LightBlue; } else { tabla_departamento.Rows[fil].BackColor = Color.White; } tabla_departamento.Rows[fil].Cells[0].Text = dt.Rows[i]["descripcion"].ToString(); tabla_departamento.Rows[fil].Cells[1].Width = 100; tabla_departamento.Rows[fil].Cells[1].Controls.Add(BotonEditar(id)); tabla_departamento.Rows[fil].Cells[1].Controls.Add(BotonEliminar(id)); tabla_departamento.Rows[fil].Cells[1].Controls.Add(BotonMunicipio(id)); } }
/// <summary> /// Carga la descripción del departamento a eliminar /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { DepartamentoLN departamentoLN = new DepartamentoLN(); int id = Convert.ToInt32(Request["id"]); DataTable dt = departamentoLN.GetDepartamento(id); Button1.Attributes.Add("data-id", id.ToString()); if (!Page.IsPostBack) { descripcion.Text = dt.Rows[0]["descripcion"].ToString(); } }
/// <summary> /// Elimina el departamento /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void EliminarDepartamento(object sender, EventArgs e) { DepartamentoLN departamentoLN = new DepartamentoLN(); int id = Convert.ToInt32(Button1.Attributes["data-id"]); DataTable dt = departamentoLN.EliminarDepartamento(id); if (!dt.HasErrors) { Response.Redirect("ListadoDepartamento.aspx"); } else { Page_Load(sender, e); } }
/// <summary> /// Obtiene la descripción del nuevo departamento y lo crea/agrega /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Crear(object sender, EventArgs e) { if (!String.IsNullOrEmpty(descripcion.Text)) { string departamento = descripcion.Text.Trim().ToUpper(); DepartamentoLN departamentoLN = new DepartamentoLN(); if (!departamentoLN.CrearDepartamento(departamento).HasErrors) { Response.Redirect("ListadoDepartamento.aspx"); } else { } } }
/// <summary> /// Edita la descripción del departamento /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void EditarDepartamento(object sender, EventArgs e) { DepartamentoLN departamentoLN = new DepartamentoLN(); int id = Convert.ToInt32(Button1.Attributes["data-id"]); string descripcion = this.descripcion.Text; if (!string.IsNullOrEmpty(descripcion)) { DataTable dt = departamentoLN.EditarDepartamento(id, descripcion.ToUpper()); if (!dt.HasErrors) { Response.Redirect("ListadoDepartamento.aspx"); } else { Page_Load(sender, e); } } }