avance de insert y update
This commit is contained in:
@@ -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