668 lines
No EOL
22 KiB
C#
668 lines
No EOL
22 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
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.ADM;
|
|
using AyABL.RCS;
|
|
using AyADAL;
|
|
|
|
public partial class webforms_ADM_wfrFuenteFinanciamiento : 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);
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R0M1", ex);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Variables (R1)
|
|
|
|
GridView grvListaDatosTemp;
|
|
ArrayList arlCondicionesFiltroBusqueda = new ArrayList();
|
|
|
|
FuenteFinanciamientoBL objFuenteFinanciamientoBL;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Eventos Formulario (R2)
|
|
|
|
protected void Page_Load(object sender, EventArgs e) //M0
|
|
{
|
|
try
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
llenarDDLTipo();
|
|
llenarDDLClase();
|
|
llenarGridView(true);
|
|
ComandosxMenu();
|
|
mostrarFilaTabla(1);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R2M0", ex);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Eventos Controles Web (R3)
|
|
|
|
/// <summary>
|
|
/// Metodo que se utiliza para extraer información del registro de la base de datos y ser mostrado en el div de Controles
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
|
|
protected void grvListaDatos_RowCommand(object sender, GridViewCommandEventArgs e) //M0
|
|
{
|
|
try
|
|
{
|
|
if (e.CommandName == "editar")
|
|
{
|
|
int i = Convert.ToInt32(e.CommandArgument);
|
|
GridViewRow selectedRow = grvListaDatos.Rows[i];
|
|
int intPkFuenteFinanciamiento = Convert.ToInt32(selectedRow.Cells[2].Text);
|
|
ViewState["PkFuenteFinanciamiento"] = intPkFuenteFinanciamiento;
|
|
ViewState["MODO"] = "Modifica";
|
|
|
|
mostrarFilaTabla(2);
|
|
|
|
mostrarDatos(intPkFuenteFinanciamiento);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R3M0", ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Metodo que se utiliza para la paginación del Grid en caso de que el Rol desee ver mas registros
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
|
|
protected void grvListaDatos_PageIndexChanging(object sender, GridViewPageEventArgs e) //M1
|
|
{
|
|
try
|
|
{
|
|
grvListaDatos.PageIndex = e.NewPageIndex;
|
|
llenarGridView(true);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error R3M1", ex);
|
|
}
|
|
}
|
|
|
|
///<summary>
|
|
///Activar el botón de Refrescar
|
|
///</summary>
|
|
///<param name="sender"></param>
|
|
///<param name="e"></param>
|
|
|
|
protected void btnRefrescar_Click(object sender, System.Web.UI.ImageClickEventArgs e) //M2
|
|
{
|
|
try
|
|
{
|
|
llenarGridView(true);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R3M2", ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Activa el evento del botón Buscar (binoculares)
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnBuscar_Click(object sender, System.Web.UI.ImageClickEventArgs e) //M3
|
|
{
|
|
try
|
|
{
|
|
llenarGridView(true);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R3M3", ex);
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Activa el evento del boton Nuevo
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
|
|
protected void btnNuevo_Click(object sender, EventArgs e) //M4
|
|
{
|
|
try
|
|
{
|
|
ViewState["MODO"] = "Nuevo";
|
|
mostrarFilaTabla(2);
|
|
//MensajeError("Error en R3M4", null);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R3M4", ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Metodo que activa el botón de Eliminar
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnEliminar_Click(object sender, EventArgs e) //M5
|
|
{
|
|
try
|
|
{
|
|
//********** Instanciar objeto ******
|
|
// recorro el grid
|
|
foreach (GridViewRow row in grvListaDatos.Rows)
|
|
{
|
|
|
|
HtmlInputCheckBox chkTemp = (HtmlInputCheckBox)row.Controls[0].Controls[1];
|
|
if (chkTemp != null)
|
|
{
|
|
// si el registro esta marcado
|
|
if (chkTemp.Checked)
|
|
{
|
|
//Iguala la variable al valor en la celda seleccionada
|
|
int intPkEliminar = Convert.ToInt32(row.Cells[2].Text);
|
|
string registro = row.Cells[3].Text;
|
|
//Obtiene el valor del objeto y lo iguala a la variable
|
|
//**********aqui******** = intPkEliminar;
|
|
|
|
//Ejecuta el eliminar con el valor de la variable
|
|
MensajeInformativo(registro);
|
|
eliminarDatos(intPkEliminar, registro);
|
|
}
|
|
}
|
|
}
|
|
llenarGridView(true);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R3M5", ex);
|
|
}
|
|
}
|
|
|
|
///<summary>
|
|
///Activa el metodo del boton Anterior, regresa a mostrar el listado
|
|
///</summary>
|
|
///<param name="sender"></param>
|
|
///<param name="e"></param>
|
|
|
|
protected void btnAnterior_Click(object sender, EventArgs e) //M6
|
|
{
|
|
try
|
|
{
|
|
llenarGridView(true);
|
|
divDatosSuperiores.Visible = true;
|
|
divDatosInferiores.Visible = false;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R3M6", ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Activa el evento del boton guardar.
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
|
|
protected void btnGuardar_Click(object sender, EventArgs e) //M7
|
|
{
|
|
try
|
|
{
|
|
string strMensaje = string.Empty;
|
|
|
|
//******Reparar, aqui no van los llenarGridView(true);
|
|
if (GuardarDatos())
|
|
llenarGridView(true);
|
|
else
|
|
llenarGridView(true);
|
|
|
|
mostrarFilaTabla(1);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R3M7", ex);
|
|
}
|
|
}
|
|
|
|
protected void ddlTipo_SelectedIndexChanged(object sender, EventArgs e) //M8
|
|
{
|
|
try
|
|
{
|
|
llenarGridView(true);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R3M8", ex);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Metodos Personalizados (R4)
|
|
|
|
/// <summary>
|
|
/// Oculta los divs según la necesidad
|
|
/// </summary>
|
|
/// <param name="p_intFila"></param>
|
|
private void mostrarFilaTabla(int p_intFila) //M0
|
|
{
|
|
try
|
|
{
|
|
divDatosSuperiores.Visible = false;
|
|
divDatosInferiores.Visible = false;
|
|
|
|
switch (p_intFila)
|
|
{
|
|
case 1:
|
|
llenarGridView(true);
|
|
divDatosSuperiores.Visible = true;
|
|
break;
|
|
case 2:
|
|
llenarGridView(true);
|
|
divDatosInferiores.Visible = true;
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R4M0", ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Metodo que se utiliza para construir el Grid al inicio de la pantalla
|
|
/// </summary>
|
|
private void construirGridView() //M1
|
|
{
|
|
try
|
|
{
|
|
//Se Instancia la variable con el control
|
|
grvListaDatosTemp = (GridView)divDatosSuperiores.FindControl("grvListaDatos");
|
|
|
|
//Se crean las columnas del grid
|
|
GridViewBoundField bdfPkFuenteFinanciamiento = new GridViewBoundField("PKFUENTEFINANCIAMIENTO", "PK", false, false, false);
|
|
GridViewBoundField bdfNombreFuenteFinanciamiento = new GridViewBoundField("NOMBREFUENTEFINANCIAMIENTO", "FUENTEFINANCIAMIENTO", true, false, true);
|
|
|
|
////Asigna las columnas a los campos a la hora de hacer la consulta
|
|
grvListaDatosTemp.Columns.Add(bdfPkFuenteFinanciamiento);
|
|
grvListaDatosTemp.Columns.Add(bdfNombreFuenteFinanciamiento);
|
|
|
|
////Le damos estilo a las filas (opcional)
|
|
grvListaDatosTemp.Columns[0].ItemStyle.Width = 25;
|
|
grvListaDatosTemp.Columns[1].ItemStyle.Width = 25;
|
|
grvListaDatosTemp.Columns[2].ItemStyle.Width = 25;
|
|
|
|
////Carga el buscador con las columnas del grid
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R4M1", ex);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Metodo que se utiliza para limpiar los campos en la pantalla
|
|
/// </summary>
|
|
private void limpiarCampos() //M3
|
|
{
|
|
try
|
|
{
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R4M3", ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 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
|
|
/// </summary>
|
|
private void Buscar() //M4
|
|
{
|
|
try
|
|
{
|
|
llenarGridView(true);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R4M4", ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Metodo que se utiliza para el despliegue de los botones segun el rol del usuario
|
|
/// </summary>
|
|
private void ComandosxMenu() //M5
|
|
{
|
|
try
|
|
{
|
|
//General general = null;
|
|
|
|
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 "ELIMINAR":
|
|
btnEliminar.Visible = true;
|
|
break;
|
|
case "MODIFICA":
|
|
//Inicio de variable tipo VIEWSTATE
|
|
ViewState["PUEDEMODIFICAR"] = true;
|
|
btnGuardar.Visible = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R4M5", ex);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Metodos Controles a Datos (R5)
|
|
|
|
/// <summary>
|
|
/// guarda y modifica registros en la tabla.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
|
|
private bool GuardarDatos() //M0
|
|
{
|
|
bool blnValorRetornado = false; //Se utiliza para verificar si se ejecuto el proceso tanto de guardar como el de eliminar
|
|
int intPk = 0;
|
|
|
|
try
|
|
{
|
|
string strModo = ViewState["MODO"].ToString();
|
|
ViewState["PUEDEMODIFICAR"] = true;
|
|
|
|
//Igualar los valores de los controles a las propiedades del objeto a utilizar
|
|
//Ejemplo
|
|
objFuenteFinanciamientoBL = new FuenteFinanciamientoBL();
|
|
objFuenteFinanciamientoBL.objFuenteFinanciamientoEL.Nombre = txtNombre.Text;
|
|
objFuenteFinanciamientoBL.objFuenteFinanciamientoEL.Padre = Int32.Parse(ddlClase.SelectedValue.ToString());
|
|
|
|
if (strModo == "Nuevo")
|
|
{
|
|
//Si es un nuevo registro se llama al metodo respectivo del objeto para hacer la inserción
|
|
//***** Para este caso se obtiene el pk al utilizar el metodo del objeto para insertar información *******
|
|
//Ejemplo
|
|
if (objFuenteFinanciamientoBL.insertarFuenteFinanciamiento())
|
|
{
|
|
|
|
blnValorRetornado = true;
|
|
|
|
GuardarEventoBitacora(
|
|
Session["LOGIN"].ToString(), //Usuario
|
|
AccionBitacora.INSERT.ToString(), //Accion que se va a ejecutar
|
|
MensajesBitacora.IngresarRegistro + ": " + ddlClase.SelectedValue.ToString() + ", " + txtNombre.Text, //Mensaje de la bitacora
|
|
"wfrFuenteFinanciamiento.aspx"
|
|
);
|
|
}
|
|
}
|
|
else if (strModo == "Modifica")
|
|
{
|
|
//Si se va a modificar el registro y si tiene el permiso de modificar
|
|
if (Convert.ToBoolean(ViewState["PUEDEMODIFICAR"]) != false)
|
|
{
|
|
// Para hacer la modificación del registro se debe proporsionar la PK del registro a modificar
|
|
//Ejemplo
|
|
objFuenteFinanciamientoBL.objFuenteFinanciamientoEL.PK = Convert.ToInt32(ViewState["PkFuenteFinanciamiento"]);
|
|
|
|
if (objFuenteFinanciamientoBL.actualizarFuenteFinanciamiento())
|
|
{
|
|
|
|
blnValorRetornado = true;
|
|
|
|
//Se ingresa a bitacora la transacción
|
|
GuardarEventoBitacora(
|
|
Session["LOGIN"].ToString(),
|
|
AccionBitacora.UPDATE.ToString(),
|
|
MensajesBitacora.ModificarRegistro + ": " + ddlClase.SelectedValue.ToString() + ", " + txtNombre.Text,
|
|
"wfrFuenteFinanciamiento.aspx"
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R5M0", ex);
|
|
General.ReportarError(ex, Session["LOGIN"].ToString());
|
|
}
|
|
return blnValorRetornado;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Metodo que se utiliza para eliminar registros de la base de datos
|
|
/// </summary>
|
|
/// <param name="p_intPksAEliminar"></param>
|
|
|
|
private void eliminarDatos(int p_intPkFuenteFinanciamiento, string registroFuenteFinanciamiento) //M1
|
|
{
|
|
try
|
|
{
|
|
//Para eliminar datos inicialmente se instancia el objeto
|
|
//Ejemplo
|
|
objFuenteFinanciamientoBL = new FuenteFinanciamientoBL();
|
|
|
|
//Se asignan los valores a las propiedades el objeto
|
|
//Ejemplo
|
|
objFuenteFinanciamientoBL.objFuenteFinanciamientoEL.PK = p_intPkFuenteFinanciamiento;
|
|
objFuenteFinanciamientoBL.objFuenteFinanciamientoEL.ASTATE = false;
|
|
|
|
if (objFuenteFinanciamientoBL.actualizarEstadoFuenteFinanciamiento())
|
|
{
|
|
|
|
//Se ingresa a bitacora la transacción
|
|
GuardarEventoBitacora(
|
|
Session["LOGIN"].ToString(),
|
|
AccionBitacora.DELETE.ToString(),
|
|
MensajesBitacora.EliminarRegistro + ": " + registroFuenteFinanciamiento,
|
|
"wfrFuenteFinanciamiento.aspx"
|
|
);
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R5M1", ex);
|
|
General.ReportarError(ex, Session["LOGIN"].ToString());
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Metodos Datos a Controles (R6)
|
|
|
|
/// <summary>
|
|
/// Carga el grid principal
|
|
/// </summary>
|
|
/// <param name="p_Llenar"></param>
|
|
private void llenarGridView(bool p_Llenar) //M0
|
|
{
|
|
try
|
|
{
|
|
if (!IsPostBack || p_Llenar)
|
|
{
|
|
|
|
//Se llena el dataset con la información
|
|
//Ejemplo
|
|
objFuenteFinanciamientoBL = new FuenteFinanciamientoBL();
|
|
objFuenteFinanciamientoBL.objFuenteFinanciamientoEL.Padre = Int32.Parse(ddlTipo.SelectedValue);
|
|
objFuenteFinanciamientoBL.objFuenteFinanciamientoEL.PK = 0;
|
|
|
|
DataSet dsListaDatos = objFuenteFinanciamientoBL.getFuenteFinanciamiento();
|
|
|
|
//Hago el llamado del metodo que carga el grid o listado
|
|
//Ejemplo
|
|
General.detalleGridView(dsListaDatos, grvListaDatosTemp, lblTotalDatos);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R6M0", ex);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Muestra los datos del registro
|
|
|
|
/// </summary>
|
|
/// <param name="p_intPkConsultar"></param>
|
|
private void mostrarDatos(int p_intPkConsultar) //M1
|
|
{
|
|
try
|
|
{
|
|
//Se instancia el objeto
|
|
//Ejemplo
|
|
objFuenteFinanciamientoBL = new FuenteFinanciamientoBL();
|
|
objFuenteFinanciamientoBL.objFuenteFinanciamientoEL.Padre = 0;
|
|
//Se obtiene la PK del registro por medio el parametro
|
|
//Ejemplo
|
|
objFuenteFinanciamientoBL.objFuenteFinanciamientoEL.PK = p_intPkConsultar;
|
|
|
|
//Se llena un dataset con la inforación suministrada.
|
|
//Ejemplo
|
|
DataSet dsFuenteFinanciamiento = objFuenteFinanciamientoBL.getFuenteFinanciamiento();
|
|
|
|
//Se llenan los campos
|
|
//Ejemplo
|
|
if (dsFuenteFinanciamiento.Tables[0].Rows.Count > 0)
|
|
{
|
|
|
|
ddlClase.SelectedValue = dsFuenteFinanciamiento.Tables[0].Rows[0]["PADREFUENTEFINANCIAMIENTO"].ToString();
|
|
txtNombre.Text = dsFuenteFinanciamiento.Tables[0].Rows[0]["NOMBREFUENTEFINANCIAMIENTO"].ToString();
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R6M1", ex);
|
|
General.ReportarError(ex, Session["LOGIN"].ToString());
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Llena el dropDownList
|
|
|
|
/// </summary>
|
|
private void llenarDDLTipo() //M2
|
|
{
|
|
try
|
|
{
|
|
//Limpia el control
|
|
ddlTipo.Items.Clear();
|
|
//Instancia el objeto
|
|
objFuenteFinanciamientoBL = new FuenteFinanciamientoBL();
|
|
|
|
objFuenteFinanciamientoBL.objFuenteFinanciamientoEL.Padre = -1;
|
|
objFuenteFinanciamientoBL.objFuenteFinanciamientoEL.PK = 0;
|
|
objFuenteFinanciamientoBL.objFuenteFinanciamientoEL.ASTATE = true;
|
|
//Carga la información en un dataset
|
|
//DataSet dsFuenteFinanciamiento = objFuenteFinanciamientoBL.getFuenteFinanciamiento();
|
|
ddlTipo.DataSource = objFuenteFinanciamientoBL.getFuenteFinanciamiento();
|
|
ddlTipo.DataTextField = Concepto.NOMBRE.ToString() + Tablas.fuentefinanciamiento.ToString().ToUpper();
|
|
ddlTipo.DataValueField = Constraints.PK.ToString() + Tablas.fuentefinanciamiento.ToString().ToUpper();
|
|
ddlTipo.DataBind();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R6M2", ex);
|
|
}
|
|
}
|
|
|
|
private void llenarDDLClase() //M3
|
|
{
|
|
try
|
|
{
|
|
//Limpia el control
|
|
ddlClase.Items.Clear();
|
|
//Instancia el objeto
|
|
objFuenteFinanciamientoBL = new FuenteFinanciamientoBL();
|
|
|
|
objFuenteFinanciamientoBL.objFuenteFinanciamientoEL.Padre = -1;
|
|
objFuenteFinanciamientoBL.objFuenteFinanciamientoEL.PK = 0;
|
|
objFuenteFinanciamientoBL.objFuenteFinanciamientoEL.ASTATE = true;
|
|
//Carga la información en el dropdownlist
|
|
ddlClase.DataSource = objFuenteFinanciamientoBL.getFuenteFinanciamiento(); ;
|
|
ddlClase.DataTextField = Concepto.NOMBRE.ToString() + Tablas.fuentefinanciamiento.ToString().ToUpper();
|
|
ddlClase.DataValueField = Constraints.PK.ToString() + Tablas.fuentefinanciamiento.ToString().ToUpper();
|
|
ddlClase.DataBind();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R6M3", ex);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
} |