618 lines
No EOL
20 KiB
C#
618 lines
No EOL
20 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_wfrPartidaPresupuestaria : 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();
|
|
|
|
PartidaPresupuestariaBL objPartidaPresupuestariaBL;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Eventos Formulario (R2)
|
|
|
|
protected void Page_Load(object sender, EventArgs e) //M0
|
|
{
|
|
try
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
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 intPkPartidaPresupuestaria = Convert.ToInt32(selectedRow.Cells[2].Text);
|
|
ViewState["PkPartidaPresupuestaria"] = intPkPartidaPresupuestaria;
|
|
ViewState["MODO"] = "Modifica";
|
|
|
|
mostrarFilaTabla(2);
|
|
txtIndice.Text = selectedRow.Cells[3].Text;
|
|
mostrarDatos(intPkPartidaPresupuestaria);
|
|
}
|
|
}
|
|
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[4].Text;
|
|
//Obtiene el valor del objeto y lo iguala a la variable
|
|
|
|
//**********aqui******** = intPkEliminar;
|
|
|
|
//Ejecuta el eliminar con el valor de la variable
|
|
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
|
|
{
|
|
llenarGridView(true);
|
|
}
|
|
|
|
#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 bdfPkPartidaPresupuestaria = new GridViewBoundField("PKPartidaPresupuestaria", "PK", false, false, false);
|
|
GridViewBoundField bdfNombrePartidaPresupuestaria = new GridViewBoundField("NOMBREPartidaPresupuestaria", "PartidaPresupuestaria", true, false, true);
|
|
GridViewBoundField bdfIndicePartidaPresupuestaria = new GridViewBoundField("INDICEPartidaPresupuestaria", "Indice", true, false, true);
|
|
|
|
////Asigna las columnas a los campos a la hora de hacer la consulta
|
|
grvListaDatosTemp.Columns.Add(bdfPkPartidaPresupuestaria);
|
|
grvListaDatosTemp.Columns.Add(bdfIndicePartidaPresupuestaria);
|
|
grvListaDatosTemp.Columns.Add(bdfNombrePartidaPresupuestaria);
|
|
|
|
////Le damos estilo a las filas (opcional)
|
|
grvListaDatosTemp.Columns[0].ItemStyle.Width = 25;
|
|
grvListaDatosTemp.Columns[1].ItemStyle.Width = 50;
|
|
grvListaDatosTemp.Columns[2].ItemStyle.Width = 25;
|
|
grvListaDatosTemp.Columns[3].ItemStyle.Width = 75;
|
|
|
|
////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
|
|
objPartidaPresupuestariaBL = new PartidaPresupuestariaBL();
|
|
objPartidaPresupuestariaBL.objPartidaPresupuestariaEL.Nombre = txtNombre.Text;
|
|
objPartidaPresupuestariaBL.objPartidaPresupuestariaEL.Indice = Int32.Parse(txtIndice.Text);
|
|
|
|
|
|
if (strModo == "Nuevo")
|
|
{
|
|
objPartidaPresupuestariaBL.objPartidaPresupuestariaEL.PK = 0;
|
|
//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 (objPartidaPresupuestariaBL.insertarPartidaPresupuestaria())
|
|
{
|
|
|
|
blnValorRetornado = true;
|
|
|
|
GuardarEventoBitacora(
|
|
Session["LOGIN"].ToString(), //Usuario
|
|
AccionBitacora.INSERT.ToString(), //Accion que se va a ejecutar
|
|
MensajesBitacora.IngresarRegistro + ": "+ txtNombre.Text, //Mensaje de la bitacora
|
|
"wfrPartidas.aspx"
|
|
);
|
|
MensajeInformativo(txtNombre.Text + " se guardó correctamente.");
|
|
divDatosInferiores.Visible = false;
|
|
}
|
|
}
|
|
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
|
|
objPartidaPresupuestariaBL.objPartidaPresupuestariaEL.PK = Int32.Parse(ViewState["PkPartidaPresupuestaria"].ToString());
|
|
|
|
if (objPartidaPresupuestariaBL.actualizarPartidaPresupuestaria())
|
|
{
|
|
|
|
blnValorRetornado = true;
|
|
|
|
//Se ingresa a bitacora la transacción
|
|
GuardarEventoBitacora(
|
|
Session["LOGIN"].ToString(),
|
|
AccionBitacora.UPDATE.ToString(),
|
|
MensajesBitacora.ModificarRegistro + ": " + txtNombre.Text,
|
|
"wfrPartidas.aspx"
|
|
);
|
|
MensajeInformativo("Se Modificó el registro correctamente.");
|
|
divDatosInferiores.Visible = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
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_intPkPartidaPresupuestaria, string registroPartidaPresupuestaria) //M1
|
|
{
|
|
try
|
|
{
|
|
//Para eliminar datos inicialmente se instancia el objeto
|
|
//Ejemplo
|
|
objPartidaPresupuestariaBL = new PartidaPresupuestariaBL();
|
|
|
|
//Se asignan los valores a las propiedades el objeto
|
|
//Ejemplo
|
|
objPartidaPresupuestariaBL.objPartidaPresupuestariaEL.PK = p_intPkPartidaPresupuestaria;
|
|
objPartidaPresupuestariaBL.objPartidaPresupuestariaEL.ASTATE = false;
|
|
|
|
if (objPartidaPresupuestariaBL.borradoLogicoPartidaPresupuestaria())
|
|
{
|
|
MensajeInformativo("Se eliminó ("+ registroPartidaPresupuestaria + ") Correctamente.");
|
|
//Se ingresa a bitacora la transacción
|
|
GuardarEventoBitacora(
|
|
Session["LOGIN"].ToString(),
|
|
AccionBitacora.DELETE.ToString(),
|
|
MensajesBitacora.EliminarRegistro + ": " + registroPartidaPresupuestaria,
|
|
"wfrPartidas.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
|
|
objPartidaPresupuestariaBL = new PartidaPresupuestariaBL();
|
|
objPartidaPresupuestariaBL.objPartidaPresupuestariaEL.PK = 0;
|
|
|
|
DataSet dsListaDatos = objPartidaPresupuestariaBL.getPartidaPresupuestaria();
|
|
|
|
//Asigna al txtIndice el valor de la ultima fila
|
|
txtIndice.Text = dsListaDatos.Tables[0].Rows.Count.ToString();
|
|
|
|
//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
|
|
objPartidaPresupuestariaBL = new PartidaPresupuestariaBL();
|
|
|
|
//Se obtiene la PK del registro por medio el parametro
|
|
//Ejemplo
|
|
objPartidaPresupuestariaBL.objPartidaPresupuestariaEL.PK = p_intPkConsultar;
|
|
|
|
//Se llena un dataset con la inforación suministrada.
|
|
//Ejemplo
|
|
DataSet dsPartidaPresupuestaria = objPartidaPresupuestariaBL.getPartidaPresupuestaria();
|
|
|
|
//Se llenan los campos
|
|
//Ejemplo
|
|
if (dsPartidaPresupuestaria.Tables[0].Rows.Count > 0)
|
|
{
|
|
txtNombre.Text = dsPartidaPresupuestaria.Tables[0].Rows[0]["NOMBREPARTIDAPRESUPUESTARIA"].ToString();
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MensajeError("Error en R6M1", ex);
|
|
General.ReportarError(ex, Session["LOGIN"].ToString());
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
} |