public TimeSlotVM()
        {
            Bands = Band.GetBands();
            Stages = Stage.GetStages();
            Timeslots = TimeSlot.GetTimeSlots();

            SelectedSlot = new TimeSlot();

            Hours = new ObservableCollection<int>();
            for (int i = 0; i < 24; ++i)
                Hours.Add(i);

            Minutes = new ObservableCollection<int>();
            for (int i = 0; i < 60; i += 5)
                Minutes.Add(i);

            CancelUpdateSlot(this);

            SelectedSlot = new TimeSlot();
            StartDate = DateTime.Now;

            _oldSlot = null;

            Enabled = true;
            ShowEdit = "Hidden";
            ShowCancel = "Hidden";
            ShowSave = "Visible";
        }
        public static int AddTimeSlot(TimeSlot timeSlot)
        {
            // If _TimeSlots is null, create the Observable Collection
            if (_TimeSlots == null) GetTimeSlots();

            try
            {
                // Add to db
                DbParameter param1 = Database.AddParameter("@bandid", timeSlot.BandID);
                DbParameter param2 = Database.AddParameter("@stageid", timeSlot.StageID);
                DbParameter param3 = Database.AddParameter("@startdate", timeSlot.StartDate);
                DbParameter param4 = Database.AddParameter("@enddate", timeSlot.EndDate);
                DbDataReader reader = Database.GetData("INSERT INTO TimeSlot(BandID, StageID, StartDate, EndDate) VALUES(@bandid, @stageid, @startdate, @enddate); SELECT LAST_INSERT_ID() AS ID;", param1, param2, param3, param4);
                foreach (DbDataRecord record in reader)
                {
                    // Get ID
                    if (DBNull.Value.Equals(record["ID"])) timeSlot.ID = -1;
                    else timeSlot.ID = Convert.ToInt32(record["ID"]);
                }
                if (reader != null)
                    reader.Close();

                _TimeSlots.Add(timeSlot);
                return timeSlot.ID;
            }

            // Fail
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return -1;
        }
        public static void DeleteTimeSlot(TimeSlot timeSlot)
        {
            // If _TimeSlots is null, create the Observable Collection
            if (_TimeSlots == null) GetTimeSlots();

            try
            {
                // Add to db
                DbParameter param = Database.AddParameter("@id", timeSlot.ID);
                int affectedRows = Database.ModifyData("DELETE FROM TimeSlot WHERE id = @id", param);
                if (affectedRows == 0) return;

                // Update _TimeSlots
                _TimeSlots.RemoveAt(GetIndexFromID(timeSlot.ID));
            }

            // Fail
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public static void UpdateTimeSlot(TimeSlot timeSlot)
        {
            // If _TimeSlots is null, create the Observable Collection
            if (_TimeSlots == null) GetTimeSlots();

            try
            {
                // Update db
                DbParameter param1 = Database.AddParameter("@id", timeSlot.ID);
                DbParameter param2 = Database.AddParameter("@bandid", timeSlot.BandID);
                DbParameter param3 = Database.AddParameter("@stageid", timeSlot.StageID);
                DbParameter param4 = Database.AddParameter("@startdate", timeSlot.StartDate);
                DbParameter param5 = Database.AddParameter("@enddate", timeSlot.EndDate);
                int affectedRows = Database.ModifyData("UPDATE timeslot SET BandID = @bandid, StageID = @stageid, StartDate = @startdate, EndDate = @enddate WHERE id = @id", param1, param2, param3, param4, param5);
                if (affectedRows == 0) return;

                // Update _TimeSlots
                _TimeSlots[GetIndexFromID(timeSlot.ID)] = timeSlot;
            }

            // Fail
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public static ObservableCollection<TimeSlot> GetTimeSlots()
        {
            // If _TimeSlots is null, create the Observable Collection
            if (_TimeSlots == null)
            {
                try
                {
                    // Create _Contactperson
                    _TimeSlots = new ObservableCollection<TimeSlot>();

                    // Get data
                    DbDataReader reader = Database.GetData("SELECT * FROM timeslot");
                    foreach (DbDataRecord record in reader)
                    {
                        // Create new TimeSlot
                        TimeSlot timeslot = new TimeSlot();

                        // Get ID
                        if (DBNull.Value.Equals(record["ID"])) timeslot.ID = -1;
                        else timeslot.ID = Convert.ToInt32(record["ID"]);

                        // Get BandID
                        if (DBNull.Value.Equals(record["BandID"])) timeslot.BandID = -1;
                        else timeslot.BandID = Convert.ToInt32(record["BandID"]);

                        // Get StageID
                        if (DBNull.Value.Equals(record["StageID"])) timeslot.StageID = -1;
                        else timeslot.StageID = Convert.ToInt32(record["StageID"]);

                        // Get StartDate
                        if (DBNull.Value.Equals(record["StartDate"])) timeslot.StartDate = new DateTime();
                        else timeslot.StartDate = Convert.ToDateTime(record["StartDate"]);

                        // Get EndDate
                        if (DBNull.Value.Equals(record["EndDate"])) timeslot.EndDate = new DateTime();
                        else timeslot.EndDate = Convert.ToDateTime(record["EndDate"]);

                        // Add TimeSlot
                        _TimeSlots.Add(timeslot);
                    }
                    if (reader != null)
                        reader.Close();
                }

                // Fail
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);

                    // Clear TimeSlots
                    _TimeSlots.Clear();
                    _TimeSlots = null;
                }

            }

            // Return _TimeSlots
            return _TimeSlots;
        }
        private void SelectionChanged(TimeSlotVM slotvm)
        {
            if (SelectedSlot == null) return;
            if (ShowCancel == "Visible") CancelUpdateSlot(this);
            _oldSlot = SelectedSlot.Copy();

            slotvm.ShowEdit = "Visible";
            slotvm.ShowCancel = "Hidden";
            slotvm.ShowSave = "Hidden";
            Enabled = false;
        }
        private void DeleteSlot(TimeSlotVM timeslotVM)
        {
            if (SelectedSlot == null) return;

            TimeSlot.DeleteTimeSlot(SelectedSlot);

            SelectedSlot = new TimeSlot();
            Enabled = true;
            ShowEdit = "Hidden";
            ShowCancel = "Hidden";
            ShowSave = "Visible";
        }
        private void AddSlot(TimeSlotVM timeslotVM)
        {
            SelectedSlot = new TimeSlot();

            StartDate = DateTime.Now;
            EndDate = StartDate;

            _oldSlot = null;
            timeslotVM.ShowEdit = "Hidden";
            timeslotVM.ShowCancel = "Visible";
            timeslotVM.ShowSave = "Visible";
            timeslotVM.Enabled = true;
        }