TFS_ANTIGUO/AYA.FROPI/FOPI/webforms/FOR/wfrPartidas.aspx.cs

705 lines
No EOL
26 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*===========================================================================================================================
* Instituto Costarricense de Acueductos y Alcantarillados. - 2019
* Formularios para Proyectos de Inversión
* Nombre de la Pantalla: wfrPartidas.aspx
*
* Explicación de los contenidos del archivo
*===========================================================================================================================
* HISTORIAL
*
* PERSONA DIA MES - AÑO DESCRIPCIÓN
* Esteban Gutierrez Rapso 17 02 - 2019 Se inicia con el diseño de la pagina
* …………………………………………………………
* …………………………………………………………
*===========================================================================================================================
* Derechos Reservados (C) 2019 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.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 AyADAL;
using AyABL.RCS;
using AyABL.PPP;
using AyABL.AGP;
using AyABL.ADM;
using AyABL.FNP;
public partial class webforms_FOR_wfrPartidas : 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);
Javascript.CheckAllGridViewItems(Page);
construirGrvPartidasTab();
construirGrvListaDetalle();
construirgrvTotalPartidas();
}
catch (Exception ex)
{
MensajeError("Error en R0M1", ex);
}
}
#endregion
#region Variables (R1)
GridView grvPartidasTabTemp, grvListaDetalleTemp, grvTotalPartidasTemp;
ProyectoBL objProyectoBL;
DistribucionPartidaBL objDistribucionPartidaBL;
PartidaPresupuestariaBL objPartidaPresupuestariaBL;
FinanciamientoBL objFinanciamientoBL;
#endregion
#region Eventos Formulario (R2)
protected void Page_Load(object sender, EventArgs e) //M0
{
try
{
if ((!IsPostBack) && (Session.Count > 0))
{
objProyectoBL = new ProyectoBL();
objProyectoBL.objProyectoEL.PK = Int32.Parse(Session["PKPROYECTO"].ToString());
DataSet dsProyecto = objProyectoBL.getProyectos();
if (dsProyecto.Tables[0].Rows.Count != 0)
{
txtProyecto.Text = dsProyecto.Tables[0].Rows[0]["NOMBREPROYECTO"].ToString();
txtNumeroBPIP.Text = dsProyecto.Tables[0].Rows[0]["NUMEROBPIPPROYECTO"].ToString();
txtEstadoProyecto.Text = string.IsNullOrEmpty(dsProyecto.Tables[0].Rows[0]["NOMBREESTADO"].ToString()) ? "Sin Asignar" : dsProyecto.Tables[0].Rows[0]["NOMBREESTADO"].ToString();
}
llenarDDLPartida();
llenarDDLAnio();
llenarGrvPartidasTab();
llenarGRVTotalPartida();
}
ScriptManager.RegisterStartupScript(Page, typeof(Page), "Check", "validarEstado()", true);
}
catch (Exception ex)
{
MensajeError("Error en R2M0", ex);
}
}
#endregion
#region Eventos Controles Web (R3)
protected void btnAnterior_Click(object sender, EventArgs e) //M0
{
try
{
Response.Redirect("wfrProyectos.aspx");
}
catch (Exception ex)
{
MensajeError("Error en R3M0", ex);
}
}
protected void btnVerDetalle_Click(object sender, EventArgs e) //M1
{
try
{
mostrarDetalleyTabulado(1);
}
catch (Exception ex)
{
MensajeError("Error en R3M1", ex);
General.ReportarError(ex, Session["LOGIN"].ToString());
}
}
protected void btnVerTabulado_Click(object sender, EventArgs e) //M2
{
try
{
mostrarDetalleyTabulado(2);
}
catch (Exception ex)
{
MensajeError("Error en R3M2", ex);
General.ReportarError(ex, Session["LOGIN"].ToString());
}
}
protected void btnNuevo_Click(object sender, EventArgs e) //M3
{
try
{
ViewState["Modo"] = "Nuevo";
mostrarFilasDetalle(2);
}
catch (Exception ex)
{
MensajeError("Error en R3M3", ex);
}
}
protected void btnEliminar_Click(object sender, EventArgs e) //M4
{
try
{
// recorro el grid
foreach (GridViewRow row in grvListaDetalleTemp.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);
eliminarDatos(intPkEliminar);
}
}
llenarGrvListaDetalle();
}
MensajeInformativo("El registro fue eliminado");
}
catch (Exception ex)
{
MensajeError("Error en R3M4", ex);
}
}
protected void grvListaDetalle_RowCommand(object sender, GridViewCommandEventArgs e) //M5
{
try
{
if (e.CommandName == "editar")
{
int i = Convert.ToInt32(e.CommandArgument);
GridViewRow selectedRow = grvListaDetalle.Rows[i];
ViewState["PkPartida"] = Convert.ToInt32(selectedRow.Cells[2].Text);
ViewState["Modo"] = "Modifica";
mostrarFilasDetalle(2);
mostrarDatos();
}
}
catch (Exception ex)
{
MensajeError("Error en R3M5", ex);
}
}
protected void grvListaDetalle_PageIndexChanging(object sender, GridViewPageEventArgs e) //M6
{
try
{
grvListaDetalle.PageIndex = e.NewPageIndex;
llenarGrvListaDetalle();
}
catch (Exception ex)
{
MensajeError("Error R3M6", ex);
}
}
protected void btnGuardar_Click(object sender, EventArgs e) //M7
{
try
{
if (GuardarDatos())
{
MensajeInformativo("El registro fue almacenado");
}
else
{
MensajeError("El registro no fue almacenado, verifique", null);
}
}
catch (Exception ex)
{
MensajeError("Error en R3M7", ex);
General.ReportarError(ex, Session["LOGIN"].ToString());
}
}
protected void btnAnteriorPP_Click(object sender, EventArgs e) //M8
{
try
{
mostrarFilasDetalle(1);
}
catch (Exception ex)
{
MensajeError("Error en R3M8", ex);
}
}
#endregion
#region Metodos Personalizados (R4)
private void mostrarDetalleyTabulado(int p_intFila) //M0
{
try
{
divTabulado.Visible = false;
divDetalle.Visible = false;
switch (p_intFila)
{
case 1:
llenarGrvListaDetalle();
divDetalle.Visible = true;
break;
case 2:
llenarGrvPartidasTab();
divTabulado.Visible = true;
break;
}
}
catch (Exception ex)
{
MensajeError("Error en R4M0", ex);
}
}
private void construirGrvPartidasTab() //M1
{
try
{
grvPartidasTabTemp = (GridView)divTabulado.FindControl("grvPartidasTab");
}
catch (Exception ex)
{
MensajeError("Error en R4M1", ex);
}
}
private void construirGrvListaDetalle() //M2
{
try
{
grvListaDetalleTemp = (GridView)divDetalle.FindControl("grvListaDetalle");
GridViewBoundField bdfPkDistribucionPartida = new GridViewBoundField("PKDISTRIBUCIONPARTIDA", "PK", false, false, false);
GridViewBoundField bdfPkPartida = new GridViewBoundField("PKPARTIDAPRESUPUESTARIA", "PK", false, false, false);
GridViewBoundField bdfIndice = new GridViewBoundField("INDICEPARTIDAPRESUPUESTARIA", "INDICE", true, false, true);
GridViewBoundField bdfNombrePartida = new GridViewBoundField("NOMBREPARTIDAPRESUPUESTARIA", "PARTIDA", true, false, true);
GridViewBoundField bdfAnio = new GridViewBoundField("ANIODISTRIBUCIONPARTIDA", "AÑO", true, false, true);
GridViewBoundField bdfMonto = new GridViewBoundField("MONTODISTRIBUCIONPARTIDA", "MONTO", true, false, true);
GridViewBoundField bdfFkProyecto = new GridViewBoundField("FKPROYECTO", "PROYECTO", true, false, false);
grvListaDetalleTemp.Columns.Add(bdfPkDistribucionPartida);
grvListaDetalleTemp.Columns.Add(bdfPkPartida);
grvListaDetalleTemp.Columns.Add(bdfIndice);
grvListaDetalleTemp.Columns.Add(bdfNombrePartida);
grvListaDetalleTemp.Columns.Add(bdfAnio);
grvListaDetalleTemp.Columns.Add(bdfMonto);
grvListaDetalleTemp.Columns.Add(bdfFkProyecto);
grvListaDetalleTemp.Columns[0].ItemStyle.Width = 25;
grvListaDetalleTemp.Columns[1].ItemStyle.Width = 25;
grvListaDetalleTemp.Columns[4].ItemStyle.Width = 60;
grvListaDetalleTemp.Columns[4].ItemStyle.HorizontalAlign = HorizontalAlign.Center;
grvListaDetalleTemp.Columns[6].ItemStyle.HorizontalAlign = HorizontalAlign.Center;
grvListaDetalleTemp.Columns[7].ItemStyle.HorizontalAlign = HorizontalAlign.Right;
bdfMonto.DataFormatString = "{0:N2}";
}
catch (Exception ex)
{
MensajeError("Error en R4M3", ex);
}
}
private void mostrarFilasDetalle(int p_intFila) //M3
{
try
{
divListado.Visible = false;
divFormularioDatos.Visible = false;
switch (p_intFila)
{
case 1:
llenarGrvListaDetalle();
llenarGRVTotalPartida();
divListado.Visible = true;
break;
case 2:
limpiarCampos();
divFormularioDatos.Visible = true;
break;
}
}
catch (Exception ex)
{
MensajeError("Error en R4M3", ex);
}
}
private void limpiarCampos() //M4
{
llenarDDLPartida();
llenarDDLAnio();
txtMonto.Text = string.Empty;
}
private void construirgrvTotalPartidas() //M5
{
try
{
grvTotalPartidasTemp = (GridView)divTabulado.FindControl("grvTotalPartidas");
}
catch (Exception ex)
{
MensajeError("Error en R4M5", ex);
}
}
#endregion
#region Metodos Controles a Datos (R5)
private bool GuardarDatos() //M0
{
bool blnEjecutado = false;
try
{
string strModo = ViewState["Modo"].ToString();
objDistribucionPartidaBL = new DistribucionPartidaBL();
objDistribucionPartidaBL.objDistribucionPartidaEL.Anio = Int32.Parse(ddlAnio.SelectedItem.Text);
objDistribucionPartidaBL.objDistribucionPartidaEL.Monto = Decimal.Parse(txtMonto.Text);
objDistribucionPartidaBL.objDistribucionPartidaEL.PartidaPresupuestaria = Int32.Parse(ddlPartida.SelectedValue);
objDistribucionPartidaBL.objDistribucionPartidaEL.Proyecto = Int32.Parse(Session["PKPROYECTO"].ToString());
if (strModo == "Nuevo")
{
if (objDistribucionPartidaBL.insertarDistribucionPartida())
{
blnEjecutado = true;
GuardarEventoBitacora(
Session["LOGIN"].ToString(),
AccionBitacora.INSERT.ToString(),
MensajesBitacora.IngresarRegistro + ": " + " Año: " + ddlAnio.SelectedItem.Text + " Monto: " + Decimal.Parse(txtMonto.Text).ToString("###,###,###.#0") + " Partida: " +
ddlPartida.SelectedItem.Text,
"wfrDistribucionPartida.aspx");
}
}
else if (strModo == "Modifica")
{
objDistribucionPartidaBL.objDistribucionPartidaEL.PK = Int32.Parse(ViewState["PkPartida"].ToString());
if (objDistribucionPartidaBL.actualizarDistribucionPartida())
{
blnEjecutado = true;
GuardarEventoBitacora(Session["LOGIN"].ToString(),
AccionBitacora.UPDATE.ToString(),
MensajesBitacora.ModificarRegistro + ": " + " Año: " + ddlAnio.SelectedItem.Text + " Monto: " + Decimal.Parse(txtMonto.Text).ToString("###,###,###.#0") + " Partida: " + ddlPartida.SelectedItem.Text,
"wfrDistribucionPartidas.aspx");
}
}
llenarGrvListaDetalle();
}
catch (Exception ex)
{
throw ex;
blnEjecutado = false;
General.ReportarError(ex, Session["LOGIN"].ToString());
}
return blnEjecutado;
}
private void eliminarDatos(int p_intPKPartida) //M1
{
try
{
objDistribucionPartidaBL = new DistribucionPartidaBL();
objDistribucionPartidaBL.objDistribucionPartidaEL.PK = p_intPKPartida;
objDistribucionPartidaBL.objDistribucionPartidaEL.ASTATE = false;
objDistribucionPartidaBL.actualizaEstadoDistribucionPartida();
foreach (GridViewRow row in grvListaDetalle.Rows)
{
HtmlInputCheckBox chkTemp = (HtmlInputCheckBox)row.Controls[0].Controls[1];
if (chkTemp != null)
{
// si el registro esta marcado
if (chkTemp.Checked)
{
GuardarEventoBitacora(Session["LOGIN"].ToString(),
AccionBitacora.DELETE.ToString(),
MensajesBitacora.EliminarRegistro + ": PK: " + row.Cells[2].Text + " Indice: " + row.Cells[4].Text + " Partida: " + row.Cells[5].Text + " Año: " + row.Cells[6].Text + " Monto: " + row.Cells[7].Text,
"frwDistribucionPartidas.aspx");
}
}
}
}
catch (Exception ex)
{
MensajeError("Error en R5M1", ex);
General.ReportarError(ex, Session["LOGIN"].ToString());
}
}
#endregion
#region Metodos Datos a Controles (R6)
private void llenarGrvPartidasTab() //M0
{
string strTipoFinanciamiento = string.Empty;
string strTipoRecurso = string.Empty;
try
{
objDistribucionPartidaBL = new DistribucionPartidaBL();
objDistribucionPartidaBL.objDistribucionPartidaEL.Proyecto = Int32.Parse(Session["PKPROYECTO"].ToString());
DataSet dsPartidas = objDistribucionPartidaBL.getDistribucionPartida();
if (dsPartidas.Tables.Count == 0)
dsPartidas.Tables.Add();
detalleGRVDatos(dsPartidas, grvPartidasTab);
for (int i = 0; i <= grvPartidasTab.Rows.Count - 1; ++i)
{
for (int j = 2; j <= grvPartidasTab.Rows[i].Cells.Count - 1; ++j)
{
if (grvPartidasTab.Rows[i].Cells[j].Text != "0.00")
grvPartidasTab.Rows[i].Cells[j].Text = Decimal.Parse(grvPartidasTab.Rows[i].Cells[j].Text).ToString("###,###,###,###.#0");
grvPartidasTab.Rows[i].Cells[j].HorizontalAlign = HorizontalAlign.Right;
}
}
}
catch (Exception ex)
{
MensajeError("Error en R6M0", ex);
General.ReportarError(ex, Session["LOGIN"].ToString());
}
}
private void llenarGrvListaDetalle() //M1
{
try
{
objDistribucionPartidaBL = new DistribucionPartidaBL();
objDistribucionPartidaBL.objDistribucionPartidaEL.PK = 0;
objDistribucionPartidaBL.objDistribucionPartidaEL.Proyecto = Int32.Parse(Session["PKPROYECTO"].ToString()
);
DataSet dsDetalle = objDistribucionPartidaBL.getDetalle();
detalleGRVDatos(dsDetalle, grvListaDetalle);
}
catch (Exception ex)
{
MensajeError("Error en R6M5", ex);
General.ReportarError(ex, Session["LOGIN"].ToString());
}
}
private void mostrarDatos() //M2
{
try
{
objDistribucionPartidaBL = new DistribucionPartidaBL();
objDistribucionPartidaBL.objDistribucionPartidaEL.PK = Int32.Parse(ViewState["PkPartida"].ToString());
DataSet dsPartida = objDistribucionPartidaBL.getDetalle();
if (dsPartida.Tables[0].Rows.Count > 0)
{
ddlPartida.SelectedValue = dsPartida.Tables[0].Rows[0]["PKPARTIDAPRESUPUESTARIA"].ToString();
ddlAnio.SelectedItem.Text = dsPartida.Tables[0].Rows[0]["ANIODISTRIBUCIONPARTIDA"].ToString();
txtMonto.Text = dsPartida.Tables[0].Rows[0]["MONTODISTRIBUCIONPARTIDA"].ToString();
}
}
catch (Exception ex)
{
MensajeError("Error en R6M2" +
"", ex);
General.ReportarError(ex, Session["LOGIN"].ToString());
}
}
private void llenarDDLPartida() //M3
{
try
{
//Limpia el control
ddlPartida.Items.Clear();
//Instancia el objeto
objPartidaPresupuestariaBL = new PartidaPresupuestariaBL();
objPartidaPresupuestariaBL.objPartidaPresupuestariaEL.PK = 0;
objPartidaPresupuestariaBL.objPartidaPresupuestariaEL.ASTATE = true;
//Carga la información en un dataset
DataSet dsPartida = objPartidaPresupuestariaBL.getPartidaPresupuestaria();
if (dsPartida.Tables[0].Rows.Count != 0)
{
ddlPartida.DataSource = dsPartida;
ddlPartida.DataTextField = dsPartida.Tables[0].Columns["NOMBREPARTIDAPRESUPUESTARIA"].ColumnName;
ddlPartida.DataValueField = dsPartida.Tables[0].Columns["PKPARTIDAPRESUPUESTARIA"].ColumnName;
ddlPartida.DataBind();
ddlPartida.Items.Insert(0, new ListItem("Seleccione una Partida Presupuestatia", "-1"));
}
}
catch (Exception ex)
{
MensajeError("Error en R6M3", ex);
}
}
private void llenarDDLAnio() //M4
{
try
{
//Limpia el control
ddlAnio.Items.Clear();
ListItem lstAnios = new ListItem("Seleccione un Año");
ddlAnio.Items.Add(lstAnios);
for (int i = DateTime.Now.Year - 7; i <= DateTime.Now.Year + 7; i++)
{
lstAnios = new ListItem(i.ToString());
ddlAnio.Items.Add(lstAnios);
}
}
catch (Exception ex)
{
MensajeError("Error en R6M4", ex);
}
}
private void llenarGRVTotalPartida() //M5
{
string strTipoFinanciamiento = string.Empty;
string strTipoRecurso = string.Empty;
try
{
objDistribucionPartidaBL = new DistribucionPartidaBL();
objFinanciamientoBL = new FinanciamientoBL();
objDistribucionPartidaBL.objDistribucionPartidaEL.Proyecto = Int32.Parse(Session["PKPROYECTO"].ToString());
objFinanciamientoBL.objFinanciamientoEL.Proyecto = Int32.Parse(Session["PKPROYECTO"].ToString());
DataSet dsPartidas = objDistribucionPartidaBL.getTotalPartida();
DataSet dsRecursos = objFinanciamientoBL.getTotalFinanciamiento();
if (dsPartidas.Tables.Count == 0)
dsPartidas.Tables.Add();
detalleGRVDatos(dsPartidas, grvTotalPartidas);
decimal vMontoTotalPartidas = 0M;
decimal vMontoTotalFinanciamiento = 0M;
#region VERIFICAR MONTO FINANCIAMIENTO
if (dsRecursos != null || dsRecursos.Tables.Count > 0 || dsRecursos.Tables[0].Rows.Count > 0)
{
for (int i = 1; i <= dsRecursos.Tables[0].Columns.Count - 1; ++i)
{
vMontoTotalFinanciamiento += Convert.ToDecimal(dsRecursos.Tables[0].Rows[0][i].ToString());
}
}
#endregion
if (grvTotalPartidas.HeaderRow != null)
{
grvTotalPartidas.HeaderRow.Cells[0].Text = "";
for (int i = 0; i <= grvTotalPartidas.Rows.Count - 1; ++i)
{
for (int j = 1; j <= grvTotalPartidas.Rows[i].Cells.Count - 1; ++j)
{
vMontoTotalPartidas += Convert.ToDecimal(grvTotalPartidas.Rows[i].Cells[j].Text);
if (grvTotalPartidas.Rows[i].Cells[j].Text != "0.00")
grvTotalPartidas.Rows[i].Cells[j].Text = Decimal.Parse(grvTotalPartidas.Rows[i].Cells[j].Text).ToString("###,###,###,###.#0");
grvTotalPartidas.Rows[i].Cells[j].HorizontalAlign = HorizontalAlign.Right;
grvTotalPartidas.FooterRow.Cells[j].BorderStyle = BorderStyle.None;
}
grvTotalPartidas.Rows[i].Font.Bold = true;
}
#region Mostrar Total
var vMontosCoinciden = vMontoTotalPartidas == vMontoTotalFinanciamiento;
grvTotalPartidas.FooterRow.Cells[0].Text = "TOTAL";
grvTotalPartidas.FooterRow.Cells[0].Font.Bold = true;
grvTotalPartidas.FooterRow.Cells[0].HorizontalAlign = HorizontalAlign.Left;
grvTotalPartidas.FooterRow.Cells[1].Text = vMontoTotalPartidas.ToString("###,###,###,###.#0");
grvTotalPartidas.FooterRow.Cells[1].Font.Bold = true;
grvTotalPartidas.FooterRow.Cells[1].HorizontalAlign = HorizontalAlign.Right;
grvTotalPartidas.FooterRow.Cells[1].BackColor = vMontosCoinciden ? System.Drawing.Color.LightGreen : System.Drawing.Color.IndianRed;
grvTotalPartidas.FooterRow.Cells[1].ForeColor = System.Drawing.Color.White;
grvTotalPartidas.FooterRow.Cells[0].BorderStyle = BorderStyle.Solid;
grvTotalPartidas.FooterRow.Cells[1].BorderStyle = BorderStyle.Solid;
#endregion
}
}
catch (Exception ex)
{
General.ReportarError(ex, Session["LOGIN"].ToString());
MensajeError("Error en R6M5", ex);
}
}
#endregion
}