Dim conectar As New OleDbConnection(conexion)
conectar.Open()
'borra las columnas del datagreedview
Me.DataGridView1.DataSource = ""
Me.DataGridView1.Columns.Clear()
If Me.ComboBox1.Text <> "Seleccionar Establecimiento" And Me.ComboBox2.Text <> "" Then
Dim mosene As New OleDb.OleDbDataAdapter("select DISTINCT (d.CodigoPrestacion) as Código, p.NOMBRE_PRESTACION as Prestación, p.REM_PRESTACION as Rem, p.SECCION as Sección, d.Col01 as Enero from DatosSerieA d, PRESTACIONES p where d.CodigoPrestacion=p.CODIGO_PRESTACION and d.IdEstablecimiento='" & Me.Label7.Text & "' and d.Mes=1 and Ano=" & Me.ComboBox2.Text & "", conectar)
Dim datos As New DataSet
mosene.Fill(datos)
Me.DataGridView1.DataSource = datos.Tables(0)
Dim pb As ToolStripProgressBar = MDIParent1.ToolStripProgressBar1
pb.Visible = True
pb.Maximum = Me.DataGridView1.RowCount - 1
pb.Step = 1
'--------------------------------------------------------------------
'crea las columnas del datagredview
'--------------------------------------------------------------------
Me.DataGridView1.Columns.Add("Febrero", "Febrero")
Me.DataGridView1.Columns.Add("Marzo", "Marzo")
Me.DataGridView1.Columns.Add("Abril", "Abril")
Me.DataGridView1.Columns.Add("Mayo", "Mayo")
Me.DataGridView1.Columns.Add("Junio", "Junio")
Me.DataGridView1.Columns.Add("Julio", "Julio")
Me.DataGridView1.Columns.Add("Agosto", "Agosto")
Me.DataGridView1.Columns.Add("Septiembre", "Septiembre")
Me.DataGridView1.Columns.Add("Octubre", "Octubre")
Me.DataGridView1.Columns.Add("Noviembre", "Noviembre")
Me.DataGridView1.Columns.Add("Diciembre", "Diciembre")
Me.DataGridView1.Columns.Add("Total", "Total")
'--------------------------------------------------------------------
'--------------------------------------------------------------------
'--------------------------------------------------------------------
'inserta el valor corespondiente a cada mes
'--------------------------------------------------------------------
For i As Integer = 0 To Me.DataGridView1.RowCount - 2
Dim feb As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 2 and Ano=" & Me.ComboBox2.Text & "", conectar)
Dim mar As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 3 and Ano=" & Me.ComboBox2.Text & "", conectar)
Dim abr As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 4 and Ano=" & Me.ComboBox2.Text & "", conectar)
Dim may As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 5 and Ano=" & Me.ComboBox2.Text & "", conectar)
Dim jun As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 6 and Ano=" & Me.ComboBox2.Text & "", conectar)
Dim jul As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 7 and Ano=" & Me.ComboBox2.Text & "", conectar)
Dim ago As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 8 and Ano=" & Me.ComboBox2.Text & "", conectar)
Dim sep As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 9 and Ano=" & Me.ComboBox2.Text & "", conectar)
Dim oct As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 10 and Ano=" & Me.ComboBox2.Text & "", conectar)
Dim nov As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 11 and Ano=" & Me.ComboBox2.Text & "", conectar)
Dim dic As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 12 and Ano=" & Me.ComboBox2.Text & "", conectar)
Try
Me.DataGridView1.Item(5, i).Value = feb.ExecuteScalar()
Me.DataGridView1.Item(6, i).Value = mar.ExecuteScalar()
Me.DataGridView1.Item(7, i).Value = abr.ExecuteScalar()
Me.DataGridView1.Item(8, i).Value = may.ExecuteScalar()
Me.DataGridView1.Item(9, i).Value = jun.ExecuteScalar()
Me.DataGridView1.Item(10, i).Value = jul.ExecuteScalar()
Me.DataGridView1.Item(11, i).Value = ago.ExecuteScalar()
Me.DataGridView1.Item(12, i).Value = sep.ExecuteScalar()
Me.DataGridView1.Item(13, i).Value = oct.ExecuteScalar()
Me.DataGridView1.Item(14, i).Value = nov.ExecuteScalar()
Me.DataGridView1.Item(15, i).Value = dic.ExecuteScalar()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
pb.Value += 1
Next
'--------------------------------------------------------------------
'--------------------------------------------------------------------
'--------------------------------------------------------------------
'suma las columnas de enero a diciembre
'--------------------------------------------------------------------
Dim suma As Integer = 0
For i As Integer = 0 To DataGridView1.Rows.Count - 2
For x As Integer = 4 To DataGridView1.Columns.Count - 2
If IsDBNull(DataGridView1.Rows(i).Cells(x).Value) Then
Else
suma = suma + DataGridView1.Rows(i).Cells(x).Value
End If
Me.DataGridView1.Item(16, i).Value = suma
Next
suma = 0
Next
pb.Value = 0
pb.Visible = False
'--------------------------------------------------------------------
'--------------------------------------------------------------------