683 lines
24 KiB
C#
683 lines
24 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;
|
|
|
|
public partial class OI_DocumentoDetalle : ClsPaginas
|
|
{
|
|
private int CveUsuarioResponsable
|
|
{
|
|
get
|
|
{
|
|
return 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;
|
|
}
|
|
}
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
Cargar();
|
|
}
|
|
}
|
|
#region "CARGAS"
|
|
private void CargarCveDocumento()
|
|
{
|
|
string CveDocumentoAux = Page.Request["CveDocumento"];
|
|
if (CveDocumentoAux != null)
|
|
{
|
|
this.CveDocumento = CveDocumentoAux.ToEntero();
|
|
}
|
|
else
|
|
{
|
|
this.CveDocumento = -1;
|
|
}
|
|
}
|
|
|
|
private void CargarMensajeNuevoEditado()
|
|
{
|
|
string MensajeNuevoEditado = Page.Request["Mensaje"];
|
|
if (MensajeNuevoEditado == "Nuevo")
|
|
{
|
|
Alert("El Documento ha sido creado correctamente");
|
|
}
|
|
else if (MensajeNuevoEditado == "Editado")
|
|
{
|
|
Alert("Los cambios en el Documento han sido guardado correctamente");
|
|
}
|
|
}
|
|
|
|
private void CargarUsuarios()
|
|
{
|
|
GvUsuarios.DataSource = get_GlobalDTUsuarios(CveEmpresa: UsuarioActual.CveEmpresa);
|
|
GvUsuarios.DataBind();
|
|
}
|
|
|
|
private void CargarUsuariosParticipantes()
|
|
{
|
|
|
|
DataTable UsuariosAux = null;
|
|
ClsOIEventos ObjOI = new ClsOIEventos();
|
|
if (ObjOI.GetDocumentoAutorizacion(this.CveDocumento))
|
|
{
|
|
GvUsuarios.DataSource = 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 FechaAprobacion = Usuarios.FiltroPrimeroValor("FechaAprobacion", string.Format("CveUsuario = {0}", CveUsuario));
|
|
Usuario.FCCheckBox("ChkAprobar").Checked = FechaAprobacion != "" || (UsuarioActual.CveUsuario == CveUsuarioResponsable && CveUsuario == UsuarioActual.CveUsuario);
|
|
}
|
|
}
|
|
}
|
|
|
|
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()
|
|
{
|
|
ClsOIEventos ObjOI = new ClsOIEventos();
|
|
if (ObjOI.GetDocumentoSubCategoria())
|
|
{
|
|
DdlSubCategoria.DataSource = ObjOI.DtResultados;
|
|
DdlSubCategoria.DataBind();
|
|
}
|
|
ObjOI.Dispose();
|
|
}
|
|
|
|
private void CargarResponsable()
|
|
{
|
|
TxtResponsable.Text = UsuarioActual.Nombre;
|
|
}
|
|
|
|
private void CargarDocumentoYaExistente()
|
|
{
|
|
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();
|
|
DdlSubCategoria.SelectedValue = Documento["CveSubCategoria"].ToString();
|
|
DdlEstatus.SelectedValue = Documento["CveEstatus"].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;
|
|
}
|
|
}
|
|
ObjOI.Dispose();
|
|
}
|
|
|
|
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;
|
|
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;
|
|
DdlEstatus.Enabled = false;
|
|
TxtVersion.Enabled = false;
|
|
TxtResponsable.Enabled = false;
|
|
TxtObs.Disabled = true;
|
|
DivFileDropZone.Visible = false;
|
|
LkbActualizar.Visible = false;
|
|
}
|
|
}
|
|
|
|
private void Cargar()
|
|
{
|
|
CargarSubCategoria();
|
|
CargarResponsable();
|
|
CargarCveDocumento();
|
|
CargarUsuarios();
|
|
if (this.CveDocumento > 0)
|
|
{
|
|
CargarDocumentoYaExistente();
|
|
CargarUsuariosParticipantes();
|
|
CargarUsuariosAutorizo();
|
|
ConfiguracionActualizar();
|
|
ConfigurarGridUsuariosParticipantes();
|
|
ConfigurarCamposDetalleSegunUsuario();
|
|
CargarMensajeNuevoEditado();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region "GENERAR DOCUMENTO"
|
|
protected void LblGuardar_Click(object sender, EventArgs e)
|
|
{
|
|
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);
|
|
}
|
|
|
|
//Gestión de errores y resultados
|
|
if (!TieneError)
|
|
{
|
|
ObjOI.Commit();
|
|
string ParamMensaje = LkbGuardar.Text == "Guardar" ? "Nuevo" : "Editado";//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();
|
|
}
|
|
|
|
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, DdlEstatus.SelectedValue.ToEntero(),
|
|
"", 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);
|
|
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, DdlEstatus.SelectedValue.ToEntero(),
|
|
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 Version = TxtVersion.Text;
|
|
string NombreArchivo = fileItem.filenameO;
|
|
//Preparamos la ruta donde moveremos el archivo cargado
|
|
//string NombreArchivoGuardado = NombreArchivo;
|
|
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";
|
|
}
|
|
}
|
|
}
|
|
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 void NotificarPorCorreo(string Para, string NombreArchivo, byte[] Adjunto)
|
|
{
|
|
string Descripcion = TxtDescripcion.Text;
|
|
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}Empresas/{1}/DocumentosRepo/{2}/{3}", ModExtensiones.DirectorioBaseEmpresas, UsuarioActual.CveEmpresa, 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);
|
|
ActualizarUsuario(this.CveAsignacion, Archivo);
|
|
}
|
|
|
|
private string SubirPropuestaEnDirectorio(int CveUsuario)
|
|
{
|
|
List<Archivo> Filesgral = TxtArchivoPropuesta.getfiles().Archivos;
|
|
string fileNameReturn = "-1";
|
|
if (TxtArchivoPropuesta.Text != "[]")
|
|
{
|
|
foreach (Archivo fileItem in Filesgral)
|
|
{
|
|
try
|
|
{
|
|
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 void 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");
|
|
}
|
|
ObjOI.Dispose();
|
|
}
|
|
#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);
|
|
}
|
|
|
|
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", DateTime.Now))
|
|
{
|
|
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();
|
|
}
|
|
|
|
protected void LkbPublicar_Click(object sender, EventArgs e)
|
|
{
|
|
GridViewRowCollection Usuarios = GvUsuarios.Rows;
|
|
bool Aprobado = true;
|
|
foreach (GridViewRow Usuario in Usuarios)
|
|
{
|
|
if (!Usuario.FCCheckBox("ChkAprobar").Checked)
|
|
{
|
|
Aprobado = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (Aprobado)
|
|
{
|
|
ClsOIEventos ObjOI = new ClsOIEventos();
|
|
if (ObjOI.UpdateDocumento(this.CveDocumento, DdlSubCategoria.SelectedValue.ToEntero(), TxtDescripcion.Text, TxtObs.InnerText, TxtVersion.Text, 2, "-1", TxtResponsable.Text,
|
|
DateTime.Now, -1, -1, UsuarioActual.CveEmpresa))
|
|
{
|
|
Cargar();
|
|
UpCliente.Update();
|
|
Alert("Documento publicado");
|
|
}
|
|
ObjOI.Dispose();
|
|
}
|
|
else
|
|
{
|
|
Alert("Los usuarios participantes aún no autorizan este Documento");
|
|
}
|
|
}
|
|
#endregion
|
|
} |