/// <summary> /// Event for delete drug click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeleteDrug_Click(object sender, RoutedEventArgs e) { selectedDataToDelete = (sender as MenuItem).DataContext as Prescription; NewRepeatSummaryViewModel _objNewRepeatSummaryViewModel = this.DataContext as NewRepeatSummaryViewModel; _objNewRepeatSummaryViewModel.DrugSearchCollection.Remove(selectedDataToDelete); App.prescriptionCollection = _objNewRepeatSummaryViewModel.DrugSearchCollection; if (_objNewRepeatSummaryViewModel.DrugSearchCollection.Count == 0) { tbkNameHeader.Visibility = Visibility.Collapsed; tbkQtyHeader.Visibility = Visibility.Collapsed; txbNoItems.Visibility = Visibility.Visible; } }
/// <summary> /// Method invoked on clikking add button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAdd_Click(object sender, RoutedEventArgs e) { bool _isValid = false; if (_isSearchDone == false) { prescription = new Prescription(); if (!string.IsNullOrEmpty(tbxDrugSearch.Text) && !string.IsNullOrWhiteSpace(tbxDrugSearch.Text)) { if (!string.IsNullOrEmpty(tbxQty.Text) || !string.IsNullOrWhiteSpace(tbxQty.Text)) { try { QtyValidator = Convert.ToInt16(tbxQty.Text); QtyValidatorToString = Convert.ToString(QtyValidator); if ((QtyValidator <= 0) || (QtyValidator >= 10000)) { MessageBox.Show("Please enter a quantity between 1 and 9999 "); tbxQty.Text = string.Empty; } else { prescription.quantity = QtyValidatorToString; _isValid = true; prescription.drugname = tbxDrugSearch.Text; if (!string.IsNullOrEmpty(tbxReason.Text) || !string.IsNullOrWhiteSpace(tbxReason.Text)) { prescription.reason = tbxReason.Text; } else { prescription.reason = string.Empty; } prescription.amp = string.Empty; prescription.vmp = string.Empty; prescription.vmpp = string.Empty; prescription.ampp = string.Empty; } } catch (OverflowException ex) { MessageBox.Show("Please enter a quantity between 1 and 9999"); tbxQty.Text = string.Empty; } catch (FormatException ex) { MessageBox.Show("Enter a number"); tbxQty.Text = string.Empty; } } else { _isValid = false; MessageBox.Show("Enter quantity of drug."); } } else { _isValid = false; MessageBox.Show("Enter drug name."); } } else { if (!string.IsNullOrEmpty(tbxDrugSearch.Text) || !string.IsNullOrWhiteSpace(tbxDrugSearch.Text)) { if (!string.IsNullOrEmpty(tbxQty.Text) || !string.IsNullOrWhiteSpace(tbxQty.Text)) { try { QtyValidator = Convert.ToInt16(tbxQty.Text); QtyValidatorToString = Convert.ToString(QtyValidator); if ((QtyValidator <= 0) || (QtyValidator >= 10000)) { MessageBox.Show("Please enter a quantity between 1 and 9999 "); tbxQty.Text = string.Empty; } else { prescription.quantity = QtyValidatorToString; _isValid = true; prescription.drugname = tbxDrugSearch.Text; if (!string.IsNullOrEmpty(tbxReason.Text) || !string.IsNullOrWhiteSpace(tbxReason.Text)) { prescription.reason = tbxReason.Text; } else { prescription.reason = string.Empty; } } } catch (OverflowException ex) { MessageBox.Show("Please enter a quantity between 1 and 9999"); tbxQty.Text = string.Empty; } catch (FormatException ex) { MessageBox.Show("Enter a number"); tbxQty.Text = string.Empty; } } else { _isValid = false; MessageBox.Show("Enter quantity of drug."); } } else { _isValid = false; MessageBox.Show("Enter drug name."); } } if (_isValid == true) { prescriptionCollection.Add(prescription); App.autoCompleteListDrug.Add(tbxDrugSearch.Text); tbxDrugSearch.Text = string.Empty; tbxQty.Text = string.Empty; tbxReason.Text = string.Empty; NewRepeatSummaryViewModel _objNewRepeatSummaryViewModel = this.DataContext as NewRepeatSummaryViewModel; _objNewRepeatSummaryViewModel.DrugSearchCollection = prescriptionCollection; App.prescriptionCollection = prescriptionCollection; this.DataContext = _objNewRepeatSummaryViewModel; tbkNameHeader.Visibility = Visibility.Visible; tbkQtyHeader.Visibility = Visibility.Visible; txbNoItems.Visibility = Visibility.Collapsed; } }