void btnRemoveProgram_Click(object sender, EventArgs e)
        {
            if (dgvPrograms.SelectedRows.Count <= 0)
            {
                return;
            }

            var index = -1;

            foreach (DataGridViewRow selectedRow in dgvPrograms.SelectedRows)
            {
                // take the smallest selected row index
                if (index < 0 || index > selectedRow.Index)
                {
                    index = selectedRow.Index;
                }
                ProgramList.RemoveAt(selectedRow.Index);
            }

            if (ProgramList.Count > 0)
            {
                index = index < ProgramList.Count ? index : ProgramList.Count - 1;
                ProgramList.ResetBindings(); // cell selection doesn't work half the time without this
                dgvPrograms.CurrentCell = dgvPrograms[0, index];
            }
        }
Example #2
0
        //OK
        private void SetProgramList(string content)
        {
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(content);

            HtmlNodeCollection progDates = doc.DocumentNode.SelectNodes("//td[@class='mlistaido']");
            HtmlNodeCollection progNamesTitles = doc.DocumentNode.SelectNodes("//td[@class='mlistacim']");

            const String br = "|||";
            bool gotCurrent = false;
            programs = new ProgramList<Data.Program>();

            for (int i = 0; i < progDates.Count && i < progNamesTitles.Count; i++)
            {
                String time = progDates[i].InnerText;
                String txt = progNamesTitles[i].InnerHtml;

                txt = txt.Replace("<br>", br);
                txt = Regex.Replace(txt, "<.*?>", string.Empty);

                int hours = int.Parse(time.Substring(0, time.IndexOf(":")));
                int mins = int.Parse(time.Substring(time.IndexOf(":") + 1));

                DateTime dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, hours, mins, DateTime.Now.Second);

                Data.Program program = new Data.Program(
                    txt.Substring(0, txt.IndexOf(br)),
                    txt.Substring(txt.IndexOf(br) + br.Length),
                    dt, false
                );

                programs.Add(program);

                if (!gotCurrent && DateTime.Now.CompareTo(program.DateTime) < 0)
                {
                    if (programs.Count == 1)
                    {
                        programs[0].Current = true;
                    }
                    else
                    {
                        programs[programs.Count - 2].Current = true;
                    }

                    gotCurrent = true;
                }
            }

            for (int i = programs.Count - 1; i >= 0; i--)
            {
                if (DateTime.Now.CompareTo(programs[i].DateTime) > 0 && !programs[i].Current)
                {
                    programs.RemoveAt(i);
                }
            }

            if (programs.Count > 0)
            {
                lblTitle.Text = programs[0].Title;
                lblProgram.Text = programs[0].Description;
            }

            foreach (Data.Program program in programs)
            {
                int row = ProgramsForm.Instance.ProgramList.Rows.Add(
                    UppercaseFirst(program.DateTime.ToString("MMM dd. HH:mm")),
                    program.Title +
                    (!program.Description.Equals(string.Empty) ? " - " + program.Description : string.Empty)
                );

                if (program.Current)
                {
                    ProgramsForm.Instance.ProgramList.Rows[row].DefaultCellStyle.BackColor = Color.FromArgb(8, 16, 8);
                    ProgramsForm.Instance.ProgramList.Rows[row].DefaultCellStyle.ForeColor = Color.FromArgb(55, 194, 55);

                    ProgramsForm.Instance.ProgramList.Rows[row].DefaultCellStyle.SelectionBackColor = Color.FromArgb(16, 32, 16);
                    ProgramsForm.Instance.ProgramList.Rows[row].DefaultCellStyle.SelectionForeColor = Color.FromArgb(55, 194, 55);
                }
            }
        }