private void ButtonAdd_OnClick(object sender, RoutedEventArgs e) { ClearStatusbar(); if (TextBoxMachine.Text.Length > 0) { if (Entities.Machines.Any(x => x.MachineName.ToLower() == TextBoxMachine.Text.ToLower())) { ShowMessageInStatusbar("the machine is already added"); return; } MachineWithNotify newMachine = new MachineWithNotify(); newMachine.MachineName = TextBoxMachine.Text; newMachine.MachineCode = Convert.ToInt32(TextBoxMachineCode.Text); var result = MachinesCollection.AddNew(0, newMachine); if (result) { NotifyOpenWindows(); TextBoxMachine.Text = ""; TextBoxMachineCode.Text = ""; ShowMessageInStatusbar("new machine added"); } } }
private void RibbonButtonDelete_OnClick(object sender, RoutedEventArgs e) { if (GridViewMachines.SelectedItem == null) { ClearStatusbar(); ShowMessageInStatusbar("First select an item"); return; } MachineWithNotify selectedMachine = (MachineWithNotify)View.CurrentItem; if (Entities.Parts.Any(x => x.MachineId == selectedMachine.MachineId)) { ClearStatusbar(); ShowMessageInStatusbar("This machine is in use"); return; } var result = MachinesCollection.Delete(View.CurrentPosition); if (result) { ClearStatusbar(); ShowMessageInStatusbar("Machine removed"); NotifyOpenWindows(); } else { ClearStatusbar(); ShowMessageInStatusbar("Failed"); } }