Beispiel #1
0
        /// <summary>
        /// Delete row from database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteAddress(object sender, RoutedEventArgs e)
        {
            if (updatingAddressID == 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_ADDRESS
                             where d.ID_ADDRESS == this.updatingAddressID
                             select d;

                TB_ADDRESS obj = result.SingleOrDefault();

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

                    ResetFieldValue(textboxStreetUpdate, textboxCityUpdate, textboxZIPUpdate);
                    updatingAddressID = null;
                    ReloadGrid();
                }
            }
        }
Beispiel #2
0
 public AddressClass(TB_ADDRESS adres)
 {
     this.ID     = adres.ID_ADDRESS;
     this.Street = adres.STREET_NUMBER;
     this.City   = adres.CITY;
     this.ZIP    = adres.ZIP_CODE;
 }
Beispiel #3
0
        /// <summary>
        /// Add new record to database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddAddress(object sender, RoutedEventArgs e)
        {
            bool validation = InputDataValidator(textboxStreet, textboxCity, textboxZIP);

            if (validation)
            {
                CarDealerManagementDBEntities db = new CarDealerManagementDBEntities();

                TB_ADDRESS address = new TB_ADDRESS()
                {
                    STREET_NUMBER = this.textboxStreet.Text,
                    CITY          = this.textboxCity.Text,
                    ZIP_CODE      = this.textboxZIP.Text
                };

                // Add new object to DB
                db.TB_ADDRESS.Add(address);
                db.SaveChanges();

                ResetFieldValue(this.textboxStreet, this.textboxCity, this.textboxZIP);
                ReloadGrid();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Update a record in database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UpdateAddress(object sender, RoutedEventArgs e)
        {
            bool validation = InputDataValidator(textboxStreetUpdate, textboxCityUpdate, textboxZIPUpdate);

            if (validation)
            {
                CarDealerManagementDBEntities db = new CarDealerManagementDBEntities();

                if (updatingAddressID == null)
                {
                    ShowInformationMessageBox("Please select a row from the DataGrid to update", "Row not selected");
                    return;
                }
                var result = from r in db.TB_ADDRESS where r.ID_ADDRESS == this.updatingAddressID select r;

                TB_ADDRESS obj = result.SingleOrDefault();

                //Check for null
                if (obj != null)
                {
                    //dodać walidacje czy user wprowadza poprawne dane
                    var id = obj.ID_ADDRESS;
                    obj.STREET_NUMBER = this.textboxStreetUpdate.Text;
                    obj.CITY          = this.textboxCityUpdate.Text;
                    obj.ZIP_CODE      = this.textboxZIPUpdate.Text;

                    db.SaveChanges();

                    //Reset values
                    ResetFieldValue(this.textboxStreetUpdate, this.textboxCityUpdate, this.textboxZIPUpdate);
                    updatingAddressID = null;
                    ManageIsFieldEnabled(false, textboxStreetUpdate, textboxStreetUpdate, textboxZIPUpdate);
                    ReloadGrid();
                    ShowInformationMessageBox("Item successfully updated!", "Update");
                }
            }
        }