private void calculateNotDrawn()
        {
            Loto mainLoto  = AllLotoResults[dgvLottery.CurrentCell.RowIndex];
            int  draws     = trackBar1.Value;
            bool flagFound = false;

            for (int i = 1; i <= mainLoto.Numbers; i++)
            {
                for (int j = 0; j < draws; j++)
                {
                    Result r = mainLoto.Drawn[j];
                    foreach (int n in r.DrawnNumbers)
                    {
                        if (n == i)
                        {
                            flagFound = true;
                            break;
                        }
                    }
                    if (flagFound)
                    {
                        break;
                    }
                    else
                    {
                        Control c = drawn_notDrawn1.Controls[(i - 1) * 2 + 1];
                        if (c is Label)
                        {
                            c.Text = (Convert.ToInt32(c.Text) + 1).ToString();
                        }
                    }
                }
                flagFound = false;
            }
        }
        private void setCommonArrays()
        {
            dgvPairs.Columns.Clear();
            List <Pair> pairs = new List <Pair>();
            //foreach (Result r in AllLotoResults[comboBox1.SelectedIndex].Drawn
            Loto mainLoto = AllLotoResults[dgvLottery.CurrentCell.RowIndex];
            int  n        = trackBar1.Value;

            for (int k = 0; k < n; k++)
            {
                Result r = mainLoto.Drawn[k];
                for (int i = 0; i < r.DrawnNumbers.Count - 1; i++)
                {
                    for (int j = i + 1; j < r.DrawnNumbers.Count; j++)
                    {
                        if (i == 0)
                        {
                            Pair p = new Pair(r.DrawnNumbers[i], r.DrawnNumbers[j]);
                            pairs.Add(p);
                        }
                        else
                        {
                            Pair p    = new Pair(r.DrawnNumbers[i], r.DrawnNumbers[j]);
                            bool flag = false;
                            foreach (Pair pair in pairs)
                            {
                                if (p.Number1 == pair.Number1 && p.Number2 == pair.Number2)
                                {
                                    pair.Counter++;
                                    flag = true;
                                }
                            }
                            if (flag == false)
                            {
                                pairs.Add(p);
                            }
                        }
                    }
                }
            }
            pairs = (from p in pairs
                     orderby p.Counter descending
                     select p).ToList();
            foreach (Pair p in pairs)
            {
                dgvPairs.ColumnCount = 3;
                var row = new DataGridViewRow();
                row.Cells.Add(new DataGridViewImageCell {
                    Value = new Bitmap(Form1.GetImageByName(p.Number1))
                });
                row.Cells.Add(new DataGridViewImageCell {
                    Value = new Bitmap(Form1.GetImageByName(p.Number2))
                });
                row.Cells.Add(new DataGridViewTextBoxCell {
                    Value = (p.Counter / n * 100).ToString() + "%"
                });
                dgvPairs.Rows.Add(row);
            }
            dgvPairs.Visible = true;
        }
        private void calculateDraws()
        {
            foreach (Control c in drawn_notDrawn1.Controls)
            {
                if (c is Label)
                {
                    c.Text = "0";
                }
            }
            Loto mainLoto = AllLotoResults[dgvLottery.CurrentCell.RowIndex];
            int  draws    = trackBar1.Value;

            for (int i = 0; i < draws; i++)
            {
                Result r = mainLoto.Drawn[i];
                foreach (int n in r.DrawnNumbers)
                {
                    Control c = drawn_notDrawn1.Controls[(n - 1) * 2];
                    if (c is Label)
                    {
                        c.Text = (Convert.ToInt32(c.Text) + 1).ToString();
                    }
                }
            }
        }
        private void setMostFrequent()
        {
            float draws    = trackBar1.Value;
            Loto  mainLoto = AllLotoResults[dgvLottery.CurrentCell.RowIndex];
            int   draw     = mainLoto.Draw;

            int[] countArray = new int[91];
            for (int i = 0; i < 91; i++)
            {
                countArray[i] = 0;
            }
            for (int i = 0; i < draws; i++)
            {
                foreach (int n in mainLoto.Drawn[i].DrawnNumbers)
                {
                    countArray[n]++;
                }
            }
            int       max = 0, imax = 0;
            var       row  = new DataGridViewRow();
            ArrayList row2 = new ArrayList();

            dgvMostFrequent.Columns.Clear();
            dgvMostFrequent.ColumnCount = 12;
            try
            {
                for (int j = 0; j < 12; j++)
                {
                    for (int i = 0; i < 91; i++)
                    {
                        if (countArray[i] > max)
                        {
                            max  = countArray[i];
                            imax = i;
                        }
                    }
                    row.Cells.Add(new DataGridViewImageCell {
                        Value = new Bitmap(GetImageByName(imax))
                    });
                    row2.Add((max / draws * 100).ToString() + "%");
                    countArray[imax] = 0; max = 0; imax = 0;
                }
            }
            catch (Exception ex) { }
            dgvMostFrequent.Rows.Add(row);
            dgvMostFrequent.Rows.Add(row2.ToArray());
            //dgvMostFrequent.Width = dgvMostFrequent.Columns[0].Width * Convert.ToInt32(cbMostFrequent.SelectedItem)+10;
        }
        public int countNotDrawn(Loto l)
        {
            int  count = 0, i = 0;
            bool flag1 = true, flag2 = true;

            do
            {
                foreach (int n in l.Drawn[i].DrawnNumbers)
                {
                    if (n == number1)
                    {
                        flag1 = true;
                        break;
                    }
                    else
                    {
                        flag1 = false;
                    }
                }
                foreach (int n in l.Drawn[i].DrawnNumbers)
                {
                    if (n == number2)
                    {
                        flag2 = true;
                        break;
                    }
                    else
                    {
                        flag2 = false;
                    }
                }
                if (!flag1 || !flag2)
                {
                    count++;
                }
                if (flag1 && flag2)
                {
                    break;
                }
                i++; flag1 = true; flag2 = true;
            } while (flag1 && flag2);
            return(count);
        }
        private void setWindow()
        {
            int  i        = 0;
            Loto mainLoto = AllLotoResults[dgvLottery.CurrentCell.RowIndex];

            foreach (Control c in drawn_notDrawn1.Controls)
            {
                if (i >= mainLoto.Numbers * 2)
                {
                    if (c is Label)
                    {
                        c.Visible = false;
                    }
                }
                i++;
            }
            i = 0;
            foreach (Control c in drawn_notDrawn1.Controls)
            {
                if (c is PictureBox)
                {
                    if (i >= mainLoto.Numbers)
                    {
                        c.Visible = false;
                    }
                    i++;
                }
            }
            if (mainLoto.Numbers % 10 == 0)
            {
                drawn_notDrawn1.Size = new Size(550, mainLoto.Numbers / 10 * 50 + 20);
            }
            else
            {
                drawn_notDrawn1.Size = new Size(550, (1 + mainLoto.Numbers / 10) * 50 + 20);
            }
        }
        private void setLotoResults(WebBrowser wb)
        {
            List <string> AllLotoNames = new List <string>();
            List <int>    AllNumbers   = new List <int>();
            var           parentEls    = webBrowser1.Document.GetElementsByTagName("tr");

            foreach (HtmlElement parent in parentEls)
            {
                MessageBox.Show(parent.InnerHtml);
                var els = parent.GetElementsByTagName("td");
                foreach (HtmlElement el in els)
                {
                    if (el.GetAttribute("className") == "loto-rezultati-naziv")
                    {
                        AllLotoNames.Add(el.InnerText);
                        MessageBox.Show(el.InnerText);
                    }
                }
                var NumEls = parent.GetElementsByTagName("div");

                foreach (HtmlElement el in NumEls)
                {
                    if (el.GetAttribute("className") == "loto-rezultati-broj")
                    {
                        int number = Convert.ToInt32(el.InnerText);
                        AllNumbers.Add(number);
                        MessageBox.Show(el.InnerText);
                    }
                }
            }
            int drawNumbers = 0;

            int[]      lotteryLook = { 20, 90, 10, 20, 5, 41, 6, 44, 5, 90, 7, 45, 6, 45, 20, 70, 6, 45, 6, 49, 7, 49, 5, 41, 5, 32, 6, 42, 6, 44, 5, 50, 20, 70, 5, 36, 20, 70, 5, 49, 12, 24, 20, 80, 6, 49, 6, 52, 6, 47, 6, 90, 20, 62, 20, 62, 20, 62, 6, 40, 5, 36, 7, 42, 5, 90, 6, 49, 5, 39, 6, 47, 6, 49, 20, 80, 6, 59, 6, 49, 20, 70, 6, 49, 6, 48, 5, 30, 6, 49, 20, 80, 6, 49, 6, 49, 5, 35, 7, 39, 6, 49, 6, 42, 5, 35, 12, 24, 6, 54, 6, 59, 5, 75, 6, 49, 10, 20, 5, 31 };
            List <int> change      = new List <int>();

            for (int i = 0; i < AllLotoNames.Count; i++)
            {
                string loto = AllLotoNames[i];
                if (loto != null)
                {
                    Loto l = new Loto();
                    l.Name    = loto;
                    l.Draw    = lotteryLook[drawNumbers++];
                    l.Numbers = lotteryLook[drawNumbers++];
                    AllLotoResults.Add(l);
                    change.Add(i);
                }
                if (AllLotoNames.Count - 1 == i)
                {
                    change.Add(i);
                }
            }
            int        j = 0, cursor = 0, k = 0, next = 0;
            List <int> draw = new List <int>();

            foreach (Loto l in AllLotoResults)
            {
                int numbersInLoto = (change[j + 1] - change[j]) * l.Draw;
                for (int i = cursor; i <= numbersInLoto + k; i++)
                {
                    if (next / l.Draw == 1 && next != 0)
                    {
                        Result r = new Result();
                        foreach (int number in draw)
                        {
                            r.AddNum(number);
                        }
                        draw.Clear();
                        draw.Add(AllNumbers[i]);
                        l.AddResult(r);
                        next = 1;
                    }
                    else
                    {
                        draw.Add(AllNumbers[i]);
                        next++;
                    }
                    cursor = i;
                }
                k = k + numbersInLoto;
                j++; cursor++; next = 1;
            }
            dgvLottery.ColumnCount = 1;
            foreach (Loto l in AllLotoResults)
            {
                dgvLottery.Rows.Add(l.Name);
            }
            dgvLottery.ClearSelection();
            AllLotoNames.Clear();
        }
        private void set2MostFrequent(int columns)
        {
            int   index = dgvLottery.CurrentCell.RowIndex;
            Loto  l     = AllLotoResults[index];
            float draws = trackBar1.Value;
            int   draw  = l.Draw;

            int[] countArray = new int[l.Numbers];
            for (int i = 0; i < l.Numbers; i++)
            {
                countArray[i] = 0;
            }
            for (int i = 0; i < draws; i++)
            {
                foreach (int n in l.Drawn[i].DrawnNumbers)
                {
                    countArray[n - 1]++;
                }
            }
            int max = 0, imax = 0;

            for (int k = 0; k < 10; k++)
            {
                var row  = new DataGridViewRow();
                var row2 = new DataGridViewRow();
                for (int j = 0; j < columns; j++)
                {
                    for (int i = 10 * j; i < 10 * (j + 1); i++)
                    {
                        if (i >= l.Numbers)
                        {
                            break;
                        }
                        if (countArray[i] > max)
                        {
                            max  = countArray[i];
                            imax = i;
                        }
                    }
                    if (max != 0)
                    {
                        row.Cells.Add(new DataGridViewImageCell {
                            Value = new Bitmap(GetImageByName(imax + 1))
                        });
                    }
                    else
                    {
                        row.Cells.Add(new DataGridViewTextBoxCell {
                            Value = ""
                        });
                    }
                    if (max != 0)
                    {
                        row2.Cells.Add(new DataGridViewTextBoxCell {
                            Value = (max / draws * 100).ToString() + "%"
                        });
                    }
                    else
                    {
                        row2.Cells.Add(new DataGridViewTextBoxCell {
                            Value = ""
                        });
                    }
                    countArray[imax] = 0; max = 0; imax = 0;
                }
                dgvStats.Rows.Add(row);
                dgvStats.Rows.Add(row2);
            }
            dgvStats.Width         = dgvStats.Columns[0].Width * columns + 5;
            dataGridView1.Location = new Point(dgvStats.Width + 10, 34);
        }
 public Form3(Loto l)
 {
     InitializeComponent();
     mainLoto = l;
 }