Example #1
0
 public TVProgram(string title, string episodeTitle, string description, BroadcastStation Channel, DateTime StartTime, int duration)
 {
     this.Title        = title;
     this.EpisodeTitle = episodeTitle;
     this.Description  = description;
     this.Channel      = Channel;
     this.StartTime    = StartTime;
     this.Duration     = duration;
 }
Example #2
0
        //To display all programs based on selecting datetime and channel.
        private void displayPrograms(object sender, EventArgs e)
        {
            DateTime         chosenDate      = dateTimePicker.Value;
            BroadcastStation selectedChannel = (BroadcastStation)channelList.SelectedItem;

            IEnumerable <TVProgram> tvps = from t in table.AsEnumerable()
                                           where chosenDate.Month == t.Field <DateTime>("starttime").Month
                                           where chosenDate.Day == t.Field <DateTime>("starttime").Day
                                           where chosenDate.Year == t.Field <DateTime>("starttime").Year
                                           where selectedChannel == (BroadcastStation)Enum.Parse(typeof(BroadcastStation), t.Field <string>("channel"))
                                           select new TVProgram
            {
                Title        = t.Field <string>("title"),
                EpisodeTitle = t.Field <string>("episodetitle"),
                Description  = t.Field <string>("description"),
                Duration     = t.Field <int>("duration"),
                Channel      = (BroadcastStation)Enum.Parse(typeof(BroadcastStation), t.Field <string>("channel")),
                StartTime    = t.Field <DateTime>("starttime")
            };

            programView.DataSource    = tvps.ToList <TVProgram>();
            programView.DisplayMember = "GuideTitle";
        }
Example #3
0
 public SeasonProgram(string title, BroadcastStation Channel, DateTime StartTime, int duration)
 {
     this.Title = title;
 }
Example #4
0
        //the season pass button method to record into tbl_seasonpass and tbl_todolist from tbl_tvguide.
        private void createSeasonPass(object sender, EventArgs e)
        {
            TVProgram tvp = (TVProgram)programView.SelectedItem;

            bool          noSelectedSeason = true;  //to check if current title have already stored in the tbl_seasonpass.
            bool          noSelectedList   = true;  //to check if current title have already stored in the tbl_todolist.
            SeasonProgram sp = new SeasonProgram(); //intial the seasonProgram to using Priority.

            //To search the current title from tbl_SeasonPass and if there are any value and return noSelectedSeason a false.
            using (MySqlCommand checkRecordCmd = new MySqlCommand("select title from tbl_SeasonPass where title = ?title", conn))
            {
                checkRecordCmd.Parameters.AddWithValue("?title", tvp.Title);

                using (MySqlDataReader rdr = checkRecordCmd.ExecuteReader())
                {
                    if (rdr.Read())
                    {
                        noSelectedSeason = false;
                    }
                }
            }

            //To search the current title from tbl_ToDoList and if there are any value and return noSelectedList a false.
            using (MySqlCommand checkRecordCmd = new MySqlCommand("select * from tbl_ToDoList where title = ?title", conn))
            {
                checkRecordCmd.Parameters.AddWithValue("?title", tvp.Title);

                using (MySqlDataReader rdr = checkRecordCmd.ExecuteReader())
                {
                    if (rdr.Read())
                    {
                        noSelectedList = false;
                    }
                }
            }

            //To get the max priority value from tbl_SeasonPass. If return a null then set Priority to 0 and if not, then increase the Priority.
            using (MySqlCommand maxPriorityCmd = new MySqlCommand("select max(priority) from tbl_SeasonPass", conn))
            {
                using (MySqlDataReader rdr = maxPriorityCmd.ExecuteReader())
                {
                    if (rdr.Read() && rdr.IsDBNull(0))
                    {
                        sp.Priority = 0;
                    }
                    else
                    {
                        sp.Priority = rdr.GetInt16(rdr.GetOrdinal("max(priority)")) + 1;
                    }
                }
            }

            //Check if current title did not exist in tbl_seasonPass and if so, then insert the new priority and title into tbl_seasonPass.
            if (noSelectedSeason)
            {
                using (MySqlCommand insertPriorityCmd = new MySqlCommand("insert into tbl_SeasonPass (title,priority) values (?title,?priority)", conn))
                {
                    insertPriorityCmd.Parameters.AddWithValue("?title", tvp.Title);
                    insertPriorityCmd.Parameters.AddWithValue("?priority", sp.Priority);

                    insertPriorityCmd.ExecuteNonQuery();
                }
            }

            //Check if current title did not exist in tbl_ToDoList and if so, then insert all match value from tbl_tvguide to tbl_ToDoList.
            if (noSelectedList)
            {
                using (MySqlCommand findCmd = new MySqlCommand("select * from tbl_tvguide where title = ?title", conn))
                {
                    findCmd.Parameters.AddWithValue("?title", tvp.Title);

                    TVProgramIndexer list = new TVProgramIndexer(20);

                    using (MySqlDataReader rdr = findCmd.ExecuteReader())
                    {
                        int count = 0;

                        //To store all value from tbl_tvguide using ToRecordProgram class as a list.
                        while (rdr.Read())
                        {
                            BroadcastStation bcs = (BroadcastStation)Enum.Parse(typeof(BroadcastStation), (string)rdr[2]);
                            list[count] = new ToRecordProgram((string)rdr["title"], (string)rdr["episodetitle"], (string)rdr["description"], bcs, rdr.GetDateTime(rdr.GetOrdinal("starttime")), rdr.GetInt16(rdr.GetOrdinal("duration")));
                            count++;
                        }

                        rdr.Close();

                        //To insert all value from list.
                        for (int i = 0; i < count; i++)
                        {
                            using (MySqlCommand insertCmd = new MySqlCommand("insert into tbl_ToDoList (title, episodetitle, description, channel, starttime, duration) values (?title,?episodetitle,?description,?channel,?starttime,?duration)", conn))
                            {
                                insertCmd.Parameters.AddWithValue("?title", list[i].Title);
                                insertCmd.Parameters.AddWithValue("?episodetitle", list[i].EpisodeTitle);
                                insertCmd.Parameters.AddWithValue("?description", list[i].Description);
                                insertCmd.Parameters.AddWithValue("?channel", list[i].Channel.ToString());
                                insertCmd.Parameters.AddWithValue("?starttime", list[i].StartTime);
                                insertCmd.Parameters.AddWithValue("?duration", list[i].Duration);

                                insertCmd.ExecuteNonQuery();
                            }
                        }
                    }
                }
            }
        }