/// <summary>
        /// Delete record from the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteTransaction(object sender, RoutedEventArgs e)
        {
            if (updatingTransactionID == null)
            {
                ShowInformationMessageBox("Select a row to delete", "No row selected");
                return;
            }

            //Ask user to confirm action
            MessageBoxResult removeResult = MessageBox.Show("Remove selected object from database?",
                                                            "Remove",
                                                            MessageBoxButton.YesNo,
                                                            MessageBoxImage.Warning,
                                                            MessageBoxResult.No);

            if (removeResult == MessageBoxResult.Yes)
            {
                CarDealerManagementDBEntities context = new CarDealerManagementDBEntities();
                var result = from d in context.TB_TRANSACTIONS
                             where d.ID_TRANSACTION == this.updatingTransactionID
                             select d;

                TB_TRANSACTIONS obj = result.SingleOrDefault();

                if (obj != null)
                {
                    context.TB_TRANSACTIONS.Remove(obj);
                    context.SaveChanges();

                    ResetFieldValue(displayCarBox, displayClientBox, datepickerDisplayTransactionDate);
                    updatingTransactionID = null;
                    ReloadGrid();
                }
            }
        }
        /// <summary>
        /// Add record to the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddTransaction(object sender, RoutedEventArgs e)
        {
            CarDealerManagementDBEntities db = new CarDealerManagementDBEntities();

            //ComboBox SelectedIndex property counts from 0, so we add 1 to match ID
            TB_TRANSACTIONS transaction = new TB_TRANSACTIONS()
            {
                ID_CAR           = db.TB_CAR.Where(car => car.ID_CAR == this.comboboxCar.SelectedIndex + 1).Select(car => car.ID_CAR).FirstOrDefault(),
                ID_CLIENT        = db.TB_CLIENT.Where(client => client.ID_CLIENT == this.comboboxClient.SelectedIndex + 1).Select(client => client.ID_CLIENT).FirstOrDefault(),
                TRANSACTION_DATE = (DateTime)(this.datepickerTransaction.SelectedDate)
            };

            // Add new object to DB
            db.TB_TRANSACTIONS.Add(transaction);
            db.SaveChanges();

            ResetFieldValue(this.comboboxCar, this.comboboxClient, this.datepickerTransaction);
            ReloadGrid();
        }
Пример #3
0
        public TransactionManager(TB_TRANSACTIONS transaction)
        {
            //Build display format
            string clientBuilder = $"{transaction.TB_CLIENT.NAME}, " +
                                   $"{transaction.TB_CLIENT.SURNAME}, " +
                                   $"pesel: {transaction.TB_CLIENT.PESEL}, " +
                                   $"nip: {transaction.TB_CLIENT.NIP}, " +
                                   $"Address: {transaction.TB_CLIENT.TB_ADDRESS.STREET_NUMBER}," +
                                   $" {transaction.TB_CLIENT.TB_ADDRESS.CITY}," +
                                   $" {transaction.TB_CLIENT.TB_ADDRESS.ZIP_CODE}";
            //Build display format
            string carBuilder = $"{transaction.TB_CAR.TB_CAR_MODEL.CAR_MODEL}, " +
                                $"color: {transaction.TB_CAR.TB_CAR_COLOR.COLOR}, " +
                                $"condition: {transaction.TB_CAR.TB_CAR_CONDITION.CONDITION}, " +
                                $"country: {transaction.TB_CAR.TB_CAR_COUNTRY.COUNTRY}";

            this.ID = transaction.ID_TRANSACTION;

            this.Client            = clientBuilder;
            this.Car               = carBuilder;
            this.DateOfTransaction = transaction.TRANSACTION_DATE;
        }