/// <summary>
        /// Hilfsmethode, die aus einem durch eine Query zurückgelieferten Statement ein Objekt des Typs Kanal extrahiert.
        /// Je nach Typ des Kanals werden zusätzliche Informationen aus Subklassen-Tabellen abgefragt und ein Objekt
        /// der Subklasse extrahiert.
        /// </summary>
        /// <param name="conn">Eine aktive Connection zur Datenbank, um Informationen aus Subklassen-Tabellen abfragen zu können.</param>
        /// <param name="stmt">Das Statement, aus dem die Informationen extrahiert werden sollen.</param>
        /// <returns>Ein Objekt vom Typ Channel.</returns>
        private Channel retrieveChannelObjectFromStatement(SQLiteConnection conn, ISQLiteStatement stmt)
        {
            // Channel Objekt.
            Channel channel = null;

            try
            {
                // Initialisierung der Variablen.
                int id;
                string name, description, term, location, dates, contact, website, startDate, endDate, lecturer,
                    assistant, cost, organizer, participants;
                bool deleted;
                ChannelType type;
                Faculty faculty;
                NotificationSetting announcementNotificationSetting;
                DateTimeOffset creationDate, modificationDate;

                // Frage Kanal-Werte ab.
                id = Convert.ToInt32(stmt["Id"]);
                name = (string)stmt["Name"];
                description = (string)stmt["Description"];
                type = (ChannelType)Enum.ToObject(typeof(ChannelType), stmt["Type"]);
                creationDate = DatabaseManager.DateTimeFromSQLite(stmt["CreationDate"].ToString());
                modificationDate = DatabaseManager.DateTimeFromSQLite(stmt["ModificationDate"].ToString());
                term = (string)stmt["Term"];
                location = (string)stmt["Location"];
                dates = (string)stmt["Dates"];
                contact = (string)stmt["Contact"];
                website = (string)stmt["Website"];
                deleted = ((long)stmt["Deleted"] == 1) ? true : false;
                announcementNotificationSetting = (NotificationSetting)Enum.ToObject(typeof(NotificationSetting), stmt["NotificationSettings_NotifierId"]);

                // Falls notwendig, hole Daten aus Tabelle der Subklasse.
                switch (type)
                {
                    case ChannelType.LECTURE:
                        using (var getLectureStmt = conn.Prepare("SELECT * FROM Lecture WHERE Channel_Id=?;"))
                        {
                            getLectureStmt.Bind(1, id);

                            // Hole Ergebnis der Query.
                            if (getLectureStmt.Step() == SQLiteResult.ROW)
                            {
                                faculty = (Faculty)Enum.ToObject(typeof(Faculty), getLectureStmt["Faculty"]);
                                startDate = (string)getLectureStmt["StartDate"];
                                endDate = (string)getLectureStmt["EndDate"];
                                lecturer = (string)getLectureStmt["Lecturer"];
                                assistant = (string)getLectureStmt["Assistant"];

                                // Erstelle Lecture Objekt und füge es der Liste hinzu.
                                Lecture lecture = new Lecture(id, name, description, type, creationDate, modificationDate, term, location,
                                    dates, contact, website, deleted, faculty, startDate, endDate, lecturer, assistant);
                                channel = lecture;
                            }
                        }
                        break;
                    case ChannelType.EVENT:
                        using (var getEventStmt = conn.Prepare("SELECT * FROM Event WHERE Channel_Id=?;"))
                        {
                            getEventStmt.Bind(1, id);

                            // Hole Ergebnis der Query.
                            if (getEventStmt.Step() == SQLiteResult.ROW)
                            {
                                cost = (string)getEventStmt["Cost"];
                                organizer = (string)getEventStmt["Organizer"];

                                // Erstelle Event Objekt und füge es der Liste hinzu.
                                Event eventObj = new Event(id, name, description, type, creationDate, modificationDate, term, location,
                                    dates, contact, website, deleted, cost, organizer);
                                channel = eventObj;
                            }
                        }
                        break;
                    case ChannelType.SPORTS:
                        using (var getSportsStmt = conn.Prepare("SELECT * FROM Sports WHERE Channel_Id=?;"))
                        {
                            getSportsStmt.Bind(1, id);

                            // Hole Ergebnis der Query.
                            if (getSportsStmt.Step() == SQLiteResult.ROW)
                            {
                                cost = (string)getSportsStmt["Cost"];
                                participants = (string)getSportsStmt["NumberOfParticipants"];

                                // Erstelle Sports Objekt und füge es der Liste hinzu.
                                Sports sportsObj = new Sports(id, name, description, type, creationDate, modificationDate, term, location,
                                    dates, contact, website, deleted, cost, participants);
                                channel = sportsObj;
                            }
                        }
                        break;
                    default:
                        // Keine Subklasse, also erzeuge Kanal Objekt.
                        channel = new Channel(id, name, description, type, creationDate, modificationDate, term, location,
                            dates, contact, website, deleted);
                        break;
                }

                // Füge announcementNotificationSetting Einstellung noch dem Objekt hinzu.
                channel.AnnouncementNotificationSetting = announcementNotificationSetting;
            }
            catch(SQLiteException sqlEx){
                Debug.WriteLine("SQLiteException has occurred in retrieveChannelObjectFromStatement. The message is: {0}.", sqlEx.Message);
                throw new DatabaseException("Retrieve channel has failed.");
            }
            catch(Exception ex)
            {
                Debug.WriteLine("Exception has occurred in retrieveChannelObjectFromStatement. The message is: {0}, " +
                    "and the stack trace: {1}.", ex.Message, ex.StackTrace);
                throw new DatabaseException("Retrieve channel has failed.");
            }
            
            return channel;
        }
        /// <summary>
        /// Hilfsmethode, welche aus den eingegebenen Daten ein Objekt
        /// vom Typ Channel erstellt. Eventuelle Subklassen-Attribute
        /// werden ebenfalls gesetzt.
        /// </summary>
        /// <returns>Ein Objekt der Klasse Channel, welches die vom Nutzer eingegebenen Daten enthält.</returns>
        private Channel createChannelObjectFromEnteredData()
        {
            // Setze den String für das Semester zusammen.
            string termString = string.Empty;
            if (TermYear != null)
            {
                if (IsSummerTermSelected)
                {
                    termString += "S" + TermYear;
                }
                else if (IsWinterTermSelected)
                {
                    termString += "W" + TermYear;
                }
            }

            // Erzeuge Instanz aus den eingegebenen Daten.
            Channel newChannel = null;
            switch (SelectedChannelType)
            {
                case ChannelType.LECTURE:
                    Lecture lecture = new Lecture()
                    {
                        Name = ChannelName,
                        Description = ChannelDescription,
                        Type = SelectedChannelType,
                        Term = termString,
                        Locations = this.Locations,
                        Dates = this.Dates,
                        Contacts = this.Contacts,
                        Website = this.Website,
                        Faculty = SelectedFaculty,
                        StartDate = LectureStartDate,
                        EndDate = LectureEndDate,
                        Lecturer = this.Lecturer,
                        Assistant = this.Assistant
                    };
                    newChannel = lecture;
                    break;
                case ChannelType.EVENT:
                    Event eventObj = new Event()
                    {
                        Name = ChannelName,
                        Description = ChannelDescription,
                        Type = SelectedChannelType,
                        Term = termString,
                        Locations = this.Locations,
                        Dates = this.Dates,
                        Contacts = this.Contacts,
                        Website = this.Website,
                        Cost = EventCost,
                        Organizer = EventOrganizer
                    };
                    newChannel = eventObj;
                    break;
                case ChannelType.SPORTS:
                    Sports sportsObj = new Sports()
                    {
                        Name = ChannelName,
                        Description = ChannelDescription,
                        Type = SelectedChannelType,
                        Term = termString,
                        Locations = this.Locations,
                        Dates = this.Dates,
                        Contacts = this.Contacts,
                        Website = this.Website,
                        Cost = SportsCost,
                        NumberOfParticipants = AmountOfParticipants
                    };
                    newChannel = sportsObj;
                    break;
                default:
                    newChannel = new Channel()
                    {
                        Name = ChannelName,
                        Description = ChannelDescription,
                        Type = SelectedChannelType,
                        Term = termString,
                        Locations = this.Locations,
                        Dates = this.Dates,
                        Contacts = this.Contacts,
                        Website = this.Website
                    };
                    break;
            }

            return newChannel;
        }
        /// <summary>
        /// Bereitet ein Objekt vom Typ Channel vor, welches alle Properties enthält, die sich geändert haben.
        /// Die Methode bekommt eine alte Version eines Channel Objekts und eine neue Version und ermittelt 
        /// dann die Properties, die eine Aktualisierung erhalten haben und schreibt diese in eine neue Channel
        /// Instanz. Die von der Methode zurückgelieferte Channel Instanz kann dann direkt für die Aktualisierung auf
        /// dem Server verwendet werden. Achtung: Hat sich überhaupt keine Property geändert, so gibt die Methode null zurück.
        /// </summary>
        /// <param name="oldChannel">Das Channel Objekt vor der Aktualisierung.</param>
        /// <param name="newChannel">Das Channel Objekt mit den aktuellen Werten.</param>
        /// <returns>Ein Objekt der Klasse Channel, bei dem die Properties, die sich geändert haben, mit den
        ///     aktualisierten Werten gefüllt sind.</returns>
        private Channel prepareUpdatableChannelInstance(Channel oldChannel, Channel newChannel)
        {
            bool hasChanged = false;
            Channel updatedChannel = new Channel();

            // Vergleiche zunächst Properties der allgemeinen Channel Klasse.
            if (oldChannel.Name != newChannel.Name)
            {
                hasChanged = true;
                updatedChannel.Name = newChannel.Name;
            }

            if (oldChannel.Description != newChannel.Description)
            {
                hasChanged = true;
                updatedChannel.Description = newChannel.Description;
            }

            if (oldChannel.Term != newChannel.Term)
            {
                hasChanged = true;
                updatedChannel.Term = newChannel.Term;
            }

            if (oldChannel.Locations != newChannel.Locations)
            {
                hasChanged = true;
                updatedChannel.Locations = newChannel.Locations;
            }

            if (oldChannel.Dates != newChannel.Dates)
            {
                hasChanged = true;
                updatedChannel.Dates = newChannel.Dates;
            }

            if (oldChannel.Contacts != newChannel.Contacts)
            {
                hasChanged = true;
                updatedChannel.Contacts = newChannel.Contacts;
            }

            if (oldChannel.Website != newChannel.Website)
            {
                hasChanged = true;
                updatedChannel.Website = newChannel.Website;
            }

            // Vergleiche, ob kanalspezifische Felder sich geändert haben bei den Kanälen eines Typs mit solchen Feldern.
            if (oldChannel.Type == newChannel.Type)
            {
                switch (oldChannel.Type)
                {
                    case ChannelType.LECTURE:
                        Lecture updatedLecture = new Lecture()
                        {
                            Name = updatedChannel.Name,
                            Description = updatedChannel.Description,
                            Type = ChannelType.LECTURE,
                            Term = updatedChannel.Term,
                            Locations = updatedChannel.Locations,
                            Dates = updatedChannel.Dates,
                            Contacts = updatedChannel.Contacts,
                            Website = updatedChannel.Website
                        };

                        Lecture oldLecture = oldChannel as Lecture;
                        Lecture newLecture = newChannel as Lecture;

                        if (oldLecture.Lecturer != newLecture.Lecturer)
                        {
                            hasChanged = true;
                            updatedLecture.Lecturer = newLecture.Lecturer;
                        }

                        if (oldLecture.Assistant != newLecture.Assistant)
                        {
                            hasChanged = true;
                            updatedLecture.Assistant = newLecture.Assistant;
                        }

                        if (oldLecture.Faculty != newLecture.Faculty)
                        {
                            hasChanged = true;
                            updatedLecture.Faculty = newLecture.Faculty;
                        }

                        if (oldLecture.StartDate != newLecture.StartDate)
                        {
                            hasChanged = true;
                            updatedLecture.StartDate = newLecture.StartDate;
                        }

                        if (oldLecture.EndDate != newLecture.EndDate)
                        {
                            hasChanged = true;
                            updatedLecture.EndDate = newLecture.EndDate;
                        }

                        // Setze updatedChannel neu.
                        updatedChannel = updatedLecture;
                        break;
                    case ChannelType.EVENT:
                        Event updatedEvent = new Event()
                        {
                            Name = updatedChannel.Name,
                            Description = updatedChannel.Description,
                            Type = ChannelType.EVENT,
                            Term = updatedChannel.Term,
                            Locations = updatedChannel.Locations,
                            Dates = updatedChannel.Dates,
                            Contacts = updatedChannel.Contacts,
                            Website = updatedChannel.Website
                        };

                        Event oldEvent = oldChannel as Event;
                        Event newEvent = newChannel as Event;

                        if (oldEvent.Cost != newEvent.Cost)
                        {
                            hasChanged = true;
                            updatedEvent.Cost = newEvent.Cost;
                        }

                        if (oldEvent.Organizer != newEvent.Organizer)
                        {
                            hasChanged = true;
                            updatedEvent.Organizer = newEvent.Organizer;
                        }

                        // Setze updatedChannel neu.
                        updatedChannel = updatedEvent;
                        break;
                    case ChannelType.SPORTS:
                        Sports updatedSport = new Sports()
                        {
                            Name = updatedChannel.Name,
                            Description = updatedChannel.Description,
                            Type = ChannelType.SPORTS,
                            Term = updatedChannel.Term,
                            Locations = updatedChannel.Locations,
                            Dates = updatedChannel.Dates,
                            Contacts = updatedChannel.Contacts,
                            Website = updatedChannel.Website
                        };

                        Sports oldSport = oldChannel as Sports;
                        Sports newSport = newChannel as Sports;

                        if (oldSport.Cost != newSport.Cost)
                        {
                            hasChanged = true;
                            updatedSport.Cost = newSport.Cost;
                        }

                        if (oldSport.NumberOfParticipants != newSport.NumberOfParticipants)
                        {
                            hasChanged = true;
                            updatedSport.NumberOfParticipants = newSport.NumberOfParticipants;
                        }

                        // Setze updatedChannel neu.
                        updatedChannel = updatedSport;
                        break;
                    case ChannelType.OTHER:
                        updatedChannel.Type = ChannelType.OTHER;
                        break;
                    case ChannelType.STUDENT_GROUP:
                        updatedChannel.Type = ChannelType.STUDENT_GROUP;
                        break;
                }
            }

            // Prüfe, ob sich überhaupt eine Property geändert hat.
            if (!hasChanged)
            {
                Debug.WriteLine("No Property of channel has been updated. Method will return null.");
                updatedChannel = null;
            }

            return updatedChannel;
        }