首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

统计数据库的用户数量的有关问题

2013-12-10 
统计数据库的用户数量的问题!想统计一下在00:00-01:00内收看比如湖南卫视的用户数。写了如下程序不过统计有

统计数据库的用户数量的问题!
想统计一下在00:00-01:00内收看比如湖南卫视的用户数。写了如下程序不过统计有误,不知道错在哪里!求老大指点!


public int[] PerChannelCount(string str,string Time)
        {
            int[] PerUserCount = new int[27];     
            int[] Channel_1 = new int[27];
            DB db = new DB();
            DataTable dt = db.reDt(str);
            int TimeStart = 0;
            int TimeEnd = 0;
            //时间选择,每小时
            #region
            switch (Time)
            {
                case "00:00-01:00": TimeStart = 1; TimeEnd = 12; break; //00:00-00:55
                case "01:00-02:00": TimeStart = 13; TimeEnd = 24; break;
                case "02:00-03:00": TimeStart = 25; TimeEnd = 36; break;
                case "03:00-04:00": TimeStart = 37; TimeEnd = 48; break;
                case "04:00-05:00": TimeStart = 49; TimeEnd = 60; break;
                case "05:00-06:00": TimeStart = 61; TimeEnd = 72; break;
                case "06:00-07:00": TimeStart = 73; TimeEnd = 84; break;//06:00-06:55
                case "07:00-08:00": TimeStart = 85; TimeEnd = 104; break;//07:00-07:57
                case "08:00-09:00": TimeStart = 105; TimeEnd = 124; break;
                case "09:00-10:00": TimeStart = 125; TimeEnd = 144; break;
                case "10:00-11:00": TimeStart = 145; TimeEnd = 164; break;
                case "11:00-12:00": TimeStart = 165; TimeEnd = 184; break;
                case "12:00-13:00": TimeStart = 185; TimeEnd = 204; break;
                case "13:00-14:00": TimeStart = 205; TimeEnd = 224; break;
                case "14:00-15:00": TimeStart = 225; TimeEnd = 244; break;
                case "15:00-16:00": TimeStart = 245; TimeEnd = 264; break;
                case "16:00-17:00": TimeStart = 265; TimeEnd = 284; break;
                case "17:00-18:00": TimeStart = 285; TimeEnd = 304; break;
                case "18:00-19:00": TimeStart = 305; TimeEnd = 324; break;//18:00-18:57
                case "19:00-20:00": TimeStart = 325; TimeEnd = 384; break;//19:00-19:59
                case "20:00-21:00": TimeStart = 385; TimeEnd = 444; break;
                case "21:00-22:00": TimeStart = 445; TimeEnd = 504; break;
                case "22:00-23:00": TimeStart = 505; TimeEnd = 564; break;//22:00-22:59
                case "23:00-00:00": TimeStart = 565; TimeEnd = 576; break;//23:00-23:55


            }
            #endregion
            for (int i = 0; i <= dt.Rows.Count - 1; i++)
            {
                for(int j=TimeStart;j<=TimeEnd;j++)
                {
                    switch (dt.Rows[i][j].ToString())
                    {
                        #region
                        case "CCTV-1": Channel_1[0]++; break;
                        case "CCTV-2": Channel_1[1]++; break;
                        case "CCTV-3": Channel_1[2]++; break;
                        case "CCTV-4": Channel_1[3]++; break;
                        case "CCTV-5": Channel_1[4]++; break;
                        case "CCTV-6": Channel_1[5]++; break;
                        case "CCTV-7": Channel_1[6]++; break;
                        case "CCTV-8": Channel_1[7]++; break;
                        case "CCTV-9": Channel_1[8]++; break;
                        case "浙江卫视": Channel_1[9]++; break;
                        case "东方卫视": Channel_1[10]++; break;
                        case "安徽卫视": Channel_1[11]++; break;
                        case "北京卫视": Channel_1[12]++; break;
                        case "辽宁卫视": Channel_1[13]++; break;
                        case "山东卫视": Channel_1[14]++; break;
                        case "天津卫视": Channel_1[15]++; break;
                        case "宁夏卫视": Channel_1[16]++; break;
                        case "河南卫视": Channel_1[17]++; break;
                        case "湖北卫视": Channel_1[18]++; break;
                        case "四川卫视": Channel_1[19]++; break;
                        case "江西卫视": Channel_1[20]++; break;
                        case "贵州卫视": Channel_1[21]++; break;
                        case "广东卫视": Channel_1[22]++; break;
                        case "吉林卫视": Channel_1[23]++; break;
                        case "河北卫视": Channel_1[24]++; break;


                        case "重庆卫视": Channel_1[25]++; break;
                        case "广西卫视": Channel_1[26]++; break;
                        default: break;
                        #endregion
                    }                
                } 
///////不知道这儿写的对不对!!!!
                for (int k = 0; k < 27; k++)
                {    
                    if (Channel_1[k] > 0)
                    {
PerUserCount [k]++;
                    }
                    else
                    {
}
                }
            }
return PerUserCount;
}


谢谢!
[解决办法]
用这种语法计算要判断太多了,而且容易出错,直接放到数据库里计算最容易.

热点排行