Option Explicit On Option Strict On Imports Extensiones Imports System.IO Imports System.Data Imports Newtonsoft.Json Imports ClosedXML.Excel 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 Private Property CveContratoEstimacion As Integer Get If ViewState("CveContratoEstimacion") Is Nothing Then Return Nothing Else Return ViewState("CveContratoEstimacion").ToString.ToEntero End If End Get Set(value As Integer) ViewState("CveContratoEstimacion") = 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 Property CveEstimacionNueva As Integer Get If ViewState("CveEstimacionNueva") Is Nothing Then Return -1 Else Return ViewState("CveEstimacionNueva").ToString.ToEntero End If End Get Set(value As Integer) ViewState("CveEstimacionNueva") = value End Set End Property Property NuemeroEstimacionNuevo As Integer Get If ViewState("NuemeroEstimacionNuevo") Is Nothing Then Return -1 Else Return ViewState("NuemeroEstimacionNuevo").ToString.ToEntero End If End Get Set(value As Integer) ViewState("NuemeroEstimacionNuevo") = 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 in (30,31) AND CveEmpresa = {UsuarioActual.CveEmpresa}")) DdlContratos.DataBind() DDlContratosEstimaciones.DataSource = GlobalDTContratos.FiltraParametros(String.Format($"CveContratoTipo in (30,31) AND CveEmpresa = {UsuarioActual.CveEmpresa}")) DDlContratosEstimaciones.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 If e.Row.DataKey("CveContratoDetalle").ToEntero > 0 Then Dim LnkAnexo As LinkButton = e.Row.FCLinkButton("LnkModalDropzone") 'LnkAnexo.Visible = True Dim DVAnexo As Control = DirectCast(e.Row.FindControl("ModalAnexoEvidencia"), Control) LnkAnexo.OnClientClick = $" $('#{DVAnexo.ClientID}').modal('show'); return false;" If DdlAvances.SelectedIndex > 0 Then LnkAnexo.Visible = False Else LnkAnexo.Visible = True End If End If End If End Sub Protected Sub GetAnexos(sender As Object, e As System.EventArgs) Dim GvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow) LblTituloModalAnexo.Text = "Anexo " & GvRow.DataKey("PS") '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() UpModalAnexos.Update() RegistraScript("$('#ModalAnexos').modal('show');") 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 LnkArchivo As LinkButton = e.Row.FCLinkButton("LnkArchivo") LnkArchivo.Text = Archivo.Substring(start + 1) 'link.NavigateUrl = String.Format("/Empresas/{0}/Contrato/{1}/Anexos/{2}", UsuarioActual.CveEmpresa, CveContrato, Archivo) ScriptManager.GetCurrent(Me).RegisterPostBackControl(LnkArchivo) End If End Sub Protected Sub LnkArchivo_Click(sender As Object, e As EventArgs) Dim GvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow) Dim Archivo As String = GvRow.DataKey("Archivo").ToString Response.ContentType = "application/octet-stream" Response.AppendHeader("Content-Disposition", $"attachment; filename={Archivo}") Response.TransmitFile($"{UsuarioActual.Empresa.Ruta}\Contrato\{DdlContratos.SelectedValue.ToEntero}\Anexos\{Archivo}") Response.End() 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 'GENERAL ' 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.Replace($".{fileItem.Extencion}", ""), urlsave) Next ObjContratos.Commit() Alert("se guardo Correctamente") End If AnexoGral.Text = "[]" ObjContratos.Dispose() CargaddlAvance() CargaDatosAvance() End Sub #Region "ESTIMACION" Private Sub CargaAvancesParaEstimar() CveContratoEstimacion = -1 Dim ObjContratos As New ClsContratos() Dim DTEstimaciones As New DataTable If ObjContratos.GetContratosAvanceEstimacion(DDlContratosEstimaciones.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then DTEstimaciones = ObjContratos.DtResultados CveContratoEstimacion = DDlContratosEstimaciones.SelectedValue.ToEntero End If ObjContratos.Dispose() If DTEstimaciones.Rows.Count > 0 Then GvEstimaciones.DataSource = DTEstimaciones BtnGuardarEstimacion.Visible = True Else GvEstimaciones.DataSource = Nothing BtnGuardarEstimacion.Visible = False End If GvEstimaciones.DataBind() UpEstimaciones.Update() End Sub Private Sub BtnConsultarEstimaciones_Click(sender As Object, e As EventArgs) Handles BtnConsultarEstimaciones.Click CargaAvancesParaEstimar() End Sub Private Sub GvEstimaciones_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvEstimaciones.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.DBCampo("CveContratoDetalle").ToString.ToEntero = 0 Then 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 Private Sub BtnGuardarEstimacion_Click(sender As Object, e As EventArgs) Handles BtnGuardarEstimacion.Click CveEstimacionNueva = -1 NuemeroEstimacionNuevo = -1 Dim ObjContratos As New ClsContratos() Dim ErrorProceso As Boolean = False ObjContratos.IniciaTransacSQL() If ObjContratos.AddContratosAvanceEstimacion(CveContratoEstimacion, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then CveEstimacionNueva = ObjContratos.CveEstimacionNueva NuemeroEstimacionNuevo = ObjContratos.NumeroEstimacionNueva For Each GvRow As GridViewRow In GvEstimaciones.Rows If GvRow.DataKey("CveContratoAvance").ToEntero > 0 Then If Not ObjContratos.UpdateContratosAvanceEstimacion(GvRow.DataKey("CveContratoAvance").ToEntero, ObjContratos.CveEstimacionNueva, UsuarioActual.CveEmpresa) Then ErrorProceso = True Exit For End If End If Next Else ErrorProceso = True End If 'AddContratosAvanceEstimacion 'UpdateContratosAvanceEstimacion If Not ErrorProceso Then ObjContratos.Commit() Alert($"Estimación {NuemeroEstimacionNuevo} agregada correctamente.") BtnGuardarEstimacion.Visible = False BtnDescargarGenerado.Visible = True Else ObjContratos.RollBack() End If ObjContratos.Dispose() UpEstimaciones.Update() End Sub Private Sub BtnDescargarGenerado_Click(sender As Object, e As EventArgs) Handles BtnDescargarGenerado.Click GeneraAnexo(CveEstimacionNueva, NuemeroEstimacionNuevo, Now, DDlContratosEstimaciones.SelectedItem.Text) End Sub Private Sub GeneraAnexo(CveEstimacion As Integer, NumeroEstimacion As Integer, FechaEstimacion As Date, NumeroContrato As String) Dim PlantillaAnexo As String = $"{UsuarioActual.Empresa.Ruta}\Formatos\Anexo.xlsx" If Not System.IO.File.Exists(PlantillaAnexo) Then Alert("No se encuentra la platilla de anexos.", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim DtControl As New DataTable Dim ObjContratos As New ClsContratos Dim Lugar As String = "" Dim DescripcionContrato As String = "" If ObjContratos.GetContratosObraAvancesControlAcumulativo(CveContrato, CveEstimacion, UsuarioActual.CveEmpresa) Then DtControl = ObjContratos.DtResultados If DtControl.Rows.Count > 0 Then Lugar = DtControl(0)("Lugar").ToString DescripcionContrato = DtControl(0)("DescripcionContrato").ToString End If End If ObjContratos.Dispose() If DtControl.Rows.Count > 0 Then Dim WBAnexo = New ClosedXML.Excel.XLWorkbook(PlantillaAnexo) Dim WBAnexoSalvar = New ClosedXML.Excel.XLWorkbook Dim WSControl = WBAnexo.Worksheet(1) Dim WSDetalle = WBAnexo.Worksheet(2) Dim CuerrentRow As Integer = 28 WSControl.Cell(17, 2).Value = NumeroEstimacion 'Estimacion WSControl.Cell(20, 9).Value = FechaEstimacion.ToString("dd/MM/yyyy") 'Fecha estimacion WSControl.Cell(19, 8).Value = "$ " & DtControl.SUM("Importe").ToString("###,###,###.00") 'Total WSControl.Cell(19, 8).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Right) WSControl.Cell(20, 6).Value = NumeroContrato WSControl.Cell(18, 2).Value = Lugar WSControl.Cell(18, 2).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left) WSControl.Cell(18, 2).Style.Alignment.SetVertical(XLAlignmentVerticalValues.Top) WSControl.Cell(17, 6).Value = "" 'Periodo Fecha Inicial WSControl.Cell(17, 7).Value = "" 'Periuodo Fecha Final WSControl.Cell(20, 2).Value = DescripcionContrato WSControl.Cell(20, 2).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left) WSControl.Cell(20, 2).Style.Alignment.SetVertical(XLAlignmentVerticalValues.Top) WSControl.Cell(22, 7).Value = "" 'Presupuesto segun contrato WSControl.Cell(19, 5).Value = "" 'Contrtatista Dim RowCountControl As Integer = 1 For Each Drow As DataRow In DtControl.Rows WSControl.Cell(CuerrentRow, 1).Value = Drow("Codigo").ToString WSControl.Cell(CuerrentRow, 2).Value = Drow("PS").ToString WSControl.Cell(CuerrentRow, 3).Value = Drow("Abreviatura").ToString WSControl.Cell(CuerrentRow, 4).Value = Drow("Cantidad").ToString.ToDecimal WSControl.Cell(CuerrentRow, 5).Value = Drow("AcumuladoTotal").ToString.ToDecimal WSControl.Cell(CuerrentRow, 6).Value = Drow("AcumuladoAnterior").ToString.ToDecimal WSControl.Cell(CuerrentRow, 7).Value = Drow("CantidadActual").ToString.ToDecimal WSControl.Cell(CuerrentRow, 8).Value = Drow("PU").ToString.ToDecimal WSControl.Cell(CuerrentRow, 9).Value = Drow("Total").ToString.ToDecimal WSControl.Cell(CuerrentRow, 9).Style.NumberFormat.Format = "$ ###,###,###.00" WSControl.Cell(CuerrentRow, 1).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow, 2).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow, 3).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow, 4).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow, 5).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow, 6).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow, 7).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow, 8).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow, 9).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow, 1).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow, 2).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow, 3).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow, 4).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow, 5).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow, 6).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow, 7).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow, 8).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow, 9).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Medium 'ultimo Row If DtControl.Rows.Count = RowCountControl Then WSControl.Cell(CuerrentRow + 1, 1).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow + 1, 2).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow + 1, 3).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow + 1, 4).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow + 1, 5).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow + 1, 6).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow + 1, 7).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow + 1, 8).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow + 1, 9).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow + 1, 1).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow + 1, 2).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow + 1, 3).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow + 1, 4).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow + 1, 5).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow + 1, 6).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow + 1, 7).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow + 1, 8).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Thin WSControl.Cell(CuerrentRow + 1, 9).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Medium WSControl.Cell(CuerrentRow + 1, 8).Value = "Total:" WSControl.Cell(CuerrentRow + 1, 8).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Right) WSControl.Cell(CuerrentRow + 1, 8).Style.Font.Bold = True WSControl.Cell(CuerrentRow + 1, 9).Value = DtControl.SUM("Total") WSControl.Cell(CuerrentRow + 1, 9).Style.Font.Bold = True WSControl.Cell(CuerrentRow + 1, 9).Style.NumberFormat.Format = "$ ###,###,###.00" Dim range = WSControl.Range($"A{CuerrentRow + 3}:D{CuerrentRow + 3}") range.Merge() range.Style.Border.TopBorder = ClosedXML.Excel.XLBorderStyleValues.Thin range.Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin range.Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Thin range.Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center) range = WSControl.Range($"E{CuerrentRow + 3}:I{CuerrentRow + 3}") range.Merge() range.Style.Border.TopBorder = ClosedXML.Excel.XLBorderStyleValues.Thin range.Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin range.Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Medium range.Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center) range = WSControl.Range($"A{CuerrentRow + 4}:D{CuerrentRow + 4}") range.Merge() range.Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin range.Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Thin range.Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center) range.Value = "ING. WALTER ROBERTO VILLEGAS LARES" range = WSControl.Range($"E{CuerrentRow + 4}:I{CuerrentRow + 4}") range.Merge() range.Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin range.Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Medium range.Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center) range.Value = "C. SALVADOR SUAREZ" range = WSControl.Range($"A{CuerrentRow + 5}:D{CuerrentRow + 5}") range.Merge() range.Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin range.Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Thin range.Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center) range.Value = "SERVICIOS ELECTRICOS Y CONTROL DE HERMOSILLO S.A. DE C.V." range.Style.Font.Bold = True range = WSControl.Range($"E{CuerrentRow + 5}:I{CuerrentRow + 5}") range.Merge() range.Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Thin range.Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Medium range.Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center) range.Value = "GASERVICIO MATAMOROS SA DE CV" range.Style.Font.Bold = True End If CuerrentRow = CuerrentRow + 1 RowCountControl = RowCountControl + 1 Next WBAnexo.Worksheet(1).CopyTo(WBAnexoSalvar, "CONTROL") For Each Drow As DataRow In DtControl.Rows If Drow("CantidadActual").ToString.ToDecimal > 0 Then WSDetalle.Cell(3, 6).Value = NumeroContrato WSDetalle.Cell(4, 9).Value = "" 'Fecha de WSDetalle.Cell(4, 10).Value = "" 'Fecha a WSDetalle.Cell(4, 11).Value = NumeroEstimacion WSDetalle.Cell(6, 6).Value = DescripcionContrato WSDetalle.Cell(14, 2).Value = Drow("Codigo").ToString WSDetalle.Cell(14, 3).Value = Drow("PS").ToString WSDetalle.Cell(14, 4).Value = Drow("Abreviatura").ToString WSDetalle.Cell(12, 3).Value = "" 'Concepto WSDetalle.Cell(14, 10).Value = Drow("CantidadActual").ToString.ToDecimal WSDetalle.Cell(14, 11).Value = Drow("CantidadActual").ToString.ToDecimal 'WSDetalle.Cell(61, 6).Value = "" 'Empresario WSDetalle.Cell(61, 9).Value = Drow("Nombre").ToString 'Cliente Dim objContrato As New ClsContratos Dim DTArchivos As New DataTable If objContrato.GetContratosAvanceAnexos(Drow("CveContratoDetalle").ToString.ToEntero, Drow("Fecha").ToString, UsuarioActual.CveUsuario, CveEstimacion:=CveEstimacion) Then DTArchivos = objContrato.DtResultados End If objContrato.Dispose() Dim Imagenes As New List(Of ClosedXML.Excel.Drawings.IXLPicture) Dim CurrectRowImg As Integer = 19 'Row 19 primera imggen Dim RowH As Double = WSDetalle.Row(19).Height For Each drowArchivos As DataRow In DTArchivos.Rows Dim Archivo As String = "" Archivo = drowArchivos("Archivo").ToString Dim RutaArchivo As String = $"{UsuarioActual.Empresa.Ruta}\Contrato\{CveContrato}\Anexos\{Archivo}" If File.Exists(RutaArchivo) Then Dim Imagen = WSDetalle.AddPicture(RutaArchivo).MoveTo(WSDetalle.Cell(CurrectRowImg, 3)) Imagen.Scale(WSDetalle.Column(3).Width / (Imagen.OriginalWidth * 0.145D)) Dim ImgWidth As Double = Imagen.Height Dim nRowmas As Integer = (ImgWidth / RowH).ToEntero CurrectRowImg = CurrectRowImg + nRowmas Imagenes.Add(Imagen) End If Next WBAnexo.Worksheet(2).CopyTo(WBAnexoSalvar, If(Drow("Codigo").ToString.Trim.Length > 0, Drow("Codigo").ToString, Drow("CvePS").ToString)) For Each img As ClosedXML.Excel.Drawings.IXLPicture In Imagenes img.Delete() Next End If Next Dim msB = New MemoryStream() WBAnexoSalvar.SaveAs(msB) Dim BB As Byte() = msB.ToArray msB.Dispose() Response.Clear() Response.Buffer = True Response.AddHeader("content-disposition", "attachment; filename=Anexo_Estimacion" & NumeroEstimacion & ".xlsx") Response.ContentType = "application/vnd.ms-excel" Response.BinaryWrite(BB) Response.End() Else Alert("No se encontraron datos des control", TipoMensaje.MsgAdvertencia) End If End Sub #End Region End Class