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

            int        selectedID = ((Dealers)SelectedItem).ID;
            DealerInfo dealerInfo = new DealerInfo();

            if (!dealersData.SelectWhereID(selectedID, out dealerInfo))
            {
                MessageBoxes.ShowError(MessageBoxes.PreviewErrorMessage);
                return;
            }

            DealersDialog drugsDialog  = new DealersDialog(dealerInfo, DialogModes.Edit, this);
            bool?         dialogResult = drugsDialog.ShowDialog();

            if (dialogResult == false)
            {
                return;
            }

            if (!dealersData.UpdateWhereID(selectedID, dealerInfo))
            {
                MessageBoxes.ShowError(MessageBoxes.EditErrorMessage);
                return;
            }

            itemsSource[SelectedIndex] = dealerInfo.dealer;
        }
Exemple #2
0
        public bool SelectWhereID(int ID, out DealerInfo dealerInfo)
        {
            Dealers dealer = new Dealers();

            dealerInfo = new DealerInfo();

            //Get dealer
            if (!dealersTable.SelectRecord(ID, out dealer))
            {
                MessageBoxes.ShowError(MessageBoxes.LoadDataErrorMessage);
                return(false);
            }

            //Get drug info list
            List <DrugsInfo.DrugsInfo> drugsInfoList = new List <DrugsInfo.DrugsInfo>();

            if (!SelectAllDrugsInfo(drugsInfoList, ID))
            {
                MessageBoxes.ShowError(MessageBoxes.LoadDataErrorMessage);
                return(false);
            }

            //Get drugs list
            List <Drugs.Drugs> drugsList = new List <Drugs.Drugs>();

            for (int i = 0; i < drugsInfoList.Count; i++)
            {
                Drugs.Drugs drug = new Drugs.Drugs();
                if (!drugsData.SelectWhereID(drugsInfoList[i].DrugID, out drug))
                {
                    MessageBoxes.ShowError(MessageBoxes.LoadDataErrorMessage);
                    return(false);
                }
                drugsList.Add(drug);
            }


            dealerInfo.dealer        = dealer;
            dealerInfo.drugsInfoList = drugsInfoList;
            dealerInfo.drugsList     = drugsList;

            return(true);
        }
        /* Context menu override */
        protected override void OnAddClick(object sender, RoutedEventArgs e)
        {
            DealersDialog drugsDialog  = new DealersDialog(new DealerInfo(), DialogModes.Add, this);
            bool?         dialogResult = drugsDialog.ShowDialog();

            if (dialogResult == false)
            {
                return;
            }

            DealerInfo dealerInfo = drugsDialog.dealerInfo;

            if (!dealersData.Insert(dealerInfo.dealer))
            {
                MessageBoxes.ShowError(MessageBoxes.AddErrorMessage);
                return;
            }

            itemsSource.Add(dealerInfo.dealer);
        }
        /* Context menu override */
        protected override void OnPreviewClick(object sender, RoutedEventArgs e)
        {
            if (SelectedItems.Count != 1)
            {
                return;
            }

            int        selectedID = ((Dealers)SelectedItem).ID;
            DealerInfo dealerInfo = new DealerInfo();

            if (!dealersData.SelectWhereID(selectedID, out dealerInfo))
            {
                MessageBoxes.ShowError(MessageBoxes.PreviewErrorMessage);
                return;
            }

            DealersDialog drugsDialog = new DealersDialog(dealerInfo, DialogModes.Preview, this);

            drugsDialog.ShowDialog();
        }
Exemple #5
0
        public bool UpdateWhereID(int ID, DealerInfo dealerInfo)
        {
            //Get dealer
            if (!dealersTable.EditRecord(ID, dealerInfo.dealer))
            {
                MessageBoxes.ShowError(MessageBoxes.LoadDataErrorMessage);
                return(false);
            }

            //Get dealer
            foreach (var drugInfo in dealerInfo.drugsInfoList)
            {
                if (!drugsInfoData.UpdateWhereID(drugInfo.ID, drugInfo))
                {
                    MessageBoxes.ShowError(MessageBoxes.EditErrorMessage);
                    return(false);
                }
            }

            return(true);
        }
Exemple #6
0
 public DealersDialog(DealerInfo _dealerInfo, DialogModes _dialogMode, DependencyObject parent = null) : base(_dialogMode, parent)
 {
     dealerInfo = _dealerInfo;
     InitializeComponent();
 }