Пример #1
0
        private static void NotifyOnException(Exception e)
        {
            var exceptionLogger = _container.GetInstance <IExceptionLogger>();

            exceptionLogger.Log(e);

            NotifyMessageBox.ShowError($"Something went wrong.\r\n{e.Message}");
        }
Пример #2
0
        private async void submitOrderBtn_Click(object sender, EventArgs e)
        {
            var selectedProductBoxesAndQuantitiesHash = _productsQuantityHash
                                                        .Where(x => x.Key.SelectedValue != null)
                                                        .ToDictionary(x => x.Key, x => x.Value);

            if (!selectedProductBoxesAndQuantitiesHash.Any())
            {
                NotifyMessageBox.ShowWarning("No products selected.");
                return;
            }

            var selectedSupplierDto = suppliersComboBox.SelectedValue as SupplierDto;

            var products = new Dictionary <int, ProductDto>();

            foreach (var item in selectedProductBoxesAndQuantitiesHash)
            {
                int quantity;
                var parsed = int.TryParse(item.Value.Text, out quantity);
                if (!parsed || quantity < 1)
                {
                    NotifyMessageBox.ShowError("Quantity must be a whole positive number.");
                    return;
                }

                var currentProduct = item.Key.SelectedValue as ProductDto;
                if (!products.ContainsKey(currentProduct.Id))
                {
                    currentProduct.Quantity = quantity;
                    products.Add(currentProduct.Id, currentProduct);
                }
                else
                {
                    products[currentProduct.Id].Quantity += quantity;
                }
            }

            var totalPrice   = products.Sum(x => x.Value.Price * x.Value.Quantity);
            var confirmation = PromptMessage.ConfirmationMessage($"Are you sure you want to order? Your total price is: ${totalPrice}");

            if (!confirmation)
            {
                return;
            }

            await Presenter.PlaceOrder(
                Mapper.Map <CustomerModel>(Constants.Customer),
                selectedSupplierDto.Name,
                Mapper.Map <ProductModel[]>(products.Values.ToArray()));

            NotifyMessageBox.ShowSuccess("Order request sent.");
            ClearProductsQuantityAndPrice();
        }
Пример #3
0
        private void deleteCategory_Click(object sender, EventArgs e)
        {
            var result = Presenter.DeleteCategory(categoryComboBox.Text);

            if (!result.Valid)
            {
                NotifyMessageBox.ShowError(result.GetAllErrorMessages());
                return;
            }

            NotifyMessageBox.ShowSuccess("Category deleted");
            FillProductsAndCategoriesComboBoxes();
        }
Пример #4
0
        private void customerContinueBtn_Click(object sender, EventArgs e)
        {
            var loginValidationResult = Presenter.LoginCustomer(firstNameTextBox.Text, lastNameTextBox.Text);

            if (!loginValidationResult.Valid)
            {
                NotifyMessageBox.ShowError(loginValidationResult.GetAllErrorMessages());
                return;
            }

            ClearTextBoxes();

            _viewService.ShowView <ICategoriesView>(this);
        }
Пример #5
0
        private void adminLoginButton_Click(object sender, EventArgs e)
        {
            var loginValidationResult = Presenter.LoginAdministrator(identificationNumberBox.Text);

            if (!loginValidationResult.Valid)
            {
                NotifyMessageBox.ShowError(loginValidationResult.GetAllErrorMessages());
                return;
            }

            ClearTextBoxes();

            _viewService.ShowView <IAdminManagerView>(this);
        }
Пример #6
0
        private void saveProductQuantityBtn_Click(object sender, EventArgs e)
        {
            var result = Presenter.SaveProductQuantity(productInsertStock.Text, productQuantityToAdd.Text);

            if (!result.Valid)
            {
                NotifyMessageBox.ShowError(result.GetAllErrorMessages());
                return;
            }

            NotifyMessageBox.ShowSuccess("Record successfully added");
            productInsertStock.Text   = string.Empty;
            productQuantityToAdd.Text = string.Empty;
            FillProductsAndCategoriesComboBoxes();
        }
Пример #7
0
        private void addToCartBtn_Click(object sender, EventArgs e)
        {
            var result = Presenter.AddProductToCart(productsList.SelectedValue.ToString(), productQuantityBox.Text);

            if (!result.Valid)
            {
                NotifyMessageBox.ShowError(result.GetAllErrorMessages());
                return;
            }

            productQuantityBox.Clear();

            // result.Object should hold the current quantity of product: the count of the product minus the count in the session
            onStock.Text = result.Object.ToString();
        }
Пример #8
0
        private void saveCategoryButton_Click(object sender, EventArgs e)
        {
            var result = Presenter.AddNewCategory(categoryNameBox.Text, _categoryImage);

            if (!result.Valid)
            {
                NotifyMessageBox.ShowError(result.GetAllErrorMessages());
                return;
            }

            NotifyMessageBox.ShowSuccess("Record successfully added");
            categoryNameBox.Text            = string.Empty;
            _categoryImage                  = null;
            categoryImageSelectedLabel.Text = "No image selected...";
            FillProductsAndCategoriesComboBoxes();
        }
Пример #9
0
        private void choosePictureButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    var file = openFileDialog.FileName;

                    _categoryImage = _imageUtil.ConvertImageToByteArray(file);

                    var fileName = openFileDialog.SafeFileName;
                    categoryImageSelectedLabel.Text = fileName;
                }
                catch (Exception ex)
                {
                    NotifyMessageBox.ShowError("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Пример #10
0
        private void productSave_Click(object sender, EventArgs e)
        {
            var result = Presenter.AddNewProduct(productPriceBox.Text,
                                                 productNameBox.Text,
                                                 productCategoryComboBox.Text,
                                                 _productImage);

            if (!result.Valid)
            {
                NotifyMessageBox.ShowError(result.GetAllErrorMessages());
                return;
            }

            NotifyMessageBox.ShowSuccess("Record successfully added");
            productNameBox.Text          = string.Empty;
            productPriceBox.Text         = string.Empty;
            productCategoryComboBox.Text = string.Empty;
            _productImage = null;
            imageSelectedLabelProduct.Text = "No image selected...";
            FillProductsAndCategoriesComboBoxes();
        }
Пример #11
0
        private void minusButton_Click(object sender, EventArgs e)
        {
            var rowsSelected = productsGridView.SelectedRows;

            if (rowsSelected.Count != 1)
            {
                NotifyMessageBox.ShowWarning("Only 1 row can be edited!");
                return;
            }

            var result = Presenter.PerformProdcutQuantityChange(GetSelectedRowProductId(), Constants.MINUS_OPERATION);

            if (!result.Valid)
            {
                NotifyMessageBox.ShowWarning(result.GetAllErrorMessages());
                return;
            }

            var product = result.Object as Product;

            LoadDatagridView();
        }
Пример #12
0
        private async void closeOrderButton_Click(object sender, EventArgs e)
        {
            var selectedOrder = ordersGridView.SelectedRows[0].DataBoundItem as OrderDto;

            if (selectedOrder == null)
            {
                NotifyMessageBox.ShowError("No orders selected.");
                return;
            }

            var result = PromptMessage.ConfirmationMessage("Are you sure you want to close this order");

            if (!result)
            {
                return;
            }

            await _orderService.CloseOrderAsync(selectedOrder.OrderId);

            NotifyMessageBox.ShowSuccess("Order close successfully.");
            InitializeOrdersGridView();
        }