2348 lines
No EOL
111 KiB
C#
2348 lines
No EOL
111 KiB
C#
/*===========================================================================================================================
|
||
* Instituto Costarricense de Acueductos y Alcantarillados. - 2015
|
||
* Administración de la Seguridad
|
||
* Nombre de la Pantalla: frwBusquedaSolicitud.aspx
|
||
*
|
||
* Explicación de los contenidos del archivo
|
||
*===========================================================================================================================
|
||
* HISTORIAL
|
||
*
|
||
* PERSONA DIA – MES - AÑO DESCRIPCIÓN
|
||
* Esteban Gutierrez Rapso 20 – 04 - 2015 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 AyABL.APL;
|
||
using AyADAL;
|
||
using System.Configuration;
|
||
using AyABL.RCS;
|
||
using AyABL.Tran;
|
||
using AyABL.Usuario;
|
||
using System.Globalization;
|
||
using System.Text;
|
||
using System.Security.Cryptography;
|
||
using System.IO;
|
||
using AyABL.TRA;
|
||
using iTextSharp.text;
|
||
using iTextSharp.text.pdf;
|
||
public partial class Forms_Trans_frwCartaSolicitud : 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);
|
||
grvListaCartaSolicitud.Columns[1].ItemStyle.Width = 150;
|
||
|
||
//cuwVentanaEmergenteDevolucion.AbrirVentanaEmergenteDevolucion += new ControlUsuario_cuwVentanaEmergenteDevolucion.SearchEvent(AbrirVentanaEmergenteDevolucion);
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R0M1", ex);
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Variables (R1)
|
||
estadoCartaBL objEstadoCargaBL;
|
||
tipoCartaBL objTipoCartaBL;
|
||
//solicitudBL objSolicitudBL;
|
||
usuarioBL objUsuarioBL;
|
||
UsuarioBL objUsuarioAyABL ;
|
||
cartaBL objCartaBL;
|
||
DropDownList ddlTemporal, ddlTemporal2;
|
||
string strNumSolicitudTMP = string.Empty;
|
||
#region variable firma digital
|
||
int nNumSolicitudTMP = 0;
|
||
int nPKReutilizaTMP = 0;
|
||
/// <summary>
|
||
/// Código del sistema cliente del servicio de firma digital. Cada sistema cliente debe usar un código diferente.
|
||
/// </summary>
|
||
private const string CodigoSistema = "SIGPC";
|
||
|
||
/// <summary>
|
||
/// Identificador del usuario definido para el sistema cliente
|
||
/// </summary>
|
||
private long IdUsuarioSistemaCliente
|
||
{
|
||
get
|
||
{
|
||
return long.Parse(ConfigurationManager.AppSettings["IdUsuarioSistemaCliente"]);
|
||
}
|
||
}
|
||
#endregion
|
||
#region variables del estandar
|
||
string strPagina = string.Empty;
|
||
string strScript = string.Empty;
|
||
#endregion
|
||
|
||
|
||
#endregion
|
||
|
||
#region Eventos Formulario (R2)
|
||
|
||
protected void Page_Load(object sender, EventArgs e) //M0
|
||
{
|
||
try
|
||
{
|
||
|
||
ScriptManager.GetCurrent(Page).RegisterPostBackControl(btnNuevoCarta);
|
||
ScriptManager.GetCurrent(Page).RegisterPostBackControl(grvListaCartaSolicitud);
|
||
|
||
if (Session["SOLICITUD"] != null && !Session["SOLICITUD"].ToString().Contains("-TMP"))
|
||
{
|
||
nNumSolicitudTMP = int.Parse(Session["PKSOLICITUD"].ToString());
|
||
nPKReutilizaTMP = int.Parse(Session["FKREUTILIZA"].ToString());
|
||
lblNumSolicitud.Text = Session["SOLICITUD"].ToString();
|
||
strNumSolicitudTMP = Session["SOLICITUD"].ToString();
|
||
|
||
if (Request["d"] != null)
|
||
{
|
||
if (Request["d"].ToString() == "deshabilitar" || Request["d"].ToString() == "finalizado" )// || Request["d"].ToString() == "constancia") probar esto
|
||
{
|
||
mostrarFilaTabla(1);
|
||
ddlJefatura1.Enabled = false;
|
||
ddlJefatura2.Enabled = false;
|
||
btnGuardar.Enabled = false;
|
||
btnNuevoCarta.Enabled = false;
|
||
|
||
//cuwVentanaEmergenteDevolucion.Visible = false;
|
||
}
|
||
if (Request["d"].ToString() == "finalizado")
|
||
{
|
||
btnFinalizar.Enabled = false;
|
||
}
|
||
if (Request["d"].ToString() == "firmar")
|
||
chkFirmado.Visible = true;
|
||
}
|
||
|
||
if ((!IsPostBack) && (Session.Count > 0))
|
||
{
|
||
Session["Pagina"] = "";
|
||
|
||
mostrarFilaTabla(2);
|
||
|
||
//solicitudBL objSolicitudBL = new solicitudBL();
|
||
//objSolicitudBL.objSolicitudEL.PK = int.Parse(Session["PKPROGRAMACION"].ToString());
|
||
////objSolicitudBL.objSolicitudEL.FKUSUARIOXDEPENDENCIA = int.Parse(Session["PKUSUARIOXDEPENDENCIA"].ToString());
|
||
//DataSet ds = objSolicitudBL.dsListaActividadesEncargado(null);
|
||
|
||
//if (ds.Tables[0].Rows[0]["CLASIFICACIONSOLICITUD"].ToString() == "Crecimiento vegetativo")
|
||
//{
|
||
// ddlJefatura2.Enabled = false;
|
||
//}
|
||
|
||
verificarCartaSolicitud(nNumSolicitudTMP, "", nPKReutilizaTMP);
|
||
llenarDDLtipoformulario();
|
||
ddlTemporal = (DropDownList)tdLista.FindControl("ddlJefatura1");
|
||
llenarDDLjefatura(ddlTemporal);
|
||
ddlTemporal2 = (DropDownList)tdLista.FindControl("ddlJefatura2");
|
||
llenarDDLjefatura(ddlTemporal2);
|
||
}
|
||
|
||
}
|
||
else
|
||
|
||
{ ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>javascript:parent.closeIFrameConstancia();</script>"); }
|
||
if (ViewState["MODO"] != null)
|
||
{
|
||
if (ViewState["MODO"].ToString() == "Firmador")
|
||
{
|
||
obtenerDocumentoFirmado();
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R2M0", ex);
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Eventos Controles Web (R3)
|
||
|
||
|
||
protected void btnNuevaCarta_Click(object sender, EventArgs e) //M1
|
||
{
|
||
try
|
||
{
|
||
//limpiarCampos();
|
||
ViewState["MODO"] = "Nuevo";
|
||
mostrarFilaTabla(3);
|
||
//Limpia el grid de Active Directory
|
||
ddlTipoFormulario.Focus();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M6", ex);
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// Metodo que se utiliza para borrar clientes
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
|
||
protected void grvListaCartaSolicitud_RowCommand(object sender, GridViewCommandEventArgs e) //M2
|
||
{
|
||
PdfReader reader = null;
|
||
|
||
FileStream fs = null;
|
||
|
||
PdfStamper stamp = null;
|
||
|
||
Document document = null;
|
||
try
|
||
{
|
||
int i = Convert.ToInt32(e.CommandArgument);
|
||
GridViewRow selectedRow = grvListaCartaSolicitud.Rows[i];
|
||
int nPk = int.Parse(selectedRow.Cells[0].Text);
|
||
Char delimiter = '-';
|
||
string[] arrayDoc = selectedRow.Cells[1].Text.Split(delimiter);//SIGDD - AÑO - CONTADOR - CONTADOR DOCUMENTO - CONTADOR VERSION
|
||
string strNombreCarta = arrayDoc[0].ToString() + "-" + arrayDoc[1].ToString() + "-" + arrayDoc[2].ToString() + "-" + arrayDoc[3].ToString() + "-" + arrayDoc[4].ToString() + "-" + arrayDoc[5].ToString();
|
||
if (e.CommandName == "eliminar")
|
||
{
|
||
if (eliminarCartaSolicitud(nPk))
|
||
obtenerCartaSolicitud(nNumSolicitudTMP, "", nPKReutilizaTMP);
|
||
|
||
GuardarEventoBitacora(
|
||
Session["LOGIN"].ToString(),
|
||
AccionBitacora.INSERT.ToString(),
|
||
MensajesBitacora.EliminarRegistro + ": Se ha eliminado la carta " + strNombreCarta + " de la solicitud " + selectedRow.Cells[1].Text,
|
||
"frwCartaSolicitud.aspx",
|
||
Convert.ToInt32(ConfigurationManager.AppSettings["pkApp"])
|
||
);
|
||
}
|
||
|
||
if (e.CommandName == "renovar")
|
||
{
|
||
if (RenovarDocumento(nNumSolicitudTMP, selectedRow.Cells[1].Text, nPk))
|
||
obtenerCartaSolicitud(nNumSolicitudTMP, "", nPKReutilizaTMP);
|
||
|
||
GuardarEventoBitacora(
|
||
Session["LOGIN"].ToString(),
|
||
AccionBitacora.INSERT.ToString(),
|
||
MensajesBitacora.IngresarRegistro + ": Se ha renovado el documento " + selectedRow.Cells[1].Text + " para la solicitud " + Session["SOLICITUD"].ToString().Trim(),
|
||
"frwCartaSolicitud.aspx",
|
||
Convert.ToInt32(ConfigurationManager.AppSettings["pkApp"])
|
||
);
|
||
}
|
||
|
||
if (e.CommandName == "reconsiderar")
|
||
{
|
||
//Instancia el objeto
|
||
objCartaBL = new cartaBL();
|
||
|
||
//Asigna un valor al atributo de referencia del objeto
|
||
objCartaBL.objCartaEL.FKNUMSOLICITUD = nNumSolicitudTMP;
|
||
|
||
objCartaBL.objCartaEL.NOMBREDOCUMENTO = selectedRow.Cells[1].Text;
|
||
//Carga en un dataset la información
|
||
DataSet ds = objCartaBL.listarCartas();
|
||
|
||
if (int.Parse(ds.Tables[0].Rows[0]["FKESTADO"].ToString()) == 1)
|
||
{
|
||
//limpiarCampos();
|
||
eliminarCartaSolicitud(nPk);
|
||
ViewState["MODO"] = "Reconsiderar";
|
||
ViewState["RECONSIDERAR"] = selectedRow.Cells[1].Text;
|
||
mostrarFilaTabla(3);
|
||
//Limpia el grid de Active Directory
|
||
ddlTipoFormulario.Focus();
|
||
llenarDDLtipoformulario();
|
||
ddlTemporal = (DropDownList)tdLista.FindControl("ddlJefatura1");
|
||
llenarDDLjefatura(ddlTemporal);
|
||
ddlTemporal2 = (DropDownList)tdLista.FindControl("ddlJefatura2");
|
||
llenarDDLjefatura(ddlTemporal2);
|
||
}
|
||
else
|
||
{
|
||
{ ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>javascript: MensajeInformativo('El documento no puede ser reconsiderado.');</script>"); }
|
||
}
|
||
}
|
||
if (e.CommandName == "editar")
|
||
{
|
||
//limpiarCampos();
|
||
|
||
editarDocumento(strNombreCarta);
|
||
|
||
|
||
}
|
||
if (e.CommandName == "firmar")
|
||
{
|
||
//limpiarCampos();
|
||
firmarDocumento(strNombreCarta);
|
||
|
||
|
||
}
|
||
if (e.CommandName == "ver")
|
||
{
|
||
//limpiarCampos();
|
||
char delimitador = '-';
|
||
string[] arrayNombre = strNombreCarta.Split(delimitador);
|
||
string strResultado = string.Empty;
|
||
string pdfPath = ConfigurationManager.AppSettings["DocumentosPDF"].ToString() + @"\" + arrayNombre[1].ToString() + "-" + arrayNombre[2].ToString() + "-" + arrayNombre[3].ToString() + @"\" + strNombreCarta + ".pdf";
|
||
string targetURL = "'../../DocumentosPDF/" + arrayNombre[1].ToString() + "-" + arrayNombre[2].ToString() + "-" + arrayNombre[3].ToString() + "/" + strNombreCarta + ".pdf'";
|
||
|
||
string ruta = ConfigurationManager.AppSettings["DocumentosPDF"].ToString() + @"\" + arrayNombre[1].ToString() + "-" + arrayNombre[2].ToString() + "-" + arrayNombre[3].ToString();
|
||
|
||
if (System.IO.File.Exists(pdfPath))
|
||
{
|
||
#region constancias
|
||
Documento oDoc = new Documento();
|
||
|
||
byte[] bDoc = System.IO.File.ReadAllBytes(pdfPath);
|
||
//se carga el archivo y el registro a vision 2020
|
||
strResultado = oDoc.Archivar_Documento(strNumSolicitudTMP.ToString().Trim() + "|" + "Constancia", strNombreCarta + ".pdf", bDoc);
|
||
if (strResultado == string.Empty )
|
||
{
|
||
//File.Delete(pdfPath);
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
|
||
|
||
//if (!File.Exists(pdfPath))
|
||
|
||
|
||
{
|
||
//obtener la constancia y ponerla en la carpeta compartida para el envio de correo
|
||
|
||
//se el registro de vision 2020
|
||
|
||
|
||
Documento oDoc = new Documento();
|
||
strResultado = oDoc.Consultar_Documento(arrayNombre[1].ToString() + "-" + arrayNombre[2].ToString() + "-" + arrayNombre[3].ToString() + "|Constancia", strNombreCarta, strNombreCarta + ".pdf");
|
||
|
||
solicitudBL objSolicitudBL = new solicitudBL();
|
||
objSolicitudBL.objSolicitudEL.PK = int.Parse(Session["PKPROGRAMACION"].ToString());
|
||
objSolicitudBL.objSolicitudEL.ORDEN = 6;//se valida la tarea 6 Validación y firma se encuentre finalizada
|
||
objSolicitudBL.objSolicitudEL.FKESTADO = 5;
|
||
objSolicitudBL.objSolicitudEL.FKESTADO2 = 8;
|
||
|
||
DataSet dsEncargadosActividades = objSolicitudBL.dsListaActividadesEncargado(null);
|
||
|
||
if (dsEncargadosActividades.Tables[0].Rows.Count > 0)
|
||
{
|
||
|
||
int nTipoInspeccion = int.Parse(dsEncargadosActividades.Tables[0].Rows[0]["FKTIPOINSPECCION"].ToString());
|
||
if (strResultado != string.Empty && strResultado != "No existe")
|
||
{
|
||
|
||
EjecutarScript("abrirPDF('" + strResultado + "');");
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
if (strResultado != string.Empty && strResultado != "No existe")
|
||
{
|
||
reader = new PdfReader(strResultado);
|
||
fs = null;
|
||
document = null;
|
||
if (!Directory.Exists(ConfigurationManager.AppSettings["DocumentosPDF"].ToString() + @"\DocumentosVisor\"))
|
||
Directory.CreateDirectory(ConfigurationManager.AppSettings["DocumentosPDF"].ToString() + @"\DocumentosVisor\");
|
||
if (File.Exists(ConfigurationManager.AppSettings["DocumentosPDF"].ToString() + @"\DocumentosVisor\" + strNombreCarta + ".pdf"))
|
||
File.Delete(ConfigurationManager.AppSettings["DocumentosPDF"].ToString() + @"\DocumentosVisor\" + strNombreCarta + ".pdf");
|
||
|
||
document = new Document();
|
||
string outputPdf = String.Format(ConfigurationManager.AppSettings["DocumentosPDF"].ToString() + @"\DocumentosVisor\" + strNombreCarta + ".pdf",
|
||
|
||
Guid.NewGuid().ToString());
|
||
|
||
fs = new FileStream(outputPdf,
|
||
FileMode.CreateNew,
|
||
FileAccess.Write);
|
||
//crear estampador
|
||
stamp = null;
|
||
stamp = new PdfStamper(reader, fs);
|
||
byte[] USER = Encoding.ASCII.GetBytes(Session["LOGIN"].ToString());
|
||
byte[] OWNER = Encoding.ASCII.GetBytes(Session["LOGIN"].ToString());
|
||
//stamp.SetEncryption(USER, OWNER, PdfWriter.ALLOW_SCREENREADERS, PdfWriter.ENCRYPTION_AES_128);
|
||
|
||
BaseFont bf = BaseFont.CreateFont(@"c:\windows\fonts\arial.ttf", BaseFont.CP1252, true);
|
||
PdfGState gs = new PdfGState();
|
||
gs.FillOpacity = 0.35F;
|
||
gs.StrokeOpacity = 0.35F;
|
||
|
||
//escribir texto en las paginas
|
||
for (int nPag = 1; nPag <= reader.NumberOfPages; nPag++)
|
||
{
|
||
Rectangle tamPagina = reader.GetPageSizeWithRotation(nPag);
|
||
|
||
PdfContentByte over = stamp.GetOverContent(nPag);
|
||
over.BeginText();
|
||
WriteTextToDocument(bf, tamPagina, over, gs, "COPIA INVALIDA");
|
||
over.EndText();
|
||
|
||
}
|
||
|
||
|
||
|
||
stamp.Close();
|
||
reader.Close();
|
||
|
||
//if (stamp != null) stamp.Close();
|
||
|
||
if (fs != null) fs.Close();
|
||
|
||
if (document != null) document.Close();
|
||
|
||
|
||
//System.Diagnostics.Process proc = new System.Diagnostics.Process();
|
||
//proc.StartInfo.FileName = ConfigurationManager.AppSettings["DocumentosPDF"].ToString() + @"\DocumentosVisor\" + strNombreCarta + ".pdf";
|
||
//proc.Start();
|
||
//proc.Close();
|
||
if (System.IO.File.Exists(ConfigurationManager.AppSettings["DocumentosPDF"].ToString() + @"\DocumentosVisor\" + strNombreCarta + ".pdf"))
|
||
{
|
||
#region constancias
|
||
Documento oDoc2 = new Documento();
|
||
|
||
byte[] bDoc = System.IO.File.ReadAllBytes(ConfigurationManager.AppSettings["DocumentosPDF"].ToString() + @"\DocumentosVisor\" + strNombreCarta + ".pdf");
|
||
//se carga el archivo y el registro a vision 2020
|
||
strResultado = oDoc2.Archivar_Documento(strNumSolicitudTMP.ToString().Trim() + "|" + "Constancia", strNombreCarta + "Copia.pdf", bDoc);
|
||
if (strResultado == string.Empty)
|
||
{
|
||
|
||
//File.Delete(pdfPath);
|
||
}
|
||
oDoc2 = new Documento();
|
||
strResultado = oDoc2.Consultar_Documento(arrayNombre[1].ToString() + "-" + arrayNombre[2].ToString() + "-" + arrayNombre[3].ToString() + "|Constancia", strNombreCarta, strNombreCarta + "Copia.pdf");
|
||
if (strResultado != string.Empty && strResultado != "No existe")
|
||
{
|
||
EjecutarScript("abrirPDF('" + strResultado + "');");
|
||
}
|
||
else
|
||
{
|
||
ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>javascript: MensajeInformativo('Se presentó un problema al abrir el documento, intente de nuevo.');</script>");
|
||
}
|
||
#endregion
|
||
}
|
||
//strResultado += pdfPath + ";"; ;
|
||
//EjecutarScript("abrirPDF('" + ConfigurationManager.AppSettings["DocumentosPDF"].ToString() + @"\DocumentosVisor\" + strNombreCarta + ".pdf" + "');");
|
||
}
|
||
|
||
else
|
||
{
|
||
if (strResultado == string.Empty || strResultado == "No existe")
|
||
ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>javascript: MensajeInformativo('No se ha generado el documento PDF." + pdfPath + "');</script>");
|
||
}
|
||
}
|
||
|
||
}
|
||
//EjecutarScript("abrirPDF(" + targetURL + ");");
|
||
// //System.Diagnostics.Process proc = new System.Diagnostics.Process();
|
||
// //proc.StartInfo.FileName = pdfPath;
|
||
// //proc.Start();
|
||
// //proc.Close();
|
||
// //EjecutarScript("JavaScript: window.open('" + targetURL + "','','width=500,height=245,left=350,top=50');");
|
||
}
|
||
|
||
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M15", ex);
|
||
}
|
||
finally
|
||
{
|
||
if(reader!= null)
|
||
reader.Close();
|
||
|
||
//if (stamp != null) stamp.Close();
|
||
|
||
if (fs != null) fs.Close();
|
||
|
||
if (document != null) document.Close();
|
||
}
|
||
}
|
||
|
||
protected void grvListaCartaSolicitud_PageIndexChanging(object sender, GridViewPageEventArgs e) //M3
|
||
{
|
||
try
|
||
{
|
||
grvListaCartaSolicitud.PageIndex = e.NewPageIndex;
|
||
obtenerCartaSolicitud(nNumSolicitudTMP, "",nPKReutilizaTMP);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M3", ex);
|
||
}
|
||
}
|
||
|
||
///<summary>
|
||
///Activa el metodo del boton Anterior, regresa a la primera fila de la tabla
|
||
///</summary>
|
||
///<param name="sender"></param>
|
||
///<param name="e"></param>
|
||
|
||
protected void btnAnterior_Click(object sender, EventArgs e) //M3
|
||
{
|
||
try
|
||
{
|
||
obtenerCartaSolicitud(nNumSolicitudTMP, "", nPKReutilizaTMP);
|
||
divDatosSuperiores.Visible = true;
|
||
|
||
divDatosInferiores.Visible = false;
|
||
|
||
}
|
||
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) //M8
|
||
{
|
||
try
|
||
{
|
||
//limpiarCampos();
|
||
ViewState["MODO"] = "Nuevo";
|
||
mostrarFilaTabla(3);
|
||
//Limpia el grid de Active Directory
|
||
ddlTipoFormulario.Focus();
|
||
llenarDDLtipoformulario();
|
||
ddlTemporal = (DropDownList)tdLista.FindControl("ddlJefatura1");
|
||
llenarDDLjefatura(ddlTemporal);
|
||
ddlTemporal2 = (DropDownList)tdLista.FindControl("ddlJefatura2");
|
||
llenarDDLjefatura(ddlTemporal2);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M8" + MensajesAplicacion.GuardadoFallido.ToString(), ex);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// Activa el evento de guardar
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnGuardar_Click(object sender, EventArgs e) //M9
|
||
{
|
||
try
|
||
{
|
||
|
||
{
|
||
string strModo = ViewState["MODO"].ToString();
|
||
string strDocumento = string.Empty;
|
||
//if (ddlTipoFormulario.SelectedValue == "-1")
|
||
//{
|
||
// MensajeAlerta("Debe seleccionar el tipo de formulario.");
|
||
// ddlTipoFormulario.Focus();
|
||
//}
|
||
//else
|
||
{
|
||
if (ddlJefatura1.SelectedValue == "-1")
|
||
{
|
||
MensajeAlerta("Debe seleccionar la jefatura 1.");
|
||
ddlJefatura1.Focus();
|
||
}
|
||
if (ddlJefatura1.SelectedValue == ddlJefatura2.SelectedValue)
|
||
{
|
||
MensajeAlerta("No se puede seleccionar la misma jefatura para ambas jefaturas.");
|
||
ddlJefatura1.Focus();
|
||
}
|
||
else
|
||
{
|
||
inspeccionasBL objInspeccionasBL = new inspeccionasBL();
|
||
objInspeccionasBL.objinspeccionasEL.FKSOLICITUD = int.Parse(Session["PKSOLICITUD"].ToString());
|
||
objInspeccionasBL.objinspeccionasEL.DESCRIPCIONESTADOINSPECCION = "Asignada";
|
||
DataSet dsInspeccionASBL = objInspeccionasBL.listarInspeccionesAS(null);
|
||
|
||
inspeccionapBL objInspeccionapBL = new inspeccionapBL();
|
||
objInspeccionapBL.objinspeccionapEL.FKSOLICITUD = int.Parse(Session["PKSOLICITUD"].ToString());
|
||
objInspeccionapBL.objinspeccionapEL.DESCRIPCIONESTADOINSPECCION = "Asignada";
|
||
DataSet dsInspeccionPABL = objInspeccionapBL.listarInspecciones(null);
|
||
int nFKTipoConstancia = 0;
|
||
|
||
int nTipoInspeccion =0 ;
|
||
if (dsInspeccionASBL.Tables[0].Rows.Count > 0)
|
||
nTipoInspeccion= int.Parse(dsInspeccionASBL.Tables[0].Rows[0]["FKTIPOINSPECCION"].ToString());
|
||
if (dsInspeccionPABL.Tables[0].Rows.Count > 0)
|
||
nTipoInspeccion = int.Parse(dsInspeccionPABL.Tables[0].Rows[0]["FKTIPOINSPECCION"].ToString());
|
||
#region Ambos
|
||
if (nTipoInspeccion == 3)
|
||
{
|
||
|
||
|
||
|
||
|
||
if (dsInspeccionPABL.Tables[0].Rows[0]["EXISTEDISPONIBILIDADINSPECCIONAP"].ToString().ToLower() == "true" && dsInspeccionASBL.Tables[0].Rows[0]["EXISTEDISPONIBILIDADINSPECCIONAS"].ToString().ToLower() == "true")
|
||
{
|
||
nFKTipoConstancia = 1; //Formulario N°1 SI SI
|
||
|
||
strDocumento = GuardarDatos(nFKTipoConstancia);
|
||
generarDocumento(strDocumento, nFKTipoConstancia.ToString());
|
||
}
|
||
if (dsInspeccionPABL.Tables[0].Rows[0]["EXISTEDISPONIBILIDADINSPECCIONAP"].ToString().ToLower() == "false" && dsInspeccionASBL.Tables[0].Rows[0]["EXISTEDISPONIBILIDADINSPECCIONAS"].ToString().ToLower() == "false")
|
||
{
|
||
nFKTipoConstancia = 2; //Formulario N°2 NO NO
|
||
|
||
strDocumento = GuardarDatos(nFKTipoConstancia);
|
||
generarDocumento(strDocumento, nFKTipoConstancia.ToString());
|
||
|
||
if (dsInspeccionASBL.Tables[0].Rows[0]["EXISTEDISPONIBILIDADINSPECCIONAS"].ToString().ToLower() == "false" && dsInspeccionASBL.Tables[0].Rows[0]["CRITECNICONOEXISTEDISPONIBILIDAD"].ToString().ToLower() == "true")
|
||
{
|
||
nFKTipoConstancia = 6 ; //Formulario N°6 SI-NO CCR
|
||
|
||
strDocumento = GuardarDatos(nFKTipoConstancia);
|
||
generarDocumento(strDocumento, nFKTipoConstancia.ToString());
|
||
}
|
||
|
||
if (dsInspeccionPABL.Tables[0].Rows[0]["EXISTEDISPONIBILIDADINSPECCIONAP"].ToString().ToLower() == "false" && dsInspeccionPABL.Tables[0].Rows[0]["EXISTECAPACIDADHIDRICAEXISTEDISPONIBILIDADAP"].ToString().ToLower() == "true")
|
||
{
|
||
nFKTipoConstancia = 5; //Formulario N°5 NO-SI CCH
|
||
|
||
strDocumento = GuardarDatos(nFKTipoConstancia);
|
||
generarDocumento(strDocumento, nFKTipoConstancia.ToString());
|
||
}
|
||
}
|
||
if (dsInspeccionPABL.Tables[0].Rows[0]["EXISTEDISPONIBILIDADINSPECCIONAP"].ToString().ToLower() == "true" && dsInspeccionASBL.Tables[0].Rows[0]["EXISTEDISPONIBILIDADINSPECCIONAS"].ToString().ToLower() == "false")
|
||
{
|
||
nFKTipoConstancia = 4; //Formulario N°4 SI NO
|
||
|
||
strDocumento = GuardarDatos(nFKTipoConstancia);
|
||
generarDocumento(strDocumento, nFKTipoConstancia.ToString());
|
||
|
||
if (dsInspeccionASBL.Tables[0].Rows[0]["EXISTEDISPONIBILIDADINSPECCIONAS"].ToString().ToLower() == "false" && dsInspeccionASBL.Tables[0].Rows[0]["CRITECNICONOEXISTEDISPONIBILIDAD"].ToString().ToLower() == "true")
|
||
{
|
||
nFKTipoConstancia = 6; //Formulario N°6 SI-NO CCR
|
||
|
||
strDocumento = GuardarDatos(nFKTipoConstancia);
|
||
generarDocumento(strDocumento, nFKTipoConstancia.ToString());
|
||
}
|
||
}
|
||
if (dsInspeccionPABL.Tables[0].Rows[0]["EXISTEDISPONIBILIDADINSPECCIONAP"].ToString().ToLower() == "false" && dsInspeccionASBL.Tables[0].Rows[0]["EXISTEDISPONIBILIDADINSPECCIONAS"].ToString().ToLower() == "true")
|
||
{
|
||
nFKTipoConstancia = 3; //Formulario N°4 NO SI
|
||
|
||
strDocumento = GuardarDatos(nFKTipoConstancia);
|
||
generarDocumento(strDocumento, nFKTipoConstancia.ToString());
|
||
|
||
if (dsInspeccionPABL.Tables[0].Rows[0]["EXISTEDISPONIBILIDADINSPECCIONAP"].ToString().ToLower() == "false" && dsInspeccionPABL.Tables[0].Rows[0]["EXISTECAPACIDADHIDRICAEXISTEDISPONIBILIDADAP"].ToString().ToLower() == "true")
|
||
{
|
||
nFKTipoConstancia = 5; //Formulario N°5 NO-SI CCH
|
||
|
||
strDocumento = GuardarDatos(nFKTipoConstancia);
|
||
generarDocumento(strDocumento, nFKTipoConstancia.ToString());
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region Agua potable
|
||
if (nTipoInspeccion == 1 )
|
||
{
|
||
nFKTipoConstancia = 0;
|
||
if (dsInspeccionPABL.Tables[0].Rows[0]["EXISTEDISPONIBILIDADINSPECCIONAP"].ToString().ToLower() == "true" )
|
||
{
|
||
nFKTipoConstancia = 4; //Formulario N°4 SI NO
|
||
|
||
strDocumento = GuardarDatos(nFKTipoConstancia);
|
||
generarDocumento(strDocumento, nFKTipoConstancia.ToString());
|
||
}
|
||
|
||
if (dsInspeccionPABL.Tables[0].Rows[0]["EXISTEDISPONIBILIDADINSPECCIONAP"].ToString().ToLower() == "false")
|
||
{
|
||
nFKTipoConstancia = 2; //Formulario N°2 NO NO
|
||
|
||
strDocumento = GuardarDatos(nFKTipoConstancia);
|
||
generarDocumento(strDocumento, nFKTipoConstancia.ToString());
|
||
}
|
||
|
||
if (dsInspeccionPABL.Tables[0].Rows[0]["EXISTEDISPONIBILIDADINSPECCIONAP"].ToString().ToLower() == "false" && dsInspeccionPABL.Tables[0].Rows[0]["EXISTECAPACIDADHIDRICAEXISTEDISPONIBILIDADAP"].ToString().ToLower() == "true")
|
||
{
|
||
nFKTipoConstancia = 5; //Formulario N°5 NO-NO CCH
|
||
|
||
strDocumento = GuardarDatos(nFKTipoConstancia);
|
||
generarDocumento(strDocumento, nFKTipoConstancia.ToString());
|
||
}
|
||
|
||
dsInspeccionPABL = null;
|
||
}
|
||
#endregion
|
||
|
||
#region alcantarillado sanitario
|
||
if (nTipoInspeccion == 2 )
|
||
{
|
||
nFKTipoConstancia = 0;
|
||
|
||
if (dsInspeccionASBL.Tables[0].Rows[0]["EXISTEDISPONIBILIDADINSPECCIONAS"].ToString().ToLower() == "true" )
|
||
{
|
||
nFKTipoConstancia = 3; //Formulario N°3 NO-SI
|
||
|
||
strDocumento = GuardarDatos(nFKTipoConstancia);
|
||
generarDocumento(strDocumento, nFKTipoConstancia.ToString());
|
||
}
|
||
|
||
if (dsInspeccionASBL.Tables[0].Rows[0]["EXISTEDISPONIBILIDADINSPECCIONAS"].ToString().ToLower() == "false")
|
||
{
|
||
nFKTipoConstancia = 2; //Formulario N°2 NO NO
|
||
|
||
strDocumento = GuardarDatos(nFKTipoConstancia);
|
||
generarDocumento(strDocumento, nFKTipoConstancia.ToString());
|
||
}
|
||
|
||
if (dsInspeccionASBL.Tables[0].Rows[0]["EXISTEDISPONIBILIDADINSPECCIONAS"].ToString().ToLower() == "false" && dsInspeccionASBL.Tables[0].Rows[0]["CRITECNICONOEXISTEDISPONIBILIDAD"].ToString().ToLower() == "true")
|
||
{
|
||
nFKTipoConstancia = 6; //Formulario N°6 NO-NO CCR
|
||
|
||
strDocumento = GuardarDatos(nFKTipoConstancia);
|
||
generarDocumento(strDocumento, nFKTipoConstancia.ToString());
|
||
}
|
||
|
||
dsInspeccionASBL = null;
|
||
}
|
||
#endregion
|
||
|
||
obtenerCartaSolicitud(nNumSolicitudTMP, "", nPKReutilizaTMP);
|
||
|
||
|
||
MensajeInformativo(AyABL.BASESDEDATOS.ADS + "Interfaz: " + MensajesAplicacion.GuardadoExitoso.ToString());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M8" + MensajesAplicacion.GuardadoFallido.ToString(), ex);
|
||
}
|
||
}
|
||
protected void btnGuardarPDF_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
//FirmadorWeb.FirmadorWebSvcClient cliente = new FirmadorWeb.FirmadorWebSvcClient();
|
||
|
||
if (documento != null && documento.Firmas.Count() > 0)
|
||
{
|
||
//byte[] contenido = cliente.ObtenerContenidoDocumento(
|
||
// long.Parse(ViewState["DocumentoID"].ToString()),
|
||
// CodigoSistema);
|
||
//System.IO.File.WriteAllBytes(ConfigurationManager.AppSettings["DocumentosPDF"].ToString() + @"\" + Session["SOLICITUD"].ToString() + @"\" + ViewState["Documento"].ToString() + ".pdf", contenido);
|
||
//ViewState.Remove("DocumentoID");
|
||
|
||
////var uri = new System.Uri(ConfigurationManager.AppSettings["DocumentosPDF"].ToString() + @"\" + Session["SOLICITUD"].ToString() + @"\" + ViewState["Documento"].ToString() + ".pdf", UriKind.Absolute);
|
||
//string targetURL = "'../../DocumentosPDF/" + Session["SOLICITUD"].ToString() + "/" + ViewState["Documento"].ToString() + ".pdf'";
|
||
//EjecutarScript("abrirPDF(" + targetURL + ");");
|
||
//System.Diagnostics.Process proc = new System.Diagnostics.Process();
|
||
//proc.StartInfo.FileName = ConfigurationManager.AppSettings["DocumentosPDF"].ToString() + @"\" + Session["SOLICITUD"].ToString() + @"\" + ViewState["Documento"].ToString() + ".pdf'";
|
||
//proc.Start();
|
||
//proc.Close();
|
||
}
|
||
else
|
||
{
|
||
MensajeAlerta("El documento no se firmó correctamente por favor vuelava a intentarlo.");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Se produjo un error al firmar el documento pdf.", ex);
|
||
}
|
||
ViewState["MODO"] = string.Empty;
|
||
ViewState["Documento"] = string.Empty;
|
||
}
|
||
#endregion
|
||
|
||
#region Metodos Personalizados (R4)
|
||
|
||
/// <summary>
|
||
/// Oculta las filas que lo requieran
|
||
/// </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:
|
||
|
||
divDatosSuperiores.Visible = true;
|
||
break;
|
||
|
||
case 3:
|
||
|
||
divDatosInferiores.Visible = true;
|
||
|
||
break;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// Metodo que se utiliza para remover el role asignado al usuario
|
||
/// </summary>
|
||
/// <param name="p_nPk"></param>
|
||
private bool eliminarCartaSolicitud(int p_nPk) //M1
|
||
{
|
||
bool blnValorRetornado = false;
|
||
try
|
||
{
|
||
objCartaBL = new cartaBL();
|
||
objCartaBL.objCartaEL.PK = p_nPk;
|
||
objCartaBL.objCartaEL.FKESTADOCARTA = 3;//eliminado
|
||
objCartaBL.activarInactivarCarta();
|
||
blnValorRetornado = true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
return blnValorRetornado;
|
||
}
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
#region Metodos Controles a Datos (R5)
|
||
/// <summary>
|
||
/// guarda y modifica registros en la tabla.
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private string GuardarDatos(int p_fkTipoFormulario) //M0
|
||
{
|
||
string strValorRetornado = "";
|
||
int nValorRetornado = 0;
|
||
|
||
try
|
||
{
|
||
string strModo = ViewState["MODO"].ToString();
|
||
|
||
DataSet ds = obtenerDocumento(nNumSolicitudTMP, "");
|
||
int Contador = ds.Tables[0].Rows.Count + 1;
|
||
|
||
objCartaBL = new cartaBL();
|
||
objCartaBL.objCartaEL.FKNUMSOLICITUD = int.Parse(Session["PKSOLICITUD"].ToString());
|
||
objCartaBL.objCartaEL.NOMBREDOCUMENTO = ConfigurationManager.AppSettings["SIGLAS"].ToString() + "-" + Session["SOLICITUD"].ToString().Trim() + "-" + Contador.ToString() +"-1"; //SDAA - AÑO - CONTADOR - CONTADOR DOCUMENTO - CONTADOR VERSION
|
||
objCartaBL.objCartaEL.FECHAEMITIDO = DateTime.Now;
|
||
objCartaBL.objCartaEL.FECHAVENCE = DateTime.Now.AddYears(1);
|
||
objCartaBL.objCartaEL.RENOVACION = 0;
|
||
objCartaBL.objCartaEL.ANOMBRE = int.Parse(rdlAnombre.SelectedValue.ToString());
|
||
objCartaBL.objCartaEL.FKJEFATURA1 = ddlJefatura1.SelectedValue;
|
||
objCartaBL.objCartaEL.NOMBREJEFATURA1 = ddlJefatura1.SelectedItem.Text;
|
||
objCartaBL.objCartaEL.FKJEFATURA2 = ddlJefatura2.SelectedValue;
|
||
objCartaBL.objCartaEL.NOMBREJEFATURA2 = ddlJefatura2.SelectedItem.Text;
|
||
objCartaBL.objCartaEL.FKTIPOFORMULARIO = p_fkTipoFormulario;
|
||
objCartaBL.objCartaEL.FKESTADOCARTA = 1;//ASTATE
|
||
|
||
|
||
|
||
objCartaBL.objCartaEL.CODIGOCARTA = Session["SOLICITUD"].ToString().Trim();
|
||
|
||
if (strModo == "Nuevo")
|
||
{
|
||
nValorRetornado = objCartaBL.insertarCarta();
|
||
strValorRetornado = objCartaBL.objCartaEL.NOMBREDOCUMENTO.ToString();
|
||
strValorRetornado = ConfigurationManager.AppSettings["SIGLAS"].ToString() + "-" + Session["SOLICITUD"].ToString().Trim() + "-" + Contador.ToString() + "-1_";
|
||
GuardarEventoBitacora(
|
||
Session["LOGIN"].ToString(),
|
||
AccionBitacora.INSERT.ToString(),
|
||
MensajesBitacora.IngresarRegistro + ": Se ha generado la carta " + objCartaBL.objCartaEL.NOMBREDOCUMENTO + " para la solicitud N° " + Session["SOLICITUD"].ToString().Trim(),
|
||
"frwCartaSolicitud.aspx",
|
||
Convert.ToInt32(ConfigurationManager.AppSettings["pkApp"])
|
||
);
|
||
}
|
||
|
||
if (strModo == "Reconsiderar")
|
||
{
|
||
//aumentar el consecutivo del documento
|
||
Char delimiter = '-';
|
||
string[] arrayDoc = ViewState["RECONSIDERAR"].ToString().Split(delimiter);//SIGDD - AÑO - CONTADOR - CONTADOR DOCUMENTO - CONTADOR VERSION
|
||
|
||
objCartaBL.objCartaEL.NOMBREDOCUMENTO = arrayDoc[0].ToString() + "-" + arrayDoc[1].ToString() + "-" + arrayDoc[2].ToString() + "-" + arrayDoc[3].ToString() + "-" + (int.Parse(arrayDoc[4].ToString()) + 1).ToString() + "_";
|
||
//objCartaBL.objCartaEL.NOMBREDOCUMENTO = arrayDoc[0].ToString() + "-" + arrayDoc[1].ToString() + "-" + arrayDoc[2].ToString() + "-" + (int.Parse(arrayDoc[3].ToString()) + 1).ToString();
|
||
|
||
nValorRetornado = objCartaBL.insertarCarta();
|
||
strValorRetornado = objCartaBL.objCartaEL.NOMBREDOCUMENTO.ToString();
|
||
strValorRetornado = arrayDoc[0].ToString() + "-" + arrayDoc[1].ToString() + "-" + arrayDoc[2].ToString() + "-" + (int.Parse(arrayDoc[3].ToString()) + 1).ToString();
|
||
GuardarEventoBitacora(
|
||
Session["LOGIN"].ToString(),
|
||
AccionBitacora.INSERT.ToString(),
|
||
MensajesBitacora.IngresarRegistro + ": Se ha generado la carta " + strValorRetornado + " al reconsiderar, para la solicitud " + Session["SOLICITUD"].ToString().Trim(),
|
||
"frwCartaSolicitud.aspx",
|
||
Convert.ToInt32(ConfigurationManager.AppSettings["pkApp"])
|
||
);
|
||
}
|
||
|
||
obtenerCartaSolicitud(nNumSolicitudTMP, "", nPKReutilizaTMP);
|
||
}
|
||
|
||
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
return strValorRetornado;
|
||
}
|
||
|
||
private void generarDocumento(string pstrDocumento, string strFKTipoConstancia)
|
||
{
|
||
try
|
||
{
|
||
|
||
string sourcePath = ConfigurationManager.AppSettings["DocumentosMachote"].ToString() + @"\Formulario_N°" + strFKTipoConstancia + ".odt";
|
||
string targetPath = ConfigurationManager.AppSettings["DocumentosODT"].ToString() + @"\" + pstrDocumento + ".odt";
|
||
|
||
|
||
|
||
if (System.IO.File.Exists(sourcePath))
|
||
{
|
||
System.IO.File.Copy(sourcePath, targetPath, true);
|
||
|
||
|
||
|
||
//string targetUrl = "../../../DocumentosODT/" + pstrDocumento + ".odt";
|
||
string targetUrl = "'../../../DocumentosODT/" + pstrDocumento + ".odt'";
|
||
|
||
|
||
if (System.IO.File.Exists(targetPath))
|
||
{
|
||
|
||
// EjecutarScript("abrirOdt(" + targetUrl + ");");
|
||
//{ ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>javascript: abrirOdt('" + targetUrl + "');</script>"); }
|
||
|
||
}
|
||
}
|
||
//else
|
||
//{
|
||
// { ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>javascript: MensajeInformativo('No existe el documento por favor verifique.');</script>"); }
|
||
|
||
|
||
//}
|
||
|
||
//// To copy a file to another location and
|
||
//// overwrite the destination file if it already exists.
|
||
// System.IO.File.Copy(sourcePath, targetPath, true);
|
||
// System.Diagnostics.Process proc = new System.Diagnostics.Process();
|
||
// proc.StartInfo.FileName = targetPath;
|
||
// proc.Start();
|
||
// proc.Close();
|
||
}
|
||
catch(Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
private void editarDocumento(string pstrDocumento)
|
||
{
|
||
try
|
||
{
|
||
string strResultado = string.Empty;
|
||
string targetPath = ConfigurationManager.AppSettings["DocumentosODT"].ToString() + @"\" + pstrDocumento + ".odt";
|
||
|
||
string targetUrl = "'../../DocumentosODT/" + pstrDocumento + ".odt'";
|
||
|
||
if (!System.IO.File.Exists(targetPath))
|
||
{
|
||
targetPath = ConfigurationManager.AppSettings["DocumentosODT"].ToString() + @"\" + pstrDocumento + "_.odt";
|
||
|
||
if (!System.IO.File.Exists(targetPath))
|
||
{
|
||
targetPath = string.Empty;
|
||
// ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>javascript: MensajeInformativo('No existe el documento por favor verifique.');</script>");
|
||
}
|
||
}
|
||
|
||
if (System.IO.File.Exists(targetPath))
|
||
{
|
||
#region constancias
|
||
Documento oDoc = new Documento();
|
||
|
||
byte[] bDoc = System.IO.File.ReadAllBytes(targetPath);
|
||
//se carga el archivo y el registro a vision 2020
|
||
strResultado = oDoc.Archivar_Documento(strNumSolicitudTMP.ToString().Trim() + "|" + "Constancia", pstrDocumento + "_.odt", bDoc);
|
||
if (strResultado == string.Empty)
|
||
{
|
||
|
||
// File.Delete(targetPath);
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
//if (!File.Exists(targetPath))
|
||
{
|
||
//obtener la constancia y ponerla en la carpeta compartida para el envio de correo
|
||
|
||
//se el registro de vision 2020
|
||
Documento oDoc = new Documento();
|
||
strResultado = oDoc.Consultar_Documento(strNumSolicitudTMP.ToString().Trim() + "|Constancia", pstrDocumento, pstrDocumento + "_.odt");
|
||
if (strResultado != string.Empty && strResultado != "No existe")
|
||
{
|
||
//strResultado += pdfPath + ";"; ;
|
||
GuardarEventoBitacora(
|
||
Session["LOGIN"].ToString(),
|
||
AccionBitacora.CONSULTA.ToString(),
|
||
MensajesBitacora.IngresarRegistro + ": Se ha descargado la constancia " + pstrDocumento.ToString() + " para edición, de la solicitud " + Session["SOLICITUD"].ToString(),
|
||
Path.GetFileNameWithoutExtension(Page.AppRelativeVirtualPath),
|
||
Convert.ToInt32(ConfigurationManager.AppSettings["pkApp"])
|
||
);
|
||
EjecutarScript("abrirPDF('" + strResultado + "');");
|
||
|
||
}
|
||
else
|
||
{
|
||
ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>javascript: MensajeInformativo('No se ha generado el documento PDF." + targetPath + "');</script>");
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
private void firmarDocumento(string pstrDocumento)
|
||
{
|
||
try
|
||
{
|
||
|
||
string sourcePath = ConfigurationManager.AppSettings["DocumentosMachote"].ToString() + @"\SIGPC_firma_electronica .odt";
|
||
string targetPath = ConfigurationManager.AppSettings["DocumentosODT"].ToString() + @"\" + pstrDocumento + "_" + Session["SOLICITUD"].ToString() + "_.odt";
|
||
string pdfPath = ConfigurationManager.AppSettings["DocumentosPDF"].ToString() + @"\" + Session["SOLICITUD"].ToString() + @"\" + pstrDocumento + ".pdf";
|
||
|
||
List<string> signatarios = new List<string>();
|
||
List<string> emails = new List<string>();
|
||
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["CedulaFirmaSIGPC"].ToString()))
|
||
{
|
||
signatarios.Add(ConfigurationManager.AppSettings["CedulaFirmaSIGPC"].ToString());
|
||
// emails.Add("jmonged@aya.go.cr");
|
||
}
|
||
|
||
#region constancias
|
||
if (!File.Exists(pdfPath))
|
||
{
|
||
//obtener la constancia y ponerla en la carpeta compartida para el envio de correo
|
||
|
||
|
||
//strResultado = oDoc.Consultar_Documento(arrayNombre[1].ToString() + "-" + arrayNombre[2].ToString() + "-" + arrayNombre[3].ToString() + "|Constancia", row["NOMBREDOCUMENTOCARTA"].ToString(), row["NOMBREDOCUMENTOCARTA"].ToString() + ".pdf");
|
||
Documento oDoc = new Documento();
|
||
string strResultado = oDoc.Visor_Documento(lblNumSolicitud.Text + "|" + "Constancia", lblNumSolicitud.Text.Trim(), pdfPath, pstrDocumento + ".pdf");
|
||
|
||
if (strResultado == string.Empty || strResultado == "No existe")
|
||
{
|
||
|
||
|
||
ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>javascript: MensajeInformativo('No se ha generado el documento PDF." + pdfPath + "');</script>");
|
||
}
|
||
|
||
|
||
}
|
||
|
||
#endregion
|
||
|
||
if (System.IO.File.Exists(pdfPath))
|
||
{
|
||
byte[] bytes = System.IO.File.ReadAllBytes(pdfPath);
|
||
|
||
//verificar si el documento ya se habia firmado
|
||
|
||
|
||
|
||
|
||
|
||
using(FirmadorWeb.FirmadorWebSvcClient cliente = new FirmadorWeb.FirmadorWebSvcClient())
|
||
{
|
||
long idDocumentoFirmado = cliente.CrearDocumento(
|
||
pstrDocumento + ".pdf",
|
||
"Firma de documentos",
|
||
bytes,
|
||
IdUsuarioSistemaCliente,
|
||
signatarios.ToArray(),
|
||
emails.ToArray(),
|
||
CodigoSistema,
|
||
"01");
|
||
|
||
// cliente.PonerOpcionesDocumento(idDocumentoFirmado, CodigoSistema, false, false, false);
|
||
|
||
documento.DocumentoID = idDocumentoFirmado;
|
||
|
||
ViewState["DocumentoID"] = idDocumentoFirmado;
|
||
Session["Cedula"] = ConfigurationManager.AppSettings["CedulaFirmaSIGPC"].ToString();
|
||
_UrlFirmadorWeb = null;
|
||
EjecutarScript("AbrirFirmadorWeb();");
|
||
ViewState["MODO"] = "Firmador";
|
||
ViewState["Documento"] = pstrDocumento;
|
||
|
||
ObservacionesBL objObservacionesBL = new ObservacionesBL();
|
||
//objObservacionesBL.objobservacionesEL.FKNUMSOLICITUD = strNumSolicitudTMP;
|
||
objObservacionesBL.objobservacionesEL.OBSERVACIONES = "El usuario " + Session["NOMBREEMPLEADO"].ToString() + " descargó la constancia " + pstrDocumento + ".pdf, para realizar la firma.";
|
||
objObservacionesBL.objobservacionesEL.Fecha = DateTime.Now;
|
||
objObservacionesBL.objobservacionesEL.FKSOLICITUD = int.Parse(Session["PKSOLICITUD"].ToString());
|
||
objObservacionesBL.objobservacionesEL.USUARIO = Session["LOGIN"].ToString();
|
||
|
||
int nValorRetornado = objObservacionesBL.insertarObservaciones();
|
||
|
||
|
||
|
||
GuardarEventoBitacora(
|
||
Session["LOGIN"].ToString(),
|
||
AccionBitacora.FIRMAR.ToString(),
|
||
MensajesBitacora.IngresarRegistro + ": El usuario " + Session["NOMBREEMPLEADO"].ToString() + " descargó la constancia " + pstrDocumento + ".pdf, para realizar la firma.",
|
||
Path.GetFileNameWithoutExtension(Page.AppRelativeVirtualPath),
|
||
Convert.ToInt32(ConfigurationManager.AppSettings["pkApp"])
|
||
);
|
||
|
||
//FirmadorWeb.Documento documentoFirmado = cliente.ObtenerDocumento(
|
||
// idDocumentoFirmado,
|
||
// CodigoSistema);
|
||
|
||
|
||
//if (documentoFirmado.Firmas.Count() == 0)
|
||
//{
|
||
// documento.DocumentoID = idDocumentoFirmado;
|
||
// ViewState["DocumentoID"] = idDocumentoFirmado;
|
||
// Session["Cedula"] = ConfigurationManager.AppSettings["CedulaFirmaSIGPC"].ToString();
|
||
// EjecutarScript("AbrirFirmadorWeb();");
|
||
//}
|
||
//else
|
||
//{
|
||
// MensajeInformativo("El documento ya fue firmado.");
|
||
//}
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
// System.IO.File.Copy(sourcePath, targetPath, true);
|
||
|
||
|
||
|
||
// string targetUrl = "'../../../DocumentosODT/" + pstrDocumento + "_" + Session["SOLICITUD"].ToString() + "_.odt'";
|
||
//// string targetUrl = "'../../../../DocumentosODT/" + pstrDocumento + ".odt'";
|
||
|
||
|
||
// if (System.IO.File.Exists(targetPath))
|
||
// {
|
||
|
||
// EjecutarScript("abrirOdt(" + targetUrl + ");");
|
||
|
||
// }
|
||
}
|
||
|
||
|
||
else
|
||
{
|
||
{ ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>javascript: MensajeInformativo('No se ha generado el documento PDF." + pdfPath + "');</script>"); }
|
||
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
private void obtenerDocumentoFirmado()
|
||
{
|
||
try
|
||
{
|
||
|
||
//string sourcePath = ConfigurationManager.AppSettings["DocumentosMachote"].ToString() + @"\SIGPC_firma_electronica .odt";
|
||
//string targetPath = ConfigurationManager.AppSettings["DocumentosODT"].ToString() + @"\" + pstrDocumento + "_" + Session["SOLICITUD"].ToString() + "_.odt";
|
||
string pdfPath = ConfigurationManager.AppSettings["DocumentosPDF"].ToString() + @"\" + Session["SOLICITUD"].ToString() + @"\" + ViewState["Documento"] + ".pdf";
|
||
|
||
|
||
|
||
if (System.IO.File.Exists(pdfPath))
|
||
{
|
||
byte[] bytes = System.IO.File.ReadAllBytes(pdfPath);
|
||
|
||
//verificar si el documento ya se habia firmado
|
||
|
||
|
||
|
||
|
||
|
||
using (FirmadorWeb.FirmadorWebSvcClient cliente = new FirmadorWeb.FirmadorWebSvcClient())
|
||
{
|
||
byte[] contenido = cliente.ObtenerContenidoDocumento(long.Parse(ViewState["DocumentoID"].ToString()), CodigoSistema);
|
||
File.WriteAllBytes(pdfPath, contenido);
|
||
|
||
}
|
||
#region constancias
|
||
Documento oDoc = new Documento();
|
||
|
||
byte[] bDoc = System.IO.File.ReadAllBytes(pdfPath);
|
||
//se carga el archivo y el registro a vision 2020
|
||
string strResultado = oDoc.Archivar_Documento(strNumSolicitudTMP.ToString().Trim() + "|" + "Constancia", ViewState["Documento"] + ".pdf", bDoc);
|
||
if (strResultado == string.Empty)
|
||
{
|
||
|
||
//File.Delete(pdfPath);
|
||
}
|
||
|
||
#endregion
|
||
|
||
}
|
||
|
||
|
||
|
||
else
|
||
{
|
||
{ ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>javascript: MensajeInformativo('No se pudo descargar el documento firmado por favor intente firmarlo de nuevo." + pdfPath + "');</script>"); }
|
||
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// guarda y modifica registros en la tabla.
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
///
|
||
|
||
|
||
private int GuardarDatosActividad(string p_accion, int p_nOrden)
|
||
{
|
||
int nValorRetornado = 0;
|
||
|
||
try
|
||
{
|
||
|
||
|
||
int nPkSolicitud = 0;
|
||
int nResultadoActualizar = 0;
|
||
string strMensajeContenido = "";
|
||
string strAsuntoCorreo = "";
|
||
string strPiePagina = "</BR> </BR></BR>AVISO DE CONFIDENCIALIDAD: este mensaje y la información incluida en él es confidencial y está dirigida únicamente al destinatario. Puede contener información privilegiada, confidencial, amparada por el secreto profesional o que no debe ser revelada. Si usted ha recibido este correo por error, por favor comunicarlo inmediatamente vía correo y tener la amabilidad de eliminarlo de su sistema. Queda notificado que no deberá copiar este mensaje, ni utilizar, divulgar, publicar o distribuir su contenido de modo alguno. Todo mensaje enviado a esta dirección de correo electrónico puede ser sujeto a inspección por alguien distinto de su receptor originario. La transmisión de correos no garantiza que el correo electrónico sea seguro o libre de error. Por consiguiente, se advierte que esta información pueda estar incompleta o ser poco precisa ya que toda información está sujeta a alterarse sin previo aviso.”";
|
||
string strDescripcionActividad = string.Empty;
|
||
|
||
if (p_nOrden == 5)
|
||
strDescripcionActividad = "confección de la constancia";
|
||
if (p_nOrden == 6)
|
||
strDescripcionActividad = "validación y firma de la constancia";
|
||
|
||
solicitudBL objSolicitudBL = new solicitudBL();
|
||
objSolicitudBL.objSolicitudEL.PK = int.Parse(Session["PKPROGRAMACION"].ToString());
|
||
objSolicitudBL.objSolicitudEL.FKUSUARIOXDEPENDENCIA = int.Parse(Session["PKUSUARIOXDEPENDENCIA"].ToString());
|
||
objSolicitudBL.objSolicitudEL.ORDEN = p_nOrden;//5:Confeccion de constancias 6:Validacion y firma
|
||
|
||
DataSet dsEncargadosActividades = objSolicitudBL.dsListaActividadesEncargado(null);
|
||
|
||
if (dsEncargadosActividades.Tables[0].Rows.Count > 0)
|
||
{
|
||
if (int.Parse(dsEncargadosActividades.Tables[0].Rows[0]["PKUSUARIOXDEPENDENCIA"].ToString()) == int.Parse(Session["PKUSUARIOXDEPENDENCIA"].ToString()) && int.Parse(dsEncargadosActividades.Tables[0].Rows[0]["FKESTADO"].ToString()) != 5
|
||
&& int.Parse(dsEncargadosActividades.Tables[0].Rows[0]["FKESTADO"].ToString()) != 8)
|
||
{
|
||
string strEncargadoActividad = dsEncargadosActividades.Tables[0].Rows[0]["PKRESPONSABLEACTIVIDAD"].ToString();
|
||
|
||
ObservacionesActividadesBL objObservacionesBL = new ObservacionesActividadesBL();
|
||
|
||
objObservacionesBL.objobservacionesEL.DESCRIPCION = "\n" + DateTime.Now.ToString()+ " - " + Session["NOMBREEMPLEADO"].ToString() + " - Se " + p_accion + " la actividad " + strDescripcionActividad + " de la solicitud N° " + Session["SOLICITUD"].ToString() + " por parte del usuario " + Session["NOMBREEMPLEADO"].ToString();
|
||
//objObservacionesBL.objobservacionesEL.FKUSUARIOXDEPENDENCIA = int.Parse(Session["PKUSUARIOXDEPENDENCIA"].ToString());
|
||
objObservacionesBL.objobservacionesEL.PKRESPONSABLEACTIVIDAD = int.Parse(strEncargadoActividad);
|
||
objObservacionesBL.objobservacionesEL.Fecha = DateTime.Now;
|
||
objObservacionesBL.objobservacionesEL.TIPO = 1;//1:observaciones 2:devolucion
|
||
|
||
nValorRetornado = objObservacionesBL.insertarObservacionActividad();
|
||
|
||
|
||
if (nValorRetornado != 0)
|
||
{
|
||
solicitudBL objSolicitud = new solicitudBL();
|
||
objSolicitud.objresponsableActividadEL.FECHADEVOLUCION = DateTime.Now;
|
||
foreach (DataRow row in dsEncargadosActividades.Tables[0].Rows)
|
||
{
|
||
|
||
objSolicitud.objresponsableActividadEL.PK = int.Parse(row["PKRESPONSABLEACTIVIDAD"].ToString());
|
||
if (p_accion == "finalizó")
|
||
{
|
||
|
||
decimal nTiempoActividad = 0;
|
||
if (row["CLASIFICACIONSOLICITUD"].ToString() == "Crecimiento vegetativo")
|
||
nTiempoActividad = decimal.Parse(row["TIEMPOCVACTIVIDAD"].ToString());
|
||
if (row["CLASIFICACIONSOLICITUD"].ToString() == "Desarrollo urbanistico")
|
||
nTiempoActividad = decimal.Parse(row["TIEMPODUACTIVIDAD"].ToString());
|
||
|
||
|
||
objSolicitudBL.objSolicitudEL.ORDEN = p_nOrden;//5:Confeccion de constancias 6:Validacion y firma
|
||
|
||
|
||
|
||
|
||
char[] separadorColumna = { '.' };
|
||
string[] strArrayTiempo = nTiempoActividad.ToString().Replace(",", ".").Split(separadorColumna);
|
||
|
||
DateTime dtFechaRecibido = DateTime.Parse(row["FECHAASIGNACIONRESPONSABLEACTIVIDAD"].ToString()).AddDays(double.Parse(strArrayTiempo[0].ToString()));
|
||
if (double.Parse(strArrayTiempo[1].ToString()) > 0)
|
||
dtFechaRecibido = dtFechaRecibido.AddHours(4);
|
||
|
||
|
||
|
||
|
||
if (dtFechaRecibido > DateTime.Now)
|
||
objSolicitud.objresponsableActividadEL.FKESTADO = 5;//finalizada a tiempo t_sgm_estadoactividad
|
||
else
|
||
objSolicitud.objresponsableActividadEL.FKESTADO = 8;//finalizada fuera de tiempo t_sgm_estadoactividad
|
||
|
||
strMensajeContenido = "La actividad " + strDescripcionActividad + " de la solicitud N° " + Session["SOLICITUD"].ToString() + " ha sido concluida para ver los detalles, ingrese al sistema <a href=http://" + HttpContext.Current.Request.Url.Authority + "/Forms/wfrLogin.> SIGDD</a>" + strPiePagina;
|
||
strAsuntoCorreo = "Conclusión de actividad - SIGDD";
|
||
|
||
|
||
|
||
nResultadoActualizar = objSolicitud.actualizarActividadSolicitud();
|
||
if (nResultadoActualizar > 0)
|
||
{
|
||
#region Envio de correo
|
||
|
||
AyABL.TRA.correoBL objcorreoBL = new AyABL.TRA.correoBL();
|
||
|
||
nPkSolicitud = Convert.ToInt32(row[1].ToString());//AQUI INSERTAMOS LA PK DE LA SOLICITUD
|
||
|
||
objcorreoBL.objcorreoEL.FKNUMSOLICITUD = nPkSolicitud;
|
||
// objcorreoBL.objcorreoEL.CORREO = dsActividad.Tables[0].Rows[0]["LOGINUSUARIO"].ToString() + "@aya.go.cr";
|
||
objcorreoBL.objcorreoEL.ASUNTO = strAsuntoCorreo;
|
||
objcorreoBL.objcorreoEL.CONTENIDO = strMensajeContenido;
|
||
objcorreoBL.objcorreoEL.FKUSUARIO = Convert.ToInt32(row["FKUSUARIOXDEPENDENCIA"].ToString());
|
||
objcorreoBL.objcorreoEL.Fecha = DateTime.Now;
|
||
|
||
nValorRetornado = objcorreoBL.insertarCorreo();
|
||
|
||
//poner la siguiente actividad en pendiente
|
||
|
||
objSolicitudBL = new solicitudBL();
|
||
objSolicitudBL.objSolicitudEL.PK = int.Parse(Session["PKPROGRAMACION"].ToString());
|
||
objSolicitudBL.objSolicitudEL.ORDEN = p_nOrden + 1;
|
||
|
||
DataSet dsEncargadosActividadesSiguiente = objSolicitudBL.dsListaActividadesEncargado(null);
|
||
foreach (DataRow row6 in dsEncargadosActividadesSiguiente.Tables[0].Rows)
|
||
{
|
||
|
||
objSolicitud.objresponsableActividadEL.PK = int.Parse(row6["PKRESPONSABLEACTIVIDAD"].ToString()); ;
|
||
objSolicitud.objresponsableActividadEL.FKESTADO = 3;//pendiente t_sgm_estadoactividad
|
||
nResultadoActualizar = objSolicitud.actualizarActividadSolicitud();
|
||
|
||
objcorreoBL.objcorreoEL.ASUNTO = strAsuntoCorreo;
|
||
objcorreoBL.objcorreoEL.CONTENIDO = strMensajeContenido;
|
||
objcorreoBL.objcorreoEL.FKUSUARIO = Convert.ToInt32(row6["FKUSUARIOXDEPENDENCIA"].ToString());
|
||
objcorreoBL.objcorreoEL.Fecha = DateTime.Now;
|
||
|
||
nValorRetornado = objcorreoBL.insertarCorreo();
|
||
}
|
||
|
||
|
||
|
||
#endregion
|
||
GuardarEventoBitacora(
|
||
Session["LOGIN"].ToString(),
|
||
AccionBitacora.INSERT.ToString(),
|
||
MensajesBitacora.IngresarRegistro + ": La actividad " + strDescripcionActividad + " de la solicitud N° " + Session["SOLICITUD"].ToString() + " ha sido finalizada por parte del encargado de la actividad: " + Session["NOMBREEMPLEADO"].ToString().Trim(),
|
||
Path.GetFileNameWithoutExtension(Page.AppRelativeVirtualPath),
|
||
Convert.ToInt32(ConfigurationManager.AppSettings["pkApp"])
|
||
);
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
|
||
//if (p_accion == "edita")
|
||
//{
|
||
// //Poner la actividad 6 programacion en pendiente(3)
|
||
// objSolicitudBL = new solicitudBL();
|
||
// objSolicitudBL.objSolicitudEL.PK = int.Parse(Session["PKPROGRAMACION"].ToString());
|
||
// objSolicitudBL.objSolicitudEL.ORDEN = p_nOrden + 1;
|
||
|
||
// dsEncargadosActividades = objSolicitudBL.dsListaActividadesEncargado(null);
|
||
// foreach (DataRow row in dsEncargadosActividades.Tables[0].Rows)
|
||
// {
|
||
|
||
// objSolicitud.objresponsableActividadEL.PK = int.Parse(row["PKRESPONSABLEACTIVIDAD"].ToString()); ;
|
||
// objSolicitud.objresponsableActividadEL.FKESTADO = 3;//pendiente t_sgm_estadoactividad
|
||
// nResultadoActualizar = objSolicitud.actualizarActividadSolicitud();
|
||
// }
|
||
//}
|
||
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
|
||
return nValorRetornado;
|
||
}
|
||
private static void WriteTextToDocument(BaseFont bf, Rectangle tamPagina, PdfContentByte over, PdfGState gs, string texto)
|
||
{
|
||
try
|
||
{
|
||
over.SetGState(gs);
|
||
over.SetRGBColorFill(220, 220, 220);
|
||
over.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_STROKE);
|
||
over.SetFontAndSize(bf, 46);
|
||
Single anchoDiag = (Single)Math.Sqrt(Math.Pow((tamPagina.Height - 120), 2) + Math.Pow((tamPagina.Width - 60), 2));
|
||
|
||
Single porc = (Single)100 * (anchoDiag / bf.GetWidthPoint(texto, 46));
|
||
over.SetHorizontalScaling(porc);
|
||
double angPage = (-1) * Math.Atan((tamPagina.Height - 60) / (tamPagina.Width - 60));
|
||
over.SetTextMatrix((float)Math.Cos(angPage), (float)Math.Sin(angPage), (float)((-1F) * Math.Sin(angPage)), (float)Math.Cos(angPage), 30F, (float)tamPagina.Height - 60);
|
||
over.ShowText(texto);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
#endregion
|
||
#region Métodos para generar token de seguridad del firmador web
|
||
/// <summary>
|
||
/// Identificador único definido por el sistema cliente para el documento incluído en el firmador web
|
||
/// </summary>
|
||
private string IdCorrelacionFirmadorWeb
|
||
{
|
||
get
|
||
{
|
||
return "01";
|
||
}
|
||
}
|
||
private FirmadorWeb.Documento _documento;
|
||
protected FirmadorWeb.Documento documento
|
||
{
|
||
get
|
||
{
|
||
if (_documento == null)
|
||
{
|
||
using (FirmadorWeb.FirmadorWebSvcClient cliente = new FirmadorWeb.FirmadorWebSvcClient())
|
||
{
|
||
|
||
// recuperar el documento usando el identificador de correlación
|
||
_documento = cliente.ObtenerDocumentoXIdCorrelacion(
|
||
IdCorrelacionFirmadorWeb, CodigoSistema);
|
||
}
|
||
}
|
||
return _documento;
|
||
}
|
||
}
|
||
private string _UrlFirmadorWeb;
|
||
protected string UrlFirmadorWeb
|
||
{
|
||
get
|
||
{
|
||
if (string.IsNullOrEmpty(_UrlFirmadorWeb))
|
||
{
|
||
try
|
||
{
|
||
if (IsPostBack)
|
||
_UrlFirmadorWeb = GenerarUrlFirmadorWeb(documento.DocumentoID, (string)Session["Cedula"]);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Se presentó un error con el servicio de firma digital.", ex);
|
||
}
|
||
|
||
}
|
||
return _UrlFirmadorWeb;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Genera un url para la página del documento en el firmador web
|
||
/// Incluye en el url un token de seguridad para el firmador web
|
||
/// </summary>
|
||
/// <param name="idDocumento">Documento que se va a abrir en el firmador web</param>
|
||
/// <param name="cedula">Cédula del usuario actual</param>
|
||
/// <returns></returns>
|
||
private string GenerarUrlFirmadorWeb(long idDocumento, string cedula)
|
||
{
|
||
return string.Format(
|
||
ConfigurationManager.AppSettings["UrlFirmadorWeb"],
|
||
idDocumento,
|
||
cedula,
|
||
Server.UrlEncode(
|
||
Cipher(
|
||
string.Format("{0},{1}", idDocumento, cedula)
|
||
)
|
||
)
|
||
);
|
||
}
|
||
/// <summary>
|
||
/// Encripta un valor usando la llave de encripción especificada en el parámetro LlaveEncripcionFW
|
||
/// Debe ser la misma llave que está configurada en el servicio
|
||
/// </summary>
|
||
/// <param name="value">Valor que se va a encriptar</param>
|
||
/// <returns>Valor encriptado</returns>
|
||
private static string Cipher(string value)
|
||
{
|
||
string llaveEncripcionFW = ConfigurationManager.AppSettings["LlaveEncripcionFW"];
|
||
Random rnd = new Random(DateTime.Now.Millisecond);
|
||
for (int i = 0; i < 8; i++)
|
||
value = "1234567890"[rnd.Next(10)] + value;
|
||
value = "XYZ" + value;
|
||
UTF7Encoding enc = new System.Text.UTF7Encoding();
|
||
byte[] keyBytes = enc.GetBytes(GetHash(llaveEncripcionFW));
|
||
|
||
TripleDES tdes = TripleDES.Create();
|
||
byte[] desKey = new byte[tdes.KeySize / 8];
|
||
for (int i = 0; i < desKey.Length; i++)
|
||
desKey[i] = keyBytes[i];
|
||
tdes.Mode = CipherMode.CBC;
|
||
tdes.Padding = PaddingMode.Zeros;
|
||
byte[] plain = enc.GetBytes(value);
|
||
int cipheredSize = plain.Length / tdes.BlockSize;
|
||
if (plain.Length % tdes.BlockSize > 0)
|
||
cipheredSize++;
|
||
cipheredSize *= tdes.BlockSize;
|
||
byte[] ciphered = new byte[cipheredSize];
|
||
|
||
ICryptoTransform cry = tdes.CreateEncryptor(desKey, desKey);
|
||
byte[] input = new byte[tdes.BlockSize];
|
||
byte[] output = new byte[tdes.BlockSize];
|
||
|
||
int iPlain = 0;
|
||
int iCiphered = 0;
|
||
while (iPlain < plain.Length)
|
||
{
|
||
int iInput = 0;
|
||
for (; iPlain < plain.Length && iInput < input.Length; iPlain++)
|
||
input[iInput++] = plain[iPlain];
|
||
for (; iInput < input.Length; iInput++)
|
||
input[iInput] = 0;
|
||
cry.TransformBlock(input, 0, input.Length, output, 0);
|
||
foreach (Byte outputByte in output)
|
||
ciphered[iCiphered++] = outputByte;
|
||
}
|
||
return Convert.ToBase64String(ciphered);
|
||
}
|
||
|
||
public static string GetHash(string value)
|
||
{
|
||
UTF7Encoding enc = new UTF7Encoding();
|
||
byte[] bytes = enc.GetBytes(value);
|
||
return GetHash(bytes);
|
||
}
|
||
|
||
public static string GetHash(byte[] value)
|
||
{
|
||
using (SHA1Managed sha1 = new SHA1Managed())
|
||
{
|
||
sha1.Initialize();
|
||
byte[] hash = sha1.ComputeHash(value);
|
||
return BitConverter.ToString(hash).ToLower().Replace("-", "");
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Metodos Datos a Controles (R6)
|
||
/// <summary>
|
||
/// LLena el listado de roles de usuario
|
||
/// </summary>
|
||
private void obtenerCartaSolicitud(int nNumSolicitud,string strNombreCarta, int nPKReutiliza) //M3
|
||
{
|
||
try
|
||
{
|
||
//Instancia el objeto
|
||
objCartaBL = new cartaBL();
|
||
|
||
//Asigna un valor al atributo de referencia del objeto
|
||
objCartaBL.objCartaEL.FKNUMSOLICITUD = nNumSolicitud;
|
||
objCartaBL.objCartaEL.NOMBREDOCUMENTO = strNombreCarta;
|
||
objCartaBL.objCartaEL.FKREUTILIZA = nPKReutiliza;
|
||
|
||
if (nPKReutiliza != 0)
|
||
{
|
||
char[] separadorColumna = { '-' };
|
||
string[] arrSolicitud = Session["SOLICITUD"].ToString().Split(separadorColumna);
|
||
objCartaBL.objCartaEL.NUMEROSOLICITUD = arrSolicitud[1].ToString();
|
||
}
|
||
//Carga en un dataset la información
|
||
DataSet ds = objCartaBL.listarCartas();
|
||
if (ds.Tables[0].Rows.Count > 0)
|
||
{
|
||
//ViewState["MODO"] = "Modificar";
|
||
|
||
grvListaCartaSolicitud.DataSource = ds;
|
||
grvListaCartaSolicitud.DataBind();
|
||
//General.detalleGridView(ds, grvListaCartaSolicitud, null);
|
||
mostrarFilaTabla(1);
|
||
}
|
||
else
|
||
{
|
||
|
||
ViewState["MODO"] = "Nuevo";
|
||
mostrarFilaTabla(3);
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// LLena el listado de roles de usuario
|
||
/// </summary>
|
||
private void verificarCartaSolicitud(int nNumSolicitud, string strNombreCarta, int nPKReutiliza) //M3
|
||
{
|
||
try
|
||
{
|
||
//Instancia el objeto
|
||
objCartaBL = new cartaBL();
|
||
|
||
//Asigna un valor al atributo de referencia del objeto
|
||
objCartaBL.objCartaEL.FKNUMSOLICITUD = nNumSolicitud;
|
||
objCartaBL.objCartaEL.NOMBREDOCUMENTO = strNombreCarta;
|
||
//objCartaBL.objCartaEL.FKREUTILIZA = nPKReutiliza;
|
||
objCartaBL.objCartaEL.FKESTADOCARTA = 1;
|
||
objCartaBL.objCartaEL.FKESTADOCARTA2 = 4;
|
||
|
||
//Carga en un dataset la información
|
||
DataSet ds = objCartaBL.listarCartas();
|
||
if (ds.Tables[0].Rows.Count > 0)
|
||
{
|
||
|
||
|
||
obtenerCartaSolicitud(nNumSolicitud, strNombreCarta, nPKReutiliza);
|
||
}
|
||
else
|
||
{
|
||
|
||
ViewState["MODO"] = "Nuevo";
|
||
mostrarFilaTabla(3);
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Carga la informacion de un documento en especifico
|
||
/// </summary>
|
||
public DataSet obtenerDocumento(int nNumSolicitud, string strNombreCarta) //M3
|
||
{
|
||
try
|
||
{
|
||
//Instancia el objeto
|
||
objCartaBL = new cartaBL();
|
||
|
||
//Asigna un valor al atributo de referencia del objeto
|
||
objCartaBL.objCartaEL.FKNUMSOLICITUD = nNumSolicitud;
|
||
objCartaBL.objCartaEL.NOMBREDOCUMENTO = strNombreCarta;
|
||
//Carga en un dataset la información
|
||
DataSet ds = objCartaBL.listarCartas();
|
||
if (ds.Tables[0].Rows.Count > 0)
|
||
{
|
||
//ViewState["MODO"] = "Modificar";
|
||
mostrarFilaTabla(3);
|
||
|
||
ddlTipoFormulario.Focus();
|
||
ddlTipoFormulario.SelectedValue = ds.Tables[0].Rows[0]["FKTIPOFORMULARIO"].ToString();
|
||
// ddlJefatura1.SelectedValue = ds.Tables[0].Rows[0]["FKJEFATURA1"].ToString();
|
||
//ddlJefatura2.SelectedValue = ds.Tables[0].Rows[0]["FKJEFATURA2"].ToString();
|
||
rdlAnombre.SelectedValue = ds.Tables[0].Rows[0]["ANOMBRECARTA"].ToString();
|
||
}
|
||
return ds;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Renovar agrega 12 meses a la fecha de vencimiento
|
||
/// </summary>
|
||
private bool RenovarDocumento(int nNumSolicitud, string strNombreCarta, int p_nPk) //M3
|
||
{
|
||
try
|
||
{
|
||
bool blnValorRetornado = false;
|
||
int nValorRetornado = 0;
|
||
//Instancia el objeto
|
||
objCartaBL = new cartaBL();
|
||
|
||
//Asigna un valor al atributo de referencia del objeto
|
||
objCartaBL.objCartaEL.FKNUMSOLICITUD = nNumSolicitud;
|
||
objCartaBL.objCartaEL.PK = p_nPk;
|
||
objCartaBL.objCartaEL.NOMBREDOCUMENTO = strNombreCarta;
|
||
objCartaBL.objCartaEL.CODIGOCARTA = Session["SOLICITUD"].ToString().Trim();
|
||
//Carga en un dataset la información
|
||
DataSet ds = objCartaBL.listarCartas();
|
||
|
||
//aumentar el consecutivo del documento
|
||
Char delimiter = '-';
|
||
string[] arrayDoc = strNombreCarta.Split(delimiter);//SIGDD - AÑO - CONTADOR - CONTADOR DOCUMENTO - CONTADOR VERSION
|
||
strNombreCarta = arrayDoc[0].ToString() + "-" + arrayDoc[1].ToString() + "-" + arrayDoc[2].ToString() + "-" + arrayDoc[3].ToString() + "-" + (int.Parse(arrayDoc[4].ToString()) + 1).ToString() + "-" + arrayDoc[5].ToString();
|
||
//strNombreCarta = arrayDoc[0].ToString() + "-" + arrayDoc[1].ToString() + "-" + arrayDoc[2].ToString() + "-" + (int.Parse(arrayDoc[3].ToString()) + 1).ToString();
|
||
|
||
int nNumDocumento = int.Parse(ds.Tables[0].Rows[0]["RENOVACIONCARTA"].ToString()) + 1;// int.Parse(arrayDoc[4].ToString()) + 1;
|
||
|
||
if (nNumDocumento <= 2 && (int.Parse(ds.Tables[0].Rows[0]["FKESTADO"].ToString()) == 1)) //se valida que no tenga mas de dos renovaciones y que este activo
|
||
{
|
||
objCartaBL.objCartaEL.NOMBREDOCUMENTO = strNombreCarta;
|
||
objCartaBL.objCartaEL.FECHAEMITIDO = DateTime.Parse(ds.Tables[0].Rows[0]["FECHAEMITIDOCARTA"].ToString());
|
||
DateTime dtFechaVence = DateTime.Parse(ds.Tables[0].Rows[0]["FECHAVENCECARTA"].ToString());
|
||
objCartaBL.objCartaEL.FECHAVENCE = dtFechaVence.AddYears(1);
|
||
objCartaBL.objCartaEL.RENOVACION = int.Parse(ds.Tables[0].Rows[0]["RENOVACIONCARTA"].ToString()) + 1;
|
||
objCartaBL.objCartaEL.ANOMBRE = int.Parse(ds.Tables[0].Rows[0]["ANOMBRECARTA"].ToString());
|
||
objCartaBL.objCartaEL.FKJEFATURA1 = ds.Tables[0].Rows[0]["FKJEFATURA1"].ToString();
|
||
objCartaBL.objCartaEL.FKJEFATURA2 = ds.Tables[0].Rows[0]["FKJEFATURA2"].ToString();
|
||
objCartaBL.objCartaEL.NOMBREJEFATURA1 = ds.Tables[0].Rows[0]["NOMBREJEFATURA1CARTA"].ToString();
|
||
objCartaBL.objCartaEL.NOMBREJEFATURA2 = ds.Tables[0].Rows[0]["NOMBREJEFATURA2CARTA"].ToString();
|
||
objCartaBL.objCartaEL.FKTIPOFORMULARIO = int.Parse(ds.Tables[0].Rows[0]["FKTIPOFORMULARIO"].ToString());
|
||
objCartaBL.objCartaEL.FKESTADOCARTA = int.Parse(ds.Tables[0].Rows[0]["FKESTADO"].ToString());
|
||
|
||
//se ingresa el nuevo registro con el contador aumentado
|
||
nValorRetornado = objCartaBL.insertarCarta();
|
||
//se crea el nuevo documento
|
||
generarDocumento(strNombreCarta, ds.Tables[0].Rows[0]["FKTIPOFORMULARIO"].ToString());
|
||
//Se cambia el estado a renovacion
|
||
if (nValorRetornado > 0)
|
||
{
|
||
objCartaBL = new cartaBL();
|
||
objCartaBL.objCartaEL.PK = p_nPk;
|
||
objCartaBL.objCartaEL.FKESTADOCARTA = 4;//renovacion
|
||
objCartaBL.activarInactivarCarta();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (nNumDocumento > 2)
|
||
{ ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>javascript: MensajeInformativo('El documento no puede ser renovado mas de dos veces.');</script>"); }
|
||
if (int.Parse(ds.Tables[0].Rows[0]["FKESTADO"].ToString()) != 1)
|
||
{ ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>javascript: MensajeInformativo('El documento no puede ser renovado.');</script>"); }
|
||
}
|
||
|
||
if (nValorRetornado > 0)
|
||
blnValorRetornado = true;
|
||
|
||
|
||
return blnValorRetornado;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Llena el dropdownlist de tipo de formulario
|
||
/// </summary>
|
||
private void llenarDDLtipoformulario() //M6
|
||
{
|
||
try
|
||
{
|
||
//Limpia el control
|
||
ddlTipoFormulario.Items.Clear();
|
||
//Instancia el bjeto
|
||
objTipoCartaBL = new tipoCartaBL();
|
||
//Asigna datos al atributo
|
||
|
||
|
||
//Carga la información en un dataset
|
||
DataSet dsTipoFormualrio = objTipoCartaBL.dsListaTipoCarta(null);
|
||
if (dsTipoFormualrio.Tables[0].Rows.Count != 0)
|
||
{
|
||
ddlTipoFormulario.DataSource = dsTipoFormualrio;
|
||
ddlTipoFormulario.DataTextField = dsTipoFormualrio.Tables[0].Columns["NOMBREMACHOTETIPOCARTA"].ColumnName;
|
||
ddlTipoFormulario.DataValueField = dsTipoFormualrio.Tables[0].Columns["PKTIPOCARTA"].ColumnName;
|
||
ddlTipoFormulario.DataBind();
|
||
|
||
|
||
ddlTipoFormulario.Items.Insert(0, new System.Web.UI.WebControls.ListItem("Seleccione", "-1"));
|
||
}
|
||
else
|
||
ddlTipoFormulario.Items.Insert(0, new System.Web.UI.WebControls.ListItem("----- No existen opciones -----", "-1"));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Llena el dropdownlist de tipo de jefatura
|
||
/// </summary>
|
||
/// <summary>
|
||
/// Llena el dropdownlist de Cantonales según la aplicación
|
||
/// </summary>
|
||
private void llenarDDLjefatura(DropDownList ddlTMP) //M3
|
||
{
|
||
try
|
||
{
|
||
//Limpia el control
|
||
ddlTMP.Items.Clear();
|
||
//Instancia el bjeto
|
||
objUsuarioBL = new usuarioBL();
|
||
|
||
//Carga la información en un dataset
|
||
DataSet dsRegion = objUsuarioBL.dsListaUsuariosJefatura(null);
|
||
|
||
objUsuarioAyABL = new UsuarioBL();
|
||
DataSet ds2 = objUsuarioAyABL.dsListaUsuarios(null);
|
||
|
||
DataTable dtJefes = new DataTable();
|
||
dtJefes.Columns.Add("USUARIOUSUARIOXDEPENDENCIA");
|
||
dtJefes.Columns.Add("NOMBRECOMPLETO");
|
||
if (dsRegion.Tables[0].Rows.Count != 0)
|
||
{
|
||
foreach (DataRow row in dsRegion.Tables[0].Rows)
|
||
{
|
||
foreach (DataRow rowUsuario in ds2.Tables[0].Rows)
|
||
{
|
||
if (row[1].ToString() == rowUsuario[1].ToString())
|
||
{
|
||
DataRow rowFinal = dtJefes.NewRow();
|
||
rowFinal["USUARIOUSUARIOXDEPENDENCIA"] = row[1].ToString();
|
||
rowFinal["NOMBRECOMPLETO"] = rowUsuario[12].ToString();
|
||
|
||
dtJefes.Rows.Add(rowFinal);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
if (dtJefes.Rows.Count != 0)
|
||
{
|
||
ddlTMP.DataSource = dtJefes;
|
||
ddlTMP.DataTextField = dtJefes.Columns["NOMBRECOMPLETO"].ColumnName;
|
||
ddlTMP.DataValueField = dtJefes.Columns["USUARIOUSUARIOXDEPENDENCIA"].ColumnName;
|
||
ddlTMP.DataBind();
|
||
|
||
|
||
ddlTMP.Items.Insert(0, new System.Web.UI.WebControls.ListItem("Seleccione", "-1"));
|
||
}
|
||
|
||
else
|
||
ddlTMP.Items.Insert(0, new System.Web.UI.WebControls.ListItem("----- Vacio -----", "-1"));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
|
||
|
||
protected void grvListaCartaSolicitud_RowDataBound(object sender, GridViewRowEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
|
||
|
||
GridViewRow selectedRow = e.Row;
|
||
//if (e.Row.RowType == DataControlRowType.Header)
|
||
//{
|
||
// e.Row.Cells[13].Visible = false;
|
||
// e.Row.Cells[11].Visible = false;
|
||
|
||
//}
|
||
if (e.Row.RowType == DataControlRowType.DataRow)
|
||
{
|
||
e.Row.Cells[8].Visible = false;
|
||
grvListaCartaSolicitud.Columns[8].Visible = false;
|
||
e.Row.Cells[8].ToolTip = "Inactivar documento";
|
||
e.Row.Cells[9].ToolTip = "Renovar documento";
|
||
//e.Row.Cells[9].ToolTip = "Reconsiderar documento";
|
||
e.Row.Cells[10].ToolTip = "Editar documento";
|
||
e.Row.Cells[11].ToolTip = "Firmar documento";
|
||
e.Row.Cells[12].ToolTip = "Ver documento";
|
||
e.Row.Cells[11].Visible = false;
|
||
|
||
grvListaCartaSolicitud.Columns[11].Visible = true;
|
||
grvListaCartaSolicitud.Columns[10].Visible = true;
|
||
|
||
|
||
//e.Row.Cells[11].Style.Add("Opacity", "0.5");
|
||
|
||
if (nPKReutilizaTMP != int.Parse(e.Row.Cells[7].Text))
|
||
{
|
||
string targetPath = ConfigurationManager.AppSettings["DocumentosODT"].ToString() + @"\" + selectedRow.Cells[1].Text + ".odt";
|
||
|
||
string targetUrl = "~/../../../DocumentosODT/" + selectedRow.Cells[1].Text + ".odt";
|
||
string targetUrlFirmar = "../../DocumentosPDF/" + Session["SOLICITUD"].ToString().Trim() + "/" + selectedRow.Cells[1].Text + ".pdf";
|
||
|
||
//LinkButton lnk = (LinkButton)e.Row.FindControl("lnk_Editar");
|
||
//LinkButton lnkFirmar = (LinkButton)e.Row.FindControl("lnk_Firmar");
|
||
|
||
//if (System.IO.File.Exists(targetPath))
|
||
//{
|
||
|
||
|
||
|
||
// lnk.Attributes.Add("href", targetUrl);
|
||
// lnkFirmar.Attributes.Add("onClick", "JavaScript: window.open('" + targetUrlFirmar + "','','_blank','width=500,height=245,left=350,top=400')");
|
||
|
||
|
||
|
||
|
||
//}
|
||
}
|
||
//else
|
||
//{
|
||
// { ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>javascript: MensajeInformativo('No existe el documento por favor verifique.');</script>"); }
|
||
|
||
|
||
//}
|
||
//Request["d"].ToString() = "constancia" viene de gestion de trabajo
|
||
if (nPKReutilizaTMP == int.Parse(e.Row.Cells[7].Text) || e.Row.Cells[6].Text == "Inactivo" || Request["d"].ToString() == "deshabilitar" || e.Row.Cells[13].Text.Trim() != strNumSolicitudTMP.Trim())
|
||
{
|
||
e.Row.Cells[8].Visible = false;
|
||
grvListaCartaSolicitud.Columns[8].Visible = false;
|
||
e.Row.Cells[9].Visible = false;
|
||
grvListaCartaSolicitud.Columns[9].Visible = false;
|
||
e.Row.Cells[10].Visible = false;
|
||
//grvListaCartaSolicitud.Columns[10].Visible = false;
|
||
//e.Row.Cells[11].Visible = false;
|
||
//grvListaCartaSolicitud.Columns[11].Visible = false;
|
||
|
||
//e.Row.Cells[11].Enabled = false;
|
||
|
||
//e.Row.Cells[8].Style.Add("Opacity", "0.5");
|
||
//e.Row.Cells[9].Style.Add("Opacity", "0.5");
|
||
//e.Row.Cells[10].Style.Add("Opacity", "0.5");
|
||
//e.Row.Cells[11].Style.Add("Opacity", "0.5");
|
||
}
|
||
|
||
|
||
|
||
if (e.Row.Cells[13].Text.Trim() == strNumSolicitudTMP.Trim() && Request["d"].ToString() == "firmar" && e.Row.Cells[6].Text == "Activo")
|
||
{
|
||
e.Row.Cells[8].Visible = false;
|
||
grvListaCartaSolicitud.Columns[8].Visible = false;
|
||
//e.Row.Cells[9].Visible = false;
|
||
|
||
e.Row.Cells[10].Visible = false;
|
||
//grvListaCartaSolicitud.Columns[10].Visible = false;
|
||
e.Row.Cells[11].Visible = true;
|
||
//grvListaCartaSolicitud.Columns[11].Visible = true;
|
||
|
||
}
|
||
if (Request["d"].ToString() == "deshabilitar" || Request["d"].ToString() == "finalizado")
|
||
{
|
||
|
||
e.Row.Cells[8].Visible = false;
|
||
grvListaCartaSolicitud.Columns[8].Visible = false;
|
||
e.Row.Cells[9].Visible = false;
|
||
grvListaCartaSolicitud.Columns[9].Visible = false;
|
||
|
||
e.Row.Cells[10].Visible = true;
|
||
grvListaCartaSolicitud.Columns[10].Visible = false;
|
||
e.Row.Cells[11].Visible = false;
|
||
//grvListaCartaSolicitud.Columns[11].Visible = false;
|
||
|
||
}
|
||
if (e.Row.Cells[13].Text.Trim() == strNumSolicitudTMP.Trim() && Request["d"].ToString() == "constancia" && e.Row.Cells[6].Text == "Activo")
|
||
{
|
||
e.Row.Cells[10].Visible = true;
|
||
|
||
}
|
||
|
||
e.Row.Cells[13].Visible = false;
|
||
// grvListaCartaSolicitud.Columns[13].Visible = false;
|
||
|
||
if (Request["d"].ToString() == "firmar")
|
||
{
|
||
grvListaCartaSolicitud.Columns[11].Visible = true;
|
||
grvListaCartaSolicitud.Columns[10].Visible = false;
|
||
}
|
||
else
|
||
{
|
||
grvListaCartaSolicitud.Columns[11].Visible = false;
|
||
}
|
||
if (Request["d"].ToString() == "constancia")
|
||
{
|
||
grvListaCartaSolicitud.Columns[10].Visible = true;
|
||
grvListaCartaSolicitud.Columns[11].Visible = false;
|
||
}
|
||
//else
|
||
//{
|
||
// grvListaCartaSolicitud.Columns[10].Visible = false;
|
||
//}
|
||
|
||
|
||
}
|
||
|
||
}
|
||
catch (Exception)
|
||
{ }
|
||
finally
|
||
{
|
||
|
||
}
|
||
|
||
}
|
||
|
||
protected void btnFinalizar_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
int nActividad = 5;//confeccion de constancia
|
||
|
||
if (Request["d"] != null)
|
||
{
|
||
if (Request["d"].ToString() == "firmar")
|
||
nActividad = 6;//validacion y firma de documentos
|
||
}
|
||
if (VerificarConstancias(nActividad))
|
||
{
|
||
|
||
#region constancias
|
||
Documento oDoc = new Documento();
|
||
bool bDocumentosAlmacenados = false;
|
||
char delimitador = '-';
|
||
//Asigna un valor al atributo de referencia del objeto
|
||
objCartaBL.objCartaEL.FKNUMSOLICITUD = int.Parse(Session["PKSOLICITUD"].ToString()); ;
|
||
objCartaBL.objCartaEL.NOMBREDOCUMENTO = string.Empty;
|
||
//objCartaBL.objCartaEL.FKREUTILIZA = nPKReutiliza;
|
||
//Carga en un dataset la información
|
||
DataSet ds = objCartaBL.listarCartas();
|
||
if (ds.Tables[0].Rows.Count > 0)
|
||
{
|
||
|
||
//ViewState["MODO"] = "Modificar";
|
||
foreach (DataRow row in ds.Tables[0].Rows)
|
||
{
|
||
if (row["DESCRIPCIONESTADOCARTA"].ToString() == "Activo")
|
||
{
|
||
string[] arrayNombre = row["NOMBREDOCUMENTOCARTA"].ToString().Split(delimitador);
|
||
string pdfPathConstancia = ConfigurationManager.AppSettings["RutaPdfAdjuntosSql"].ToString() + @"\" + arrayNombre[1].ToString() + "-" + arrayNombre[2].ToString() + "-" + arrayNombre[3].ToString() + @"\" + row["NOMBREDOCUMENTOCARTA"].ToString() + ".pdf";
|
||
|
||
byte[] bDoc = System.IO.File.ReadAllBytes(pdfPathConstancia);
|
||
//se carga el archivo y el registro a vision 2020
|
||
oDoc = new Documento();
|
||
string strResultado = oDoc.Archivar_Documento(strNumSolicitudTMP.ToString().Trim() + "|" + "Constancia", row["NOMBREDOCUMENTOCARTA"].ToString().Replace(" ", "_") + ".pdf", bDoc);
|
||
if (strResultado == string.Empty)
|
||
{
|
||
oDoc = new Documento();
|
||
strResultado = oDoc.Consultar_Documento(strNumSolicitudTMP.ToString().Trim() + "|Constancia", row["NOMBREDOCUMENTOCARTA"].ToString().Replace(" ", "_"), row["NOMBREDOCUMENTOCARTA"].ToString().Replace(" ", "_") + ".pdf");
|
||
if (strResultado != string.Empty && strResultado != "No existe")
|
||
{
|
||
//strResultado += pdfPath + ";"; ;
|
||
//File.Delete(pdfPathConstancia);
|
||
bDocumentosAlmacenados = true;
|
||
}
|
||
else
|
||
{
|
||
|
||
ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>javascript: MensajeInformativo('No se ha generado el documento PDF. Debe generar el documento pdf presionando el boton ExportarPDF desde el documento editable.');</script>");
|
||
bDocumentosAlmacenados = false;
|
||
return;
|
||
}
|
||
|
||
|
||
}
|
||
//else
|
||
// bResultado = false;
|
||
}
|
||
}
|
||
if (bDocumentosAlmacenados)
|
||
{
|
||
GuardarDatosActividad("finalizó", nActividad);
|
||
if (nActividad == 5)
|
||
{
|
||
MensajeInformativo("Finalizó con éxito la actividad 5 Administración de constancias.");
|
||
//cancelar notificacion
|
||
notificacionBL objNotificacionBL = new notificacionBL();
|
||
|
||
objNotificacionBL.objnotificacionEL.ID_DOCUMENTO = Session["SOLICITUD"].ToString() + " - Confección de constancias";
|
||
objNotificacionBL.objnotificacionEL.status = "00";
|
||
objNotificacionBL.objnotificacionEL.message = "OK";
|
||
int nValorRetornado = objNotificacionBL.cancelarNotificacion(objNotificacionBL.objnotificacionEL);
|
||
}
|
||
if (nActividad == 6)
|
||
{
|
||
MensajeInformativo("Finalizó con éxito la actividad 6 Validación y firma.");
|
||
//cancelar notificacion
|
||
notificacionBL objNotificacionBL = new notificacionBL();
|
||
|
||
objNotificacionBL.objnotificacionEL.ID_DOCUMENTO = Session["SOLICITUD"].ToString() + " - Validación y firma";
|
||
objNotificacionBL.objnotificacionEL.status = "00";
|
||
objNotificacionBL.objnotificacionEL.message = "OK";
|
||
int nValorRetornado = objNotificacionBL.cancelarNotificacion(objNotificacionBL.objnotificacionEL);
|
||
}
|
||
//ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>javascript: MensajeInformativo('Se ha generado el documento PDF. ');</script>");
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
else
|
||
MensajeAlerta("Falta finalizar la generación de constancias.");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Se presentó un error al finalizar la actividad.", ex);
|
||
}
|
||
}
|
||
public bool VerificarConstancias(int p_nOrden)
|
||
{
|
||
bool bValorRetornado = false;
|
||
try
|
||
{
|
||
|
||
//Instancia el objeto
|
||
objCartaBL = new cartaBL();
|
||
|
||
//Asigna un valor al atributo de referencia del objeto
|
||
objCartaBL.objCartaEL.FKNUMSOLICITUD = nNumSolicitudTMP;
|
||
objCartaBL.objCartaEL.NOMBREDOCUMENTO = string.Empty;
|
||
//objCartaBL.objCartaEL.FKREUTILIZA = nPKReutilizaTMP;
|
||
objCartaBL.objCartaEL.FKESTADOCARTA = 1;
|
||
objCartaBL.objCartaEL.FKESTADOCARTA2 = 4;
|
||
//Carga en un dataset la información
|
||
DataSet ds = objCartaBL.listarCartas();
|
||
//se el registro de vision 2020
|
||
Documento oDoc = new Documento();
|
||
string strResultado = string.Empty;
|
||
if (ds.Tables[0].Rows.Count > 0)
|
||
{
|
||
foreach (DataRow row in ds.Tables[0].Rows)
|
||
{
|
||
string pdfPath = ConfigurationManager.AppSettings["DocumentosPDF"].ToString() + @"\" + Session["SOLICITUD"].ToString() + @"\" + row["NOMBREDOCUMENTOCARTA"].ToString() + ".pdf";
|
||
#region constancias
|
||
if (!File.Exists(pdfPath))
|
||
{
|
||
//obtener la constancia y ponerla en la carpeta compartida para el envio de correo
|
||
char delimitador = '-';
|
||
string[] arrayNombre = row["NOMBREDOCUMENTOCARTA"].ToString().Split(delimitador);
|
||
//strResultado = oDoc.Consultar_Documento(arrayNombre[1].ToString() + "-" + arrayNombre[2].ToString() + "-" + arrayNombre[3].ToString() + "|Constancia", row["NOMBREDOCUMENTOCARTA"].ToString(), row["NOMBREDOCUMENTOCARTA"].ToString() + ".pdf");
|
||
|
||
|
||
string Archivo = row["NOMBREDOCUMENTOCARTA"].ToString() + ".pdf";
|
||
string strAlmacenado = "";
|
||
if (File.Exists(@"C:\fileproyectos\FileDesarrollo\WCF-PDF\" + Archivo))
|
||
{
|
||
strAlmacenado = "EXISTE";
|
||
}
|
||
|
||
//strResultado = oDoc.Visor_Documento(arrayNombre[1].ToString() + "-" + arrayNombre[2].ToString() + "-" + arrayNombre[3].ToString() + "|" + "Constancia", lblNumSolicitud.Text.Trim(), pdfPath, row["NOMBREDOCUMENTOCARTA"].ToString() + ".pdf");
|
||
|
||
if (strResultado == string.Empty || strResultado == "No existe")
|
||
{
|
||
|
||
|
||
ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>javascript: MensajeInformativo('No se ha generado el documento PDF. Debe exportar el documento desde el archivo editable presionando EnviarPDF" + pdfPath + "');</script>");
|
||
bValorRetornado = false;
|
||
return bValorRetornado;
|
||
}
|
||
|
||
|
||
}
|
||
|
||
#endregion
|
||
if (System.IO.File.Exists(pdfPath))
|
||
{
|
||
bValorRetornado = true;
|
||
if (p_nOrden == 6 && chkFirmado.Checked == true)//revisar firma
|
||
{
|
||
oDoc = new Documento();
|
||
//se transaforma el archivo a un arreglo de bytes
|
||
byte[] bDoc = System.IO.File.ReadAllBytes(pdfPath);
|
||
string nombreAdjunto = row["NOMBREDOCUMENTOCARTA"].ToString();
|
||
//nombreAdjunto = nombreAdjunto.Replace(" ", "_");
|
||
|
||
|
||
//se verifica que el archivo a subir este firmado
|
||
using (FirmadorWeb.FirmadorWebSvcClient cliente = new FirmadorWeb.FirmadorWebSvcClient())
|
||
{
|
||
FirmadorWeb.FirmaDigital1[] signatures = null;
|
||
//Trace.Write("Paso 1");
|
||
//try
|
||
//{
|
||
//throw new Exception("Excepcion volutaria");
|
||
signatures =
|
||
cliente.ValidarDocumento(
|
||
row["NOMBREDOCUMENTOCARTA"].ToString() + ".pdf",
|
||
bDoc
|
||
);
|
||
if (signatures.Count() > 0)
|
||
{
|
||
if (signatures[0].Estado.ToString() == "Invalido")
|
||
{
|
||
|
||
MensajeAlerta("La firma digital en el documento " + row["NOMBREDOCUMENTOCARTA"].ToString() + " no es válida." );
|
||
return false;
|
||
}
|
||
}
|
||
if (signatures.Count() == 0 )
|
||
{
|
||
MensajeAlerta("El documento " + row["NOMBREDOCUMENTOCARTA"].ToString() + " no ha sido firmado por favor realice el proceso de firma digital.");
|
||
return false;
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
bValorRetornado = false;
|
||
return bValorRetornado;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
if (p_nOrden == 6)//6:validacion y firma de documentos
|
||
{
|
||
//modificar el estado de la firma
|
||
solicitudBL objSolicitudBL = new solicitudBL();
|
||
objSolicitudBL.objSolicitudEL.PK = int.Parse(Session["PKPROGRAMACION"].ToString());
|
||
objSolicitudBL.objSolicitudEL.FKUSUARIOXDEPENDENCIA = int.Parse(Session["PKUSUARIOXDEPENDENCIA"].ToString());
|
||
objSolicitudBL.objSolicitudEL.ORDEN = p_nOrden;//6:validacion y firma de documentos
|
||
objSolicitudBL.objSolicitudEL.VALIDACIONFIRMARESPONSABLEACTIVIDAD = false;
|
||
DataSet dsEncargadoSolicitudFirma = objSolicitudBL.dsListaActividadesEncargadoFirma(null);
|
||
foreach (DataRow row in dsEncargadoSolicitudFirma.Tables[0].Rows)
|
||
{
|
||
objSolicitudBL.objresponsableActividadEL.VALIDACIONFIRMA = true;
|
||
objSolicitudBL.objresponsableActividadEL.PK = int.Parse(row["PKRESPONSABLEACTIVIDAD"].ToString());
|
||
int nResultActualizarFirma = objSolicitudBL.actualizarFirmaActividadSolicitud();
|
||
}
|
||
|
||
//verificar que no faltan firmas
|
||
objSolicitudBL = new solicitudBL();
|
||
objSolicitudBL.objSolicitudEL.PK = int.Parse(Session["PKPROGRAMACION"].ToString());
|
||
//objSolicitudBL.objSolicitudEL.FKUSUARIOXDEPENDENCIA = int.Parse(Session["PKUSUARIOXDEPENDENCIA"].ToString());
|
||
objSolicitudBL.objSolicitudEL.ORDEN = p_nOrden;//6:validacion y firma de documentos
|
||
objSolicitudBL.objSolicitudEL.VALIDACIONFIRMARESPONSABLEACTIVIDAD = false;
|
||
|
||
DataSet dsEncargadosActividades = objSolicitudBL.dsListaActividadesEncargadoFirma(null);
|
||
if (dsEncargadosActividades.Tables[0].Rows.Count > 0 && chkFirmado.Checked == true)//revisar firma
|
||
{
|
||
bValorRetornado = false;
|
||
foreach (DataRow row in dsEncargadosActividades.Tables[0].Rows)
|
||
{
|
||
string strPiePagina = "</BR> </BR></BR>AVISO DE CONFIDENCIALIDAD: este mensaje y la información incluida en él es confidencial y está dirigida únicamente al destinatario. Puede contener información privilegiada, confidencial, amparada por el secreto profesional o que no debe ser revelada. Si usted ha recibido este correo por error, por favor comunicarlo inmediatamente vía correo y tener la amabilidad de eliminarlo de su sistema. Queda notificado que no deberá copiar este mensaje, ni utilizar, divulgar, publicar o distribuir su contenido de modo alguno. Todo mensaje enviado a esta dirección de correo electrónico puede ser sujeto a inspección por alguien distinto de su receptor originario. La transmisión de correos no garantiza que el correo electrónico sea seguro o libre de error. Por consiguiente, se advierte que esta información pueda estar incompleta o ser poco precisa ya que toda información está sujeta a alterarse sin previo aviso.”";
|
||
|
||
string strAsuntoCorreo = "Conclusión de actividad - SIGDD";
|
||
string strMensajeContenido = "La actividad validación y firma de la solicitud N° " + Session["SOLICITUD"].ToString() + " no puede ser concluida hasta que se firmen las constancias, ingrese al sistema <a href=http://" + HttpContext.Current.Request.Url.Authority + "/Forms/wfrLogin.> SIGDD</a>" + strPiePagina;
|
||
AyABL.TRA.correoBL objcorreoBL = new AyABL.TRA.correoBL();
|
||
|
||
int nPkSolicitud = Convert.ToInt32(row[1].ToString());//AQUI INSERTAMOS LA PK DE LA SOLICITUD
|
||
|
||
objcorreoBL.objcorreoEL.FKNUMSOLICITUD = nPkSolicitud;
|
||
// objcorreoBL.objcorreoEL.CORREO = dsActividad.Tables[0].Rows[0]["LOGINUSUARIO"].ToString() + "@aya.go.cr";
|
||
objcorreoBL.objcorreoEL.ASUNTO = strAsuntoCorreo;
|
||
objcorreoBL.objcorreoEL.CONTENIDO = strMensajeContenido;
|
||
objcorreoBL.objcorreoEL.FKUSUARIO = Convert.ToInt32(row["FKUSUARIOXDEPENDENCIA"].ToString());
|
||
objcorreoBL.objcorreoEL.Fecha = DateTime.Now;
|
||
|
||
int nValorRetornado = objcorreoBL.insertarCorreo();
|
||
MensajeAlerta("Falta finalizar la firma de documentos por parte del usuario " + CultureInfo.CurrentCulture.TextInfo.ToTitleCase(row["NOMBRECOMPLETO"].ToString().ToLower()));
|
||
}
|
||
}
|
||
|
||
//verificar que los documentos se encuentran firmados
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
return bValorRetornado;
|
||
}
|
||
|
||
private void AbrirVentanaEmergenteDevolucion()
|
||
{
|
||
|
||
{
|
||
EjecutarScript("VentanaEmergenteAbrirDevolucion('frwDevolucionActividadesSolicitud.aspx');");
|
||
ViewState["POPUP"] = "VentanaEmergente";
|
||
|
||
//Instancia el objeto
|
||
objCartaBL = new cartaBL();
|
||
|
||
//Asigna un valor al atributo de referencia del objeto
|
||
objCartaBL.objCartaEL.FKNUMSOLICITUD = nNumSolicitudTMP;
|
||
objCartaBL.objCartaEL.NOMBREDOCUMENTO = string.Empty;
|
||
//objCartaBL.objCartaEL.FKREUTILIZA = nPKReutilizaTMP;
|
||
//Carga en un dataset la información
|
||
DataSet ds = objCartaBL.listarCartas();
|
||
if (ds.Tables[0].Rows.Count > 0)
|
||
{
|
||
foreach (DataRow row in ds.Tables[0].Rows)
|
||
{
|
||
int nPK = int.Parse(row["PKCARTA"].ToString());
|
||
eliminarCartaSolicitud(nPK);
|
||
}
|
||
obtenerCartaSolicitud(nNumSolicitudTMP, "", nPKReutilizaTMP);
|
||
}
|
||
}
|
||
|
||
}
|
||
} |