public Recording GetRecordingByFileName(string fileName) { SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Recording)); sb.AddConstraint(Operator.Equals, "fileName", fileName); sb.SetRowLimit(1); SqlStatement stmt = sb.GetStatement(true); IList<Recording> recordings = ObjectFactory.GetCollection<Recording>(stmt.Execute()); if (recordings.Count == 0) { return null; } return recordings[0]; }
private void UpdateNowAndNext() { if (_currentProgram != null) { if (DateTime.Now >= _currentProgram.StartTime && DateTime.Now <= _currentProgram.EndTime) { return; } } _currentProgram = null; _nextProgram = null; DateTime date = DateTime.Now; SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Program)); sb.AddConstraint(Operator.Equals, "idChannel", IdChannel); sb.AddConstraint(Operator.GreaterThanOrEquals, "endTime", date); sb.AddOrderByField(true, "startTime"); sb.SetRowLimit(2); SqlStatement stmt = sb.GetStatement(true); IList<Program> programs = ObjectFactory.GetCollection<Program>(stmt.Execute()); if (programs.Count == 0) { return; } _currentProgram = programs[0]; if (_currentProgram.StartTime >= date) { _nextProgram = _currentProgram; _currentProgram = null; } else { if (programs.Count == 2) { _nextProgram = programs[1]; } } }
public DateTime GetNewestProgramForChannel(int idChannel) { SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Program)); sb.AddConstraint(Operator.Equals, "idChannel", idChannel); sb.AddOrderByField(false, "startTime"); sb.SetRowLimit(1); SqlStatement stmt = sb.GetStatement(true); IList<Program> progs = ObjectFactory.GetCollection<Program>(stmt.Execute()); return progs.Count > 0 ? progs[0].StartTime : DateTime.MinValue; }
public Program GetProgramAt(DateTime date, string title) { //IFormatProvider mmddFormat = new CultureInfo(String.Empty, false); //DateTime startTime = DateTime.Now; SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Program)); sb.AddConstraint(Operator.Equals, "Title", title); sb.AddConstraint(Operator.Equals, "idChannel", IdChannel); sb.AddConstraint(Operator.GreaterThan, "endTime", date); sb.AddConstraint(Operator.LessThanOrEquals, "startTime", date); sb.AddOrderByField(true, "startTime"); sb.SetRowLimit(1); SqlStatement stmt = sb.GetStatement(true); IList<Program> programs = ObjectFactory.GetCollection<Program>(stmt.Execute()); if (programs.Count == 0) { return null; } return programs[0]; }
private int GetChannelIdByDisplayName(string aChannelName) { int channelId = -1; if (string.IsNullOrEmpty(aChannelName)) return channelId; try { SqlBuilder sb = new SqlBuilder(Gentle.Framework.StatementType.Select, typeof(Channel)); sb.AddConstraint(Operator.Equals, "displayName", aChannelName); sb.SetRowLimit(1); SqlStatement stmt = sb.GetStatement(true); IList channels = ObjectFactory.GetCollection(typeof(Channel), stmt.Execute()); if (channels.Count == 1) channelId = ((Channel)channels[0]).IdChannel; } catch (Exception ex) { MessageBox.Show(string.Format("Could not get ChannelID for DisplayName: {0}\n{1}", aChannelName, ex.Message)); } return channelId; }
public Event[] RetrieveLast(int numberOfEvents) { SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof(Event)); sb.SetRowLimit(numberOfEvents); sb.AddOrderByField(false, "date"); sb.AddConstraint(Operator.LessThanOrEquals, "date", DateTime.Now); SqlStatement stmt = sb.GetStatement(true); IList events = ObjectFactory.GetCollection(typeof(Event), stmt.Execute()); List<Event> events_result = new List<Event>(); foreach (Event e in events) events_result.Add(e); return events_result.ToArray(); }
public IList<Attendance> RetrieveLastEventsAttended(Person aPerson, int numberOfEvents) { SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof(Attendance)); sb.SetRowLimit(numberOfEvents); sb.AddOrderByField(false, "date"); SqlStatement stmt = sb.GetStatement(true); Attendance[] attendances = (Attendance[])ObjectFactory.GetCollection(typeof(Attendance), stmt.Execute()); return attendances; }
/// <summary> /// Gets the DateTime of the last program entry or now if MinValue if there are no program entries in the database. /// </summary> /// <returns></returns> protected static DateTime GetLastProgramEntry() { //long lastEntry; //// FIXME: Why is the GetLastProgramEntry call returning a string? Should probably natively return a long. //Int64.TryParse(TVDatabase.GetLastProgramEntry(), out lastEntry); //DateTime lastDate = (lastEntry == 0) ? DateTime.MinValue : MediaPortal.Util.Utils.longtodate(Convert.ToInt64(lastEntry)); //return lastDate; SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof(Program)); IFormatProvider mmddFormat = new System.Globalization.CultureInfo(String.Empty, false); sb.SetRowLimit(1); sb.AddOrderByField(false, "EndTime"); SqlStatement stmt = sb.GetStatement(true); System.Collections.IList progs = ObjectFactory.GetCollection(typeof(Program), stmt.Execute()); if (progs.Count >= 1) { Program lProgram = (Program)progs[0]; return lProgram.EndTime; } return DateTime.MinValue; }