public BandPageVM(){ _bands = Band.getAll(); _genres = Genre.getAll(); NewBand = new Band(); Foto = false; NewBand = _bands[0]; Console.WriteLine("Check"); }
public static List<Band> GetBands() { List<Band> lijst = new List<Band>(); string sSQL = "SELECT * FROM [Bands]"; DbDataReader reader = Database.GetData(sSQL, null); if (reader != null && reader.HasRows) { while (reader.Read()) { Band aNew = new Band(); aNew.ID = reader["ID"].ToString(); aNew.Name = reader["Name"].ToString(); if (!DBNull.Value.Equals(reader["Description"])) { aNew.Description = reader["Description"].ToString(); } else { aNew.Description = null; } if (!DBNull.Value.Equals(reader["Picture"])) { aNew.Picture = (byte[])reader["Picture"]; } else { aNew.Picture = new byte[0]; } if (!DBNull.Value.Equals(reader["Twitter"])) { aNew.Twitter = reader["Twitter"].ToString(); } else { aNew.Twitter = null; } if (!DBNull.Value.Equals(reader["Facebook"])) { aNew.Facebook = reader["Facebook"].ToString(); } else { aNew.Facebook = null; } lijst.Add(aNew); } } return lijst; }
public static void DeleteBandGenre(Band band, Genre genre) { String sql = "DELETE FROM BandGenre WHERE BandId = @Band AND GenreId = @Genre"; DbParameter par1 = Database.AddParameter("@Band", band.ID); DbParameter par2 = Database.AddParameter("@Genre", genre.ID); if (par1.Value == null) par1.Value = DBNull.Value; Database.ModifyData(sql, par1, par2); }
protected async override void OnNavigatedTo(NavigationEventArgs e) { // Data ophalen met JSON //HttpClient client = new HttpClient(); //HttpResponseMessage response = await client.GetAsync("http://api.irail.be/stations/?format=json"); //string result = await response.Content.ReadAsStringAsync(); //Station.Stations = new ObservableCollection<Station>(); //JsonObject obj = JsonObject.Parse(result); //JsonArray stations = obj["station"].GetArray() as JsonArray; //foreach (JsonValue val in stations) //{ // Station s = new Station() { // ID = val.GetObject().GetNamedString("id"), // Name = val.GetObject().GetNamedString("name") // }; // Station.Stations.Add(s); //} //stationslist.ItemsSource = Station.Stations; //Data ophalen met XML XmlDocument xmlDoc = await XmlDocument.LoadFromUriAsync(new Uri("http://api.irail.be/stations/")); XmlNodeList stations = xmlDoc.GetElementsByTagName("station"); Band.Bands = new ObservableCollection<Band>(); for (int i = 0; i < stations.Count; i++) { Band s = new Band() { ID = stations[i].Attributes[0].InnerText, Name = stations[i].InnerText }; Band.Bands.Add(s); } bandslist.ItemsSource = Band.Bands; }
public static void EditPicture(Band band, Byte[] picture) { String sql = "UPDATE Bands Set Picture=@Picture WHERE ID=@Band"; DbParameter par1 = Database.AddParameter("@Band", band._ID); DbParameter par3 = Database.AddParameter("@Picture", picture); if (par3.Value == null) par3.Value = DBNull.Value; Database.ModifyData(sql, par1, par3); }
public static void NewBandGenre(Band band, Genre genre) { String sql = "INSERT INTO BandGenre (BandId, GenreId) VALUES(@Band, @Genre)"; DbParameter par1 = Database.AddParameter("@Band", band.ID); DbParameter par2 = Database.AddParameter("@Genre", genre.ID); if (par1.Value == null) par1.Value = DBNull.Value; Database.ModifyData(sql, par1, par2); }
public static void EditBand(Band band) { String sql = "UPDATE Bands Set Name=@Name, Description=@Description, Twitter=@Twitter, Facebook=@Facebook WHERE ID=@Band"; DbParameter par1 = Database.AddParameter("@Band", band._ID); DbParameter par2 = Database.AddParameter("@Name", band._Name); DbParameter par4 = Database.AddParameter("@Description", band._Description); DbParameter par5 = Database.AddParameter("@Twitter", band._Twitter); DbParameter par6 = Database.AddParameter("@Facebook", band._Facebook); if (par4.Value == null) par4.Value = DBNull.Value; Database.ModifyData(sql, par1, par2, par4, par5, par6); }
public static void DeleteBand(Band band) { String sql = "DELETE FROM Bands WHERE ID = @Band"; DbParameter par1 = Database.AddParameter("@Band", band._ID); if (par1.Value == null) par1.Value = DBNull.Value; Database.ModifyData(sql, par1); }
public static void NewBand(Band band) { String sql = "INSERT INTO Bands (Name, Picture, Description, Twitter, Facebook) VALUES(@Name, @Picture, @Description, @Twitter, @Facebook)"; DbParameter par1 = Database.AddParameter("@Name", band._Name); DbParameter par2 = Database.AddParameter("@Picture", band.Picture); DbParameter par3 = Database.AddParameter("@Description", band.Description); DbParameter par4 = Database.AddParameter("@Twitter", band.Twitter); DbParameter par5 = Database.AddParameter("@Facebook", band.Facebook); if (par2.Value == null) par2.Value = DBNull.Value; if (par3.Value == null) par3.Value = DBNull.Value; Database.ModifyData(sql, par1, par2, par3, par4, par5); }
public static Band getBand(String id) { Band band = new Band(); String sSQL = "SELECT * FROM Bands WHERE ID = @ID"; DbParameter par1 = Database.AddParameter("@ID", id); if (par1.Value == null) par1.Value = DBNull.Value; DbDataReader reader = Database.GetData(sSQL, par1); while (reader.Read()) { band.Name = reader["Name"].ToString(); band.ID = id; if (!DBNull.Value.Equals(reader["Description"])) { band.Description = reader["Description"].ToString(); } else { band.Description = null; } if (!DBNull.Value.Equals(reader["Picture"])) { band.Picture = (byte[])reader["Picture"]; } else { band.Picture = null; } if (!DBNull.Value.Equals(reader["Twitter"])) { band.Twitter = reader["Twitter"].ToString(); } else { band.Twitter = null; } if (!DBNull.Value.Equals(reader["Facebook"])) { band.Facebook = reader["Facebook"].ToString(); } else { band.Facebook = null; } band.Genres = Genre.getByBand(id); } return band; }
//string IDataErrorInfo.Error //{ // get { return "Model not valid"; } //} //string IDataErrorInfo.this[string columnName] //{ // get // { // try // { // object value = this.GetType().GetProperty(columnName).GetValue(this); // Validator.ValidateProperty(value, new ValidationContext(this, null, null) // { // MemberName = columnName // }); // } // catch (ValidationException ex) // { // return ex.Message; // } // return String.Empty; // } //} #endregion public static ObservableCollection<Band> getAll() { ObservableCollection<Band> lijst = new ObservableCollection<Band>(); String sSQL = "SELECT * FROM Bands"; DbDataReader reader = Database.GetData(sSQL); while (reader.Read()) { Band aNew = new Band(); aNew.ID = reader["ID"].ToString(); aNew.Name = reader["Name"].ToString(); //De reader crasht als hij iets leegs inleest, daarom vangen wij dit op met de if's if (!DBNull.Value.Equals(reader["Description"])) { aNew.Description = reader["Description"].ToString(); } else { aNew.Description = null; } if (!DBNull.Value.Equals(reader["Picture"])) { aNew.Picture = (byte[])reader["Picture"]; } else { aNew.Picture = new byte[0]; } if (!DBNull.Value.Equals(reader["Twitter"])) { aNew.Twitter = reader["Twitter"].ToString(); } else { aNew.Twitter = null; } if (!DBNull.Value.Equals(reader["Facebook"])) { aNew.Facebook = reader["Facebook"].ToString(); } else { aNew.Facebook = null; } aNew.Genres = Genre.getByBand(aNew.ID); lijst.Add(aNew); } return lijst; }