void UpdateTerritory() { using (var db = new Model.NorthwindDataContext()) { var query = db.Territories.Where(x => x.TerritoryID.Equals(IdTerritory)); foreach (Model.Territories oTerritory in query) { oTerritory.TerritoryDescription = txtDescription.Text; oTerritory.RegionID = (int)cmbRegion.SelectedValue; } try { db.SubmitChanges(); MessageBox.Show("Successfully updated", "Update", MessageBoxButton.OK, MessageBoxImage.Information); this.Clean(); // Open the MenuTerritories MainWindow.StaticMainFrame.Content = new MenuTerritories(); } catch (Exception ex) { MessageBox.Show("error: " + ex.Message); } } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { string idTerritory = (string)((Button)sender).CommandParameter; if (MessageBox.Show("Are you sure to delete?", "Confirm delete", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { using (var db = new Model.NorthwindDataContext()) { var query = db.Territories.Where(x => x.TerritoryID.Equals(idTerritory)); foreach (Model.Territories oTerritory in query) { oTerritory.habilitado = false; } try { db.SubmitChanges(); MessageBox.Show("Was successfully removed", "Delete", MessageBoxButton.OK, MessageBoxImage.Information); Refresh(); } catch (Exception ex) { MessageBox.Show("error: " + ex.Message); } } } }
void AddTerritory() { using (var db = new Model.NorthwindDataContext()) { string idTerritory = txtTerritoryId.Text; if (IdExist(idTerritory)) { MessageBox.Show("TerritoryID already exists", "Exist", MessageBoxButton.OK, MessageBoxImage.Warning); txtTerritoryId.Focus(); return; } var oTerritory = new Model.Territories { TerritoryID = idTerritory, TerritoryDescription = txtDescription.Text, RegionID = (int)cmbRegion.SelectedValue }; db.Territories.InsertOnSubmit(oTerritory); try { db.SubmitChanges(); MessageBox.Show("Successfully registered", "Add", MessageBoxButton.OK, MessageBoxImage.Information); this.Clean(); // Open the MenuTerritories MainWindow.StaticMainFrame.Content = new MenuTerritories(); } catch (Exception ex) { MessageBox.Show("error: " + ex.Message); } } }