899 lines
33 KiB
C#
899 lines
33 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using Extensiones;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Text;
|
|
using Microsoft.Reporting.WebForms;
|
|
|
|
public partial class OI_DocumentoDetalle : ClsPaginas
|
|
{
|
|
#region "PROPIEDADES"
|
|
private int CveUsuarioResponsable
|
|
{
|
|
get
|
|
{
|
|
return ViewState["CveUsuarioResponsable"] == null ? -1 : ViewState["CveUsuarioResponsable"].ToString().ToEntero();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["CveUsuarioResponsable"] = value;
|
|
}
|
|
}
|
|
|
|
private int CveDocumento
|
|
{
|
|
get
|
|
{
|
|
return ViewState["CveDocumento"].ToString().ToEntero();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["CveDocumento"] = value;
|
|
}
|
|
}
|
|
|
|
private string ErrorMensaje
|
|
{
|
|
get
|
|
{
|
|
return ViewState["ErrorMensaje"].ToString();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["ErrorMensaje"] = value;
|
|
}
|
|
}
|
|
|
|
private string ArchivoAdjuntoNombre
|
|
{
|
|
get
|
|
{
|
|
return ViewState["ArchivoAdjuntoNombre"].ToString();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["ArchivoAdjuntoNombre"] = value;
|
|
}
|
|
}
|
|
|
|
private int CveUsuarioSeleccionado
|
|
{
|
|
get
|
|
{
|
|
return ViewState["CveUsuarioSeleccionado"].ToString().ToEntero();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["CveUsuarioSeleccionado"] = value;
|
|
}
|
|
}
|
|
|
|
private int CveAsignacion
|
|
{
|
|
get
|
|
{
|
|
return ViewState["CveAsignacion"].ToString().ToEntero();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["CveAsignacion"] = value;
|
|
}
|
|
}
|
|
|
|
private DataTable DtUsuariosParticipantes
|
|
{
|
|
get
|
|
{
|
|
return ((DataTable) ViewState["DtUsuariosParticipantes"]);
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["DtUsuariosParticipantes"] = value;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
Cargar();
|
|
CargarMensajeNuevoEditado();
|
|
}
|
|
}
|
|
|
|
#region "CARGAS"
|
|
private void CargarCveDocumento()
|
|
{
|
|
string CveDocumentoAux = Page.Request["CveDocumento"];
|
|
if (CveDocumentoAux != null)
|
|
{
|
|
this.CveDocumento = CveDocumentoAux.ToEntero();
|
|
}
|
|
else
|
|
{
|
|
this.CveDocumento = -1;
|
|
this.CveUsuarioResponsable = -1;
|
|
}
|
|
}
|
|
|
|
private void CargarMensajeNuevoEditado()
|
|
{
|
|
string MensajeNuevoEditado = Page.Request["Mensaje"];
|
|
switch (MensajeNuevoEditado)
|
|
{
|
|
case "Nuevo":
|
|
Alert("El Documento ha sido creado correctamente",JSBtnAceptar: "document.location.href=\"/OI/Documentos.aspx\";");
|
|
break;
|
|
case "NuevaVersion":
|
|
Alert("Nueva versión del Documento creado correctamente");
|
|
break;
|
|
case "Publicado":
|
|
Alert("Documento publicado");
|
|
break;
|
|
case "Rechazado":
|
|
Alert("Documento rechazado");
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void CargarUsuarios()
|
|
{
|
|
GvUsuarios.DataSource = get_GlobalDTUsuarios(-1, UsuarioActual.CveEmpresa).FiltraParametros("Estatus = 1");
|
|
GvUsuarios.DataBind();
|
|
}
|
|
|
|
private void CargarUsuariosParticipantes()
|
|
{
|
|
|
|
DataTable UsuariosAux = null;
|
|
ClsOIEventos ObjOI = new ClsOIEventos();
|
|
if (ObjOI.GetDocumentoAutorizacion(this.CveDocumento))
|
|
{
|
|
GvUsuarios.DataSource = ObjOI.DtResultados;
|
|
DtUsuariosParticipantes = ObjOI.DtResultados;
|
|
UsuariosAux = ObjOI.DtResultados;
|
|
}
|
|
ObjOI.Dispose();
|
|
GvUsuarios.DataBind();
|
|
IndicarQuienesYaAutorizaron(UsuariosAux);
|
|
|
|
}
|
|
|
|
private void IndicarQuienesYaAutorizaron(DataTable Usuarios)
|
|
{
|
|
if (Usuarios != null)
|
|
{
|
|
GridViewRowCollection UsuariosEnGrid = GvUsuarios.Rows;
|
|
foreach (GridViewRow Usuario in UsuariosEnGrid)
|
|
{
|
|
int CveUsuario = Usuario.DataKey("CveUsuario").ToEntero();
|
|
string Filtro = string.Format("CveUsuario = {0}", CveUsuario);
|
|
string FechaAprobacion = Usuarios.FiltroPrimeroValor("FechaAprobacion", Filtro);
|
|
Usuario.FCCheckBox("ChkAprobar").Checked = FechaAprobacion != "" || (UsuarioActual.CveUsuario == CveUsuarioResponsable && CveUsuario == UsuarioActual.CveUsuario);
|
|
string Adjunto = Usuarios.FiltroPrimeroValor("Adjunto", Filtro);
|
|
Usuario.FCLinkButton("LkbDescargarPropuesta").Visible = Adjunto != "";
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void GvUsuarios_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
LinkButton LkbSubirPropuestaAux = e.Row.FCLinkButton("LkbSubirPropuesta");
|
|
ScriptManager.GetCurrent(this).RegisterPostBackControl(LkbSubirPropuestaAux);
|
|
LinkButton LkbDescargarPropuestaAux = e.Row.FCLinkButton("LkbDescargarPropuesta");
|
|
ScriptManager.GetCurrent(this).RegisterPostBackControl(LkbDescargarPropuestaAux);
|
|
}
|
|
}
|
|
|
|
private void CargarSubCategoria()
|
|
{
|
|
DdlSubCategoria.Items.Clear();
|
|
int CveCategoria = DdlCategoria.SelectedValue.ToEntero();
|
|
ClsOIEventos ObjOI = new ClsOIEventos();
|
|
if (ObjOI.GetDocumentoSubCategoria(CveCategoria: CveCategoria))
|
|
{
|
|
DdlSubCategoria.DataSource = ObjOI.DtResultados;
|
|
DdlSubCategoria.DataBind();
|
|
}
|
|
ObjOI.Dispose();
|
|
}
|
|
|
|
private void CargarResponsable()
|
|
{
|
|
TxtResponsable.Text = UsuarioActual.Nombre;
|
|
}
|
|
|
|
private bool CargarDocumentoYaExistente()
|
|
{
|
|
bool SeCargoInfo = false;
|
|
ClsOIEventos ObjOI = new ClsOIEventos();
|
|
if (ObjOI.GetDocumento(this.CveDocumento, UsuarioActual.CveEmpresa))
|
|
{
|
|
if (ObjOI.DtResultados.Rows.Count > 0)
|
|
{
|
|
DataRow Documento = ObjOI.DtResultados.Rows[0];
|
|
|
|
CveUsuarioResponsable = Documento["CveUsuario"].ToString().ToEntero();
|
|
TxtDescripcion.Text = Documento["Descripcion"].ToString();
|
|
DdlCategoria.SelectedValue = Documento["CveCategoria"].ToString();
|
|
CargarSubCategoria();
|
|
DdlSubCategoria.SelectedValue = Documento["CveSubCategoria"].ToString();
|
|
LblEstatus.Text =$"Estatus: {Documento["Estatus"].ToString()}";
|
|
TxtVersion.Text = Documento["Version"].ToString();
|
|
TxtResponsable.Text = Documento["Responsable"].ToString();
|
|
TxtObs.InnerText = Documento["Observacion"].ToString();
|
|
|
|
ArchivoAdjuntoNombre = Documento["ArchivoFisico"].ToString();
|
|
LkbDescargarArchivo.Text = ArchivoAdjuntoNombre;
|
|
DivDescargarArchivo.Visible = true;
|
|
|
|
SeCargoInfo = true;
|
|
}else
|
|
{
|
|
this.CveDocumento = -1;
|
|
Alert("No se encontró el Documento", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
}
|
|
}
|
|
ObjOI.Dispose();
|
|
return SeCargoInfo;
|
|
}
|
|
|
|
private void CargarUsuariosAutorizo()
|
|
{
|
|
ClsOIEventos ObjOI = new ClsOIEventos();
|
|
if (ObjOI.GetDocumentoAutorizacion(this.CveDocumento))
|
|
{
|
|
DataTable UsuariosAutorizo = ObjOI.DtResultados;
|
|
GridViewRowCollection UsuariosRowCollection = GvUsuarios.Rows;
|
|
foreach (GridViewRow UsuarioRow in UsuariosRowCollection)
|
|
{
|
|
int CveUsuarioRow = UsuarioRow.DataKey("CveUsuario").ToEntero();
|
|
UsuarioRow.FCCheckBox("ChkUnir").Checked = UsuariosAutorizo.COUNT("CveUsuario", string.Format("CveUsuario = {0}", CveUsuarioRow)) > 0;
|
|
}
|
|
}
|
|
ObjOI.Dispose();
|
|
}
|
|
|
|
private void ConfiguracionActualizar()
|
|
{
|
|
LkbGuardar.Visible = false;
|
|
LkbActualizar.Visible = true;
|
|
LkbPublicar.Visible = VerificarAprobaciónParticipantes() && UsuarioActual.CveUsuario == CveUsuarioResponsable;
|
|
GvUsuarios.Columns[1].Visible = false;
|
|
GvUsuarios.Columns[2].Visible = true;
|
|
GvUsuarios.Columns[3].Visible = true;
|
|
}
|
|
|
|
private void ConfigurarGridUsuariosParticipantes()
|
|
{
|
|
int CveUsuarioActual = UsuarioActual.CveUsuario;
|
|
GridViewRowCollection Usuarios = GvUsuarios.Rows;
|
|
foreach (GridViewRow Usuario in Usuarios)
|
|
{
|
|
int CveUsuarioIteracion = Usuario.DataKey("CveUsuario").ToEntero();
|
|
if (CveUsuarioIteracion != CveUsuarioActual)
|
|
{
|
|
Usuario.FCCheckBox("ChkAprobar").Enabled = false;
|
|
Usuario.FCLinkButton("LkbSubirPropuesta").Visible = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ConfigurarCamposDetalleSegunUsuario()
|
|
{
|
|
if (UsuarioActual.CveUsuario != CveUsuarioResponsable)
|
|
{
|
|
TxtDescripcion.Enabled = false;
|
|
DdlSubCategoria.Enabled = false;
|
|
TxtVersion.Enabled = false;
|
|
TxtResponsable.Enabled = false;
|
|
TxtObs.Disabled = true;
|
|
DivFileDropZone.Visible = false;
|
|
LkbActualizar.Visible = false;
|
|
}
|
|
}
|
|
|
|
private void ConfigurarSegunEstatus()
|
|
{
|
|
bool MostrarSegunAprobado = (LblEstatus.Text == "Estatus: Aprobado");
|
|
bool MostrarSegunRechazado = (LblEstatus.Text == "Estatus: Rechazado");
|
|
bool MostrarSegunEnProceso = (LblEstatus.Text == "Estatus: En Proceso");
|
|
LkbActualizar.Visible = !(MostrarSegunRechazado) && (UsuarioActual.CveUsuario == this.CveUsuarioResponsable);
|
|
DivBotonesAcciones.Visible = !(MostrarSegunAprobado || MostrarSegunRechazado);
|
|
LkbNuevaVersion.Visible = MostrarSegunAprobado;
|
|
}
|
|
|
|
private void CargarCategorias()
|
|
{
|
|
ClsOIEventos ObjOI = new ClsOIEventos();
|
|
if (ObjOI.GetDocumentoCategoria())
|
|
{
|
|
DdlCategoria.DataSource = ObjOI.DtResultados;
|
|
}
|
|
ObjOI.Dispose();
|
|
DdlCategoria.DataBind();
|
|
DdlCategoria.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
DdlSubCategoria.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
}
|
|
|
|
protected void DdlCategoria_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (DdlCategoria.SelectedValue != "-1")
|
|
{
|
|
CargarSubCategoria();
|
|
}
|
|
}
|
|
|
|
private void MostrarBotonRechazar()
|
|
{
|
|
LkbRechazar.Visible = (LblEstatus.Text == "Estatus: En Proceso" && this.CveUsuarioResponsable == UsuarioActual.CveUsuario);
|
|
}
|
|
|
|
private void Cargar()
|
|
{
|
|
CargarCategorias();
|
|
CargarResponsable();
|
|
CargarCveDocumento();
|
|
CargarUsuarios();
|
|
if (this.CveDocumento > 0)
|
|
{
|
|
if (CargarDocumentoYaExistente())
|
|
{
|
|
CargarUsuariosParticipantes();
|
|
CargarUsuariosAutorizo();
|
|
ConfiguracionActualizar();
|
|
ConfigurarGridUsuariosParticipantes();
|
|
ConfigurarCamposDetalleSegunUsuario();
|
|
|
|
MostrarBotonRechazar();
|
|
}
|
|
}
|
|
ConfigurarSegunEstatus();
|
|
}
|
|
#endregion
|
|
|
|
#region "GENERAR DOCUMENTO"
|
|
protected void LblGuardar_Click(object sender, EventArgs e)
|
|
{
|
|
if(TxtDocumentoFile.Text != "[]")
|
|
{
|
|
ClsOIEventos ObjOI = new ClsOIEventos();
|
|
ObjOI.IniciaTransacSQL();
|
|
bool TieneError = false;
|
|
|
|
//Esta variable es requerida más adelante
|
|
int CveDocumento = 0;
|
|
string RutaArchivo = "-1";
|
|
string CorreosNotificacion = "";
|
|
byte[] ArchivoNotifiacion = null;
|
|
|
|
CveDocumento = GuardarDocumento(ref ObjOI, ref TieneError);//Se crea el Documento
|
|
if (!TieneError) { RutaArchivo = AsignarArchivoAlDocumento(CveDocumento, ref ObjOI, ref TieneError); }//Se guarda el archivo fisico y se asigna al Documento generado
|
|
if (!TieneError) { CorreosNotificacion = GuardarUsuariosQueAutorizan(CveDocumento, RutaArchivo, ref ObjOI, ref TieneError); }//asignamos a los usuarios que participaran en aprovar este documento
|
|
if (!TieneError)
|
|
{
|
|
ArchivoNotifiacion = GenerarArchivoByte(CveDocumento, RutaArchivo);
|
|
NotificarPorCorreo(CorreosNotificacion, RutaArchivo, ArchivoNotifiacion, CveDocumento);
|
|
}
|
|
|
|
//Gestión de errores y resultados
|
|
if (!TieneError)
|
|
{
|
|
ObjOI.Commit();
|
|
string ParamMensaje = LkbGuardar.Text == "Guardar" ? "Nuevo" : "NuevaVersion";//Esto indica la acción de usuario la cual se mostrará como alert al cargar la página
|
|
Response.Redirect(string.Format("/OI/DocumentoDetalle.aspx?CveDocumento={0}&Mensaje={1}", CveDocumento, ParamMensaje));
|
|
}
|
|
else
|
|
{
|
|
ObjOI.RollBack();
|
|
Alert(this.ErrorMensaje, ModExtensiones.TipoMensaje.MsgError);
|
|
UpCliente.Update();
|
|
}
|
|
ObjOI.Dispose();
|
|
}else
|
|
{
|
|
Alert("Es necesario cargar un Documento",ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
}
|
|
}
|
|
|
|
private int GuardarDocumento(ref ClsOIEventos ObjOI, ref bool TieneError)
|
|
{
|
|
int CveDocumentoPadre = this.CveDocumento > 0 ? this.CveDocumento : -1; //Asociamos el nuevo insert con un CveDocumento ya generado en caso de ser una nueva versión del documento
|
|
|
|
int CveDocumento = ObjOI.AddDocumento(DdlSubCategoria.SelectedValue.ToEntero(), TxtDescripcion.Text, TxtObs.InnerText, TxtVersion.Text, 1,
|
|
"", TxtResponsable.Text, CveDocumentoPadre, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa);
|
|
if (!(CveDocumento > 0))
|
|
{
|
|
TieneError = true;
|
|
this.ErrorMensaje = "Hubo un error al guardar el Documento";
|
|
}
|
|
return CveDocumento;
|
|
}
|
|
|
|
private string AsignarArchivoAlDocumento(int CveDocumento, ref ClsOIEventos ObjOI, ref bool TieneError)
|
|
{
|
|
|
|
string RutaArchivo = GuardarArchivo(CveDocumento);
|
|
if (RutaArchivo != "-1")
|
|
{
|
|
if (!ObjOI.UpdateDocumento(CveDocumento, -1, "-1", "-1", "-1", -1, RutaArchivo, "-1", ModExtensiones.MinFecha, -1, -1, -1))
|
|
{
|
|
TieneError = true;
|
|
this.ErrorMensaje = "Hubo un error al asignar el archivo";
|
|
}
|
|
}
|
|
else if (RutaArchivo == "Error")
|
|
{
|
|
TieneError = true;
|
|
this.ErrorMensaje = "Hubo un error al guardar el archivo";
|
|
}
|
|
return RutaArchivo;
|
|
}
|
|
|
|
private string GuardarUsuariosQueAutorizan(int CveDocumento, string RutaArchivo, ref ClsOIEventos ObjOI, ref bool TieneError)
|
|
{
|
|
StringBuilder CorreosReturn = new StringBuilder("");
|
|
GridViewRowCollection GridUsuarios = GvUsuarios.Rows;
|
|
foreach (GridViewRow GvRow in GridUsuarios)
|
|
{
|
|
if (GvRow.FCCheckBox("ChkUnir").Checked && !TieneError)
|
|
{
|
|
int CveUsuario = GvRow.DataKey("CveUsuario").ToEntero();
|
|
if (!ObjOI.AddDocumentoAutorizacion(CveDocumento, CveUsuario, ""))
|
|
{
|
|
TieneError = true;
|
|
this.ErrorMensaje = "Hubo un error al asignar los usuarios a este documento";
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
CorreosReturn.AppendFormat("{0},", GvRow.DataKey("Correo"));
|
|
}
|
|
}
|
|
}
|
|
|
|
return CorreosReturn.ToString();
|
|
}
|
|
#endregion
|
|
|
|
#region "ACTUALIZAR DOCUMENTO"
|
|
protected void LbkActualizar_Click(object sender, EventArgs e)
|
|
{
|
|
string Archivo = ActualizarArchivoEnDirectorio();
|
|
ActualizarDocumentoYaExistente(Archivo);
|
|
TxtDocumentoFile.Text = "";
|
|
Cargar();
|
|
UpCliente.Update();
|
|
Alert("Documento actualizado");
|
|
}
|
|
|
|
private string ActualizarArchivoEnDirectorio()
|
|
{
|
|
string ArchivoFisicoActualizado = ArchivoAdjuntoNombre;
|
|
if (TxtDocumentoFile.Text != "[]")
|
|
{
|
|
string RutaArchivo = string.Format(@"{0}DocumentosRepo\{1}\{2}", UsuarioActual.Empresa.Ruta, this.CveDocumento, ArchivoAdjuntoNombre);
|
|
if (File.Exists(RutaArchivo))
|
|
{
|
|
File.Delete(RutaArchivo);
|
|
}
|
|
|
|
ArchivoFisicoActualizado = GuardarArchivo(this.CveDocumento);
|
|
}
|
|
return ArchivoFisicoActualizado;
|
|
}
|
|
|
|
private void ActualizarDocumentoYaExistente(string ArchivoFisico)
|
|
{
|
|
ClsOIEventos ObjOI = new ClsOIEventos();
|
|
if (!ObjOI.UpdateDocumento(this.CveDocumento, DdlSubCategoria.SelectedValue.ToEntero(), TxtDescripcion.Text, TxtObs.InnerText, TxtVersion.Text, 1, ArchivoFisico,
|
|
UsuarioActual.Nombre, ModExtensiones.MinFecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa))
|
|
{
|
|
Alert("Error al actualizar", ModExtensiones.TipoMensaje.MsgError);
|
|
}
|
|
ObjOI.Dispose();
|
|
}
|
|
#endregion
|
|
|
|
#region "ARCHIVO ADJUNTO"
|
|
|
|
private string GuardarArchivo(int CveDocumento)
|
|
{
|
|
string RutaArchivo = "-1";
|
|
List<Archivo> Filesgral = TxtDocumentoFile.getfiles().Archivos;
|
|
|
|
//Si no existe la carpeta donde se guardan se crea
|
|
if (!Directory.Exists(UsuarioActual.Empresa.Ruta + @"\DocumentosRepo\" + CveDocumento))
|
|
{
|
|
Directory.CreateDirectory(UsuarioActual.Empresa.Ruta + @"\DocumentosRepo\" + CveDocumento);
|
|
}
|
|
|
|
if (TxtDocumentoFile.Text != "[]")
|
|
{
|
|
foreach (Archivo fileItem in Filesgral)
|
|
{
|
|
try
|
|
{
|
|
string NombreArchivo = fileItem.filenameO;
|
|
//Preparamos la ruta donde moveremos el archivo cargado
|
|
string RutaDestino = string.Format(@"{0}DocumentosRepo\{1}\{2}", UsuarioActual.Empresa.Ruta, CveDocumento, NombreArchivo);
|
|
|
|
//Movemos el archivo de la carpeta temporal hacia la carpeta de la empresa
|
|
System.IO.File.Move(fileItem.FileUrl, RutaDestino);
|
|
RutaArchivo = NombreArchivo;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Alert(e.Message);
|
|
RutaArchivo = "Error";
|
|
}
|
|
}
|
|
}
|
|
else if (this.CveDocumento > 0)
|
|
{
|
|
try
|
|
{
|
|
if (ArchivoAdjuntoNombre != "")
|
|
{
|
|
string RutaOrigen = string.Format(@"{0}DocumentosRepo\{1}\{2}", UsuarioActual.Empresa.Ruta, this.CveDocumento, ArchivoAdjuntoNombre);
|
|
string RutaDestino = string.Format(@"{0}DocumentosRepo\{1}\{2}", UsuarioActual.Empresa.Ruta, CveDocumento, ArchivoAdjuntoNombre);
|
|
|
|
System.IO.File.Move(RutaOrigen, RutaDestino);
|
|
RutaArchivo = ArchivoAdjuntoNombre;
|
|
}
|
|
else
|
|
{
|
|
RutaArchivo = "";
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Alert(e.Message);
|
|
RutaArchivo = "Error";
|
|
}
|
|
}
|
|
|
|
return RutaArchivo;
|
|
}
|
|
|
|
protected void LkbDescargarArchivo_Click(object sender, EventArgs e)
|
|
{
|
|
string Ruta = string.Format("{0}Empresas/{1}/DocumentosRepo/{2}/{3}", ModExtensiones.DirectorioBaseEmpresas, UsuarioActual.CveEmpresa, this.CveDocumento, ArchivoAdjuntoNombre);
|
|
byte[] archivoBytes = File.ReadAllBytes(Ruta);
|
|
|
|
HttpContext.Current.Response.Clear();
|
|
HttpContext.Current.Response.ClearContent();
|
|
HttpContext.Current.Response.ContentType = "application/octet-stream";
|
|
HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}", ArchivoAdjuntoNombre));
|
|
HttpContext.Current.Response.AddHeader("Content-Length", archivoBytes.Length.ToString());
|
|
HttpContext.Current.Response.OutputStream.Write(archivoBytes, 0, archivoBytes.Length);
|
|
HttpContext.Current.Response.End();
|
|
}
|
|
#endregion
|
|
|
|
#region "NOTIFICACIONES CORREO"
|
|
private string GenerarCuerpoCorreo(int CveDocumento)
|
|
{
|
|
string URL = string.Format("{0}/OI/DocumentoDetalle.aspx?CveDocumento={1}", HttpContext.Current.Request.Url.Host,CveDocumento);
|
|
StringBuilder body = new StringBuilder();
|
|
body.Append("Ha sido invitado a revisar la generación de un documento <br /> ");
|
|
body.Append($"Documento: {TxtDescripcion.Text},<br/> ");
|
|
body.Append($"Categoria: {DdlCategoria.SelectedItem.Text},<br/> ");
|
|
body.Append($"Subcategoria: {DdlSubCategoria.SelectedItem.Text},<br/> ");
|
|
body.Append($"<a href={URL}>Detalles del Documento</a>");
|
|
return body.ToString();
|
|
}
|
|
|
|
private void NotificarPorCorreo(string Para, string NombreArchivo, byte[] Adjunto, int CveDocumento)
|
|
{
|
|
string Descripcion = GenerarCuerpoCorreo(CveDocumento);
|
|
string Asunto = "Se le ha agregado como participante en el desarrollo de un Documento";
|
|
string a = string.Format("{0} -- {1} --- {2}", Descripcion, Para, "");
|
|
a.GuardaLog();
|
|
|
|
ClsSisMail Mail = new ClsSisMail();
|
|
|
|
if (Adjunto != null)
|
|
{
|
|
List<ClsSisMail.ArchivoMail> LSRutasMail = new List<ClsSisMail.ArchivoMail>();
|
|
ClsSisMail.ArchivoMail itemMail = new ClsSisMail.ArchivoMail();
|
|
|
|
{
|
|
var withBlock = itemMail;
|
|
itemMail.ArchivoBinario = Adjunto;
|
|
itemMail.NombreArchivo = NombreArchivo;
|
|
}
|
|
|
|
LSRutasMail.Add(itemMail);
|
|
|
|
|
|
Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Descripcion, "", LSRutasMail);
|
|
Mail = null/* TODO Change to default(_) if this is not a reference type */;
|
|
}
|
|
else
|
|
{
|
|
Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Descripcion, "");
|
|
Mail = null/* TODO Change to default(_) if this is not a reference type */;
|
|
}
|
|
}
|
|
|
|
private byte[] GenerarArchivoByte(int CveDocumento, string NombreArchivo)
|
|
{
|
|
string ArchivoEnviar = string.Format(@"{0}DocumentosRepo\{1}\{2}", UsuarioActual.Empresa.Ruta, CveDocumento, NombreArchivo);
|
|
if (File.Exists(ArchivoEnviar))
|
|
{
|
|
System.IO.FileStream fs = System.IO.File.Open(ArchivoEnviar, System.IO.FileMode.Open, System.IO.FileAccess.Read);
|
|
byte[] buff = new byte[fs.Length + 1];
|
|
if (fs.Length > 0)
|
|
{
|
|
fs.Read(buff, 0, (fs.Length.ToString().ToEntero() - 1));
|
|
fs.Close();
|
|
}
|
|
return buff;
|
|
}
|
|
|
|
return new byte[] { };
|
|
}
|
|
#endregion
|
|
|
|
#region "PROPUESTAS DE USUARIOS"
|
|
private DataRow GetUsuarioParticipante(int CveUsuario)
|
|
{
|
|
DataRow UsuarioRetorno = null;
|
|
ClsOIEventos ObjOI = new ClsOIEventos();
|
|
if (ObjOI.GetDocumentoAutorizacion(this.CveDocumento))
|
|
{
|
|
UsuarioRetorno = ObjOI.DtResultados.FiltroPrimero(string.Format("CveUsuario = {0}", CveUsuario));
|
|
}
|
|
ObjOI.Dispose();
|
|
return UsuarioRetorno;
|
|
}
|
|
|
|
protected void LkbSubirPropuesta_Click(object sender, EventArgs e)
|
|
{
|
|
GridViewRow GvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
|
|
int CveUsuarioSeleccionado = GvRow.DataKey("CveUsuario").ToEntero();
|
|
DataRow UsuarioSeleccionado = GetUsuarioParticipante(CveUsuarioSeleccionado);
|
|
this.CveUsuarioSeleccionado = CveUsuarioSeleccionado;
|
|
this.CveAsignacion = UsuarioSeleccionado["CveAutorizacion"].ToString().ToEntero();
|
|
RegistraScript(String.Format("$('#{0}').modal();", "DivAgregarPropuesta"));
|
|
}
|
|
|
|
protected void LkbDescargarPropuesta_Click(object sender, EventArgs e)
|
|
{
|
|
GridViewRow GvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
|
|
int CveUsuario = GvRow.DataKey("CveUsuario").ToEntero();
|
|
DataRow UsuarioSeleccionado = GetUsuarioParticipante(CveUsuario);
|
|
string Propuesta = UsuarioSeleccionado["Adjunto"] == null ? "" : UsuarioSeleccionado["Adjunto"].ToString();
|
|
string Ruta = string.Format("{0}DocumentosRepo/{1}/{2}", UsuarioActual.Empresa.Ruta, this.CveDocumento, Propuesta);
|
|
if (File.Exists(Ruta))
|
|
{
|
|
byte[] archivoBytes = File.ReadAllBytes(Ruta);
|
|
|
|
HttpContext.Current.Response.Clear();
|
|
HttpContext.Current.Response.ClearContent();
|
|
HttpContext.Current.Response.ContentType = "application/octet-stream";
|
|
HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}", Propuesta));
|
|
HttpContext.Current.Response.AddHeader("Content-Length", archivoBytes.Length.ToString());
|
|
HttpContext.Current.Response.OutputStream.Write(archivoBytes, 0, archivoBytes.Length);
|
|
HttpContext.Current.Response.End();
|
|
}
|
|
else
|
|
{
|
|
Alert("El Usuario no ha realizado una propuesta", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
}
|
|
}
|
|
|
|
protected void BtnAgregarPropuesta_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
string Archivo = SubirPropuestaEnDirectorio(this.CveUsuarioSeleccionado);
|
|
bool UsuarioActualizado = ActualizarUsuario(this.CveAsignacion, Archivo);
|
|
if (UsuarioActualizado)
|
|
{
|
|
RegistraScript(String.Format("$('#{0}').modal('hide');", "DivAgregarPropuesta"));
|
|
Alert("La propuesta se realizó correctamente");
|
|
CargarUsuariosParticipantes();
|
|
CargarUsuariosAutorizo();
|
|
ConfigurarGridUsuariosParticipantes();
|
|
UpDatosUsuarios.Update();
|
|
}
|
|
}
|
|
|
|
private string SubirPropuestaEnDirectorio(int CveUsuario)
|
|
{
|
|
List<Archivo> Filesgral = TxtArchivoPropuesta.getfiles().Archivos;
|
|
string fileNameReturn = "-1";
|
|
if (TxtArchivoPropuesta.Text != "[]")
|
|
{
|
|
foreach (Archivo fileItem in Filesgral)
|
|
{
|
|
try
|
|
{
|
|
string AdjuntoYaCargado = GetUsuarioParticipante(CveUsuario)["Adjunto"] == null ? "": GetUsuarioParticipante(CveUsuario)["Adjunto"].ToString();
|
|
string RutaBuscar = string.Format(@"{0}DocumentosRepo\{1}\{2}", UsuarioActual.Empresa.Ruta, this.CveDocumento, AdjuntoYaCargado);
|
|
if (File.Exists(RutaBuscar))
|
|
{
|
|
File.Delete(RutaBuscar);
|
|
}
|
|
string NombreArchivo = fileItem.filenameO;
|
|
fileNameReturn = string.Format("{0}_{1}", CveUsuario, NombreArchivo);
|
|
string RutaDestino = string.Format(@"{0}DocumentosRepo\{1}\{2}_{3}", UsuarioActual.Empresa.Ruta, this.CveDocumento, CveUsuario, NombreArchivo);
|
|
System.IO.File.Move(fileItem.FileUrl, RutaDestino);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Alert(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
return fileNameReturn;
|
|
}
|
|
|
|
private bool ActualizarUsuario(int CveAutorizacion, string Archivo)
|
|
{
|
|
ClsOIEventos ObjOI = new ClsOIEventos();
|
|
if (!ObjOI.UpdateDocumentoAutorizacion(CveAutorizacion, this.CveDocumento, TxtComentarios.InnerText, Archivo, ModExtensiones.MinFecha))
|
|
{
|
|
Alert("Error al actualizar el archivo subido propuesto por el usuario");
|
|
return false;
|
|
}
|
|
ObjOI.Dispose();
|
|
return true;
|
|
}
|
|
#endregion
|
|
|
|
#region "APROBACIÓN DEL DOCUMENTO"
|
|
protected void ChkAprobar_Checked(object sender, EventArgs e)
|
|
{
|
|
CheckBox SelectedCheckBox = (CheckBox)sender;
|
|
GridViewRow UsuarioAux = (GridViewRow)((Control)sender).Parent.Parent;
|
|
int CveUsuario = UsuarioAux.DataKey("CveUsuario").ToEntero();
|
|
DataRow Usuario = GetUsuarioParticipante(CveUsuario);
|
|
|
|
AprobacionDeUsuario(Usuario, SelectedCheckBox.Checked);
|
|
|
|
LkbPublicar.Visible = VerificarAprobaciónParticipantes() && UsuarioActual.CveUsuario == CveUsuarioResponsable;
|
|
UpCliente.Update();
|
|
|
|
}
|
|
|
|
private void AprobacionDeUsuario(DataRow Usuario, bool Autorizar)
|
|
{
|
|
int CveAutorizacion = Usuario["CveAutorizacion"].ToString().ToEntero();
|
|
ClsOIEventos ObjOI = new ClsOIEventos();
|
|
if (Autorizar)
|
|
{
|
|
if (ObjOI.UpdateDocumentoAutorizacion(CveAutorizacion, -1, "-1", "-1", NowADS()))
|
|
{
|
|
Alert("Haz aprobado la versión actual del Documento");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (ObjOI.DesaprobarDocumentoAutorizacion(CveAutorizacion))
|
|
{
|
|
Alert("Haz desaprobado la versión actual del Documento");
|
|
}
|
|
}
|
|
ObjOI.Dispose();
|
|
}
|
|
|
|
private bool VerificarAprobaciónParticipantes()
|
|
{
|
|
GridViewRowCollection Usuarios = GvUsuarios.Rows;
|
|
bool Aprobado = true;
|
|
foreach (GridViewRow Usuario in Usuarios)
|
|
{
|
|
if (!Usuario.FCCheckBox("ChkAprobar").Checked)
|
|
{
|
|
Aprobado = false;
|
|
break;
|
|
}
|
|
}
|
|
return Aprobado;
|
|
}
|
|
|
|
protected void LkbPublicar_Click(object sender, EventArgs e)
|
|
{
|
|
bool Aprobado = VerificarAprobaciónParticipantes();
|
|
|
|
if (Aprobado)
|
|
{
|
|
ClsOIEventos ObjOI = new ClsOIEventos();
|
|
if (ObjOI.UpdateDocumento(this.CveDocumento, DdlSubCategoria.SelectedValue.ToEntero(), TxtDescripcion.Text, TxtObs.InnerText, TxtVersion.Text, 2, "-1", TxtResponsable.Text,
|
|
NowADS(), -1, -1, UsuarioActual.CveEmpresa))
|
|
{
|
|
Alert("Documento publicado");
|
|
}
|
|
ObjOI.Dispose();
|
|
}
|
|
else
|
|
{
|
|
Alert("Los usuarios participantes aún no autorizan este Documento");
|
|
}
|
|
Response.Redirect(string.Format("/OI/DocumentoDetalle.aspx?CveDocumento={0}&Mensaje={1}", this.CveDocumento, "Publicado"));
|
|
}
|
|
#endregion
|
|
|
|
#region "NUEVA VERSION"
|
|
protected void LkbNuevaVersion_Click(object sender, EventArgs e)
|
|
{
|
|
CargarUsuarios();
|
|
LkbGuardar.Text = "Crear Nueva Versión";
|
|
DivBotonesAcciones.Visible = true;
|
|
LkbActualizar.Visible = false;
|
|
LkbPublicar.Visible = false;
|
|
LkbGuardar.Visible = true;
|
|
GvUsuarios.Columns[1].Visible = true;
|
|
GvUsuarios.Columns[2].Visible = false;
|
|
GvUsuarios.Columns[3].Visible = false;
|
|
UpCliente.Update();
|
|
}
|
|
#endregion
|
|
|
|
#region "RECHAZAR"
|
|
protected void LkbRechazar_Click(object sender, EventArgs e)
|
|
{
|
|
ClsOIEventos ObjOI = new ClsOIEventos();
|
|
if (ObjOI.UpdateDocumento(this.CveDocumento, DdlSubCategoria.SelectedValue.ToEntero(), TxtDescripcion.Text, TxtObs.InnerText, TxtVersion.Text, 3, "-1", TxtResponsable.Text,
|
|
NowADS(), -1, -1, UsuarioActual.CveEmpresa))
|
|
{
|
|
Alert("Documento cancelado");
|
|
}
|
|
ObjOI.Dispose();
|
|
Response.Redirect(string.Format("/OI/DocumentoDetalle.aspx?CveDocumento={0}&Mensaje={1}", this.CveDocumento, "Rechazado"));
|
|
}
|
|
#endregion
|
|
|
|
#region "IMPRIMIR"
|
|
private void Imprimir(string Formato)
|
|
{
|
|
List<ReportParameter> Params = new List<ReportParameter>();
|
|
Params.Add(new ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa));
|
|
Params.Add(new ReportParameter("UsuarioImprimio", UsuarioActual.Nombre));
|
|
Params.Add(new ReportParameter("LogoPath", ""));
|
|
Params.Add(new ReportParameter("Descripcion", TxtDescripcion.Text));
|
|
Params.Add(new ReportParameter("Categoria", DdlCategoria.SelectedItem.Text));
|
|
Params.Add(new ReportParameter("SubCategoria", DdlSubCategoria.SelectedItem.Text));
|
|
Params.Add(new ReportParameter("Estatus", LblEstatus.Text.Substring(9)));
|
|
Params.Add(new ReportParameter("Version", TxtVersion.Text));
|
|
Params.Add(new ReportParameter("Responsable", TxtResponsable.Text));
|
|
Params.Add(new ReportParameter("Observaciones", TxtObs.InnerText));
|
|
Params.Add(new ReportParameter("Documento", this.ArchivoAdjuntoNombre));
|
|
|
|
|
|
var logouri = string.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa);
|
|
System.IO.FileInfo Imagen = new System.IO.FileInfo($"{UsuarioActual.Empresa.Ruta}/Logo.png");
|
|
string LogoRuta = (Imagen.Exists) ? logouri : "" ;
|
|
Params.Add(new ReportParameter("LogoPath", LogoRuta));
|
|
|
|
ImprimirPDF("Empresas/Grales/Formatos/RepDocumentos.rdlc", this.DtUsuariosParticipantes, Params, "Detalle del documento", Formato);
|
|
}
|
|
|
|
protected void LkbPDF_Click(object sender, EventArgs e)
|
|
{
|
|
Imprimir("PDF");
|
|
}
|
|
|
|
protected void LkbExcel_Click(object sender, EventArgs e)
|
|
{
|
|
Imprimir("Excel");
|
|
}
|
|
#endregion
|
|
} |