//record button method to record current program into tbl_ToDoList. private void recordProgram(object sender, EventArgs e) { TVProgram tvp = (TVProgram)programView.SelectedItem; bool noSelectedValue = true; //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()) { noSelectedValue = false; } } } //If it has not any current title and then insert all into tbl_todolist. if (noSelectedValue) { using (MySqlCommand insertRecordCmd = new MySqlCommand("insert into tbl_ToDoList (title, episodetitle, description, channel, starttime, duration) values (?title,?episodetitle,?description,?channel,?starttime,?duration)", conn)) { insertRecordCmd.Parameters.AddWithValue("?title", tvp.Title); insertRecordCmd.Parameters.AddWithValue("?episodetitle", tvp.EpisodeTitle); insertRecordCmd.Parameters.AddWithValue("?description", tvp.Description); insertRecordCmd.Parameters.AddWithValue("?channel", tvp.Channel.ToString()); insertRecordCmd.Parameters.AddWithValue("?starttime", tvp.StartTime); insertRecordCmd.Parameters.AddWithValue("?duration", tvp.Duration); insertRecordCmd.ExecuteNonQuery(); } } }
//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(); } } } } } }