Sort | array
This afternoon when I was doing something, I encountered this problem:
The performance of all employees of the company (return visits, fees and charges) with a column chart, requirements:
The a:y axis indicates that all employees of the company and employees with a performance of 0 are not displayed, and the X axis indicates the number of performance (return visit number + charge);
B: To achieve ascending or descending order of column charts as required
According to the above requirements, the idea is:
First create a class (also can be implemented through the structure), the class contains attributes (or fields) for the employee ID attribute (or field), the staff return to the number of attributes (or fields), employee fees properties (or fields), employee performance attributes, and so on. (In order to use the sort in array to implement an interface, it will be explained in the original code)
And then through a table to show through the color or picture. The following is the implementation of the original code:
Public Class Wordload
Implements IComparable ' must implement this interface in order to take advantage of the following: Array. Sort
Public pay as Integer ' maintenance quantity
Public go_back as Integer ' return visit number
Public name as String ' username
Public Total_ as Integer ' maintenance number + return visit quantity
' The following is to be sorted by that attribute (or field)
Public Function CompareTo (ByVal obj as Object) as Integer Implements System.IComparable.CompareTo
Dim other as Wordload = CType (obj, wordload)
Return Total_.compareto (Other.total_)
End Function
Public Sub New (ByVal pay_value As Integer, ByVal go_back_value As Integer, ByVal name_value as String)
Pay = Pay_value
Name = Name_value
Go_back = Go_back_value
Total_ = pay + Go_back
End Sub
End Class
Public Sub creat_test (ByVal Myarr () as Wordload, ByVal mytable as System.Web.UI.WebControls.Table)
Array.Sort (Myarr) ' description use array for sorting
Dim rows_num as Integer = Myarr. Length + 1 ' Description: People as the y-axis, that is, the number of people as the number of rows, in order to write a table header, to add a row, so the table's total number of people, the number of personnel +1
Dim total_comm_num as Integer = Myarr (Myarr. Length-1). Total_ ' Description: The number of columns for the workload plus 1, because the name of the person to occupy a column
Dim pay_width as Integer ' defines maintenance width
Dim go_back_width as Integer ' defines return visit width
Dim MyImage as Htmlcontrols.htmlimage
Dim MySpan as Htmlcontrols.htmlgenericcontrol
Dim Begin_myrow as New Web.UI.WebControls.TableRow
Dim mycell1 as New UI. Webcontrols.tablecell
Dim Mycol1 as New Color
Mycell1. Text = "Employee"
Mycell1. BackColor = Mycol1. Green
Mycell1. Style.add ("Background-color", "#949294")
Mycell1. Style.add ("Font-weight", "bold")
Mycell1. Style.add ("Font-size", "18pt")
Mycell1. Style.add ("COLOR", "#ffffff")
Mycell1. Width = WebControls.Unit.Pixel (60)
Begin_myrow. Cells.add (MYCELL1)
Begin_myrow. Width = Unit.pixel (700)
For b as Integer = 0 to 7 ' writes the column of the first row
Dim MyCol as New Color
If B = 0 Then
Dim MyCell as New UI. Webcontrols.tablecell
' MyCell. BackColor = MyCol. LightGreen
Begin_myrow. Cells.add (MyCell)
Else
MySpan = New Htmlcontrols.htmlgenericcontrol
MySpan. InnerText = ((Total_comm_num * (b-1)/7) \ 1). Tostring
MySpan. Style.add ("WIDTH", "80px") ' width:100px;
MySpan. Style.add ("HEIGHT", "40px") ' height:100px;: bold; font-size:18pt; COLOR: #ffffff;
MySpan. Style.add ("Background-color", "#949294")
MySpan. Style.add ("Font-weight", "bold")
MySpan. Style.add ("Font-size", "18pt")
MySpan. Style.add ("COLOR", "#ffffff")
Begin_myrow. Cells (1). Controls.Add (MySpan)
End If
Next
MyTable. Rows.Add (Begin_myrow)
For i as Integer = 0 to Rows_num-2
Pay_width = (+ * Myarr (i). Pay/total_comm_num) \ 1 ' Assign value to maintenance width
Go_back_width = (+ * Myarr (i). Go_back/total_comm_num) \ 1 ' Assign value to return visit width
Dim Myrow as New Web.UI.WebControls.TableRow
Myrow. Width = Unit.pixel (700)
Dim J as Integer
' The following loops are added maintenance
For j = 0 to Pay_width
If j = 0 Then ' in the first column to be written into the user's name
Dim MyCell as New UI. Webcontrols.tablecell
MyCell. Text = Myarr (i). Name
MyCell. Width = WebControls.Unit.Pixel (60)
Dim MyCol as New Color
MyCell. BorderColor = MyCol. Deeppink
Myrow. Cells.add (MyCell)
Dim mycell2 as New UI. Webcontrols.tablecell
Myrow. Cells.add (MYCELL2)
Else ' Add picture information in the second column
MySpan = New Htmlcontrols.htmlgenericcontrol
MyImage = New Htmlcontrols.htmlimage
MyImage. SRC = "Images/navbar.gif" ' to show the middle picture
MySpan. Controls.Add (MyImage)
Myrow. Cells (1). Controls.Add (MySpan)
End If
Next
' The following loop is to add a return visit
For j = 0 to Go_back_width
MySpan = New Htmlcontrols.htmlgenericcontrol
MyImage = New Htmlcontrols.htmlimage
MyImage. SRC = "Images/navbar2.gif" ' to show the middle picture
MySpan. Controls.Add (MyImage)
Myrow. Cells (1). Controls.Add (MySpan)
Next
MyTable. Rows.Add (Myrow)
Next
MyTable. Width = Unit.pixel (700)
End Sub
PostScript: The above code in the Win2000+vs.net run through, because is just testing completed, code a bit messy (variable name is also arbitrary, a little can not represent meaning!)