Hi,
Thank you.
You are helping me a lot.
Below I sent you project code.
About fn_CSVToTable: understood.
I have introduced view due to complex joins.
fn_CSVToTable: work OK.
-----------------------
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Data.SqlClient
Imports System.io
Imports System.Configuration
Imports Microsoft.VisualBasic
Public Class WebForm2
Inherits System.Web.UI.Page
Dim crReportDocument As ReportDocument
Dim crExportOptions As ExportOptions
Dim crDiskFileDestinationOptions As DiskFileDestinationOptions
#Region " Código generado por el Diseñador de Web Forms "
'El Diseñador de Web Forms requiere esta llamada.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
Me.DataSet31 = New Crystal1.DataSet3
CType(Me.DataSet31,
System.ComponentModel.ISupportInitialize).BeginInit()
'
'SqlDataAdapter1
'
Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
Me.SqlDataAdapter1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "sp_fnBaseAñosSumaCompara", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("empresa",
"empresa"), New System.Data.Common.DataColumnMapping("polo", "polo"), New
System.Data.Common.DataColumnMapping("tit_emp", "tit_emp"), New
System.Data.Common.DataColumnMapping("orden", "orden"), New
System.Data.Common.DataColumnMapping("texto", "texto"), New
System.Data.Common.DataColumnMapping("año_anterior", "año_anterior"), New
System.Data.Common.DataColumnMapping("presupuesto", "presupuesto"), New
System.Data.Common.DataColumnMapping("año_actual", "año_actual")})})
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "[sp_fnBaseAñosSumaCompara]"
Me.SqlSelectCommand1.CommandType =
System.Data.CommandType.StoredProcedure
Me.SqlSelectCommand1.Connection = Me.SqlConnection1
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
System.Data.SqlDbType.Int, 4,
System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0,
Byte), "",
System.Data.DataRowVersion.Current, Nothing))
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@orden",
System.Data.SqlDbType.NVarChar, 10))
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@año_anterior",
System.Data.SqlDbType.NVarChar, 5))
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@presupuesto",
System.Data.SqlDbType.NVarChar, 5))
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@año_actual",
System.Data.SqlDbType.NVarChar, 5))
'
'SqlConnection1
'
Me.SqlConnection1.ConnectionString = "workstation id=ADISPC;packet
size=4096;integrated
security=SSPI;data source=ADI" & _
"SPC;persist security info=False;initial catalog=Orion"
'
'DataSet31
'
Me.DataSet31.DataSetName = "DataSet3"
Me.DataSet31.Locale = New System.Globalization.CultureInfo("es-ES")
CType(Me.DataSet31,
System.ComponentModel.ISupportInitialize).EndInit()
End Sub
Protected WithEvents CrystalReportViewer1 As
CrystalDecisions.Web.CrystalReportViewer
Protected WithEvents SqlDataAdapter1 As
System.Data.SqlClient.SqlDataAdapter
Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
Protected WithEvents DataSet31 As Crystal1.DataSet3
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents listbox1 As System.Web.UI.WebControls.ListBox
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents DropDownList1 As
System.Web.UI.WebControls.DropDownList
Protected WithEvents Dropdownlist3 As
System.Web.UI.WebControls.DropDownList
Protected WithEvents Dropdownlist2 As
System.Web.UI.WebControls.DropDownList
Protected WithEvents Dropdownlist4 As
System.Web.UI.WebControls.DropDownList
Protected li As System.Web.UI.WebControls.ListItem
'NOTA: el Diseñador de Web Forms necesita la siguiente declaración del
marcador de posición.
'No se debe eliminar o mover.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles
MyBase.Init
'CODEGEN: el Diseñador de Web Forms requiere esta llamada de método
'No la modifique con el editor de código.
InitializeComponent()
CrystalReportViewer1.ReportSource = crReportDocument
With DropDownList1.Items
.Add("Rich Text (RTF)")
.Add("Portable Document (PDF)")
.Add("MS Word (DOC)")
.Add("MS Excel (XLS)")
.Add("Crystal Report (RPT)")
.Add("HTML 3.2 (HTML)")
.Add("HTML 4.0 (HTML)")
End With
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles
MyBase.Load
'Introducir aquà el código de usuario para inicializar la página
If Not IsPostBack Then
'listbox1.SelectedIndex = 2
Dropdownlist4.SelectedIndex = 2
cargar_listbox()
End If
End Sub
Sub cargar_listbox()
Dim strSql As String = "Select texto, orden From tablaVI_RESULTADOS
Order By orden"
Dim objConn As SqlClient.SqlConnection = _
New SqlConnection("Data Source=adispc;" & _
"Integrated Security=SSPI;" & _
"Initial Catalog=Orion")
Dim objCmd As New SqlCommand(strSql, objConn)
Try
objConn.Open()
listbox1.DataSource = objCmd.ExecuteReader()
listbox1.DataTextField = "texto"
listbox1.DataValueField = "orden"
listbox1.DataBind()
Catch exc As SqlException
Response.Write(exc.ToString())
Finally
objConn.Dispose()
End Try
End Sub
Sub ChangeWhereClause(ByVal Sender As System.Object, ByVal e As
System.EventArgs)
'VARIANTE CON LISTBOX MULTIPLE
Dim strWhereClause As String = ""
For Each li In listbox1.Items
If li.Selected Then
strWhereClause &= "orden =" &
Me.SqlSelectCommand1.Parameters("@orden").Value =
li.Value & " Or "
End If
Next
If strWhereClause.Length > 0 Then
strWhereClause = Left(strWhereClause, strWhereClause.Length() -
4)
strWhereClause = "WHERE " & strWhereClause
Dim strSql = "Select *" _
& "From sp_fnBaseAñosSumaCompara " '& strWhereClause & " or " _
End If
'Me.SqlSelectCommand1.Parameters("@orden").Value =
listbox1.SelectedItem.Value
'Me.SqlSelectCommand1.Parameters("@año_anterior").Value =
Dropdownlist4.SelectedItem.Text
'Me.SqlSelectCommand1.Parameters("@presupuesto").Value =
Dropdownlist2.SelectedItem.Text
'Me.SqlSelectCommand1.Parameters("@año_actual").Value =
Dropdownlist3.SelectedItem.Text
Me.SqlDataAdapter1.Fill(DataSet31.sp_fnBaseAñosSumaCompara)
Dim oRpt As New Resultados
oRpt.SetDataSource(DataSet31)
CrystalReportViewer1.ReportSource = oRpt
End Sub
Sub ExportReport()
Dim ExportPath As String
ExportPath = Request.PhysicalApplicationPath + "Exported\"
If Directory.Exists(ExportPath) = False Then
Directory.CreateDirectory(Request.PhysicalApplicationPath +
"Exported\")
End If
crDiskFileDestinationOptions = New DiskFileDestinationOptions
crExportOptions = crReportDocument.ExportOptions
Select Case DropDownList1.SelectedItem.Text 'this contains the value
of the selected
export format.
Case "Rich Text (RTF)"
'Export to RTF.
crDiskFileDestinationOptions.DiskFileName = ExportPath +
"RichTextFormat.rtf"
'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.RichText
.DestinationOptions = crDiskFileDestinationOptions
End With
Case "Portable Document (PDF)"
'Export to PDF
crDiskFileDestinationOptions.DiskFileName = ExportPath +
"PortableDoc.pdf"
'set the required report ExportOptions properties
With crExportOptions
.DestinationOptions = crDiskFileDestinationOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
End With
Case "MS Word (DOC)"
'Export to Word
crDiskFileDestinationOptions.DiskFileName = ExportPath +
"Word.doc"
'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.WordForWindows
.DestinationOptions = crDiskFileDestinationOptions
End With
Case "MS Excel (XLS)"
'Export to Excel
'append a filename to the export path and set this file as
the filename property
for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath +
"Excel.xls"
'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.Excel
.DestinationOptions = crDiskFileDestinationOptions
End With
Case "Crystal Report (RPT)"
'Export to Crystal reports:
crDiskFileDestinationOptions.DiskFileName = ExportPath +
"Report.rpt"
'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.CrystalReport
.DestinationOptions = crDiskFileDestinationOptions
End With
Case "HTML 3.2 (HTML)"
'Export to HTML32:
Dim HTML32Formatopts As New HTMLFormatOptions
With crExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.HTML32
End With
With HTML32Formatopts
.HTMLBaseFolderName = ExportPath + "Html32Folder"
'Foldername to place HTML
files
.HTMLFileName = "HTML32.html"
.HTMLEnableSeparatedPages = False
.HTMLHasPageNavigator = False
End With
crExportOptions.FormatOptions = HTML32Formatopts
Case "HTML 4.0 (HTML)"
'Export to Html 4.0:
Dim HTML40Formatopts As New HTMLFormatOptions
With crExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.HTML40
End With
With HTML40Formatopts
.HTMLBaseFolderName = ExportPath + "Html40Folder" '
Foldername to place HTML
files
.HTMLFileName = "HTML40.html"
.HTMLEnableSeparatedPages = True
.HTMLHasPageNavigator = True
.FirstPageNumber = 1
.LastPageNumber = 3
End With
crExportOptions.FormatOptions = HTML40Formatopts
End Select 'export format
Try
' Export the report
crReportDocument.Export()
Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles
Button1.Click
ExportReport()
End Sub
End Class
--------------------
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm2.aspx.vb"
Inherits="Crystal1.WebForm2"%>
<%@ Register TagPrefix="cr" Namespace="CrystalDecisions.Web"
Assembly="CrystalDecisions.Web,
Version=9.1.5000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm2</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="
http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<CR:CrystalReportViewer id=CrystalReportViewer1 style="Z-INDEX: 100;
LEFT: 48px; POSITION: absolute; TOP: 216px" runat="server" Width="753px"
Height="1095px"
ReportSource='<%# "c:\inetpub\wwwroot\crystal1\CrystalReport1.rpt" %>'
DisplayGroupTree="False"
DisplayToolbar="False">
</CR:CrystalReportViewer>
<asp:dropdownlist id="Dropdownlist4" style="Z-INDEX: 109; LEFT: 8px;
POSITION: absolute; TOP: 8px"
runat="server" Width="88px" Height="24px" AutoPostBack="True"
OnSelectedIndexChanged="ChangeWhereClause">
<asp:ListItem Value="1998" Selected="True">1998</asp:ListItem>
<asp:ListItem Value="1999">1999</asp:ListItem>
<asp:ListItem Value="2000">2000</asp:ListItem>
<asp:ListItem Value="2001">2001</asp:ListItem>
<asp:ListItem Value="2002">2002</asp:ListItem>
<asp:ListItem Value="2003">2003</asp:ListItem>
<asp:ListItem Value="2004P">2004P</asp:ListItem>
<asp:ListItem Value="2004">2004</asp:ListItem>
</asp:dropdownlist>
<asp:dropdownlist id="Dropdownlist2" style="Z-INDEX: 105; LEFT: 112px;
POSITION: absolute; TOP: 8px"
runat="server" Width="88px" Height="24px" AutoPostBack="True"
OnSelectedIndexChanged="ChangeWhereClause">
<asp:ListItem Value="1998">1998</asp:ListItem>
<asp:ListItem Value="1999" Selected="True">1999</asp:ListItem>
<asp:ListItem Value="2000">2000</asp:ListItem>
<asp:ListItem Value="2001">2001</asp:ListItem>
<asp:ListItem Value="2002">2002</asp:ListItem>
<asp:ListItem Value="2003">2003</asp:ListItem>
<asp:ListItem Value="2004P">2004P</asp:ListItem>
<asp:ListItem Value="2004">2004</asp:ListItem>
</asp:dropdownlist>
<asp:dropdownlist id="Dropdownlist3" style="Z-INDEX: 104; LEFT: 208px;
POSITION: absolute; TOP: 8px"
runat="server" Width="81" Height="24px" AutoPostBack="True"
OnSelectedIndexChanged="ChangeWhereClause">
<asp:ListItem Value="1998">1998</asp:ListItem>
<asp:ListItem Value="1999">1999</asp:ListItem>
<asp:ListItem Value="2000" Selected="True">2000</asp:ListItem>
<asp:ListItem Value="2001">2001</asp:ListItem>
<asp:ListItem Value="2002">2002</asp:ListItem>
<asp:ListItem Value="2003">2003</asp:ListItem>
<asp:ListItem Value="2004P">2004P</asp:ListItem>
<asp:ListItem Value="2004">2004</asp:ListItem>
</asp:dropdownlist>
<asp

ropDownList id="DropDownList1" style="Z-INDEX: 108; LEFT: 16px;
POSITION: absolute; TOP: 80px"
runat="server" Width="184px" Height="24px"></asp

ropDownList>
<asp:label id="Label1" style="Z-INDEX: 103; LEFT: 336px; POSITION:
absolute; TOP: 8px" runat="server"
Width="288px" Height="20px" Font-Bold="True" ForeColor="White"
BackColor="RoyalBlue" BorderColor="#0000C0"
BorderStyle="None">Conceptos</asp:label>
<asp:listbox id="listbox1" style="Z-INDEX: 102; LEFT: 336px; POSITION:
absolute; TOP: 32px" runat="server"
Width="288px" Height="116px" AutoPostBack="True"
OnSelectedIndexChanged="ChangeWhereClause"
SelectionMode="Multiple"></asp:listbox>
<asp:Button id="Button1" style="Z-INDEX: 106; LEFT: 232px; POSITION:
absolute; TOP: 56px" runat="server"
Width="72px" BackColor="#C0C0FF" Text="Button1"></asp:Button>
</form>
</body>
</HTML>
------------------
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER VIEW dbo.Vs_Base
AS
SELECT dbo.Codiari9.Año, dbo.coclaem9.POLO, dbo.coclaem9.EMPRESA,
dbo.coclaem9.TIT_EMP,
dbo.tablaVI_RESULTADOS.ORDEN,
dbo.tablaVI_ANEXO_DE_GASTOS_DIVISAS1_DETALLE.TEXTO,
dbo.Codiari9.Saldo
FROM dbo.tablaVI_RESULTADOS INNER JOIN
dbo.Coplade92 ON
dbo.tablaVI_RESULTADOS.ORDEN =
dbo.Coplade92.TABLAVI_RESULTADOS INNER JOIN
dbo.coclaem9 INNER JOIN
dbo.Codiari9 ON dbo.coclaem9.EMPRESA =
dbo.Codiari9.EMPRESA ON
dbo.Coplade92.CUENTA2 = dbo.Codiari9.CUENTA AND
dbo.Coplade92.CTO_GTO_2 = dbo.Codiari9.CTO_GTO1
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
---------------------------
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER FUNCTION dbo.fnBaseAñosCompara(@orden nvarchar(10),
@año_anterior nvarchar (5),
@presupuesto nvarchar (5),
@año_actual nvarchar (5))
RETURNS TABLE
AS
RETURN ( SELECT Año, ORDEN, TEXTO,POLO, EMPRESA, TIT_EMP, Saldo, CASE
WHEN año =
@año_anterior THEN saldo ELSE 0 END AS año_anterior,
CASE WHEN año = @presupuesto THEN saldo ELSE 0 END AS
presupuesto,
CASE WHEN año = @año_actual THEN saldo ELSE 0 END AS
año_actual,
CASE WHEN año = @año_anterior THEN año ELSE 0 END AS
año_anterior_lb,
CASE WHEN año = @presupuesto THEN año ELSE 0 END AS
presupuesto_lb,
CASE WHEN año = @año_actual THEN año ELSE 0 END AS
año_actual_lb
FROM dbo.Vs_Base
WHERE (Año = @año_anterior) AND (ORDEN = @orden) OR
(Año = @presupuesto) AND (ORDEN = @orden)OR
(Año = @año_actual) AND (ORDEN = @orden))
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER FUNCTION dbo.fnBaseAñosSumaCompara(@orden nvarchar (10),
@año_anterior nvarchar (5),
@presupuesto nvarchar (5),
@año_actual nvarchar (5))
RETURNS TABLE
AS
RETURN ( SELECT TOP 100 PERCENT EMPRESA, POLO, TIT_EMP, ORDEN, TEXTO,
MAX(año_anterior_lb) AS
año_anterior_lb2, MAX(presupuesto_lb) AS presupuesto_lb2,
MAX(año_actual_lb) AS año_actual_lb2,
SUM(año_anterior) AS año_anterior,
SUM(presupuesto) AS presupuesto, SUM(año_actual) AS año_actual
FROM dbo.fnBaseAñosCompara(@orden, @año_anterior, @presupuesto,
@año_actual)
fnBaseAñosCompara
GROUP BY EMPRESA, TIT_EMP, ORDEN, TEXTO, POLO
ORDER BY EMPRESA )
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
-----------------------
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER PROCEDURE dbo.sp_fnBaseAñosSumaCompara
(@orden nvarchar(10),
@año_anterior nvarchar (5),
@presupuesto nvarchar (5),
@año_actual nvarchar (5))
AS SELECT *
FROM dbo.fnBaseAñosSumaCompara(@orden, @año_anterior,@presupuesto,
@año_actual )
fnBaseAñosSumaCompara
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
Thank again.
Adis
------------------------------------------------------------------------------------------