440 lines
18 KiB
C#
440 lines
18 KiB
C#
//=======================================================================
|
||
// Instituto Costarricense de Acueductos y Alcantarillados. - 2012
|
||
// Sistema de Autoevaluación para Control Interno
|
||
//
|
||
// Explicación de los contenidos del archivo.
|
||
// =========================================================================
|
||
// Historial
|
||
// PERSONA DIA – MES - AÑO DESCRIPCIÓN
|
||
// Pedro Leiva Cerdas 10 – Febrero - 2014 Entrega del sistema. (Versión original del archivo)
|
||
// Clase para trabajar con VISION 2020
|
||
// //======================================================================
|
||
// Derechos Reservados (C) 2012 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 BASEBL; // Para usar a enumsBL
|
||
using System.IO;
|
||
using System.Web;
|
||
using System.Text;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using System.Web.UI;
|
||
using System.Collections;
|
||
using System.Configuration;
|
||
using System.Web.UI.WebControls;
|
||
using System.Web.UI.HtmlControls;
|
||
using System.Collections.Generic;
|
||
using System.Security.Cryptography;
|
||
using System.Text.RegularExpressions;
|
||
using System.Net;
|
||
using wcfSigdd.vision2020serverapionline;
|
||
|
||
public partial class Documento : Page
|
||
{
|
||
//Se hace referencia del WS
|
||
wsapi wsVision2020;
|
||
|
||
//public const string const_strArchivadores = "Sistemas";
|
||
//public const string strIdGaveta = ""; //para sisproap siempre serà id_gabeta="0000003C" pero mejor buscamos el id_gabeta por si ha cambiado
|
||
|
||
//public const string const_strUsuario = "sevri";
|
||
//public const string const_strClave = "usersevri";
|
||
//public const string const_strGaveta = "sevri";
|
||
//public string const_strLlaves = ConfigurationSettings.AppSettings["const_strLlaves"].ToString(); //para este sistema SDI estas son las llaves por default
|
||
public string const_strUsuario = ConfigurationSettings.AppSettings["const_strUsuario"].ToString();
|
||
public string const_strClave = ConfigurationSettings.AppSettings["const_strClave"].ToString();
|
||
public string const_strArchivadores = ConfigurationSettings.AppSettings["const_strArchivadores"].ToString();
|
||
public string const_strGaveta = ConfigurationSettings.AppSettings["const_strGaveta"].ToString();
|
||
public string strIdGaveta = ""; //para este sistema sevri simpre serà ="00000035" pero mejor lo buscamos
|
||
public string const_strLlaves = ConfigurationSettings.AppSettings["const_strLlaves"].ToString(); //para este sistema SDI estas son las llaves por default
|
||
|
||
|
||
/// <summary>
|
||
/// Método que se utiliza para retornar un DS con el àrbol Estructura
|
||
/// </summary>
|
||
public DataSet dsEstructura(string strUsuario, string strClave, bool bolMappingTypeAttribute)
|
||
{
|
||
DataSet dsArbolEstructura = new DataSet();
|
||
try
|
||
{
|
||
wsVision2020 = new wcfSigdd.vision2020serverapionline.wsapi();
|
||
dsArbolEstructura = wsVision2020.Arbol_Estructura(strUsuario, strClave, bolMappingTypeAttribute);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return null;
|
||
}
|
||
return dsArbolEstructura;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Método que se utiliza para retornar el id de la Carpeta o sea la DEPENDENCIA que nos interesa
|
||
/// si retorna un null es que no encontro la Carpeta
|
||
/// </summary>
|
||
private string Id_Carpeta(string strLlaves, string strValores)
|
||
{
|
||
DataSet dataSet1 = new DataSet();
|
||
string str = (string)null;
|
||
try
|
||
{
|
||
this.wsVision2020 = new wsapi();
|
||
DataSet dataSet2 = this.wsVision2020.Devuelve_Ids_Gaveta_Carpeta(this.const_strUsuario, this.const_strClave, this.const_strArchivadores, this.const_strGaveta, strLlaves, strValores);
|
||
if (dataSet2.Tables[0].Rows.Count > 0)
|
||
str = dataSet2.Tables[0].Rows[1]["valor"].ToString();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return str;
|
||
}
|
||
return str;
|
||
}
|
||
|
||
public DataSet dsLista_archivos_soportados()
|
||
{
|
||
DataSet dataSet1 = new DataSet();
|
||
DataSet dataSet2;
|
||
try
|
||
{
|
||
this.wsVision2020 = new wsapi();
|
||
dataSet2 = this.wsVision2020.Lista_De_Archivos_Soportados();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return (DataSet)null;
|
||
}
|
||
return dataSet2;
|
||
}
|
||
|
||
private DataSet dsLista_Carpetas(string strLlaves, string strValoresLlaves)
|
||
{
|
||
DataSet dataSet1 = new DataSet();
|
||
DataSet dataSet2;
|
||
try
|
||
{
|
||
this.wsVision2020 = new wsapi();
|
||
dataSet2 = this.wsVision2020.Buscar_Carpetas(this.const_strUsuario, this.const_strClave, this.const_strArchivadores, this.const_strGaveta, this.strIdGaveta, strLlaves, strValoresLlaves);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
return dataSet2;
|
||
}
|
||
|
||
private DataSet dsLista_Simple_Documentos_Carpeta(string strId_Carpeta)
|
||
{
|
||
DataSet dataSet1 = new DataSet();
|
||
DataSet dataSet2;
|
||
try
|
||
{
|
||
this.wsVision2020 = new wsapi();
|
||
dataSet2 = this.wsVision2020.Lista_De_Documentos(strId_Carpeta);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
return dataSet2;
|
||
}
|
||
|
||
public string strURLArchivo(string strID_Carpeta, string strIde_obj)
|
||
{
|
||
DataSet dataSet = new DataSet();
|
||
string str;
|
||
try
|
||
{
|
||
this.wsVision2020 = new wsapi();
|
||
str = this.wsVision2020.Descargar_Documento(this.const_strUsuario, this.const_strClave, this.const_strArchivadores, this.const_strGaveta, strID_Carpeta, strIde_obj, true);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "";
|
||
}
|
||
return str;
|
||
}
|
||
|
||
public string strDescripcionArchivo(string strIde_obj)
|
||
{
|
||
DataSet dataSet1 = new DataSet();
|
||
string str = "";
|
||
try
|
||
{
|
||
this.wsVision2020 = new wsapi();
|
||
DataSet dataSet2 = this.wsVision2020.Lista_Notas_Documento(this.const_strUsuario, this.const_strClave, strIde_obj);
|
||
if (dataSet2.Tables.Count > 0)
|
||
str = dataSet2.Tables[0].Rows[0]["Nota"].ToString();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "Sin descripción";
|
||
}
|
||
return str;
|
||
}
|
||
|
||
public bool bolInsertar_DescripcionArchivo(
|
||
string strIde_carpeta,
|
||
string strIde_objeto,
|
||
string strDescripcion_obj)
|
||
{
|
||
bool flag1 = false;
|
||
bool flag2;
|
||
try
|
||
{
|
||
this.wsVision2020 = new wsapi();
|
||
this.wsVision2020.Insertar_Nota_Documento(this.const_strUsuario, this.const_strClave, this.const_strArchivadores, this.const_strGaveta, strIde_carpeta, strIde_objeto, strDescripcion_obj);
|
||
flag2 = true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return flag1;
|
||
}
|
||
return flag2;
|
||
}
|
||
|
||
public bool bolInsertar_DescripcionCarpeta(
|
||
string strArchivadores,
|
||
string strIde_carpeta,
|
||
string strDescripcion_obj)
|
||
{
|
||
bool flag1 = false;
|
||
bool flag2;
|
||
try
|
||
{
|
||
this.wsVision2020 = new wsapi();
|
||
this.wsVision2020.Insertar_Nota_Expediente(this.const_strUsuario, this.const_strClave, this.const_strArchivadores, this.const_strGaveta, strIde_carpeta, strDescripcion_obj);
|
||
flag2 = true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return flag1;
|
||
}
|
||
return flag2;
|
||
}
|
||
|
||
public DataSet dsLista_Completa_Documentos_Carpeta(
|
||
string strLlaves,
|
||
string strValoresLlaves)
|
||
{
|
||
DataSet dataSet1 = new DataSet();
|
||
DataSet dataSet2 = new DataSet();
|
||
DataSet dataSet3 = new DataSet();
|
||
try
|
||
{
|
||
DataSet dataSet4 = this.dsLista_Carpetas(strLlaves, strValoresLlaves);
|
||
if (!dataSet4.Tables.Count.Equals(0))
|
||
{
|
||
if (dataSet4.Tables[0].Rows.Count > 0)
|
||
{
|
||
DataSet dataSet5 = this.dsLista_Simple_Documentos_Carpeta(dataSet4.Tables[0].Rows[0]["ide_reg"].ToString());
|
||
if (dataSet5.Tables.Count > 0)
|
||
{
|
||
DataTable table = new DataTable();
|
||
table.Columns.Add("ide_carpeta", typeof(string));
|
||
table.Columns.Add("ide_objeto", typeof(string));
|
||
table.Columns.Add("des_objeto", typeof(string));
|
||
table.Columns.Add("FechaArchivado", typeof(DateTime));
|
||
table.Columns.Add("MB", typeof(string));
|
||
table.Columns.Add("ext_objeto", typeof(string));
|
||
table.Columns.Add("descripcion_objeto", typeof(string));
|
||
table.Columns.Add("Estado", typeof(string));
|
||
foreach (DataRow row in (InternalDataCollectionBase)dataSet5.Tables[0].Rows)
|
||
table.Rows.Add((object)dataSet4.Tables[0].Rows[0]["ide_reg"].ToString(), (object)row["ide_obj"].ToString(), (object)row["des_obj"].ToString(), (object)row["Archivado"].ToString(), (object)row["MB"].ToString(), (object)row["ext_tip"].ToString(), (object)this.strDescripcionArchivo(row["ide_obj"].ToString()).ToString(), (object)"~/App_Themes/Estados/imgBolita_Verde.png");
|
||
dataSet3.Tables.Add(table);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
return dataSet3;
|
||
}
|
||
|
||
public string strInsertar_Carpeta(
|
||
string strArchivadores,
|
||
string strLlaves,
|
||
string strValoresLlaves)
|
||
{
|
||
string str = (string)null;
|
||
try
|
||
{
|
||
this.wsVision2020 = new wsapi();
|
||
str = this.wsVision2020.Existe_Carpeta(this.const_strArchivadores, this.const_strGaveta, strLlaves, strValoresLlaves) ? this.Id_Carpeta(strLlaves, strValoresLlaves) : this.wsVision2020.Insertar_Carpeta(this.const_strUsuario, this.const_strClave, this.const_strArchivadores, this.const_strGaveta, strLlaves, strValoresLlaves);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
}
|
||
return str;
|
||
}
|
||
|
||
public bool Archivar_Documento_Byte(
|
||
string strEtiquetaCarpeta,
|
||
string strLlaves,
|
||
string strValoresLlaves,
|
||
string strNombreArchivo,
|
||
byte[] byteArchivoEnByte,
|
||
string strDescripcionDocumento)
|
||
{
|
||
bool flag = false;
|
||
string strIde_objeto = "";
|
||
try
|
||
{
|
||
this.wsVision2020 = new wsapi();
|
||
string str;
|
||
if (!this.wsVision2020.Existe_Carpeta(this.const_strArchivadores, this.const_strGaveta, strLlaves, strValoresLlaves))
|
||
{
|
||
str = this.wsVision2020.Insertar_Carpeta(this.const_strUsuario, this.const_strClave, this.const_strArchivadores, this.const_strGaveta, strLlaves, strValoresLlaves);
|
||
this.wsVision2020.Insertar_Nota_Expediente(this.const_strUsuario, this.const_strClave, this.const_strArchivadores, this.const_strGaveta, str, strEtiquetaCarpeta);
|
||
}
|
||
else
|
||
str = this.Id_Carpeta(strLlaves, strValoresLlaves);
|
||
if (str.ToString().Trim() != "")
|
||
strIde_objeto = this.wsVision2020.ArchivarDocumentoByteDevuelveIdObjeto(this.const_strUsuario, this.const_strClave, this.const_strArchivadores, this.const_strGaveta, str, strNombreArchivo, byteArchivoEnByte);
|
||
if (!(strDescripcionDocumento.ToString() == string.Empty) || !(strIde_objeto == string.Empty))
|
||
flag = this.bolInsertar_DescripcionArchivo(str, strIde_objeto, strDescripcionDocumento);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return flag;
|
||
}
|
||
return flag;
|
||
}
|
||
|
||
public string Archivar_Documento(
|
||
string strValoresLlaves,
|
||
string strNombreArchivo,
|
||
byte[] byteArchivoEnByte)
|
||
{
|
||
string str = "Error al guardar el archivo";
|
||
try
|
||
{
|
||
this.wsVision2020 = new wsapi();
|
||
if ((this.wsVision2020.Existe_Carpeta(this.const_strArchivadores, this.const_strGaveta, this.const_strLlaves, strValoresLlaves) ? (object)this.Id_Carpeta(this.const_strLlaves, strValoresLlaves) : (object)this.wsVision2020.Insertar_Carpeta(this.const_strUsuario, this.const_strClave, this.const_strArchivadores, this.const_strGaveta, this.const_strLlaves, strValoresLlaves)).ToString().Trim() != "")
|
||
str = this.wsVision2020.Archivar_DocumentoByte(this.const_strUsuario, this.const_strClave, this.const_strArchivadores, this.const_strGaveta, this.const_strLlaves, strValoresLlaves, strNombreArchivo, byteArchivoEnByte);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
return str;
|
||
}
|
||
|
||
public string Visor_Documento(
|
||
string strValoresLlaves,
|
||
string strCarpeta,
|
||
string ruta,
|
||
string strNombreDocumento)
|
||
{
|
||
this.wsVision2020 = new wsapi();
|
||
string str = "";
|
||
string ide_obj = "";
|
||
DataSet dataSet1 = new DataSet();
|
||
bool flag = true;
|
||
string empty = string.Empty;
|
||
try
|
||
{
|
||
if (!this.wsVision2020.Existe_Carpeta(this.const_strArchivadores, this.const_strGaveta, this.const_strLlaves, strValoresLlaves))
|
||
return "No existe";
|
||
string Id_Carpeta = this.wsVision2020.Buscar_Carpetas(this.const_strUsuario, this.const_strClave, this.const_strArchivadores, this.const_strGaveta, this.strIdGaveta, this.const_strLlaves, strValoresLlaves).Tables[0].Rows[0]["ide_reg"].ToString();
|
||
DataSet dataSet2 = this.wsVision2020.Lista_De_Documentos(Id_Carpeta);
|
||
if (dataSet2.Tables[0].Rows.Count <= 0)
|
||
return "No existe";
|
||
DateTime dateTime = Convert.ToDateTime(dataSet2.Tables[0].Rows[0]["Archivado"].ToString());
|
||
foreach (DataRow row in (InternalDataCollectionBase)dataSet2.Tables[0].Rows)
|
||
{
|
||
if (Convert.ToDateTime(row["Archivado"].ToString()) >= dateTime)
|
||
{
|
||
dateTime = Convert.ToDateTime(row["Archivado"].ToString());
|
||
if (row["des_obj"].ToString().Replace(" ", "_") == strNombreDocumento.Replace(" ", "_"))
|
||
ide_obj = row["ide_obj"].ToString();
|
||
}
|
||
}
|
||
using (wsapi wsapi = new wsapi())
|
||
{
|
||
string url = wsapi.Descargar_Documento(this.const_strUsuario, this.const_strClave, this.const_strArchivadores, this.const_strGaveta, Id_Carpeta, ide_obj, true);
|
||
str = str + this.GetFileName(url.Replace("|", "")) + "|";
|
||
if (url != string.Empty)
|
||
flag = this.DescargarArchivo2020(url, ruta, strCarpeta);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return str;
|
||
}
|
||
return str;
|
||
}
|
||
|
||
private string GetFileName(string hrefLink)
|
||
{
|
||
string[] strArray = hrefLink.Split('/');
|
||
return strArray.Length <= 0 ? hrefLink : strArray[strArray.Length - 1];
|
||
}
|
||
|
||
private bool DescargarArchivo2020(string url, string ruta, string strCarpeta)
|
||
{
|
||
bool flag;
|
||
try
|
||
{
|
||
WebRequest webRequest = WebRequest.Create(url);
|
||
WebResponse response = webRequest.GetResponse();
|
||
string path = ConfigurationManager.AppSettings["DocumentosPDF"].ToString() + "\\" + strCarpeta + "\\";
|
||
Directory.CreateDirectory(path);
|
||
Directory.CreateDirectory(path + "\\DocumentosREQ\\");
|
||
webRequest.RequestUri.ToString().Substring(webRequest.RequestUri.ToString().LastIndexOf("/") + 1);
|
||
Stream responseStream = response.GetResponseStream();
|
||
using (Stream destination = (Stream)System.IO.File.OpenWrite(ruta))
|
||
{
|
||
responseStream.CopyTo(destination);
|
||
responseStream.Close();
|
||
}
|
||
flag = true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
return flag;
|
||
}
|
||
|
||
public string Consultar_Documento(
|
||
string strValoresLlaves,
|
||
string strCarpeta,
|
||
string strNombreDocumento)
|
||
{
|
||
this.wsVision2020 = new wsapi();
|
||
string str = "";
|
||
string ide_obj = "";
|
||
DataSet dataSet1 = new DataSet();
|
||
try
|
||
{
|
||
if (!this.wsVision2020.Existe_Carpeta(this.const_strArchivadores, this.const_strGaveta, this.const_strLlaves, strValoresLlaves))
|
||
return "No existe";
|
||
string Id_Carpeta = this.wsVision2020.Buscar_Carpetas(this.const_strUsuario, this.const_strClave, this.const_strArchivadores, this.const_strGaveta, this.strIdGaveta, this.const_strLlaves, strValoresLlaves).Tables[0].Rows[0]["ide_reg"].ToString();
|
||
DataSet dataSet2 = this.wsVision2020.Lista_De_Documentos(Id_Carpeta);
|
||
DateTime dateTime = Convert.ToDateTime(dataSet2.Tables[0].Rows[0]["Archivado"].ToString());
|
||
foreach (DataRow row in (InternalDataCollectionBase)dataSet2.Tables[0].Rows)
|
||
{
|
||
if (Convert.ToDateTime(row["Archivado"].ToString()) >= dateTime)
|
||
{
|
||
dateTime = Convert.ToDateTime(row["Archivado"].ToString());
|
||
if (row["des_obj"].ToString() == strNombreDocumento)
|
||
ide_obj = row["ide_obj"].ToString();
|
||
}
|
||
}
|
||
using (wsapi wsapi = new wsapi())
|
||
str = wsapi.Descargar_Documento(this.const_strUsuario, this.const_strClave, this.const_strArchivadores, this.const_strGaveta, Id_Carpeta, ide_obj, false);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return str;
|
||
}
|
||
return str;
|
||
}
|
||
}
|
||
|
||
|
||
|