/// <summary> /// Constructor for the Application object. /// </summary> public App() { // Global handler for uncaught exceptions. UnhandledException += Application_UnhandledException; // Standard Silverlight initialization InitializeComponent(); // Phone-specific initialization InitializePhoneApplication(); // Show graphics profiling information while debugging. if (System.Diagnostics.Debugger.IsAttached) { // Display the current frame rate counters. Application.Current.Host.Settings.EnableFrameRateCounter = true; // Show the areas of the app that are being redrawn in each frame. //Application.Current.Host.Settings.EnableRedrawRegions = true; // Enable non-production analysis visualization mode, // which shows areas of a page that are handed off to GPU with a colored overlay. //Application.Current.Host.Settings.EnableCacheVisualization = true; // Disable the application idle detection by setting the UserIdleDetectionMode property of the // application's PhoneApplicationService object to Disabled. // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run // and consume battery power when the user is not using the phone. PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled; } appSettings.Add("Calorie", 2000); appSettings.Add("Carboidrati", 2000); appSettings.Add("Grassi", 2000); appSettings.Add("Proteine", 2000); appSettings.Add("DataCorrente", DateTime.Today); using(Database db = new Database(App.PathDB)){ if (db.DatabaseExists() == false) { // Create the local database. db.CreateDatabase(); Categoria catPanini = new Categoria { NomeCategoria = "Panini" }; Categoria catBevande = new Categoria { NomeCategoria = "Bevande" }; Categoria catPanificati = new Categoria { NomeCategoria = "Panificati" }; // Prepopulate the categories. db.Categorie.InsertOnSubmit(catPanini); db.Categorie.InsertOnSubmit(catBevande); db.Categorie.InsertOnSubmit(catPanificati); // Create a new to-do item. db.Prodotti.InsertOnSubmit(new Prodotto { NomeProdotto = "crispy", CategoriaFK = catPanini, PathFoto = "crispy.png", Quantita = 1, Carboidrati = 70, UnitaDiMisura = "pz", Grassi = 20, Proteine = 10, Calorie = 150, Media = 1, Piccola = 1, Grande = 1 } ); Prodotto p = new Prodotto { NomeProdotto = "coca coea", CategoriaFK = catBevande, Quantita = 100, PathFoto = "cocacoea.jpg", UnitaDiMisura = "ml", Carboidrati = 10, Grassi = 10, Proteine = 11, Calorie = 200, Media = 250, Piccola = 500, Grande = 1000 }; db.Prodotti.InsertOnSubmit(p); Prodotto p2 = new Prodotto { NomeProdotto = "medoemedo", CategoriaFK = catBevande, Quantita = 100, PathFoto = "cocacoea.jpg", UnitaDiMisura = "ml", Carboidrati = 10, Grassi = 10, Proteine = 11, Calorie = 200, Media = 250, Piccola = 500, Grande = 1000 }; db.Prodotti.InsertOnSubmit(p2); db.Pasti.InsertOnSubmit(new Pasto { ProdottoFK=p2, Quantita=200, Calorie = Math.Round(((200 * p2.Calorie) / p2.Quantita),2), // quantità media prodotto : calorie prodotto = quantità assunta : calorie assunte Grassi=Math.Round(((200*p2.Grassi)/p2.Quantita),2), Carboidrati = Math.Round(((200 * p2.Carboidrati) / p2.Quantita),2), Proteine = Math.Round(((200 * p2.Proteine) / p2.Quantita),2), Data=DateTime.Today }); db.SubmitChanges(); } } categoriaVM = new CategoriaViewModel(); }
// Called during an add operation private void attach_ToDo(Prodotto toDo) { NotifyPropertyChanging("Prodotto"); toDo.CategoriaFK = this; }
// Called during a remove operation private void detach_ToDo(Prodotto toDo) { NotifyPropertyChanging("Prodotto"); toDo.CategoriaFK = null; }
//COSTRUTTORE public ProdottoViewModel(int id) : base() { this._prodotto = base.Db.RitornaProdotto(id); }