Chugach Consumers


Chugach Electric Association

<% '----------------- connections stuff --------------------------- 'Dimension variables Dim adoCon 'Holds the database Connection Object Dim objRS 'Holds the recordset for the records in the database Dim strSQL 'Holds the SQL query to query the database Dim strConnect 'Create an ADO connnection object Set adoCon=Server.CreateObject("ADODB.Connection") 'Create an ADO recordset object Set objRS = Server.CreateObject("ADODB.Recordset") 'Set an active connection to the Connection object using a DSN-less connection adoCon.Open strConnect '----------------- Setting up Variables ------------------------------- 'Declare variables Dim i 'for use in counting Dim OrderDesc Dim A(5,9) Dim myRcdCt Dim myGraph myRcdCt=0 FldCount=9 'Populate arrays -- could even have a table in the database of these that is read in!! 'Fields A(1,1)="Job_Title" A(1,2)="Total_Cost" A(1,3)="Total_Hours" A(1,4)="Hourly_Cost" A(1,5)="Total_Wages" A(1,6)="OT_Percent" A(1,7)="All_Benefits" A(1,8)="Other_Costs" A(1,9)="Leave_Cashed_In" 'Headings A(2,1)="Job Title" A(2,2)="Total Cost" A(2,3)="Hours" A(2,4)="Cost/Hour" A(2,5)="Total Wages" A(2,6)="OT Percent" A(2,7)="Benefits" A(2,8)="Other Costs" A(2,9)="Cashed Leave" 'Rounding A(4,1)="" A(4,2)=0 A(4,3)=0 A(4,4)=2 A(4,5)=0 A(4,6)=1 A(4,7)=0 A(4,8)=0 A(4,9)=0 'Formatting A(5,1)="text" A(5,2)="currency" A(5,3)="number" A(5,4)="currency" A(5,5)="currency" A(5,6)="percent" A(5,7)="currency" A(5,8)="currency" A(5,9)="currency" if request.querystring("Yr") <> "" then myYear=request.querystring("Yr") else mySort=2008 end if if request.querystring("SortVar") <> "" then mySort=request.querystring("SortVar") else mySort=1 end if if request.querystring("OrderVar") <> "" then myOrder=request.querystring("OrderVar") else myOrder="ASC" end if If myOrder="DESC" then OrderDesc="Descending" else OrderDesc="Ascending" end if '-------------------------------------find record count-------------------------------- strSQL="SELECT Count("&A(1,mySort)&") as myCount FROM CEAComp"&myYear&";" objRS.Open strSQL, adoCon myRcdCt=objRS("myCount") objRS.Close '---------------------------------------reading in the data to graph------------------- strSQL="SELECT "&A(1,mySort)&" FROM CEAComp" &myYear&" ORDER BY " & A(1,mySort)&" "& myOrder&";" objRS.Open strSQL, adoCon Redim myGraph(myRcdCt) for i= 1 to myRcdCt myGraph(i) = objRS(A(1,mySort)) objRS.MoveNext next 'Reset server objects objRS.Close Set objRS = Nothing Set adoCon = Nothing '---------------------------------------the graph ------------------- 'thanks to: http://www.asp101.com/samples/download.asp?file=bar%5Fchart%2Easp Sub ShowChart(ByRef aValues, ByRef strTitle, ByRef strXAxisLabel, ByRef strYAxisLabel) 'User changeable graph defining constants ' All units are in screen pixels Const GRAPH_WIDTH = 300 ' The width of the body of the graph Const GRAPH_HEIGHT = 250 ' The heigth of the body of the graph Const GRAPH_BORDER = 5 ' The size of the black border Const GRAPH_SPACER = 0 ' The size of the space between the bars Const TABLE_BORDER = 0 ' Make 0 unless debugging ' Declare variables Dim iMaxValue Dim iBarWidth Dim iBarHeight ' Get the maximum value in the data set iMaxValue = 0 For I = 0 To UBound(aValues) If iMaxValue < aValues(I) Then iMaxValue = aValues(I) Next 'I ' Calculate the width of the bars ' Take the overall width and divide by number of items and round down. ' Reduce it by the size of the spacer so the end result should be GRAPH_WIDTH or less! iBarWidth = (GRAPH_WIDTH \ (UBound(aValues) + 1)) - GRAPH_SPACER ' Start drawing the graph RESPONSE.WRITE ("") RESPONSE.WRITE ("") RESPONSE.WRITE ("") RESPONSE.WRITE ("") RESPONSE.WRITE ("

" &strTitle& "

" &strYAxisLabel& "") RESPONSE.WRITE ("") RESPONSE.WRITE (" ") RESPONSE.WRITE ("
") Select Case A(5,mySort) Case "number" RESPONSE.WRITE formatnumber(iMaxValue,A(4,mySort)) Case "percent" RESPONSE.WRITE formatpercent(iMaxValue,A(4,mySort)) Case "currency" RESPONSE.WRITE formatcurrency(iMaxValue,A(4,mySort)) Case else RESPONSE.WRITE iMaxValue,A(4,mySort) End Select RESPONSE.WRITE ("  
") Select Case A(5,mySort) Case "number" RESPONSE.WRITE formatnumber("0",A(4,mySort)) Case "percent" RESPONSE.WRITE formatpercent("0",A(4,mySort)) Case "currency" RESPONSE.WRITE formatcurrency("0",A(4,mySort)) Case else RESPONSE.WRITE "0",A(4,mySort) End Select RESPONSE.WRITE ("  
") RESPONSE.WRITE ("") ' For the body of the chart -- Loop through the data showing the bars! For I = 0 To UBound(aValues) iBarHeight = Int((aValues(I) / iMaxValue) * GRAPH_HEIGHT) ' This is a hack since browsers ignore a 0 as an image dimension! If iBarHeight = 0 Then iBarHeight = 1 RESPONSE.WRITE ("") RESPONSE.WRITE ("") Next 'I RESPONSE.WRITE (" ") RESPONSE.WRITE ("
&aValues(I)&
") RESPONSE.WRITE ("

" &strXAxisLabel& "

") End Sub ' Chart made from DATA without Bar Labels) ShowChart myGraph, "Chart of "&myYear& " CEA Salaries sorted by "&OrderDesc&" "&A(2,mySort), myRcdCt&" Employees", "" %>