From 1868bffe8c21ca98ed41a9082471a6e4d2de51fa Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Mon, 20 Jul 2020 18:22:26 -0700 Subject: [PATCH] avance de insert y update --- App_Code/ClsOIEventos.vb | 52 +++++++- OI/DocumentoDetalle.aspx | 93 ++++++++++++- OI/DocumentoDetalle.aspx.cs | 253 +++++++++++++++++++++++++++++++++++- 3 files changed, 391 insertions(+), 7 deletions(-) diff --git a/App_Code/ClsOIEventos.vb b/App_Code/ClsOIEventos.vb index 8a65a1f30..4e36ab9e0 100644 --- a/App_Code/ClsOIEventos.vb +++ b/App_Code/ClsOIEventos.vb @@ -2944,9 +2944,9 @@ Public Class ClsOIEventos End Function Public Function AddDocumento(CveSubCategoria As Integer, Descripcion As String, Observacion As String, Version As String, CveEstatus As Integer, ArchivoFisico As String, - Responsable As String, FechaAprobacion As Date, CveDocumentoPadre As Integer, CveUsuario As Integer, CveEmpresa As Integer) As Boolean + Responsable As String, CveDocumentoPadre As Integer, CveUsuario As Integer, CveEmpresa As Integer) As Integer - Dim Retorno As Boolean = False + Dim Retorno As Integer = -1 DataAdapter("PA_OI_DocumentosAdd") @@ -2958,15 +2958,15 @@ Public Class ClsOIEventos .Add("@CveEstatus", SqlDbType.Int).Value = CveEstatus .Add("@ArchivoFisico", SqlDbType.NVarChar).Value = ArchivoFisico .Add("@Responsable", SqlDbType.NVarChar).Value = Responsable - .Add("@FechaAprobacion", SqlDbType.Date).Value = FechaAprobacion .Add("@CveDocumentoPadre", SqlDbType.Int).Value = CveDocumentoPadre .Add("@CveUsuario", SqlDbType.Int).Value = CveUsuario .Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa + .Add("@CveDocumento", SqlDbType.Int).Direction = ParameterDirection.Output End With Try SqlAdapter.Fill(Data) - Retorno = True + Retorno = SqlAdapter.SelectCommand.Parameters("@CveDocumento").Value.ToString().ToEntero() Catch ex As Exception OnError("Ocurrió un error al agregar el Documento", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo()) End Try @@ -3027,6 +3027,50 @@ Public Class ClsOIEventos End Function #End Region +#Region "OI_DocumentosAutorizacion" + Public Function AddDocumentoAutorizacion(CveDocumento As Integer, CveUsuario As Integer, Adjunto As String) As Boolean + + Dim Retorno As Boolean = False + + DataAdapter("OI_DocumentosAutorizacionesAdd") + + With SqlAdapter.SelectCommand.Parameters + .Add("@CveDocumento", SqlDbType.Int).Value = CveDocumento + .Add("@CveUsuario", SqlDbType.Int).Value = CveUsuario + .Add("@Adjunto", SqlDbType.NVarChar).Value = Adjunto + End With + + Try + SqlAdapter.Fill(Data) + Retorno = True + Catch ex As Exception + OnError("Ocurrió un error al agregar el usuario para autorizar el documento", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo()) + End Try + + Return Retorno + End Function + + Public Function GetDocumentoAutorizacion(CveDocumento As Integer) As Boolean + + Dim Retorno As Boolean = False + + DataAdapter("PA_OI_DocumentosAutorizacionesGet") + + With SqlAdapter.SelectCommand.Parameters + .Add("@CveDocumento", SqlDbType.Int).Value = CveDocumento + End With + + Try + SqlAdapter.Fill(Data) + Retorno = True + Catch ex As Exception + OnError("Ocurrió un error al obtener el usuario o usuarios para autorizar el documento", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo()) + End Try + + Return Retorno + End Function +#End Region + #End Region ' IDisposable diff --git a/OI/DocumentoDetalle.aspx b/OI/DocumentoDetalle.aspx index c68c94b1e..f84a72807 100644 --- a/OI/DocumentoDetalle.aspx +++ b/OI/DocumentoDetalle.aspx @@ -26,8 +26,97 @@ - + + +
+
+ + +
+
+ + + +
+
+
+
+ + +
+
+
+
+ + + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + +
+
+
+ + +
+
+
+ + +
+
+

+
+ " style="display: inline-block; margin-right: -20px; width: 150px; height: 25px; border-color: #89C4F4; border:1px solid #e5e5e5" /> + " class="btn btn-circle btn-sm label-info"> +
+ + + + + + + + + + + + + + +
+
+
+
+
+
+
+ +
+
+
+
+
+
- \ No newline at end of file + diff --git a/OI/DocumentoDetalle.aspx.cs b/OI/DocumentoDetalle.aspx.cs index bc578cd90..315d1512b 100644 --- a/OI/DocumentoDetalle.aspx.cs +++ b/OI/DocumentoDetalle.aspx.cs @@ -6,11 +6,262 @@ using System.Web.UI; using System.Web.UI.WebControls; using Extensiones; using System.Data; +using System.IO; public partial class OI_DocumentoDetalle : ClsPaginas { + 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; + } + } + protected void Page_Load(object sender, EventArgs e) { - + if (!IsPostBack) + { + //CargarUsuarios(); + //CargarSubCategoria(); + //CargarResponsable(); + //CargarCveDocumento(); + //if (this.CveDocumento > 0) + //{ + // CargarDocumentoYaExistente(); + // CargarUsuariosAutorizo(); + // ConfiguracionActualizar(); + //} + Cargar(); + } } + #region "CARGAS" + private void CargarCveDocumento() + { + string CveDocumentoAux = Page.Request["CveDocumento"]; + if (CveDocumentoAux != null) + { + this.CveDocumento = CveDocumentoAux.ToEntero(); + } + else + { + this.CveDocumento = -1; + } + } + + private void CargarUsuarios() + { + GvUsuarios.DataSource = get_GlobalDTUsuarios(CveEmpresa: UsuarioActual.CveEmpresa); + GvUsuarios.DataBind(); + } + + 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]; + + 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(); + + } + } + 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.Text = "Actualizar"; + } + + private void Cargar() + { + CargarUsuarios(); + CargarSubCategoria(); + CargarResponsable(); + CargarCveDocumento(); + if (this.CveDocumento > 0) + { + CargarDocumentoYaExistente(); + CargarUsuariosAutorizo(); + ConfiguracionActualizar(); + } + } + #endregion + + #region "GENERAR DOCUMENTO" + private string GuardarArchivo(int CveDocumento) + { + string RutaArchivo = "-1"; + List Filesgral = TxtDocumentoFile.getfiles().Archivos; + + foreach (Archivo fileItem in Filesgral) + { + try + { + string Version = TxtVersion.Text; + string NombreArchivo = fileItem.filenameO; + //Preparamos la ruta donde moveremos el archivo cargado + string NombreArchivoGuardado = string.Format("{0}_{1}_{2}", CveDocumento, Version, NombreArchivo); + string RutaDestino = UsuarioActual.Empresa.Ruta + @"DocumentosRepo\" + NombreArchivoGuardado; + + //Si no existe la carpeta donde se guardan se crea + if (!Directory.Exists(UsuarioActual.Empresa.Ruta + @"\DocumentosRepo")) + { + Directory.CreateDirectory(UsuarioActual.Empresa.Ruta + @"\DocumentosRepo"); + } + //Movemos el archivo de la carpeta temporal hacia la carpeta de la empresa + System.IO.File.Move(fileItem.FileUrl, RutaDestino); + RutaArchivo = RutaDestino; + } + catch (Exception e) + { + Alert(e.Message); + } + } + return RutaArchivo; + } + + 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"; + + 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) { GuardarUsuariosQueAutorizan(CveDocumento, RutaArchivo, ref ObjOI, ref TieneError); }//asignamos a los usuarios que participaran en aprovar este documento + + + //Gestión de errores y resultados + if (!TieneError) + { + ObjOI.Commit(); + Alert("Documento guardado correctamente"); + } + else + { + ObjOI.RollBack(); + Alert(this.ErrorMensaje, ModExtensiones.TipoMensaje.MsgError); + this.CveDocumento = CveDocumento; + Cargar(); + 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 guardr 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 + { + TieneError = true; + this.ErrorMensaje = "Hubo un error al guardar el archivo"; + } + return RutaArchivo; + } + + private void GuardarUsuariosQueAutorizan(int CveDocumento, string RutaArchivo, ref ClsOIEventos ObjOI, ref bool TieneError) + { + 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, RutaArchivo)) + { + TieneError = true; + this.ErrorMensaje = "Hubo un error al asignar los usuarios a este documento"; + break; + } + } + } + } + #endregion + + } \ No newline at end of file