Пример #1
0
        public BandVM()
        {
            Bands = Band.GetBands();
            Genres = Genre.GetGenres();

            SelectedBand = new Band();

            SelectedBandGenres = new ObservableCollection<BandGenre>();
            AddGenre(this);

            Enabled = true;
            ShowEdit = "Hidden";
            ShowCancel = "Hidden";
            ShowSave = "Visible";
        }
Пример #2
0
        private void DeleteBand(BandVM bandvm)
        {
            if (SelectedBand == null) return;

            // Delete the previous genres
            foreach (BandGenre bg in _oldBandGenres)
            {
                BandGenre.DeleteBandGenre(bg);
            }

            Band.DeleteBand(SelectedBand);

            SelectedBand = new Band();
            Enabled = true;
            ShowEdit = "Hidden";
            ShowCancel = "Hidden";
            ShowSave = "Visible";
        }
Пример #3
0
        private void SelectionChanged(BandVM bandvm)
        {
            if (SelectedBand == null) return;
            if (ShowCancel == "Visible") CancelUpdateBand(this);
            _oldBand = SelectedBand.Copy();

            SelectedBandGenres = BandGenre.GetBandGenres(SelectedBand.ID);
            _oldBandGenres = BandGenre.GetBandGenres(SelectedBand.ID);

            bandvm.ShowEdit = "Visible";
            bandvm.ShowCancel = "Hidden";
            bandvm.ShowSave = "Hidden";
            Enabled = false;
        }
Пример #4
0
        private void AddBand(BandVM bandvm)
        {
            SelectedBand = new Band();

            SelectedBandGenres = new ObservableCollection<BandGenre>();
            AddGenre(this);

            _oldBand = null;
            bandvm.ShowEdit = "Hidden";
            bandvm.ShowCancel = "Visible";
            bandvm.ShowSave = "Visible";
            bandvm.Enabled = true;
        }
Пример #5
0
        public static void UpdateBand(Band band)
        {
            // If _Band is null, create the Observable Collection
            if (_Bands == null) GetBands();

            try
            {
                // Update db
                DbParameter param1 = Database.AddParameter("@id", band.ID);
                DbParameter param2 = Database.AddParameter("@name", band.Name);
                DbParameter param3 = Database.AddParameter("@twitter", band.Twitter);
                DbParameter param4 = Database.AddParameter("@facebook", band.Facebook);
                DbParameter param5 = Database.AddParameter("@picture", band.Picture);
                DbParameter param6 = Database.AddParameter("@description", band.Description);
                int affectedRows = Database.ModifyData("UPDATE band SET Name = @name, Twitter = @twitter, Facebook = @facebook, Picture = @picture, Description = @description WHERE id = @id", param1, param2, param3, param4, param5, param6);
                if (affectedRows == 0) return;

                // Update _Band
                _Bands[GetIndexByID(band.ID)] = band;
            }

            // Fail
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #6
0
        public static ObservableCollection<Band> GetBands()
        {
            // If _Band is null, create the Observable Collection
            if (_Bands == null)
            {
                try
                {
                    // Create _Band
                    _Bands = new ObservableCollection<Band>();

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

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

                        // Get Name
                        if (DBNull.Value.Equals(record["Name"])) band.Name = "";
                        else band.Name = record["Name"].ToString();

                        // Get Twitter
                        if (DBNull.Value.Equals(record["Twitter"])) band.Twitter = "";
                        else band.Twitter = record["Twitter"].ToString();

                        // Get Facebook
                        if (DBNull.Value.Equals(record["Facebook"])) band.Facebook = "";
                        else band.Facebook = record["Facebook"].ToString();

                        // Get Picture
                        if (DBNull.Value.Equals(record["Picture"])) band.Picture = null;
                        else band.Picture = (byte[])record["Picture"];

                        // Get Description
                        if (DBNull.Value.Equals(record["Description"])) band.Description = "";
                        else band.Description = record["Description"].ToString();

                        // Add Band
                        _Bands.Add(band);
                    }
                    if (reader != null)
                        reader.Close();
                }

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

                    // Clear Bands
                    _Bands.Clear();
                    _Bands = null;
                }

            }

            // Return _Band
            return _Bands;
        }
Пример #7
0
        public static void DeleteBand(Band band)
        {
            // If _Band is null, create the Observable Collection
            if (_Bands == null) GetBands();

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

                // Update _Band
                _Bands.RemoveAt(GetIndexByID(band.ID));
            }

            // Fail
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #8
0
        public static int AddBand(Band band)
        {
            // If _Band is null, create the Observable Collection
            if (_Bands == null) GetBands();

            try
            {
                // Add to db
                DbParameter param1 = Database.AddParameter("@name", band.Name);
                DbParameter param2 = Database.AddParameter("@twitter", band.Twitter);
                DbParameter param3 = Database.AddParameter("@facebook", band.Facebook);
                DbParameter param4 = Database.AddParameter("@picture", band.Picture);
                DbParameter param5 = Database.AddParameter("@description", band.Description);

                DbDataReader reader = Database.GetData("INSERT INTO band(Name, Twitter, Facebook, Picture, Description) VALUES(@name, @twitter, @facebook, @picture, @description); SELECT LAST_INSERT_ID() AS ID;", param1, param2, param3, param4, param5);
                foreach (DbDataRecord record in reader)
                {
                    // Get ID
                    if (DBNull.Value.Equals(record["ID"])) band.ID = -1;
                    else band.ID = Convert.ToInt32(record["ID"]);
                }
                if (reader != null)
                    reader.Close();

                _Bands.Add(band);
                return band.ID;
            }

            // Fail
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return -1;
        }