/* Context menu override */ protected override void OnEditClick(object sender, RoutedEventArgs e) { if (SelectedItems.Count != 1) { return; } Drugs drug = (Drugs)SelectedItem; if (!drugsData.SelectWhereID(drug.ID, out drug)) { MessageBoxes.ShowError(MessageBoxes.EditErrorMessage); return; } DrugsDialog drugsDialog = new DrugsDialog(drug, DialogModes.Edit, this); bool? dialogResult = drugsDialog.ShowDialog(); if (dialogResult == false) { return; } drug = drugsDialog.drug; if (!drugsData.UpdateWhereID(drug.ID, drug)) { MessageBoxes.ShowError(MessageBoxes.EditErrorMessage); return; } itemsSource[SelectedIndex] = drug; }
/* Context menu override */ protected override void OnPreviewClick(object sender, RoutedEventArgs e) { if (SelectedItems.Count != 1) { return; } Drugs drug = (Drugs)SelectedItem; if (!drugsData.SelectWhereID(drug.ID, out drug)) { MessageBoxes.ShowError(MessageBoxes.PreviewErrorMessage); return; } DrugsDialog drugsDialog = new DrugsDialog(drug, DialogModes.Preview, this); drugsDialog.ShowDialog(); }
/* Context menu override */ protected override void OnAddClick(object sender, RoutedEventArgs e) { DrugsDialog drugsDialog = new DrugsDialog(new Drugs(), DialogModes.Add, this); bool? dialogResult = drugsDialog.ShowDialog(); if (dialogResult == false) { return; } Drugs drug = drugsDialog.drug; if (!drugsData.Insert(drug)) { MessageBoxes.ShowError(MessageBoxes.AddErrorMessage); return; } itemsSource.Add(drug); }
/* Context menu override */ protected override void OnDeleteClick(object sender, RoutedEventArgs e) { if (SelectedItems.Count != 1) { return; } MessageBoxResult result = MessageBoxes.MessageBoxShowDeleteMessage(); if (result == MessageBoxResult.No) { return; } List <DrugsInfo.DrugsInfo> drugsInfoList = new List <DrugsInfo.DrugsInfo>(); Drugs drug = (Drugs)SelectedItem; if (!drugsInfoData.SelectAll(drugsInfoList, " WHERE DRUG_ID = " + drug.ID)) { MessageBoxes.ShowError(MessageBoxes.DeleteErrorMessage); return; } foreach (DrugsInfo.DrugsInfo drugInfo in drugsInfoList) { if (!drugsInfoData.DeleteWhereID(drugInfo.ID)) { MessageBoxes.ShowError(MessageBoxes.DeleteErrorMessage); return; } } if (!drugsData.DeleteWhereID(drug.ID)) { MessageBoxes.ShowError(MessageBoxes.DeleteErrorMessage); return; } itemsSource.RemoveAt(SelectedIndex); }
public DrugsDialog(Drugs _drug, DialogModes _dialogMode, DependencyObject parent = null) : base(_dialogMode, parent) { InitializeComponent(); drug = _drug; }
public bool Insert(Drugs drug) { return(drugsTable.InsertRecord(drug)); }
public bool UpdateWhereID(int ID, Drugs drug) { return(drugsTable.EditRecord(ID, drug)); }
public bool SelectWhereID(int ID, out Drugs drug) { return(drugsTable.SelectRecord(ID, out drug)); }