/* Crea un nuovo impiegato e salvalo sul DB. */ private void BtnNew_Click(object sender, RoutedEventArgs e) { MessageBox.Show("Employee add mode."); /* Apertura finestra d'aggiunta. */ Window employeeDetailWindow = new EmployeeDetailWindow(); /* Nel caso prima non ci sia stato un load della tabella. */ using (var ctx = new MainDBContext(CONNECTION_STRING)) { DtGEmployeesGrid.ItemsSource = ctx.Employees.ToList(); } /* Con la classe a parte DBInteractions: */ //DBInteraction dBInter = new DBInteraction(); //DtGEmployeesGrid.ItemsSource = dBInter.ReadEmployeesFromDB(); #region Info su ShowDialog /* Se il «.ShowDialog()» restituisce true * -> Vuol dire che * -> . */ /* Se il «.ShowDialog()» restituisce false -> Vuol dire che -> * -> Vuol dire che * -> . */ /* public void Show(); * Riepilogo: * Apre una finestra e restituisce solo quando si chiude la finestra appena aperta. * Valori restituiti: * Oggetto System.Nullable `1 valore di tipo System.Boolean che specifica se l'attività: * true -> è stato accettato * false -> annullato * Il valore restituito è il valore di System.Windows.Window.DialogResult proprietà prima della chiusura di una finestra. */ #endregion if (employeeDetailWindow.ShowDialog() != true) { return; } /* Prendo dalla finestra employeeDetailWindow l'Employee costruito in quella finestra e restituitomi tramite il «.Model». */ //ytemporaneamente commentatovia //Employee newEmployee = employeeDetailWindow.Model; //ytemporaneamente commentatovia //using (var ctx = new MainDBContext(CONNECTION_STRING)) //{ // ctx.Employees.Add(newEmployee); // ctx.SaveChanges(); //} /* Aggiorno la tabella a schermo. */ //DtGEmployeesGrid.ItemsSource = dBInter.ReadEmployeesFromDB(); }
/* Carica la tabella degl'impiegati. */ private void BtnLoad_Click(object sender, RoutedEventArgs e) { /* Carica i dati nella DataGrid, prendendoli col MainDBContext (che è un System.Data.Entity.DbContext). */ using (var ctx = new MainDBContext(CONNECTION_STRING)) { DtGEmployeesGrid.ItemsSource = ctx.Employees.ToList(); } /* Con la classe a parte DBInteractions: */ //DBInteraction dBInter = new DBInteraction(); //DtGEmployeesGrid.ItemsSource = dBInter.ReadEmployeesFromDB(); MessageBox.Show("Employees loaded!"); }