This commit is contained in:
2019-11-07 10:15:16 -07:00
parent c3b6ea41f7
commit 2535217c2b
12 changed files with 522 additions and 468 deletions

View File

@@ -2,13 +2,14 @@
Option Explicit On
Imports System.Data
Imports System.Net
Imports Extensiones
Partial Class PopOCCotizacionesDetalle
Inherits ClsPaginas
Inherits ClsPaginas
#Region "Propiedades"
Friend Property EsNuevo As Boolean
Get
EsNuevo = DirectCast(ViewState("EsNuevo"), Boolean)
@@ -43,11 +44,20 @@ Partial Class PopOCCotizacionesDetalle
Set(ByVal value As DataTable)
ViewState("DtDetalle") = value
End Set
End Property
End Property
Private Property Adjunto As String
Get
Adjunto = ViewState("Adjunto").ToString
End Get
Set(value As String)
ViewState("Adjunto") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
@@ -76,9 +86,9 @@ Partial Class PopOCCotizacionesDetalle
BtnEliminar.Visible = True
End If
End If
End Sub
End Sub
#Region " INICIALIZA VALORES - CARGA COMBOS "
Protected Sub CargaProveedoresClasificaciones()
CboClasificacionProveedor.DataSource = GlobalDTProveedorClasificacion(UsuarioActual.CveEmpresa)
@@ -97,11 +107,11 @@ Partial Class PopOCCotizacionesDetalle
Protected Sub CargaMonedas()
ddlMoneda.DataSource = GlobalDTMonedas()
ddlMoneda.DataBind()
End Sub
End Sub
#End Region
#Region "C A R G A D A T O S "
Private Sub CargaOCDetalle(pCveOrden As Integer)
Dim objOC As New ClsOC
@@ -129,11 +139,10 @@ Partial Class PopOCCotizacionesDetalle
TxtFecha.Text = objCotizacion.Fecha.ToShortDateString
ddlMoneda.SelectedValue = objCotizacion.CveMoneda.ToString
TxtDiasCredito.Text = objCotizacion.DiasCredito.ToString
Adjunto = objCotizacion.Adjunto
If objCotizacion.Adjunto <> "" Then
HplArchivo.NavigateUrl = String.Format("/Empresas/{0}/Cotizaciones/{1}", UsuarioActual.CveEmpresa, objCotizacion.Adjunto)
HplArchivo.Text = String.Format("<img targer='_blank' src='/Imagenes/{0}.png' border='0' width='18px' alt='Descargar'/>", IO.Path.GetExtension(objCotizacion.Adjunto).Replace("."c, "")) 'ImageUrl = String.Format("/Imagenes/{0}.png", IO.Path.GetExtension(Cot.NombreArchivo).Replace("."c, ""))
HplArchivo.Visible = True
'HplArchivo.NavigateUrl = String.Format("/Empresas/{0}/Cotizaciones/{1}", UsuarioActual.CveEmpresa, objCotizacion.Adjunto)
LnkArchivo.Visible = True
End If
If objCotizacion.GetCotizacionesDetalle(pCveCotizacion) Then
@@ -155,7 +164,7 @@ Partial Class PopOCCotizacionesDetalle
TxtDiasCredito.Enabled = False
TxtFecha.Enabled = False
TxtFolio.Enabled = False
FUArchivo.Enabled = False
'FUArchivo.Enabled = False
If UsuarioActual.TienePermisoProceso(146) Then
GvDC.Enabled = True
@@ -164,61 +173,71 @@ Partial Class PopOCCotizacionesDetalle
End If
BtnGuardar.Enabled = False
End Sub
End Sub
#End Region
#Region " GUARDAR "
Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click
Dim objCotizacion As New ClsOC
objCotizacion.IniciaTransacSQL()
Dim TieneError = False
Dim TieneError = False
Dim FileExtension As String = ""
Dim Filesgral As List(Of Archivo) = TxtArchivo.getfiles().Archivos
Dim Filename As String = ""
For Each fileItem As Archivo In Filesgral
FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)) '.Replace(".", "")
Filename = fileItem.filename
Next
Try
If EsNuevo Then
If objCotizacion.AddCotizacion(CveOrdenCompra, CboProveedores.SelectedValue.ToEntero, -1, TxtFolio.Text, TxtFecha.Text, IO.Path.GetExtension(FUArchivo.FileName), ddlMoneda.SelectedValue.ToEntero, TxtDiasCredito.Text.ToEntero, UsuarioActual.CveUsuario) Then
If FUArchivo.HasFile Then
'verificar que exista el directorio
If Not System.IO.Directory.Exists(String.Format("{0}/Empresas/{1}/Cotizaciones/", AppDomain.CurrentDomain.BaseDirectory, UsuarioActual.CveEmpresa)) Then
System.IO.Directory.CreateDirectory(String.Format("{0}/Empresas/{1}/Cotizaciones/", AppDomain.CurrentDomain.BaseDirectory, UsuarioActual.CveEmpresa))
End If
FUArchivo.SaveAs(String.Format("{0}/Empresas/{1}/Cotizaciones/{2}{3}", AppDomain.CurrentDomain.BaseDirectory, UsuarioActual.CveEmpresa, objCotizacion.CveCotizacion, IO.Path.GetExtension(FUArchivo.FileName)))
If objCotizacion.AddCotizacion(CveOrdenCompra, CboProveedores.SelectedValue.ToEntero, -1, TxtFolio.Text, TxtFecha.Text, FileExtension, ddlMoneda.SelectedValue.ToEntero,
TxtDiasCredito.Text.ToEntero, UsuarioActual.CveUsuario) Then
'verificar que exista el directorio
If Not System.IO.Directory.Exists(String.Format("{0}/Empresas/{1}/Cotizaciones/", AppDomain.CurrentDomain.BaseDirectory, UsuarioActual.CveEmpresa)) Then
System.IO.Directory.CreateDirectory(String.Format("{0}/Empresas/{1}/Cotizaciones/", AppDomain.CurrentDomain.BaseDirectory, UsuarioActual.CveEmpresa))
End If
If Filename <> "" Then
Filename.FilesMove(objCotizacion.CveCotizacion.ToString(), String.Format("Empresas\{0}\Cotizaciones", UsuarioActual.CveEmpresa))
End If
For Each dr As GridViewRow In GvDC.Rows
TieneError = Not objCotizacion.AddCotizacionDetalle(objCotizacion.CveCotizacion, dr.DataKey("CvePS").ToEntero, dr.FCTextBox("TxtPU").Text.ToDouble, dr.DataKey("Cantidad").ToDouble, dr.DataKey("CveUnidadMedida").ToEntero, dr.FCTextBox("txtCantidadSurtir").Text.ToDouble, If(dr.FCTextBox("txtFechaEntrega").Text.Trim = "" Or dr.FCTextBox("txtFechaEntrega").Text = "__/__/____", "-1", dr.FCTextBox("txtFechaEntrega").Text), dr.FCTextBox("txtObservacion").Text.ToString, dr.DataKey("CveOrdenCompraDetalle").ToString.ToEntero)
TieneError = Not objCotizacion.AddCotizacionDetalle(objCotizacion.CveCotizacion, dr.DataKey("CvePS").ToEntero, dr.FCTextBox("TxtPU").Text.ToDouble, dr.DataKey("Cantidad").ToDouble,
dr.DataKey("CveUnidadMedida").ToEntero, dr.FCTextBox("txtCantidadSurtir").Text.ToDouble,
If(dr.FCTextBox("txtFechaEntrega").Text.Trim = "" Or dr.FCTextBox("txtFechaEntrega").Text = "__/__/____", "-1",
dr.FCTextBox("txtFechaEntrega").Text), dr.FCTextBox("txtObservacion").Text.ToString, dr.DataKey("CveOrdenCompraDetalle").ToString.ToEntero)
If TieneError = True Then Exit For
Next
End If
Else
Dim NombreArchivo As String = ""
If objCotizacion.UpdateCotizacion(CboProveedores.SelectedValue.ToEntero, -1, TxtFolio.Text, TxtFecha.Text, IO.Path.GetExtension(FUArchivo.FileName), ddlMoneda.SelectedValue.ToEntero, TxtDiasCredito.Text.ToEntero, UsuarioActual.CveUsuario, CveCotizacion) Then
If FUArchivo.HasFile Then
'verificar que exista el directorio
If Not System.IO.Directory.Exists(String.Format("{0}/Empresas/{1}/Cotizaciones/", AppDomain.CurrentDomain.BaseDirectory, UsuarioActual.CveEmpresa)) Then
System.IO.Directory.CreateDirectory(String.Format("{0}/Empresas/{1}/Cotizaciones/", AppDomain.CurrentDomain.BaseDirectory, UsuarioActual.CveEmpresa))
End If
FUArchivo.SaveAs(String.Format("{0}/Empresas/{1}/Cotizaciones/{2}{3}", AppDomain.CurrentDomain.BaseDirectory, UsuarioActual.CveEmpresa, CveCotizacion, IO.Path.GetExtension(FUArchivo.FileName)))
NombreArchivo = CveCotizacion & IO.Path.GetExtension(FUArchivo.FileName)
If objCotizacion.UpdateCotizacion(CboProveedores.SelectedValue.ToEntero, -1, TxtFolio.Text, TxtFecha.Text, FileExtension, ddlMoneda.SelectedValue.ToEntero, TxtDiasCredito.Text.ToEntero, UsuarioActual.CveUsuario, CveCotizacion) Then
'verificar que exista el directorio
If Not System.IO.Directory.Exists(String.Format("{0}/Empresas/{1}/Cotizaciones/", AppDomain.CurrentDomain.BaseDirectory, UsuarioActual.CveEmpresa)) Then
System.IO.Directory.CreateDirectory(String.Format("{0}/Empresas/{1}/Cotizaciones/", AppDomain.CurrentDomain.BaseDirectory, UsuarioActual.CveEmpresa))
End If
If Filename <> "" Then
Filename.FilesMove(CveCotizacion.ToString(), String.Format("Empresas\{0}\Cotizaciones", UsuarioActual.CveEmpresa))
End If
For Each dr As GridViewRow In GvDC.Rows
If dr.DataKey("CveCotizacionDetalle").ToEntero > 0 Then
TieneError = Not objCotizacion.UpdateCotizacionDetalle(dr.DataKey("CveCotizacionDetalle").ToEntero, dr.FCTextBox("TxtPU").Text.ToDouble, dr.FCTextBox("txtCantidadSurtir").Text.ToDouble, dr.FCTextBox("txtFechaEntrega").Text, dr.FCTextBox("txtObservacion").Text.ToString)
Else
Dim strTemp = dr.DataKey("CveOrdenCompraDetalle").ToString
If dr.FCTextBox("txtCantidadSurtir").Text.ToString.ToDouble > 0 Then
If dr.FCTextBox("TxtPU").Text.ToDouble > 0 Then TieneError = Not objCotizacion.AddCotizacionDetalle(CveCotizacion, dr.DataKey("CvePS").ToEntero, dr.FCTextBox("TxtPU").Text.ToDouble, dr.DataKey("Cantidad").ToDouble, dr.DataKey("CveUnidadMedida").ToEntero, dr.FCTextBox("txtCantidadSurtir").Text.ToString.ToDouble, If(dr.FCTextBox("txtFechaEntrega").Text.Trim = "" Or dr.FCTextBox("txtFechaEntrega").Text = "__/__/____", "-1", dr.FCTextBox("txtFechaEntrega").Text), dr.FCTextBox("txtObservacion").Text.ToString, dr.DataKey("CveOrdenCompraDetalle").ToEntero)
End If
End If
If TieneError = True Then Exit For
Next
@@ -229,38 +248,25 @@ Partial Class PopOCCotizacionesDetalle
End If
Catch ex As Exception
TieneError = True
objCotizacion.RollBack()
OnError("Se presento un error al guardar la cotización", ex)
End Try
If Not TieneError Then
objCotizacion.Commit()
Alert(If(EsNuevo, "Cotización Guardada.", "Cotización Actualizada."), TipoMensaje.MsgInformacion)
Else
Try
objCotizacion.RollBack()
Catch ex As Exception
OnError("Error al intetar hace RollBack", ex)
End Try
Else
objCotizacion.RollBack()
End If
objCotizacion.Dispose()
RegistraScript("Ir();")
End Sub
End Sub
#End Region
#Region " ELIMINAR "
Private Sub BtnEliminar_Click(sender As Object, e As EventArgs) Handles BtnEliminar.Click
Dim objCotizacion As New ClsOC
@@ -274,10 +280,10 @@ Partial Class PopOCCotizacionesDetalle
objCotizacion.Dispose()
RegistraScript("Ir();")
End Sub
End Sub
#End Region
#Region " G V D "
Protected Sub GvD_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDC.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
@@ -365,10 +371,30 @@ Partial Class PopOCCotizacionesDetalle
'e.Row.Attributes.Add("data-validadores", ValidadoresId)
Dim asdasdasd As String = ""
End If
End Sub
Dim asdasdasd As String = ""
End If
End Sub
#End Region
Protected Sub LnkArchivo_Click(sender As Object, e As EventArgs)
If Not String.IsNullOrEmpty(Adjunto) Then
Dim filePath As String = String.Format("{0}{1}", UsuarioActual.Empresa.Ruta, "Cotizaciones\" & Adjunto)
Dim Archivo As New System.IO.FileInfo(filePath)
If Archivo.Exists Then
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ClearContent()
HttpContext.Current.Response.ContentType = "application/octet-stream"
HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment; filename=" + System.IO.Path.GetFileName(filePath))
HttpContext.Current.Response.AddHeader("Content-Length", Archivo.Length.ToString())
HttpContext.Current.Response.TransmitFile(filePath)
HttpContext.Current.Response.Flush()
HttpContext.Current.Response.End()
Archivo = Nothing
End If
End If
End Sub
End Class