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,234 @@
Option Explicit On
Option Strict On
Imports Extensiones
Imports System.IO
Imports System.Data
Imports Newtonsoft.Json
Partial Class Contratos_ContratoAvance
Inherits ClsPaginas
#Region "Propiedades"
Private Property DtDatos As DataTable
Get
If ViewState("DtDatos") Is Nothing Then
Return Nothing
Else
Return CType(ViewState("DtDatos"), DataTable)
End If
End Get
Set(value As DataTable)
ViewState("DtDatos") = value
End Set
End Property
Private Property CveContrato As Integer
Get
If ViewState("CveContrato") Is Nothing Then
Return Nothing
Else
Return ViewState("CveContrato").ToString.ToEntero
End If
End Get
Set(value As Integer)
ViewState("CveContrato") = value
End Set
End Property
'fecha seleccionada del historico de avances
Private Property fecha As String
Get
If ViewState("fecha") Is Nothing Then
Return ""
Else
Return ViewState("fecha").ToString
End If
End Get
Set(value As String)
ViewState("fecha") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
BtnGuardar.Visible = False
btnanexogral.Visible = False
CargaContrato()
End If
End Sub
#Region "Filtros"
Private Sub CargaContrato()
DdlContratos.DataSource = GlobalDTContratos.FiltraParametros(String.Format("CveContratoTipo=4"))
DdlContratos.DataBind()
CargaddlAvance()
End Sub
Protected Sub DdlContratos_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlContratos.SelectedIndexChanged
CargaddlAvance()
End Sub
Private Sub CargaddlAvance()
DdlAvances.Items.Clear()
Dim ObjContratos As New ClsContratos()
If ObjContratos.GetContratosAvanceFecha(DdlContratos.SelectedValue.ToEntero, 2) Then
DdlAvances.DataSource = ObjContratos.DtResultados
End If
ObjContratos.Dispose()
DdlAvances.DataBind()
DdlAvances.Items.Insert(0, New ListItem(" ---- ", "-1"))
End Sub
#End Region
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs) Handles BtnConsultar.Click
CveContrato = DdlContratos.SelectedValue.ToEntero
CargaDatosAvance()
End Sub
Private Sub CargaDatosAvance()
GvAnexos.Visible = False
Dim ObjContratos As New ClsContratos()
If DdlAvances.SelectedValue = "-1" Then
If ObjContratos.GetContratosAvanceTodos(CveContrato, 2) Then
fecha = ""
DtDatos = ObjContratos.DtResultados
If ObjContratos.DtResultados.Rows.Count > 0 Then
BtnGuardar.Visible = True
btnanexogral.Visible = True
End If
End If
Else
If ObjContratos.GetContratosAvanceHistoricos(CveContrato, 2, DdlAvances.SelectedValue) Then
fecha = DdlAvances.SelectedValue
DtDatos = ObjContratos.DtResultados
BtnGuardar.Visible = False
btnanexogral.Visible = False
End If
End If
ObjContratos.Dispose()
CargaGrid()
End Sub
#Region "GV"
Private Sub CargaGrid()
If DtDatos IsNot Nothing Then
If ViewState("Orden") Is Nothing Then
Gv.DataSource = DtDatos
Else
Gv.DataSource = DtDatos.FiltraParametros("", ViewState("Orden").ToString)
End If
Gv.DataBind()
Else
Alert("no se encontraron productos en el presupuesto")
End If
End Sub
Protected Sub GV_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles Gv.RowDataBound
If e.Row.RowIndex > -1 Then
e.Row.FCTextBox("TxtCantidad").Visible = (fecha = "")
e.Row.FCLinkButton("LnkAnexo").Visible = Not (fecha = "")
If e.Row.DBCampo("CveContratoDetalle").ToString.ToEntero = 0 Then
e.Row.FCTextBox("TxtCantidad").Visible = False
e.Row.FCLinkButton("LnkAnexo").Visible = False
If e.Row.DBCampo("CveSubFamilias").ToString.ToEntero = 0 Then
If e.Row.DBCampo("CveFamilias").ToString.ToEntero = 0 Then
e.Row.CssClass = "SubTotales"
Else
e.Row.CssClass = "SubTotales2"
End If
Else
e.Row.CssClass = "SubTotales3"
End If
End If
End If
End Sub
Protected Sub GetAnexos(sender As Object, e As System.EventArgs)
'Get the button that raised the event
Dim btn As LinkButton = DirectCast(sender, LinkButton)
Dim gvr As GridViewRow = DirectCast(btn.NamingContainer, GridViewRow)
Dim CveContratoDetalle As Integer = gvr.DataKey("CveContratoDetalle").ToString.ToEntero
Dim objContrato As New ClsContratos
If objContrato.GetContratosAvanceAnexos(CveContratoDetalle, fecha, UsuarioActual.CveUsuario) Then
GvAnexos.DataSource = objContrato.DtResultados
GvAnexos.DataBind()
GvAnexos.Visible = True
Else
GvAnexos.Visible = False
End If
objContrato.Dispose()
End Sub
Protected Sub GvAnexos_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GvAnexos.RowDataBound
If e.Row.RowIndex > -1 Then
Dim Archivo As String = e.Row.DBCampo("Archivo").ToString
Dim start As Integer = Len(Archivo.Split("-"c)(0))
Dim link As HyperLink = e.Row.FCHyperLink("HPLArchivo")
link.Text = Archivo.Substring(start + 1)
link.NavigateUrl = String.Format("/Empresas/{0}/Contrato/{1}/Anexos/{2}", UsuarioActual.CveEmpresa, CveContrato, Archivo)
End If
End Sub
#End Region
Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click
Dim ObjContratos As New ClsContratos
ObjContratos.IniciaTransacSQL()
Dim TieneError = False
Dim CveContratoDetalle As Integer
Dim Cantidad As Double
Dim filesgral As List(Of Archivo) = AnexoGral.getfiles().Archivos
Dim guardarArchivos As New List(Of Archivo)
For Each gvr As GridViewRow In Gv.Rows
CveContratoDetalle = gvr.DataKey("CveContratoDetalle").ToEntero
If CveContratoDetalle > 0 Then
Cantidad = gvr.FCTextBox("TxtCantidad").Text.ToDouble
If Cantidad > 0 Then
If ObjContratos.AddContratosAvance(CveContratoDetalle, Cantidad, TxtFecha.Text.ToDateTime, UsuarioActual.CveUsuario) Then
Dim CveContratoAvance As Integer = ObjContratos.DtResultados.Rows(0)("CveContratoAvance").ToString.ToEntero
Dim files As List(Of Archivo) = gvr.FCTextBox("TXTAnexo").getfiles().Archivos
For Each fileItem As Archivo In filesgral
guardarArchivos.Add(fileItem)
If Not ObjContratos.AddContratosAvanceAnexo(CveContratoAvance, fileItem.filename, UsuarioActual.CveUsuario) Then
TieneError = True
Exit For
End If
Next
For Each fileItem As Archivo In files
guardarArchivos.Add(fileItem)
If Not ObjContratos.AddContratosAvanceAnexo(CveContratoAvance, fileItem.filename, UsuarioActual.CveUsuario) Then
TieneError = True
Exit For
End If
Next
Else
TieneError = True
Exit For
End If
End If
End If
Next
If TieneError Then
ObjContratos.RollBack()
Alert("No se logro guardar el Presupuesto favor de intentarlo mas tarde o comuniquese con soporte", TipoMensaje.MsgAdvertencia)
Else
Dim urlsave As String = String.Format("Empresas\{0}\Contrato\{1}\Anexos", UsuarioActual.CveEmpresa, CveContrato)
For Each fileItem As Archivo In filesgral
fileItem.filename.filesMove(fileItem.filename, urlsave)
Next
For Each fileItem As Archivo In guardarArchivos
fileItem.filename.filesMove(fileItem.filename, urlsave)
Next
ObjContratos.Commit()
Alert("se guardo Correctamente")
End If
AnexoGral.Text = "[]"
ObjContratos.Dispose()
CargaddlAvance()
CargaDatosAvance()
End Sub
End Class