Exemple #1
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            timeTick++;
            if (timeTick >= 3600)
            {
                timeTick = 0;
                SaveData();
            }

            if (countOld == 0)
            {
                return;
            }
            countOld = 0;

            List <dataMy> list = new List <dataMy>();

            hybirdLock.Enter();

            foreach (var m in loginData)
            {
                list.Add(new dataMy(m.Key, m.Value));
            }

            hybirdLock.Leave();

            list.Sort();
            list.Reverse();

            long Count = RenderDataTable(dataGridView1, list);

            label2.Text = "总计:" + Count.ToString();

            // 统计省份功能
            List <dataMy> shengfen = new List <dataMy>();
            List <dataMy> others   = new List <dataMy>();

            for (int i = 0; i < list.Count; i++)
            {
                string tmp = string.Empty;
                if (list[i].Key.IndexOf('省') > 0)
                {
                    tmp = list[i].Key.Substring(0, list[i].Key.IndexOf('省') + 1);
                }
                else if (list[i].Key.Contains("北京市"))
                {
                    tmp = "北京市";
                }
                else if (list[i].Key.Contains("上海市"))
                {
                    tmp = "上海市";
                }
                else if (list[i].Key.Contains("天津市"))
                {
                    tmp = "天津市";
                }
                else if (list[i].Key.Contains("重庆市"))
                {
                    tmp = "重庆市";
                }
                else if (list[i].Key.IndexOf('区') > 0)
                {
                    tmp = list[i].Key.Substring(0, list[i].Key.IndexOf('区') + 1);
                }
                else
                {
                    tmp = list[i].Key;
                    others.Add(new dataMy(tmp, list[i].Value));
                    continue;
                }

                if (string.IsNullOrEmpty(tmp))
                {
                    continue;
                }
                dataMy dataMy = shengfen.Find(m => m.Key == tmp);
                if (dataMy == null)
                {
                    shengfen.Add(new dataMy(tmp, list[i].Value));
                }
                else
                {
                    dataMy.Value += list[i].Value;
                }
            }

            shengfen.Sort();
            shengfen.Reverse();
            RenderDataTable(dataGridView2, shengfen);

            others.Sort();
            others.Reverse();
            RenderDataTable(dataGridView3, others);
        }
        private void Timer_Tick(object sender, EventArgs e)
        {
            if (countOld == 0)
            {
                return;
            }
            countOld = 0;
            long Count = 0;

            List <dataMy> list = new List <dataMy>( );

            hybirdLock.Enter( );

            foreach (var m in loginData)
            {
                list.Add(new dataMy(m.Key, m.Value));
            }

            hybirdLock.Leave( );

            list.Sort( );
            list.Reverse( );

            while (dataGridView1.RowCount < list.Count)
            {
                dataGridView1.Rows.Add( );
            }

            while (dataGridView1.RowCount > list.Count)
            {
                dataGridView1.Rows.RemoveAt(0);
            }

            // 赋值
            for (int i = 0; i < list.Count; i++)
            {
                dataGridView1.Rows[i].Cells[0].Value = list[i].Key;
                dataGridView1.Rows[i].Cells[1].Value = list[i].Value.ToString( );
                Count += list[i].Value;
            }

            label2.Text = "总计:" + Count.ToString( );

            // 统计省份功能
            List <dataMy> shengfen = new List <dataMy>( );

            for (int i = 0; i < list.Count; i++)
            {
                string tmp = string.Empty;
                if (list[i].Key.IndexOf('省') > 0)
                {
                    tmp = list[i].Key.Substring(0, list[i].Key.IndexOf('省') + 1);
                }
                else if (list[i].Key.Contains("北京市"))
                {
                    tmp = "北京市";
                }
                else if (list[i].Key.Contains("上海市"))
                {
                    tmp = "上海市";
                }
                else if (list[i].Key.Contains("天津市"))
                {
                    tmp = "天津市";
                }
                else if (list[i].Key.Contains("重庆市"))
                {
                    tmp = "重庆市";
                }
                else if (list[i].Key.IndexOf('区') > 0)
                {
                    tmp = list[i].Key.Substring(0, list[i].Key.IndexOf('区') + 1);
                }

                if (string.IsNullOrEmpty(tmp))
                {
                    continue;
                }

                dataMy dataMy = shengfen.Find(m => m.Key == tmp);
                if (dataMy == null)
                {
                    shengfen.Add(new dataMy(tmp, list[i].Value));
                }
                else
                {
                    dataMy.Value += list[i].Value;
                }
            }

            shengfen.Sort( );
            shengfen.Reverse( );
            while (dataGridView2.RowCount < shengfen.Count)
            {
                dataGridView2.Rows.Add( );
            }

            while (dataGridView2.RowCount > shengfen.Count)
            {
                dataGridView2.Rows.RemoveAt(0);
            }

            // 赋值
            for (int i = 0; i < shengfen.Count; i++)
            {
                dataGridView2.Rows[i].Cells[0].Value = shengfen[i].Key;
                dataGridView2.Rows[i].Cells[1].Value = shengfen[i].Value.ToString( );
            }
        }