/*=========================================================================================================================== * Instituto Costarricense de Acueductos y Alcantarillados. - 2015 * Administración de la Seguridad * Nombre de la Pantalla: frwZonaPresion.aspx * * Explicación de los contenidos del archivo *=========================================================================================================================== * HISTORIAL * * PERSONA DIA – MES - AÑO DESCRIPCIÓN * Juan Pablo Monge Delgado 29 – 11 - 2018 Se inicia con el diseño de la pagina * ………………………………………………………… * ………………………………………………………… *=========================================================================================================================== * Derechos Reservados (C) 2015 AyA. * ESTE CÓDIGO ES PROVEÍDO “TAL CUAL ES” SIN GARANTÍA ALGUNA * DE NINGÚN TIPO, SEA IMPLICITA O EXPLICITA. * NO SE PERMITE SU REPRODUCCIÓN PARCIAL O TOTAL, NI SU COMERCIALIZACIÓN *=========================================================================================================================== */ using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using AyABL; using AyABL.AUT.Autenticacion; using AyADAL; using System.Configuration; using AyABL.RCS; using AyABL.Tran; using AyABL.APL; using AyABL.Usuario; public partial class Forms_Mantenimiento_frwZonaPresion : General { #region Inicializar Formulario (R0) override protected void OnInit(EventArgs e) //M0 { try { base.OnInit(e); InicializarFormulario(); } catch (Exception ex) { MensajeError("Error en R0M0", ex); } } private void InicializarFormulario() //M1 { try { Response.Cache.SetCacheability(HttpCacheability.NoCache); construirGridView(); Javascript.CheckAllGridViewItems(Page); cuwBusquedaList.Buscar += new _controlesusuario_Estandar_cuwBusquedaList.SearchEvent(Buscar); } catch (Exception ex) { MensajeError("Error en R0M1", ex); } } #endregion #region Variables (R1) GridView grvListaTemp, grvCantonalesADTemp; zonapresionBL objZonaPresionBL; ArrayList arlCondicionesFiltroBusqueda = new ArrayList(); #endregion #region Eventos Formulario (R2) protected void Page_Load(object sender, EventArgs e) //M0 { try { if ((!IsPostBack) && (Session.Count > 0)) { llenarGridView(true); mostrarFilaTabla(1); //llenarTipoDesarrollo(); ComandosxMenu(); } } catch (Exception ex) { MensajeError("Error en R2M0", ex); } } #endregion #region Eventos Controles Web (R3) /// /// Metodo que se utiliza para extraer información del registro de la base de datos y ser mostrado en el acordeon de Controles /// /// /// protected void grvLista_RowCommand(object sender, GridViewCommandEventArgs e) //M0 { try { if (e.CommandName == "editar") { int i = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = grvLista.Rows[i]; int intPK = Convert.ToInt32(selectedRow.Cells[2].Text); ViewState["PKZONAPRESION"] = intPK; ViewState["MODO"] = "Modifica"; mostrarFilaTabla(2); mostrarDatos(intPK); } } catch (Exception ex) { MensajeError("Error en R3M0", ex); } } /// /// Metodo que se utiliza para la paginación del Grid en caso de que el usuario desee ver mas registros /// /// /// protected void grvLista_PageIndexChanging(object sender, GridViewPageEventArgs e) //M3 { try { grvLista.PageIndex = e.NewPageIndex; llenarGridView(true); } catch (Exception ex) { MensajeError("Error en R3M3", ex); } } /// ///Activar el botón de Refrescar /// /// /// protected void btnRefrescar_Click(object sender, System.Web.UI.ImageClickEventArgs e) //M4 { try { llenarGridView(true); } catch (Exception ex) { MensajeError("Error en R3M4" + MensajesAplicacion.RefrescarFallido.ToString(), ex); } } /// /// Activa el evento del botón Buscar (binoculares) /// /// /// protected void btnBuscar_Click(object sender, System.Web.UI.ImageClickEventArgs e) //M7 { try { llenarGridView(true); } catch (Exception ex) { MensajeError("Error en R3M7" + MensajesAplicacion.UsuarioInexistente.ToString(), ex); } } /// /// Activa el evento del boton Nuevo /// /// /// protected void btnNuevo_Click(object sender, EventArgs e) //M8 { try { ViewState["MODO"] = "Nuevo"; mostrarFilaTabla(2); //Limpia el grid de Active Directory //txtDescripcion.Focus(); } catch (Exception ex) { MensajeError("Error en R3M8" + MensajesAplicacion.GuardadoFallido.ToString(), ex); } } /// /// Metodo que activa el botón de Eliminar /// /// /// protected void btnActivar_Click(object sender, EventArgs e) //M9 { try { foreach (GridViewRow row in grvLista.Rows) { HtmlInputCheckBox chkTemp = (HtmlInputCheckBox)row.Controls[0].Controls[1]; if (chkTemp != null) { // si el registro esta marcado if (chkTemp.Checked) { int intPkEliminar = Convert.ToInt32(row.Cells[2].Text); ActivarDesactivar(intPkEliminar); MensajeInformativo(AyABL.BASESDEDATOS.ADS + "Interfaz: " + MensajesAplicacion.GuardadoExitoso.ToString()); } } } llenarGridView(true); } catch (Exception ex) { MensajeError("Error en R3M9", ex); } } /// ///Activa el metodo del boton Anterior, regresa a la primera fila de la tabla /// /// /// protected void btnAnterior_Click(object sender, EventArgs e) //M12 { try { txtDescripcion.Text = ""; txtObservacion.Text = ""; divDatosSuperiores.Visible = true; divDatosMedios.Visible = false; } catch (Exception ex) { MensajeError("Error en R3M12", ex); } } /// /// Activa el evento del boton guardar.1 /// /// /// protected void btnGuardar_Click(object sender, EventArgs e) //M14 { try { //if (ddlTipoDesarrollo.SelectedValue != "-1" && txtActividad.Text != "" && txtDescripcion.Text != "" && txtDuracion.Text != "" && txtParalelo.Text != "") if (txtDescripcion.Text != "" && txtDescripcion.Text != "" ) { int nPkZonaPresion = GuardarDatos(); llenarGridView(true); mostrarFilaTabla(1); if(nPkZonaPresion > 0) MensajeInformativo(AyABL.BASESDEDATOS.SIGDD + "Interfaz: " + MensajesAplicacion.GuardadoExitoso.ToString()); else MensajeAlerta(AyABL.BASESDEDATOS.ADS + "Interfaz: " + MensajesAplicacion.GuardadoFallido.ToString()); } else { //MensajeAlerta(AyABL.BASESDEDATOS.ADS + "Interfaz: " + MensajesAplicacion.GuardadoFallido.ToString()); } } catch (Exception ex) { MensajeError("Error en R3M14", ex); } } //protected void ddlTipoDesarrollo_SelectedIndexChanged(object sender, EventArgs e)//M12 //{ // try // { // llenarTipoDesarrollo(); // } // catch (Exception ex) // { // MensajeError("Error en R3M12", ex); // } //} #endregion #region Metodos Personalizados (R4) /// /// Oculta las filas que lo requieran /// /// private void mostrarFilaTabla(int p_intFila) //M0 { try { divDatosSuperiores.Visible = false; divDatosMedios.Visible = false; switch (p_intFila) { case 1: llenarGridView(true); divDatosSuperiores.Visible = true; break; case 2: llenarGridView(true); divDatosMedios.Visible = true; break; case 3: llenarGridView(true); break; } } catch (Exception ex) { throw ex; } } /// /// Metodo que se utiliza para contruir el Grid al inicio de la pantalla /// private void construirGridView() //M1 { try { grvListaTemp = (GridView)tdLista.FindControl("grvLista"); GridViewBoundField bdfPkZonaPresion = new GridViewBoundField("PKZONAPRESION", "PK", false, false, true); GridViewBoundField bdfDescripcion = new GridViewBoundField("DESCRIPCIONZONAPRESION", "Descripción", false, false, true); GridViewBoundField bdfObservacion = new GridViewBoundField("OBSERVACIONESZONAPRESION", "Observacion", true, false, true); GridViewBoundField bdfActivo = new GridViewBoundField("ASTATEZONAPRESION", "Activo", true, "Si", "No", true); grvListaTemp.Columns.Add(bdfPkZonaPresion); grvListaTemp.Columns.Add(bdfDescripcion); grvListaTemp.Columns.Add(bdfObservacion); grvListaTemp.Columns.Add(bdfActivo); grvListaTemp.Columns[0].ItemStyle.Width = 25; grvListaTemp.Columns[1].ItemStyle.Width = 25; grvListaTemp.Columns[2].ItemStyle.Width = 500; //grvListaDatosCantonalesTemp.Columns[5].ItemStyle.Width = 25; cuwBusquedaList.LlenarCHKLBusqueda(grvListaTemp); } catch (Exception ex) { throw ex; } } /// /// Metodo que se encarga de agregar el filtro de busqueda seleccionado por el usuario /// /// private void condicionesBusqueda() //M2 { AyABL.AyABL objBL = new AyABL.AyABL(); CondicionDAL condicion; DateTime dteFechaInicio = new DateTime(); DateTime dteFechaFin = new DateTime(); ListItem li = new ListItem(); string p_parametros; p_parametros = this.cuwBusquedaList.getValorBusqueda(); try { if (p_parametros != "") { //aqui se construye el listItem con los datos que vienen del control en formato {valor : texto , valor : texto} char[] separadorTuplas = { ',' }; char[] separadorValores = { ':' }; string[] arrayTupla = p_parametros.Split(separadorTuplas); for (int i = 0; i <= (arrayTupla.Length - 1); i++) { if (arrayTupla[i].ToString() != "") { string[] arrayValores = arrayTupla[i].ToString().Split(separadorValores); li = new ListItem(arrayValores[1], arrayValores[0]); if (li.Value.Contains("FECHA") && li.Text != string.Empty) { if (li.Value.Contains("INICIO")) { dteFechaInicio = Convert.ToDateTime(li.Text.ToString()); dteFechaFin = DateTime.Now; } if (li.Value.Contains("FIN")) { dteFechaFin = Convert.ToDateTime(li.Text.ToString()); if (dteFechaFin != null || dteFechaInicio != null) if (dteFechaInicio < dteFechaFin || dteFechaFin == dteFechaInicio) { objBL = new AyABL.AyABL(); arlCondicionesFiltroBusqueda = objBL.buscarPorFechas(Tablas.BITACORA, dteFechaInicio, dteFechaFin, operadorLogico.AND, arlCondicionesFiltroBusqueda); } else MensajeInformativo(AyABL.BASESDEDATOS.ADS + "Interfaz: " + "Verifique que la Fecha de Inicio sea menor que la Fecha Final" + "M2"); else MensajeInformativo(AyABL.BASESDEDATOS.ADS + "Interfaz: " + "Verifique que los campos de las fechas no estén vacíos" + "M2"); } else { objBL = new AyABL.AyABL(); arlCondicionesFiltroBusqueda = objBL.buscarPorFechas(Tablas.BITACORA, dteFechaInicio, dteFechaFin, operadorLogico.AND, arlCondicionesFiltroBusqueda); } } else { if (li.Value.Contains("booleano") && li.Text != "2") { condicion = new CondicionDAL(); char[] separadorColumna = { '|' }; string[] strColumna = li.Value.Split(separadorColumna); condicion.valorIzquierdo = strColumna[1].ToString(); condicion.operadorGeneral = operadorGeneral.EQUAL; condicion.operadorLogico = operadorLogico.AND; condicion.valorDerecho = li.Text.Trim(); arlCondicionesFiltroBusqueda.Add(condicion); } else { if (li.Text != string.Empty && !li.Value.Contains("booleano")) { condicion = new CondicionDAL(); condicion.valorIzquierdo = li.Value; condicion.operadorGeneral = operadorGeneral.LIKEALL; condicion.operadorLogico = operadorLogico.AND; condicion.valorDerecho = "%" + li.Text.Trim() + "%"; arlCondicionesFiltroBusqueda.Add(condicion); } } } } } } } catch (Exception ex) { throw ex; } } /// /// Metodo que se utiliza con el buscador de la parte superior de la pantalla, y hace que se despliegue la información de acuerdo /// a lo solicitado /// | private void Buscar() //M4 { try { llenarGridView(true); } catch (Exception ex) { throw ex; } } /// /// Metodo que se utiliza para el despliegue de los botones /// private void ComandosxMenu() //M6 { try { DataSet dsComandos = getComandos(); if (dsComandos != null) { foreach (DataRow drTemp in dsComandos.Tables[0].Rows) { switch (drTemp["NOMBRECOMANDO"].ToString().ToUpper()) { case "NUEVO": btnNuevo.Visible = true; break; case "MODIFICA": //Inicio de variable tipo VIEWSTATE ViewState["PUEDEMODIFICAR"] = true; btnGuardar.Visible = true; btnActivar.Visible = true; break; } } } } catch (Exception ex) { throw ex; } } /// /// Limpia los campos /// private void limpiarCampos() { txtObservacion.Text = string.Empty; txtDescripcion.Text = string.Empty; //txtOrden.Text = string.Empty; } #endregion #region Metodos Controles a Datos (R5) /// /// guarda y modifica registros en la tabla. /// /// private int GuardarDatos() //M0 { int nValorRetornado = 0; try { string strModo = ViewState["MODO"].ToString(); objZonaPresionBL = new zonapresionBL(); objZonaPresionBL.objzonapresionEL.DESCRIPCION = txtDescripcion.Text; objZonaPresionBL.objzonapresionEL.OBSERVACIONES = txtObservacion.Text; objZonaPresionBL.objzonapresionEL.ASTATE = true; if (strModo == "Nuevo") { nValorRetornado = objZonaPresionBL.insertarZonaPresion(); if (nValorRetornado > 0) { limpiarCampos(); GuardarEventoBitacora( Session["LOGIN"].ToString(), AccionBitacora.INSERT.ToString(), MensajesBitacora.IngresarRegistro + ": Se ha ingresado la zona de presión " + txtDescripcion.Text.Trim(), "frwZonaPresion.aspx", Convert.ToInt32(ConfigurationManager.AppSettings["pkApp"]) ); } } else if (strModo == "Modifica" && bool.Parse(ViewState["PUEDEMODIFICAR"].ToString()) == true) { objZonaPresionBL.objzonapresionEL.PK = Convert.ToInt32(ViewState["PKZONAPRESION"]); nValorRetornado = objZonaPresionBL.modificarZonaPresion(); limpiarCampos(); GuardarEventoBitacora( Session["LOGIN"].ToString(), AccionBitacora.UPDATE.ToString(), MensajesBitacora.IngresarRegistro + ": Se ha modificado la zona de presión " + txtDescripcion.Text.Trim(), "frwZonaPresion.aspx", Convert.ToInt32(ConfigurationManager.AppSettings["pkApp"]) ); } } catch (Exception ex) { throw ex; } return nValorRetornado; } /// /// Activa o desactiva el usuario /// /// private bool ActivarDesactivar(int p_intPkEliminar) //M2 { bool blnValorRetornado = false; bool blnActivo = false; try { objZonaPresionBL = new zonapresionBL(); objZonaPresionBL.objzonapresionEL.PK = p_intPkEliminar; DataSet dsActividadDS = objZonaPresionBL.listarZonaPresion(null, false); //Verifica que el usuario se encuentre en la BD if (dsActividadDS.Tables[0].Rows.Count != 0) { //Si esta activado que lo desactive if (Convert.ToBoolean(dsActividadDS.Tables[0].Rows[0][Concepto.ASTATE.ToString() + Tablas.zonapresion.ToString()])) blnActivo = false; //Si esta desactivado que lo active else blnActivo = true; objZonaPresionBL.objzonapresionEL.OBSERVACIONES = dsActividadDS.Tables[0].Rows[0][t_adm_zonapresion.OBSERVACIONES.ToString() + Tablas.zonapresion.ToString()].ToString(); objZonaPresionBL.objzonapresionEL.DESCRIPCION = dsActividadDS.Tables[0].Rows[0][t_adm_zonapresion.DESCRIPCION.ToString() + Tablas.zonapresion.ToString()].ToString(); objZonaPresionBL.objzonapresionEL.ASTATE = blnActivo; objZonaPresionBL.modificarZonaPresion(); } GuardarEventoBitacora( Session["LOGIN"].ToString(), AccionBitacora.UPDATE.ToString(), MensajesBitacora.ModificarRegistro + ": Se ha puesto el registro de la PK=" + p_intPkEliminar + " en " + blnActivo, "frwZonaPresion.aspx", Convert.ToInt32(ConfigurationManager.AppSettings["pkApp"]) ); } catch (Exception ex) { throw ex; } return blnValorRetornado; } #endregion #region Metodos Datos a Controles (R6) /// /// Carga el grid principal /// /// private void llenarGridView(bool p_Llenar) //M0 { try { if (!IsPostBack || p_Llenar) { arlCondicionesFiltroBusqueda = new ArrayList(); objZonaPresionBL = new zonapresionBL(); condicionesBusqueda(); DataSet dsActividad = objZonaPresionBL.listarZonaPresion(null,false); General.detalleGridView(dsActividad, grvLista, lblTotalDatos); } } catch (Exception ex) { throw ex; } } /// /// Muestra los datos del registro /// /// private void mostrarDatos(int p_intPkConsultar) //M1 { try { objZonaPresionBL = new zonapresionBL(); objZonaPresionBL.objzonapresionEL.PK = p_intPkConsultar; DataSet ds = objZonaPresionBL.listarZonaPresion(null,false); if (ds.Tables[0].Rows.Count > 0) { //Información de la actividad txtObservacion.Text = ds.Tables[0].Rows[0]["OBSERVACIONESZONAPRESION"].ToString(); txtDescripcion.Text = ds.Tables[0].Rows[0]["DESCRIPCIONZONAPRESION"].ToString(); } else { } } catch (Exception ex) { throw ex; } } #endregion }