コード例 #1
0
        protected override void EditItem(BaseRowViewerViewModel viewModel)
        {
            var categoryRowViewerViewModel = viewModel as CategoryRowViewerViewModel;

            if (categoryRowViewerViewModel.IsEditable)
            {
                // Validate
                if (string.IsNullOrEmpty(categoryRowViewerViewModel.EditedName) ||
                    string.IsNullOrWhiteSpace(categoryRowViewerViewModel.EditedName))
                {
                    MessageBox.Show("Category must have a name", "Invalid data", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                // Edit
                categoryRowViewerViewModel.Name = categoryRowViewerViewModel.EditedName;
                Category category = new Category(categoryRowViewerViewModel.ID, categoryRowViewerViewModel.Name);
                categoryRowViewerViewModel.IsEditable = false;
                category.Edit();

                ApplicationDirector.UpdateCategories();
            }
            else
            {
                categoryRowViewerViewModel.IsEditable = true;
            }
        }
コード例 #2
0
        /// <summary>
        /// Attempts to add a new category to the database
        /// </summary>
        private void AddCategory()
        {
            // Validate data
            if (Category_ID == 0L || Category_ID == null)
            {
                MessageBox.Show("Category ID shouldn't be zero", "Invalid data", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (string.IsNullOrEmpty(CategoryName) || string.IsNullOrWhiteSpace(CategoryName))
            {
                MessageBox.Show("Category must have a name", "Invalid data", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Category category = new Category(Category_ID.Value, CategoryName);

            if (category.Add())
            {
                MessageBox.Show("Category was added", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                NotifyObservers();
                Category_ID  = null;
                CategoryName = null;
            }
            else
            {
                MessageBox.Show("There is already a category with the same ID", "Information", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            ApplicationDirector.UpdateCategories();
        }
コード例 #3
0
        /// <summary>
        /// Deletes the specified item from the list
        /// </summary>
        /// <param name="viewModel">The view model of the item to delete</param>
        protected override void DeleteItem(BaseRowViewerViewModel viewModel)
        {
            // Delete from the items list
            Items.Remove(viewModel);

            // Delete from the database
            SqlParameter[] sqlParameters = new SqlParameter[1];
            sqlParameters[0]       = new SqlParameter("@Category_ID", SqlDbType.Int);
            sqlParameters[0].Value = ((CategoryRowViewerViewModel)viewModel).ID;

            DataConnection.ExcuteCommand("Delete_Category_Procedure", sqlParameters);

            ApplicationDirector.UpdateCategories();
        }