Dim sqlConn As SqlClient.SqlConnection
Dim sqlCmd As New SqlClient.SqlCommand
Dim sqlRead As SqlClient.SqlDataReader
Dim varNum As Integer = 0
Dim varTotalMon As Decimal = 0
Dim varUsage As Decimal = 0
Private Sub LoadGrid()
If cboMonth.Text = "Choose Month" Then
Else
If cboYear.Text = "Choose Year" Then
Else
If varNum = 0 Then
varTotalMon = 0
varUsage = 0
Dim daPubs As SqlDataAdapter
Dim dsPubs As DataSet
SqlConnection1.ConnectionString = "workstation id=""S-KG-CFSCE-2098"";packet size=4096;integrated security=SSPI;data s" & _
"ource=""SCE-SCE-DSVR02D"";persist security info=False;initial catalog=Telecomm"
SqlConnection1.Open()
sqlCmd.Connection = SqlConnection1
sqlCmd.CommandType = CommandType.StoredProcedure
sqlCmd.CommandText = "SPCharges"
sqlCmd.Parameters.Add("@month", SqlDbType.VarChar)
sqlCmd.Parameters("@month").Value = cboMonth.Text
sqlCmd.Parameters.Add("@year", SqlDbType.VarChar)
sqlCmd.Parameters("@year").Value = cboYear.Text
daPubs = New SqlDataAdapter
daPubs.SelectCommand = sqlCmd
dsPubs = New DataSet
daPubs.Fill(dsPubs)
dgCharges.DataSource = dsPubs
dgCharges.DataMember = "Table"
SqlConnection1.Close()
SqlConnection1.ConnectionString = "workstation id=""S-KG-CFSCE-2098"";packet size=4096;integrated security=SSPI;data s" & _
"ource=""SCE-SCE-DSVR02D"";persist security info=False;initial catalog=Telecomm"
SqlConnection1.Open()
Dim cmdtext As String = "Select * from Charges where Month like '" & cboMonth.Text & "' and Year like '" & cboYear.Text & "'"
da.SelectCommand = New SqlCommand(cmdtext, SqlConnection1)
Dim dr As SqlDataReader = da.SelectCommand.ExecuteReader
While dr.Read
If dr.IsDBNull(2) Then
Else
varTotalMon = varTotalMon + CDec(dr.GetValue(2))
End If
If dr.IsDBNull(3) Then
Else
varUsage = varUsage + CDec(dr.GetValue(3))
End If
End While
txtMonthlyTot.Text = "$ " & CStr(varTotalMon)
txtUsage.Text = "$ " & CStr(varUsage)
dr.Close()
SqlConnection1.Close()
varNum = 1
Else
varTotalMon = 0
varUsage = 0
Dim daPubs As SqlDataAdapter
Dim dsPubs As DataSet
SqlConnection1.ConnectionString = "workstation id=""S-KG-CFSCE-2098"";packet size=4096;integrated security=SSPI;data s" & _
"ource=""SCE-SCE-DSVR02D"";persist security info=False;initial catalog=Telecomm"
SqlConnection1.Open()
sqlCmd.Connection = SqlConnection1
sqlCmd.CommandType = CommandType.StoredProcedure
sqlCmd.CommandText = "SPCharges"
'sqlCmd.Parameters.Add("@month", SqlDbType.VarChar)
sqlCmd.Parameters("@month").Value = cboMonth.Text
'sqlCmd.Parameters.Add("@year", SqlDbType.VarChar)
sqlCmd.Parameters("@year").Value = cboYear.Text
daPubs = New SqlDataAdapter
daPubs.SelectCommand = sqlCmd
dsPubs = New DataSet
daPubs.Fill(dsPubs)
dgCharges.DataSource = dsPubs
dgCharges.DataMember = "Table"
SqlConnection1.Close()
SqlConnection1.ConnectionString = "workstation id=""S-KG-CFSCE-2098"";packet size=4096;integrated security=SSPI;data s" & _
"ource=""SCE-SCE-DSVR02D"";persist security info=False;initial catalog=Telecomm"
SqlConnection1.Open()
Dim cmdtext As String = "Select * from Charges where Month like '" & cboMonth.Text & "' and Year like '" & cboYear.Text & "'"
da.SelectCommand = New SqlCommand(cmdtext, SqlConnection1)
Dim dr As SqlDataReader = da.SelectCommand.ExecuteReader
While dr.Read
If dr.IsDBNull(2) Then
Else
varTotalMon = varTotalMon + CDec(dr.GetValue(2))
End If
If dr.IsDBNull(3) Then
Else
varUsage = varUsage + CDec(dr.GetValue(3))
End If
End While
txtMonthlyTot.Text = "$ " & CStr(varTotalMon)
txtUsage.Text = "$ " & CStr(varUsage)
dr.Close()
SqlConnection1.Close()
End If
End If
End If
End Sub
Private Sub cboYear_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboYear.SelectedIndexChanged, cboMonth.SelectedIndexChanged
LoadGrid()
End Sub
Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
If cboMonth.Text = "Choose Month" Or cboYear.Text = "Choose Year" Then
MsgBox("Month and Year must be chosen first", MsgBoxStyle.OKOnly, "Choose month and year first")
Else
If cboMonth.SelectedIndex = 0 Then
cboMonth.SelectedIndex = 11
If cboYear.SelectedIndex = 0 Then
cboMonth.SelectedIndex = 0
MsgBox("No records before 2006", MsgBoxStyle.OKOnly, "No Records")
Else
cboYear.SelectedIndex = cboYear.SelectedIndex - 1
End If
Else
cboMonth.SelectedIndex = cboMonth.SelectedIndex - 1
End If
End If
End Sub
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
If cboMonth.Text = "Choose Month" Or cboYear.Text = "Choose Year" Then
MsgBox("Month and Year must be chosen first", MsgBoxStyle.OKOnly, "Choose month and year first")
Else
If cboMonth.SelectedIndex = 11 Then
cboMonth.SelectedIndex = 0
If cboYear.SelectedIndex = 14 Then
cboMonth.SelectedIndex = 11
MsgBox("No records after 2020", MsgBoxStyle.OKOnly, "No Records")
Else
cboYear.SelectedIndex = cboYear.SelectedIndex + 1
End If
Else
cboMonth.SelectedIndex = cboMonth.SelectedIndex + 1
End If
End If
End Sub