Exemplo n.º 1
0
        private int AddStatistic(IList<HistoryInfo> list, IDictionary<string, StatisticItem> dic,
                                  Func<int, bool> func, string maxTypeName)
        {
            if (list == null || dic == null || func == null || string.IsNullOrEmpty(maxTypeName))
            {
                return 0;
            }

            int count = 0, maxCount = 0, mostCount = 0;
            for (int i = 0; i < list.Count; i++)
            {
                if (func(list[i].Result))
                {
                    count++;
                    if (count > 1)
                    {
                        if (i == list.Count - 1)
                        {
                            mostCount++;
                        }
                        if (count > maxCount)
                            maxCount = count;
                    }
                }
                else
                {
                    if (count > 1)
                    {
                        mostCount++;
                    }
                    count = 0;
                }
            }

            dic[maxTypeName] = new StatisticItem(maxTypeName, false) { Count = maxCount };
            return mostCount;
        }
Exemplo n.º 2
0
        private void btnStatistic_Click(object sender, EventArgs e)
        {
            IList<HistoryInfo> list = GetRows();
            if (list == null || list.Count == 0)
            {
                return;
            }

            int listCount = list.Count;
            lblRows.Text = string.Format("共:{0} 条记录", listCount);

            IDictionary<string, StatisticItem> dic = new Dictionary<string, StatisticItem>()
            {
                { "单", new StatisticItem("单") } ,
                { "双", new StatisticItem("双") },
                { "分隔线1", new StatisticItem(string.Empty) },

                { "中", new StatisticItem("中") },
                { "边", new StatisticItem("边") },
                { "分隔线2", new StatisticItem(string.Empty) },

                { "大", new StatisticItem("大")},
                { "小", new StatisticItem("小")},
                { "分隔线3", new StatisticItem(string.Empty) },

                { "梅", new StatisticItem("梅")},
                { "分隔线4", new StatisticItem(string.Empty) },
            };

            for (int i = 0; i < listCount; i++)
            {
                HistoryInfo item = list[i];
                if (item.Result % 2 == 1)
                {
                    dic["单"].Count++;
                }
                else
                {
                    dic["双"].Count++;
                }

                if (item.Result >= 10 && item.Result <= 17)
                {
                    dic["中"].Count++;
                }
                else
                {
                    dic["边"].Count++;
                }

                if (item.Result >= 14)
                {
                    dic["大"].Count++;
                }
                else
                {
                    dic["小"].Count++;
                }
                if (item.Result >= 13 && item.Result <= 15)
                {
                    dic["梅"].Count++;
                }
            }

            foreach (var item in dic.Values)
            {
                item.Percent = Math.Round(item.Count * 1.0 / listCount, 2);
            }

            int mostOdd = this.AddStatistic(list, dic, (num) => { return num % 2 == 1; }, "最长连 单");
            int mostEven = this.AddStatistic(list, dic, (num) => { return num % 2 == 0; }, "最长连 双");
            int mostMid = this.AddStatistic(list, dic, (num) => { return num >= 10 && num <= 17; }, "最长连 中");
            int mostEdeg = this.AddStatistic(list, dic, (num) => { return num < 10 || num > 17; }, "最长连 边");
            int mostBig = this.AddStatistic(list, dic, (num) => { return num >= 14; }, "最长连 大");
            int mostSmal = this.AddStatistic(list, dic, (num) => { return num < 14; }, "最长连 小");

            dic["长_多分隔"] = new StatisticItem(string.Empty, false);
            dic["连的总次数 单"] = new StatisticItem("连的总次数 单", false) { Count = mostOdd };
            dic["连的总次数 双"] = new StatisticItem("连的总次数 双", false) { Count = mostEven };
            dic["连的总次数 中"] = new StatisticItem("连的总次数 中", false) { Count = mostMid };
            dic["连的总次数 边"] = new StatisticItem("连的总次数 边", false) { Count = mostEdeg };
            dic["连的总次数 大"] = new StatisticItem("连的总次数 大", false) { Count = mostBig };
            dic["连的总次数 小"] = new StatisticItem("连的总次数 小", false) { Count = mostSmal };

            IList<StatisticItem> result = dic.Values.ToList();
            dataGridStatistic.DataSource = new BindingList<StatisticItem>(result);

            dataGridHistory.Visible = false;
            dataGridStatistic.Visible = true;
            dataGridStatistic.Dock = DockStyle.Fill;
            panelHistory.Controls.Remove(dataGridHistory);
            panelHistory.Controls.Add(dataGridStatistic);
        }