Commit inicial Ventas Productivo

This commit is contained in:
JORGE LUIS CAUDILLO ESPARZA
2019-08-14 16:40:54 -07:00
commit c35cf91883
13328 changed files with 3711549 additions and 0 deletions

View File

@@ -0,0 +1,229 @@
Option Strict On
Imports Extensiones
Imports System.Data
Imports System.IO
Partial Class Contratos_CatContratosPlantillas
Inherits ClsPaginas
#Region "Propiedades"
Public Property CveContratoPlantilla As Integer
Get
Return ViewState("CveContratoPlantilla").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveContratoPlantilla") = value
End Set
End Property
Public Property EsEditar As Integer
Get
Return ViewState("EsEditar").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("EsEditar") = value
End Set
End Property
Public Property URL As String
Get
Return ViewState("URL").ToString
End Get
Set(value As String)
ViewState("URL") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
CveContratoPlantilla = -1
EsEditar = 0
dvEstatus.Visible = False
CargaDatos(-1)
End If
End Sub
Private Sub CargaDatos(CveConductor As Integer)
Dim ObjGeneral As New ClsGenerales
If ObjGeneral.ContratosPlantillaGet(-1, UsuarioActual.CveEmpresa) Then
GvDatos.DataSource = ObjGeneral.DtResultados
Else
GvDatos.DataSource = Nothing
End If
ObjGeneral.Dispose()
GvDatos.DataBind()
End Sub
Protected Sub imgE_Click(sender As Object, e As EventArgs)
Dim Boton = CType(sender, LinkButton)
CveContratoPlantilla = Boton.CommandArgument.ToEntero
Dim GvRow As GridViewRow = DirectCast(Boton.NamingContainer, GridViewRow)
TxtNombrePlantilla.Text = GvRow.DataKey("NombrePlantilla").ToString
DdlTipo.SelectedValue = GvRow.DataKey("Tipo").ToString
chkEstatus.Checked = CBool(GvRow.DataKey("Estatus"))
URL = GvRow.DataKey("URL").ToString
EsEditar = 1
BtnAgregarCatalogo.Text = "Actualizar"
dvEstatus.Visible = True
UpBodyEstatus.Update()
UpFooter.Update()
RegistraScript("$('#divAgregar').modal()")
End Sub
Protected Sub BtnAgregarCatalogo_Click(sender As Object, e As EventArgs) Handles BtnAgregarCatalogo.Click
Dim ObjGeneral As New ClsGenerales
URL = ""
Dim Filesgral As List(Of Archivo) = TxtUpDoc.getfiles().Archivos
For Each fileItem As Archivo In Filesgral
URL = FormatearNombreArchivo(fileItem.filenameO)
If URL.Length > 199 Then
Alert("El nombre del archivo excede los 200 Caracteres permitidos favor de modificarlo.", TipoMensaje.MsgAdvertencia)
URL = ""
Exit Sub
ElseIf fileItem.Extencion <> "doc" AndAlso fileItem.Extencion <> "docx" Then
Alert("Solo se permiten archivos de tipo .doc o .docx, favor de modificarlo", TipoMensaje.MsgAdvertencia)
URL = ""
Exit Sub
End If
Next
If EsEditar = 0 Then
If URL <> "" Then
Dim Path As String = UsuarioActual.Empresa.Ruta
If Not Directory.Exists(Path) Then
Directory.CreateDirectory(Path)
End If
Dim directorioNew As String = String.Format("{0}\Formatos\Plantillas\{1}", Path, URL)
If File.Exists(directorioNew) Then
My.Computer.FileSystem.DeleteFile(directorioNew)
End If
My.Computer.FileSystem.MoveFile(TxtUpDoc.getfiles().Archivos(0).FileUrl, directorioNew)
If ObjGeneral.ContratoPlantillaAdd(UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario, TxtNombrePlantilla.Text, URL, DdlTipo.SelectedValue) Then
Alert("La plantilla se agregó correctamente", TipoMensaje.MsgInformacion)
End If
Else
Alert("Es necesario que agregue el documento plantilla", TipoMensaje.MsgAdvertencia)
End If
ElseIf EsEditar = 1 Then
If TxtUpDoc.getfiles().Archivos.Count > 0 Then
Dim NuevaPlantilla As Archivo = TxtUpDoc.getfiles().Archivos(0)
Dim Path As String = UsuarioActual.Empresa.Ruta
If Not Directory.Exists(Path) Then
Directory.CreateDirectory(Path)
End If
Dim directorioNew As String = String.Format("{0}\Formatos\Plantillas\{1}", Path, URL)
If File.Exists(directorioNew) Then
My.Computer.FileSystem.DeleteFile(directorioNew)
End If
My.Computer.FileSystem.MoveFile(NuevaPlantilla.FileUrl, directorioNew)
End If
If ObjGeneral.ContratosPlantillaUpdate(UsuarioActual.CveEmpresa, TxtNombrePlantilla.Text, URL, DdlTipo.SelectedValue, CveContratoPlantilla, chkEstatus.Checked) Then
Alert("La plantilla se editó correctamente", TipoMensaje.MsgInformacion)
Else
Alert("Ocurrió un error al editar la plantilla", TipoMensaje.MsgError)
End If
EsEditar = 0
dvEstatus.Visible = False
BtnAgregarCatalogo.Text = "Agregar"
End If
RegistraScript("$('#divAgregar').modal('hide')")
ObjGeneral.Dispose()
TxtNombrePlantilla.Text = ""
DdlTipo.SelectedValue = "-1"
TxtUpDoc.Text = "[]"
CargaDatos(-1)
UpDatos.Update()
UpBodyEstatus.Update()
End Sub
Protected Sub GvDatos_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvDatos.RowDeleting
Dim ObjGeneral As New ClsGenerales
Dim CveContratoPlantilla As Integer = GvDatos.Rows(e.RowIndex).DataKey("CveContratoPlantilla").ToEntero
If ObjGeneral.ContratoPlantillaDelete(CveContratoPlantilla, UsuarioActual.CveEmpresa) Then
Alert("La plantilla se eliminó correctamente", TipoMensaje.MsgInformacion)
End If
ObjGeneral.Dispose()
CargaDatos(-1)
UpDatos.Update()
End Sub
Protected Sub GvDatos_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvDatos.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.VerticalAlign = VerticalAlign.Middle
e.Row.FCLinkButton("ImgE").CommandArgument = e.Row.DataKey("CveContratoPlantilla").ToString
If CBool(e.Row.DBCampo("Estatus")) = True Then
e.Row.FCLabel("LblEstatus").Text = "Activo"
e.Row.FCLabel("LblEstatus").ForeColor = Drawing.Color.Green
Else
e.Row.FCLabel("LblEstatus").Text = "Inactivo"
e.Row.FCLabel("LblEstatus").ForeColor = Drawing.Color.Red
End If
End If
End Sub
Protected Sub btnCancelar_Click(sender As Object, e As EventArgs) Handles btnCancelar.Click
EsEditar = 0
RegistraScript("$('#divAgregar').modal('hide')")
BtnAgregarCatalogo.Text = "Agregar"
TxtNombrePlantilla.Text = ""
DdlTipo.SelectedValue = "-1"
TxtUpDoc.Text = "[]"
dvEstatus.Visible = False
UpBodyEstatus.Update()
UpFooter.Update()
End Sub
Public Function FormatearNombreArchivo(nombreArchivoOriginal As String) As String
Dim nombreArchivoFormateado As String
nombreArchivoFormateado = nombreArchivoOriginal.Replace(" ", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("'", "")
nombreArchivoFormateado = nombreArchivoFormateado.Replace(Chr(34), "")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("$", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("#", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("%", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("!", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("&", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("?", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("¿", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("¡", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("*", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("~", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("^", "_")
Return nombreArchivoFormateado
End Function
Protected Sub BtnDescargar_Click(sender As Object, e As EventArgs) Handles LbDescargar.Click
Dim Path As String = $"{AppDomain.CurrentDomain.BaseDirectory}Empresas\Grales\Formatos\Plantilla.docx"
Dim Archivo As New System.IO.FileInfo(Path)
If Archivo.Exists Then
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ClearContent()
HttpContext.Current.Response.ContentType = If(IO.Path.GetExtension(Archivo.Name) = "doc", "application/doc", "application/docx")
HttpContext.Current.Response.AppendHeader("Content-disposition", String.Format("attachment; filename={0}", Archivo.Name))
HttpContext.Current.Response.AddHeader("Content-Length", Archivo.Length.ToString())
HttpContext.Current.Response.TransmitFile(Path)
'HttpContext.Current.Response.Flush()
HttpContext.Current.Response.End()
End If
Archivo = Nothing
End Sub
End Class