Visual Basic.NET - [Ayuda]Graficos estadisticos en tiempo real

 
Vista:

[Ayuda]Graficos estadisticos en tiempo real

Publicado por Carlos (9 intervenciones) el 03/07/2012 18:18:50
Hola a todos,

Estoy queriendo hacer un sistema de Tablero de Comandos con Graficos estadisticos actualizados en tiempo real (o lo mas real posible).

Ahora necesitaria ayuda con la forma o metodo en el que se actualizarian los graficos y los elementos que deberia utilizar.


Por ahora estaba usando un Chart, un Timer y un Data Set (común)

Con el timer actualizaba cada 5 minutos una consulta (consulta probada en vb 6, que llenando un recordset actualiza una grilla con los datos correspondientes).

Pero al utilizarlo en VB.Net solo la primera consulta era correcta y el Chart graficaba los datos de ese momento, al realizarlo por segunda vez, despues de vaciar el Data Set, este se llenaba con los datos de la 1 consulta, seguidos de los datos actuales, y el Chart no varia en nada.


Quisiera saber que puedo estar haciendo mal, o quizas hay elementos mas idoneos para este tipo de proyectos.

les dejo el codigo abajo:
Formulario
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
Imports System.Data.OleDb
Imports System.Windows.Forms.DataVisualization.Charting
Public Class frmTableroRec
    Private DA As New OleDbDataAdapter(cmdSql)
    Private sSql As String
    Dim fecHasta As Date = Now
    Dim fecDesde As Date = Now
    Dim bPrimeraVez As Boolean
 
    Private Sub frmTableroRec_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Conectarse()
        CalcularRecDiaria()
    End Sub
 
    Private Sub CalcularRecDiaria()
        Dim rsD As New DataSet
        Dim rsServ As New DataSet
        Dim cRedondeo As Double
        Dim cTotalRendicion As Double
 
        cmdSql.Connection = cnnSql
        cmdSql.CommandType = CommandType.Text
 
        On Error Resume Next
        sSql = "drop table tmp_ResCob"
        cmdSql.CommandText = sSql
        cmdSql.ExecuteNonQuery()
 
        On Error GoTo mensaje
        Me.Cursor = Cursors.WaitCursor
 
        lblProceso.Text = "Procesando Cajas..."
        ' Application.DoEvents()
 
        'Creo la tabla auxiliar
        sSql = "create table tmp_ResCob(IdCobro int, " & _
               "                        IdUsuario int, " & _
               "                        FecCobro datetime, " & _
               "                        CobroParcial bit, " & _
               "                        IntMora bit, " & _
               "                        IntCh bit, " & _
               "                        IdComprobante int, " & _
               "                        IdServicio int,  " & _
               "                        DsComp char(50), " & _
               "                        IdCtaFact int, " & _
               "                        Nombre char(50), " & _
               "                        FecEmision datetime, " & _
               "                        FecVto datetime, " & _
               "                        Total money)"
 
        cmdSql.CommandText = sSql
        cmdSql.ExecuteNonQuery()
 
        'Redondeo
        sSql = "select sum(D1.Importe)*-1 as Importe " & _
               "from DET_COBRO D1, DET_COBRANZA D2, COBRANZA CZ " & _
               "where D1.IdCobro = D2.IdCobro and " & _
               "      D2.IdCobranza = CZ.IdCobranza and " & _
               "      CZ.FecInicio between '" & Format(fecDesde, "yyyyMMdd") & "' and '" & Format(fecHasta, "yyyyMMdd 23:59") & "' AND " & _
               "      D1.IdTipoCobro = 5 "
        cmdSql.CommandText = sSql
        DA.Fill(rsD, "Recaudacion")
 
        cRedondeo = IIf(rsD.Tables("Recaudacion").Rows.Count > 0, (rsD.Tables("Recaudacion").Rows(0)("Importe")), 0)
 
        'Cobros Generales
        lblProceso.Text = "Procesando Cobros..."
 
        sSql = "insert into tmp_ResCob(IdCobro, IdUsuario,   FecCobro,    CobroParcial,    IntMora,    IntCh,    IdComprobante,IdServicio,                                                           DsComp,      IdCtaFact, Nombre, FecEmision,    FecVto, Total) " & _
               "select              CB.IdCobro, CZ.IdUsuario, CB.FecCobro, CB.CobroParcial, CC.IntMora, CC.IntCh, CC.IdComprobante,IdServicio,rtrim(TC.Abreviatura) + ' '+ rtrim(convert(char(10), CV.Numero)), CV.IdCtaFact, CV.Nombre, CV.FecEmision, CV.FecVto, CV.Total * TC.Signo as Total " & _
               "from DET_COBRANZA DC, COBRO CB, COMP_COBRO CC, COMP_VENTA CV, TIPO_COMPROBANTE TC, COBRANZA CZ " & _
               "where DC.IdCobro = CB.IdCobro and " & _
               "      DC.IdCobranza = CZ.IdCobranza and " & _
               "      CZ.FecInicio between '" & Format(fecDesde, "yyyyMMdd") & "' and '" & Format(fecHasta, "yyyyMMdd 23:59") & "' and " & _
               "      CB.IdCobro = CC.IdCobro and " & _
               "      CC.IdComprobante = CV.IdComprobante and " & _
               "      CV.IdTipoComp = TC.IdTipoComp and " & _
               "      TC.IdTipoComp in(1,2,3,29,30,32,33,34,35) and " & _
               "      CB.CobroParcial = 0 " & _
               "order by DC.IdCobro"
        cmdSql.CommandText = sSql
        cmdSql.ExecuteNonQuery()
 
        lblProceso.Text = "Procesando Cobros Parciales..."
 
        sSql = "select CB.IdCobro, CV.Total, CZ.IdUsuario " & _
               "from DET_COBRANZA DC, COBRO CB, COMP_COBRO CC, COMP_VENTA CV, TIPO_COMPROBANTE TC, COBRANZA CZ " & _
               "where DC.IdCobranza = CZ.IdCobranza and " & _
               "      CZ.FecInicio between '" & Format(fecDesde, "yyyyMMdd") & "' and '" & Format(fecHasta, "yyyyMMdd 23:59") & "' and " & _
               "      DC.IdCobro = CB.IdCobro and " & _
               "      CB.CobroParcial = 1 and " & _
               "      CB.IdCobro = CC.IdCobro and " & _
               "      CC.IdComprobante = CV.IdComprobante and " & _
               "      CV.IdTipoComp = TC.IdTipoComp and " & _
               "      TC.IdTipoComp = 34 " & _
               "order by DC.IdCobro"
        cmdSql.CommandText = sSql
        rsD.Clear()
        DA.Fill(rsD, "Recaudacion")
 
        If rsD.Tables("Recaudacion").Rows.Count > 0 Then
            Dim DT As New DataTable
            DT = _
            rsD.Tables("Recaudacion")
            Dim nombre As Long
            Dim cobro As Long
            Dim total As Double
            Dim i As Integer = 0
            For Each row As DataRow In DT.Rows
                nombre = rsD.Tables("Recaudacion").Rows(i)("IdUsuario")
                cobro = rsD.Tables("Recaudacion").Rows(i)("IdCobro")
                total = rsD.Tables("Recaudacion").Rows(i)("Total")
                sSql = "insert into tmp_ResCob(IdCobro, IdUsuario,   FecCobro,    CobroParcial,    IntMora,    IntCh,    IdComprobante,IdServicio,                                              DsComp,      IdCtaFact,    Nombre, FecEmision,    FecVto, Total) " & _
                       "select CB.IdCobro," & nombre & ", CB.FecCobro, CB.CobroParcial, CC.IntMora, CC.IntCh, CC.IdComprobante,IdServicio, rtrim(TC.Abreviatura) + ' '+ rtrim(convert(char(10), CV.Numero)), CV.IdCtaFact, CV.Nombre, CV.FecEmision, CV.FecVto, " & total & " " & _
                       "from COBRO CB, COMP_COBRO CC, COMP_VENTA CV, TIPO_COMPROBANTE TC " & _
                       "where CB.IdCobro = " & cobro & " and " & _
                       "      CB.IdCobro = CC.IdCobro and " & _
                       "      CC.IdComprobante = CV.IdComprobante and " & _
                       "      CV.IdTipoComp = TC.IdTipoComp and " & _
                       "      TC.IdTipoComp <> 34"
                cmdSql.CommandText = sSql
                cmdSql.ExecuteNonQuery()
                i = i + 1
            Next
 
        End If
 
        'Total General.
        lblProceso.Text = "Procesando Resumen de Caja..."
 
        sSql = "select Sum(Total) as Total " & _
               "from tmp_ResCob RE "
        cmdSql.CommandText = sSql
        DA.Fill(rsServ, "Recaudacion")
 
        'Resumen de Cobranza por Servicio.
        sSql = "select SE.IdServicio, SE.DsServicio , Sum(Total) as Total " & _
               "from SERVICIOS SE, tmp_ResCob RE " & _
               "where SE.idServicio = RE.idServicio " & _
               "group by SE.IdServicio, SE.DsServicio " & _
               "order by SE.DsServicio"
        rsServ.Clear()
        cmdSql.CommandText = sSql
        DA.Fill(rsServ, "Recaudacion")
 
        Graficar(rsServ)
 
        sSql = "drop table tmp_ResCob"
        cmdSql.CommandText = sSql
        cmdSql.ExecuteNonQuery()
 
        Me.Cursor = Cursors.Arrow
 
        lblProceso.Text = "PROCESO FINALIZADO!!!"
 
        Exit Sub
 
mensaje:
        MsgBox("Error Nº: " & Err.Number & Chr(13) & Err.Description, vbCritical, "Error")
 
    End Sub
 
    Private Sub Graficar(ByVal Origen As DataSet)
        chrRecaudaciones.Show()
        chrRecaudaciones.Series("Series1").XValueMember = "DsServicio"
        chrRecaudaciones.Series("Series1").YValueMembers = "Total"
 
        chrRecaudaciones.DataSource = Origen.Tables("Recaudacion")
 
        lblTotal.Text = Origen.Tables("Recaudacion").Rows(0)(0)
 
    End Sub
 
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        CalcularRecDiaria()
     End Sub
End Class


Modulo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Imports System.Data.OleDb
Module Conexion
    Public cnnSql As New OleDbConnection
    Public cmdSql As New OleDbCommand
    Public rs As DataTable
    Public varDSN As String
    Public Declare Function GetComputerName _
    Lib "Kernel32" Alias "GetComputerNameA" _
    (ByVal lpBuffer As String, ByVal nSize As Long) As Long
 
    Public Sub Conectarse()
        Dim DB As String
        Dim sServer As String
        Dim sSql As String
        cnnSql = New OleDbConnection
 
        DB = "SGC_CAROYA"
        sServer = "192.168.100.115"   'SRV2
        cnnSql.ConnectionString = "Provider=SQLOLEDB.1;Data Source=" & Trim(sServer) & ";Initial Catalog=" & Trim(DB) & ";UID=sa;PWD=password"
 
        'Seteo la DB
        sSql = "set CONCAT_NULL_YIELDS_NULL OFF"
 
        cnnSql.Open()
        cmdSql.Connection = cnnSql
        cmdSql.CommandType = CommandType.Text
        cmdSql.CommandText = sSql
        cmdSql.ExecuteNonQuery()
    End Sub
 
    Public Sub Desconectarse()
         cnnSql.Close()
    End Sub
End Module
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder