Exemple #1
0
        public DrugsInfoDialog(DrugsInfo _drugInfo, List <Drugs.Drugs> _drugsList, DialogModes _dialogMode, DependencyObject parent = null) : base(_dialogMode, parent)
        {
            drugInfo  = _drugInfo;
            drugsList = _drugsList;

            InitializeComponent();
        }
        protected override void OnEditClick(object sender, RoutedEventArgs e)
        {
            DrugsInfo drugInfo = toDrugsInfo((DrugsItem)SelectedItem);

            if (!drugsInfoData.SelectWhereID(drugInfo.ID, out drugInfo))
            {
                MessageBoxes.ShowError(MessageBoxes.PreviewErrorMessage);
                return;
            }

            DrugsInfoDialog drugsInfoDialog = new DrugsInfoDialog(drugInfo, drugsList, DialogModes.Edit);
            bool?           dialogResult    = drugsInfoDialog.ShowDialog();

            if (dialogResult == false)
            {
                return;
            }

            if (!drugsInfoData.UpdateWhereID(drugInfo.ID, drugInfo))
            {
                MessageBoxes.ShowError(MessageBoxes.EditErrorMessage);
                return;
            }

            itemsSource[SelectedIndex] = toDrugItem(drugInfo, drugsList);
        }
        protected override void OnAddClick(object sender, RoutedEventArgs e)
        {
            List <Drugs.Drugs> drugsList = new List <Drugs.Drugs>();

            if (!drugsData.SelectAll(drugsList))
            {
                MessageBoxes.ShowError(MessageBoxes.LoadDataErrorMessage);
                return;
            }

            DrugsInfoDialog drugsInfoDialog = new DrugsInfoDialog(new DrugsInfo(), drugsList, DialogModes.Add, this);
            bool?           dialogResult    = drugsInfoDialog.ShowDialog();

            if (dialogResult == false)
            {
                return;
            }

            DrugsInfo drugsInfo = drugsInfoDialog.drugInfo;

            drugsInfo.DealerID = dealerID;

            ///////////
            if (!drugsInfoData.Insert(drugsInfo))
            {
                MessageBoxes.ShowError(MessageBoxes.AddErrorMessage);
                return;
            }
            DrugsItem drugItem = toDrugItem(drugsInfo, drugsList);

            itemsSource.Add(drugItem);
        }
        private DrugsItem toDrugItem(DrugsInfo drugsInfo, List <Drugs.Drugs> drugsList)
        {
            DrugsItem drugItem = new DrugsItem();

            drugItem.ID         = drugsInfo.ID;
            drugItem.Number     = drugsInfo.Number;
            drugItem.Price      = drugsInfo.Price;
            drugItem.ExpiryDate = drugsInfo.ExpiryDate;

            Drugs.Drugs drug = drugsList.Find(element => element.ID == drugsInfo.DrugID);
            if (drug != null)
            {
                drugItem.Name  = drug.Name;
                drugItem.image = drug.image;
            }

            return(drugItem);
        }
        /// <summary>Метод при натискане на "Преглед" от контекстното меню</summary>
        protected override void OnPreviewClick(object sender, RoutedEventArgs e)
        {
            if (SelectedItems.Count != 1)
            {
                return;
            }

            DrugsInfo drugInfo = toDrugsInfo((DrugsItem)SelectedItem);

            if (!drugsInfoData.SelectWhereID(drugInfo.ID, out drugInfo))
            {
                MessageBoxes.ShowError(MessageBoxes.PreviewErrorMessage);
                return;
            }

            DrugsInfoDialog drugsInfoDialog = new DrugsInfoDialog(drugInfo, drugsList, DialogModes.Preview);

            drugsInfoDialog.ShowDialog();
        }
        private DrugsInfo toDrugsInfo(DrugsItem drugsItem)
        {
            if (!drugsData.SelectAll(drugsList))
            {
                MessageBoxes.ShowError(MessageBoxes.EditErrorMessage);
                return(new DrugsInfo());
            }

            Drugs.Drugs drug = drugsList.Find(element => element.Name == drugsItem.Name);

            DrugsInfo drugsInfo = new DrugsInfo();

            if (drug != null)
            {
                drugsInfo.ID         = drugsItem.ID;
                drugsInfo.Number     = drugsItem.Number;
                drugsInfo.Price      = drugsItem.Price;
                drugsInfo.ExpiryDate = drugsItem.ExpiryDate;
                drugsInfo.DrugID     = drug.ID;
                drugsInfo.DealerID   = dealerID;
            }

            return(drugsInfo);
        }
        protected override void OnDeleteClick(object sender, RoutedEventArgs e)
        {
            if (SelectedItems.Count != 1)
            {
                return;
            }

            MessageBoxResult result = MessageBoxes.MessageBoxShowDeleteMessage();

            if (result == MessageBoxResult.No)
            {
                return;
            }

            DrugsInfo drugInfo = toDrugsInfo((DrugsItem)SelectedItem);

            if (!drugsInfoData.DeleteWhereID(drugInfo.ID))
            {
                MessageBoxes.ShowError(MessageBoxes.DeleteErrorMessage);
                return;
            }

            itemsSource.RemoveAt(SelectedIndex);
        }
Exemple #8
0
 public bool Insert(DrugsInfo drugsInfo)
 {
     return(drugsInfoTable.InsertRecord(drugsInfo));
 }
Exemple #9
0
 public bool UpdateWhereID(int ID, DrugsInfo drugsInfo)
 {
     return(drugsInfoTable.EditRecord(ID, drugsInfo));
 }
Exemple #10
0
 public bool SelectWhereID(int ID, out DrugsInfo drugsInfo)
 {
     return(drugsInfoTable.SelectRecord(ID, out drugsInfo));
 }