avance de insert y update
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -26,8 +26,97 @@
|
||||
</asp:UpdatePanel>
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content6" ContentPlaceHolderID="C" runat="Server">
|
||||
|
||||
<asp:UpdatePanel ID="UpCliente" runat="server" UpdateMode="Conditional" class="portlet light xspadding bordered whitoutcol" style="width: 100%;">
|
||||
<ContentTemplate>
|
||||
<div class="portlet-body form-horizontal form-row-sepe formnombottom" style="padding-top: 0px; margin-top: -5px;">
|
||||
<div class="row form-group" style="width: 100%">
|
||||
<asp:UpdatePanel ID="UpDerecha" runat="server" UpdateMode="Conditional" class="col-md-2" style="width: 50%;">
|
||||
<ContentTemplate>
|
||||
<br />
|
||||
<div class="form-group form-md-line-input input-iconright" style="margin: unset; font-size: 14px">
|
||||
<asp:Label runat="server" ID="LblDescripción" Text="Descripción" />
|
||||
<asp:TextBox runat="server" ID="TxtDescripcion" class="form-control" />
|
||||
<asp:RequiredFieldValidator ID="RfvTxtDescripcion" runat="server" ControlToValidate="TxtDescripcion" CssClass="help-block errorimput" ErrorMessage="<b><span style='text-decoration: underline'>ERROR:</span></b><br />El campo <b>''Descripción''</b> es necesario, por favor ingréselo." ValidationGroup="GrpDoc"></asp:RequiredFieldValidator>
|
||||
</div>
|
||||
<br />
|
||||
<div class="form-group form-md-line-input input-iconright" style="margin: unset; font-size: 14px">
|
||||
<asp:Label runat="server" ID="LblSubCategoria" Text="Subcategoría" /><br />
|
||||
<asp:DropDownList runat="server" ID="DdlSubCategoria" CssClass="select2me" Style="width: 30%" DataValueField="CveSubCategoria" DataTextField="SubCategoria">
|
||||
</asp:DropDownList>
|
||||
</div>
|
||||
<br />
|
||||
<div class="form-group form-md-line-input input-iconright" style="margin: unset; font-size: 14px">
|
||||
<asp:Label runat="server" ID="LblEstatus" Text="Estatus" /><br />
|
||||
<asp:DropDownList runat="server" ID="DdlEstatus" CssClass="select2me" Style="width: 30%">
|
||||
<asp:ListItem Value="1" Text="En Proceso" />
|
||||
<asp:ListItem Value="2" Text="Aprobado" />
|
||||
<asp:ListItem Value="1" Text="Rechazado" />
|
||||
</asp:DropDownList>
|
||||
</div>
|
||||
<br />
|
||||
<div class="form-group form-md-line-input input-iconright" style="margin: unset; font-size: 14px">
|
||||
<asp:Label runat="server" ID="LblVersion" Text="Versión" />
|
||||
<asp:TextBox runat="server" ID="TxtVersion" class="form-control" Style="width: 30%" />
|
||||
<asp:RequiredFieldValidator ID="RfvTxtVersion" runat="server" ControlToValidate="TxtVersion" CssClass="help-block errorimput" ErrorMessage="<b><span style='text-decoration: underline'>ERROR:</span></b><br />El campo <b>''Versión''</b> es necesario, por favor ingréselo." ValidationGroup="GrpDoc"></asp:RequiredFieldValidator>
|
||||
</div>
|
||||
<br />
|
||||
<div class="form-group form-md-line-input input-iconright" style="margin: unset; font-size: 14px">
|
||||
<asp:Label runat="server" ID="LblResponsable" Text="Responsable" />
|
||||
<asp:TextBox runat="server" ID="TxtResponsable" class="form-control" Style="width: 50%" />
|
||||
<asp:RequiredFieldValidator ID="RfvTxtResponsable" runat="server" ControlToValidate="TxtResponsable" CssClass="help-block errorimput" ErrorMessage="<b><span style='text-decoration: underline'>ERROR:</span></b><br />El campo <b>''Responsable''</b> es necesario, por favor ingréselo." ValidationGroup="GrpDoc"></asp:RequiredFieldValidator>
|
||||
</div>
|
||||
<br />
|
||||
<div class="form-group form-md-line-input input-iconright" style="margin: unset; font-size: 14px">
|
||||
<asp:Label runat="server" ID="LblObs" Text="Observaciones" />
|
||||
<textarea runat="server" id="TxtObs" class="form-control" style="border: 1px solid #e5e5e5" rows="2"></textarea>
|
||||
</div>
|
||||
<br />
|
||||
<div class="form-group form-md-line-input input-iconright" style="margin: unset; font-size: 14px">
|
||||
<asp:Label runat="server" ID="LblDocumentoFile" Text="Documento" />
|
||||
<asp:TextBox ID="TxtDocumentoFile" CssClass="ADSdropzone hidden" runat="server" Style="height: 100px"></asp:TextBox>
|
||||
</div>
|
||||
</ContentTemplate>
|
||||
</asp:UpdatePanel>
|
||||
<asp:UpdatePanel ID="UpIzquierda" runat="server" UpdateMode="Conditional" class="col-md-2" style="width: 50%;">
|
||||
<ContentTemplate>
|
||||
<br />
|
||||
<div class="form-group form-md-line-input input-iconright" style="margin: unset; height: 150px; text-align: center">
|
||||
<asp:Label runat="server" ID="LblUsuarios" Text="Usuarios" Font-Size="14px" /><br /><br />
|
||||
<div class="text-right" style="">
|
||||
<input type="text" id="TxtBusqueda" class="form-control input-sm" onkeyup="<%= String.Format("FiltrarTabla('TxtBusqueda','{0}')", GvUsuarios.ClientID) %>" style="display: inline-block; margin-right: -20px; width: 150px; height: 25px; border-color: #89C4F4; border:1px solid #e5e5e5" />
|
||||
<a href="javascript:;" onclick="<%= String.Format("FiltrarTabla('TxtBusqueda','{0}')", GvUsuarios.ClientID) %>" class="btn btn-circle btn-sm label-info"><i class="icon-magnifier"></i></a>
|
||||
</div>
|
||||
<asp:UpdatePanel ID="UpDatosUsuarios" runat="server" UpdateMode="Conditional">
|
||||
<ContentTemplate>
|
||||
<asp:GridView ID="GvUsuarios" runat="server" AutoGenerateColumns="False" DataKeyNames="CveUsuario,Usuario" EmptyDataText="No se encontraron Categorías de Documentos Registrados"
|
||||
ToolTip="Listado de Categorías de Documentos" CssClass="table table-striped table-advance table-hover Widthall ScrollAD"
|
||||
Style="margin-top: -10px; text-align: center; width: 100%; overflow-x: hidden" GridLines="None">
|
||||
<Columns>
|
||||
<asp:BoundField HeaderText="Nombre" DataField="Nombre" ItemStyle-HorizontalAlign="Left" />
|
||||
<asp:TemplateField HeaderText="Unir">
|
||||
<ItemTemplate>
|
||||
<asp:CheckBox runat="server" ID="ChkUnir" />
|
||||
</ItemTemplate>
|
||||
</asp:TemplateField>
|
||||
</Columns>
|
||||
</asp:GridView>
|
||||
</ContentTemplate>
|
||||
</asp:UpdatePanel>
|
||||
</div>
|
||||
</ContentTemplate>
|
||||
</asp:UpdatePanel>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-1" style="text-align: center; width: 100%">
|
||||
<br />
|
||||
<asp:LinkButton runat="server" ID="LkbGuardar" OnClick="LblGuardar_Click" Text="Guardar" class="btn btn-primary" ValidationGroup="GrpDoc"/>
|
||||
<br />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ContentTemplate>
|
||||
</asp:UpdatePanel>
|
||||
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content7" ContentPlaceHolderID="JS" runat="Server">
|
||||
</asp:Content>
|
||||
</asp:Content>
|
||||
|
||||
@@ -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<Archivo> 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
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user