首页 - VB.NET

vb.net实现一个自定义类数组的排序

发布时间: 2007-04-19 03:57    作者: 未知    来源: 未知    浏览:    评论

 

今天下午做东西时遇到这样的问题:

    把公司所有员工的业绩(回访数量,收费情况)用一个柱型图表示出来,要求:

A:Y轴表示公司的所有员工且业绩为0的员工不显示出来,X轴表示业绩数量(回访数量+收费情况);

B:按要求对柱图实现升序或着降序

    按以上要求所得思路为:

首先建立一个类(也可以通过结构来实现),类中包含的属性(或字段)为员工ID属性(或字段),员工回访数量属性(或字段),员工收费情况属性(或字段),员工业绩属性等等。(为了能利用Array中的sort需要实现一个接口,会在原码中说明)

接着通过一个table来通过颜色或着图片表现出来。下面是实现的原码:

Public Class wordload
    Implements IComparable'一定要实现这个接口,才能利用下面的:Array.Sort
    Public pay As Integer '维护数量
    Public go_back As Integer '回访数量
    Public name As String '用户名称
    Public total_ As Integer '维护数量+回访数量

'以下是想通过那个属性(或字段),来进行排序
    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)'说明利用Array进行排序
        Dim rows_num As Integer = myarr.Length + 1 '说明:人员做为y轴,即人员的个数做为行数,其中为了写表头,要加一行,所以表的总行数为,人员个数+1
        Dim total_comm_num As Integer = myarr(myarr.Length - 1).total_ '说明:列数为工作量加1,因为人员的名字要占一列
        Dim pay_width As Integer '定义维护宽度
        Dim go_back_width As Integer '定义回访宽度
        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 = "员工"
        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 '写第一行的列
            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 = (500 * myarr(i).pay / total_comm_num) \ 1 '给维护宽度进行赋值
            go_back_width = (500 * myarr(i).go_back / total_comm_num) \ 1 '给回访宽度进行赋值
            Dim myrow As New Web.UI.WebControls.TableRow
            myrow.Width = Unit.Pixel(700)
            Dim j As Integer
            '以下循环是添加维护情况
            For j = 0 To pay_width
                If j = 0 Then '在第一列要写进用户的名称
                    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 '在第二列添加图片信息
                    myspan = New HtmlControls.HtmlGenericControl
                    myimage = New HtmlControls.HtmlImage
                    myimage.Src = "Images/navbar.gif" '要显示的中间图片
                    myspan.Controls.Add(myimage)
                    myrow.Cells(1).Controls.Add(myspan)
                End If
            Next
            '以下循环是添加回访情况
            For j = 0 To go_back_width
                myspan = New HtmlControls.HtmlGenericControl
                myimage = New HtmlControls.HtmlImage
                myimage.Src = "Images/navbar2.gif" '要显示的中间图片
                myspan.Controls.Add(myimage)
                myrow.Cells(1).Controls.Add(myspan)
            Next
            mytable.Rows.Add(myrow)
        Next
        mytable.Width = Unit.Pixel(700)
    End Sub

后记:以上代码在win2000+vs.net 中运行通过,由于是刚刚测试完成,代码有点乱(变量名称也是随意的,有点不能代表意思!)


TAG

Smile Big Smile Surprise Stick out tongue Wink Sad Tongue Tied Indifferent Crying Embarrassed Cool Angry Angel Devil [8-|] [:#] [:-*] [:^)] [<:o)] [|-)] Yes Beer Left Hug Music Star Time Snail Pizza Automobile Umbrella Computer Storm [mo] [8o|] [^o)] [+o(] [*-)] [8-)] Coffee No Drinks [Z] Right Hug Cake Broken Heart Gift Wilted Flower Movie Dog Idea Sleep Email Travel Paradise
呢称:

加粗 斜体 下划线 链接 图片 代码 邮件地址 引用 列表

最多只能输入100个字符

Tags

SQL 数据库 asp.net C# XML 控件 .NET教程 程序 事件 数据 安全 代码 Server 客户端 验证 数据库专栏 接口 文件 Oracle DataSet 函数 DataGrid 问题 .net return C#语言 JavaScript 服务 IIS 对象 语句 windows 继承 时间 web.config 设计 开发 参数 变量 解决 字符 ADO.net 环境 VB.Net语言 web 异常 工具 服务器 计算 实例 OLEDB Application VB Word WebService insert asp net 安装 记录

精华推荐

更多

精品下载

更多