public ObservableCollection <Produit> GetAllOneType(TypeMenu typeItem, TypeFormule typeRepas) { ObservableCollection <Produit> result = new ObservableCollection <Produit>(); using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.ConnectionString)) { connection.Open(); string commandText = "select Id, Designation, Prix, Image, Quantite, Unite, TypeMenu from Produit " + "join Contenir on Contenir.ProduitId = Produit.Id " + "where Contenir.MenuId = " + (int)typeRepas + " and Produit.TypeMenu = " + (int)typeItem + " order by Prix"; using (SqlCommand command = new SqlCommand(commandText, connection)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { result.Add(new Produit { Id = (decimal)reader["Id"], Name = (string)reader["Designation"], Price = (decimal)reader["Prix"], Image = (string)reader["Image"], Quantity = (decimal)reader["Quantite"], Unity = (string)reader["Unite"], TypeMenu = (TypeMenu)reader["TypeMenu"] }); } } } } return(result); }
public Menu2Items(TypeFormule type) { InitializeComponent(); MenuViewModel vm = new MenuViewModel(); this.DataContext = vm; vm.menu.Type = type; ProductDataLayer layer = new ProductDataLayer(); this.ComboDrink.ItemsSource = layer.GetAllOneType(TypeMenu.Boisson, type); this.ComboDessert.ItemsSource = layer.GetAllOneType(TypeMenu.Dessert, type); vm.RedirectEvent += (redirectTo) => this.NavigationService.Navigate(redirectTo); }
public Formule GetOne(TypeFormule type) { Formule res = null; using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.ConnectionString)) { connection.Open(); using (SqlCommand command = connection.CreateCommand()) { command.CommandText = "select Prix, Label from Menu where Number = " + (int)type; using (SqlDataReader reader = command.ExecuteReader()) { res = new Formule(); while (reader.Read()) { res.Label = (string)reader["Label"]; res.Prix = (decimal)reader["Prix"]; } } } } return(res); }