示例#1
0
        private async Task LoadSettingsAsync()
        {
            Spinner.InitSpinner();

            _appSettings = await AppServices.AppSettingsService.GetAppSettingsAsync();

            // Populate the export documents folder combo
            DocumentsFolder documentFolder = AppConstants.DocumentsFolders
                                             .FirstOrDefault(x => x.Code == _appSettings.DocumentsFolder);

            cbDocumentsFolder.DataSource    = AppConstants.DocumentsFolders;
            cbDocumentsFolder.ValueMember   = "Code";
            cbDocumentsFolder.DisplayMember = "Name";
            cbDocumentsFolder.SelectedItem  = documentFolder;
            lbDocumentsFolderPath.Text      = $"*{documentFolder.Path}";

            // Populate the language combo
            cbLanguage.DataSource    = AppConstants.AppLanguages;
            cbLanguage.ValueMember   = "Code";
            cbLanguage.DisplayMember = "Name";
            cbLanguage.SelectedItem  = AppConstants.AppLanguages.FirstOrDefault(x => x.Code == _appSettings.Language);

            // Global default min stock
            numDefaultGlobalMinStock.Value = ( decimal )_appSettings.DefaultGlobalMinStock;

            Spinner.StopSpinner();
        }
        /// <summary>
        /// Update button click
        /// </summary>
        private async void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Spinner.InitSpinner();

                await AppServices.ProductLocationService.UpdateMinStock(
                    _productLocation.ProductLocationId,
                    float.Parse(numMinStock.Value.ToString())
                    );

                Spinner.StopSpinner();

                _inventoryProductLocationsUc.LoadProductLocations();

                Close();
            }
            catch (OperationErrorException ex)
            {
                Spinner.StopSpinner();

                MessageBox.Show(
                    $"{ex.Errors[0].Error}",
                    Phrases.GlobalDialogWarningTitle,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                    );
            }
        }
示例#3
0
        /// <summary>
        /// Fill the Data Grid View
        /// </summary>
        public async Task LoadProductsAsync()
        {
            Spinner.InitSpinner();
            dgvProducts.Rows.Clear();

            IEnumerable <Product> products = await AppServices
                                             .ProductService.GetAllAsync(new ProductOptions()
            {
                SearchValue = tbSeachText.Text
            });

            _products = products;

            products.ToList().ForEach((product) => {
                dgvProducts.Rows.Add(
                    product.ProductId,
                    product.Reference,
                    product.Name,
                    product.Stock,
                    product.CreatedAt.ShortDateWithTime()
                    );
            });

            Spinner.StopSpinner();
        }
示例#4
0
        private async void btnCreatePdf_Click(object sender, System.EventArgs e)
        {
            try
            {
                if (!_notifications.Any())
                {
                    MessageBox.Show(Phrases.GlobalDialogExportWarningBody, Phrases.GlobalDialogWarningTitle,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (MessageBox.Show(Phrases.GlobalDialogExportBody, Phrases.GlobalDialogExportTitle,
                                         MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Spinner.InitSpinner();

                    await AppServices.NotificationService.ExportNotificationsToPDFAsync(_notifications);

                    Spinner.StopSpinner();
                }
            }
            catch (ServiceErrorException ex)
            {
                Spinner.StopSpinner();

                MessageBox.Show($"{ex.Errors[0].Error}", Phrases.GlobalDialogErrorTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#5
0
        public async Task LoadDataAsync()
        {
            Spinner.InitSpinner();
            dgvProductStockAlerts.Rows.Clear();

            int locationsCount = await AppServices.LocationService.CountAsync();

            int productsCount = await AppServices.ProductService.CountAsync();

            int usersCount = await AppServices.UserService.CountAsync();

            lbLocationsCount.Text = locationsCount.ToString();
            lbProductsCount.Text  = productsCount.ToString();
            lbUsersCount.Text     = usersCount.ToString();

            IEnumerable <Notification> notifications = await AppServices.NotificationService.GetAllAsync();

            _notifications = notifications;

            notifications?.ToList().ForEach(notification => dgvProductStockAlerts.Rows.Add(
                                                notification.CreatedAt.ShortDateWithTime(),
                                                notification.ProductLocation?.Product?.Reference,
                                                notification.ProductLocation?.Product?.Name,
                                                notification.ProductLocation?.Location?.Name,
                                                notification.ProductLocation?.MinStock,
                                                notification.ProductLocation?.Stock
                                                ));

            Spinner.StopSpinner();
        }
示例#6
0
        /// <summary>
        /// Show User Form and set the initial values
        /// </summary>
        public async Task ShowUserFormAsync(User user = null)
        {
            Spinner.InitSpinner();

            // Set the userId. Means that is a edit
            _userId = (user != null) ? user.UserId : 0;

            // Set the Form title
            Text = (_userId != 0)
              ? AppConstants.GetViewTitle(Phrases.UserEditUser)
              : AppConstants.GetViewTitle(Phrases.UserCreateNewUser);

            // hide the error labels
            lbErrorUsername.Visible = false;
            lbErrorPassword.Visible = false;

            // Populate the combo box
            IEnumerable <Role> roles = await AppServices.RoleService.GetAllAsync();

            cbRoles.DataSource    = roles;
            cbRoles.ValueMember   = "RoleId";
            cbRoles.DisplayMember = "Code";

            // Edit
            if (user != null)
            {
                tbUsername.Text      = user.Username;
                cbRoles.SelectedItem = roles.First(x => x.RoleId == user.RoleId);
                cbRoles.Enabled      = (user.UserId == Program.LoggedInUser.UserId) ? false : true;
            }

            Spinner.StopSpinner();
            ShowDialog();
        }
示例#7
0
        public async Task LoadDataAsync()
        {
            Spinner.InitSpinner();

            dgvMovements.Rows.Clear();

            IEnumerable <StockMovement> movements = await AppServices
                                                    .StockMovementService.GetAllAsync(GetOptions());

            _movements = movements;

            movements.ToList().ForEach((stockMovement) => {
                dgvMovements.Rows.Add(
                    stockMovement.StockMovementId,
                    stockMovement.CreatedAt.ShortDateWithTime(),
                    stockMovement.User?.Username,
                    stockMovement.Product?.Reference,
                    stockMovement.Product?.Name,
                    stockMovement.ConcatMovementString(),
                    stockMovement.Qty,
                    stockMovement.Stock
                    );
            });

            Spinner.StopSpinner();
        }
示例#8
0
        private async void btnCreatePdf_Click(object sender, EventArgs e)
        {
            try
            {
                if (!_movements.Any())
                {
                    MessageBox.Show(Phrases.GlobalDialogExportWarningBody, Phrases.GlobalDialogWarningTitle,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (MessageBox.Show(Phrases.GlobalDialogExportBody, Phrases.GlobalDialogExportTitle,
                                         MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Spinner.InitSpinner();

                    await AppServices.StockMovementService.ExportStockMovementsToPDFAsync(
                        new ExportData <IEnumerable <StockMovement>, StockMovementOptions>(_movements, GetOptions()));

                    Spinner.StopSpinner();
                }
            }
            catch (ServiceErrorException ex)
            {
                Spinner.StopSpinner();

                MessageBox.Show($"{ex.Errors[0].Error}", Phrases.GlobalDialogErrorTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#9
0
        /// <summary>
        /// Show User Form and set the initial values
        /// </summary>
        public void ShowProductForm(Product product = null)
        {
            Spinner.InitSpinner();

            // Set the productId. Means that is a edit
            _productId = (product != null) ? product.ProductId : 0;

            // Set the Form title
            Text = (_productId != 0)
              ? AppConstants.GetViewTitle(Phrases.ProductEdit)
              : AppConstants.GetViewTitle(Phrases.ProductCreateNewProduct);

            // hide the error labels
            lbErrorReference.Visible = false;
            lbErrorName.Visible      = false;

            // Edit
            if (product != null)
            {
                tbReference.Text = product.Reference;
                tbName.Text      = product.Name;
            }

            Spinner.StopSpinner();
            ShowDialog();
        }
示例#10
0
        /// <summary>
        /// Show the product locations UC
        /// </summary>
        private async Task ActionDetailsClickAsync(int productId)
        {
            Spinner.InitSpinner();
            Product product = await AppServices.ProductService.GetByIdAsync(productId);

            Spinner.StopSpinner();

            _mainForm.ShowProducLocationsFromProductsUc(product);
        }
示例#11
0
        /// <summary>
        /// Show the location products UC
        /// </summary>
        private async Task ActionDetailsClickAsync(int locationId)
        {
            Spinner.InitSpinner();
            Location location = await AppServices.LocationService.GetByIdAsync(locationId);

            Spinner.StopSpinner();

            _mainForm.ShowProducLocationsFromLocationsUc(location);
        }
示例#12
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Spinner.InitSpinner();

                AppSettings appSettings = new AppSettings
                {
                    AppSettingsId         = _appSettings.AppSettingsId,
                    DocumentsFolder       = cbDocumentsFolder.SelectedValue.ToString(),
                    Language              = cbLanguage.SelectedValue.ToString(),
                    DefaultGlobalMinStock = float.Parse(numDefaultGlobalMinStock.Value.ToString())
                };

                await AppServices.AppSettingsService.UpdateAppSettingsAsync(appSettings);

                Spinner.StopSpinner();

                if (_flagIsRestartRequired)
                {
                    // Show msg box to the user asking if he want to restart de app for the changes take effect
                    if (MessageBox.Show(
                            Phrases.AppSettingsDialogRestartBody,
                            Phrases.AppSettingsDialogRestartTitle,
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Question) == DialogResult.Yes
                        )
                    {
                        Application.Restart();
                        Environment.Exit(0);
                    }
                }

                // Reload the settings
                await LoadSettingsAsync();

                // Show success msg box
                MessageBox.Show(
                    Phrases.AppSettingsDialogSuccessBody,
                    Phrases.AppSettingsDialogSuccessTitle,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information
                    );
            }
            catch (ServiceErrorException ex)
            {
                Spinner.StopSpinner();

                MessageBox.Show(
                    $"{ex.Errors[0].Error}",
                    Phrases.GlobalDialogErrorTitle,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
            }
        }
示例#13
0
        /// <summary>
        /// Edit product button click
        /// </summary>
        private async Task ActionEditClickAsync(int userId)
        {
            Spinner.InitSpinner();
            User user = await AppServices.UserService.GetByIdAsync(userId);

            Spinner.StopSpinner();

            UserForm userForm = new UserForm(this);
            await userForm.ShowUserFormAsync(user);
        }
        private async Task ActionEditClickAsync(int id)
        {
            Spinner.InitSpinner();

            ProductLocation productLocation = await AppServices.ProductLocationService.GetByIdAsync(id);

            Spinner.StopSpinner();
            ProductLocationForm productLocationForm = new ProductLocationForm(this);

            productLocationForm.ShowLocationForm(productLocation);
        }
示例#15
0
        /// <summary>
        /// Edit product button click
        /// </summary>
        private async Task ActionEditClickAsync(int productId)
        {
            Spinner.InitSpinner();
            Product product = await AppServices.ProductService.GetByIdAsync(productId);

            Spinner.StopSpinner();

            ProductForm productForm = new ProductForm(this);

            productForm.ShowProductForm(product);
        }
示例#16
0
        /// <summary>
        /// Edit product button click
        /// </summary>
        private async Task ActionEditClickAsync(int locationId)
        {
            Spinner.InitSpinner();
            Location location = await AppServices.LocationService.GetByIdAsync(locationId);

            Spinner.StopSpinner();

            LocationForm locationForm = new LocationForm(this);

            locationForm.ShowLocationForm(location);
        }
示例#17
0
        private async void cbLocations_SelectionChangeCommitted(object sender, EventArgs e)
        {
            Location location = ( Location )cbLocations.SelectedItem;

            if (location != null)
            {
                Spinner.InitSpinner();
                await LoadProductsTableDataAsync(location.LocationId);

                Spinner.StopSpinner();
            }
        }
示例#18
0
        private async Task LoadDataAsync()
        {
            Spinner.InitSpinner();

            IEnumerable <Location> locations = await AppServices.LocationService.GetAllAsync();

            List <Location> filteredLocations = locations.Where(x => !x.IsMain).ToList();

            cbLocations.DataSource    = filteredLocations;
            cbLocations.ValueMember   = "LocationId";
            cbLocations.DisplayMember = "Name";

            await LoadProductsTableDataAsync(filteredLocations.ElementAt(0).LocationId);

            Spinner.StopSpinner();
        }
示例#19
0
        public async Task ShowManualStockMovementFormAsync()
        {
            Text = AppConstants.GetViewTitle(Phrases.StockMovementCreate);

            // hide the error labels
            lbErrorQty.Visible = false;

            Spinner.InitSpinner();

            // Get the locations
            _locations = await AppServices.LocationService.GetAllAsync();

            SetFormComboboxesData();

            Spinner.StopSpinner();
            ShowDialog();
        }
        /// <summary>
        /// Fill the UC content
        /// </summary>
        public void LoadProductLocations()
        {
            Spinner.InitSpinner();

            dgvProductLocations.Rows.Clear();

            if (_product != null)
            {
                LoadDataByProduct();
            }
            else if (_location != null)
            {
                LoadDataByLocation();
            }

            Spinner.StopSpinner();
        }
示例#21
0
        private async void btnSave_Click(object sender, System.EventArgs e)
        {
            try
            {
                Spinner.InitSpinner();

                float currentStock = float.Parse(numCurrentStock.Value.ToString());
                float refilledQty  = float.Parse(numRefillQty.Value.ToString());

                await AppServices.StockMovementService.RefillStockAsync(
                    _locationId,
                    _productId,
                    currentStock,
                    refilledQty,
                    Program.LoggedInUser.UserId
                    );

                Spinner.StopSpinner();

                // Update the table with the new data
                await _dashboardUc.UpdateTable(refilledQty);

                // Close the dialog
                btnCancel_Click(sender, e);
            }
            catch (OperationErrorException ex)
            {
                Spinner.StopSpinner();

                if (ex.Errors.Any())
                {
                    ShowFormErrors(ex.Errors);
                }
            }
            catch (ServiceErrorException ex)
            {
                Spinner.StopSpinner();

                MessageBox.Show(
                    $"{ex.Errors[0].Error}",
                    Phrases.GlobalDialogErrorTitle,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
            }
        }
        private async Task ActionDeleteClickAsync(int id)
        {
            if ((id > 0) && MessageBox.Show(
                    Phrases.GlobalDialogDeleteProductLocationBody,
                    Phrases.GlobalDialogDeleteTitle,
                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes
                )
            {
                try
                {
                    Spinner.InitSpinner();

                    await AppServices.ProductLocationService
                    .DeleteAsyn(id, Program.LoggedInUser.UserId);

                    // Reload Ui
                    LoadProductLocations();

                    Spinner.StopSpinner();
                }
                catch (OperationErrorException ex)
                {
                    Spinner.StopSpinner();

                    MessageBox.Show(
                        $"{ex.Errors[0].Error}",
                        Phrases.GlobalDialogWarningTitle,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning
                        );
                }
                catch (ServiceErrorException ex)
                {
                    Spinner.StopSpinner();

                    MessageBox.Show(
                        $"{ex.Errors[0].Error}",
                        Phrases.GlobalDialogErrorTitle,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error
                        );
                }
            }
        }
示例#23
0
        /// <summary>
        /// Delete button click
        /// </summary>
        private async Task ActionDeleteClickAsync(int[] selectedIds)
        {
            if ((selectedIds.Length > 0) && MessageBox.Show(
                    string.Format(Phrases.LocationDialogDeleteBody, selectedIds.Length),
                    Phrases.GlobalDialogDeleteTitle,
                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes
                )
            {
                try
                {
                    Spinner.InitSpinner();

                    await AppServices.LocationService
                    .DeleteAsync(selectedIds, Program.LoggedInUser.UserId);

                    Spinner.StopSpinner();

                    await LoadLocationsAsync();
                }
                catch (OperationErrorException ex)
                {
                    Spinner.StopSpinner();

                    MessageBox.Show(
                        $"{ex.Errors[0].Error}",
                        Phrases.GlobalDialogWarningTitle,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning
                        );
                }
                catch (ServiceErrorException ex)
                {
                    Spinner.StopSpinner();

                    MessageBox.Show(
                        $"{ex.Errors[0].Error}",
                        Phrases.GlobalDialogErrorTitle,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error
                        );
                }
            }
        }
示例#24
0
        /// <summary>
        /// Login button click
        /// </summary>
        private async void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                Spinner.InitSpinner();

                User user = await AppServices.UserService
                            .AuthenticateAsync(tbUsername.Text, tbPassword.Text);

                Spinner.StopSpinner();

                Program.SetLoggedInUser(user);
                _mainForm.SetUi();
            }
            catch (OperationErrorException ex)
            {
                SetFormErrors(ex.Errors);
            }
        }
示例#25
0
        private void checkMainLocationMoves_Click(object sender, EventArgs e)
        {
            Spinner.InitSpinner();

            if (checkMainLocationMoves.Checked)
            {
                lbFrom.Text = Phrases.GlobalMainLocation;
                lbTo.Text   = Phrases.GlobalMovement;

                // Get the main location
                Location mainLocation = _locations.First(x => x.IsMain == true);
                cbFrom.SelectedItem = mainLocation;

                List <Location> entryExitMovements = new List <Location>
                {
                    new Location()
                    {
                        LocationId = 0, Name = Phrases.GlobalMovementEntry
                    },
                    new Location()
                    {
                        LocationId = -1, Name = Phrases.GlobalMovementExit
                    }
                };

                //cbTo.BindingContext = new BindingContext();
                cbTo.DataSource = entryExitMovements;

                SetProductComboboxData(mainLocation);
            }
            else
            {
                lbFrom.Text = Phrases.StockMovementFrom;
                lbTo.Text   = Phrases.StockMovementTo;

                SetFormComboboxesData();
            }

            cbFrom.Enabled = !checkMainLocationMoves.Checked;

            Spinner.StopSpinner();
        }
示例#26
0
        /// <summary>
        /// Fill the Data Grid View
        /// </summary>
        public async Task LoadUsersAsync(string searchValue = null)
        {
            Spinner.InitSpinner();
            dgvUsers.Rows.Clear();

            IEnumerable <User> users = await AppServices.UserService.GetAllAsync(searchValue);

            foreach (User user in users)
            {
                dgvUsers.Rows.Add(
                    user.UserId,
                    user.Username,
                    user.Role.Code,
                    user.LastLogin.ShortDateWithTime(),
                    user.CreatedAt.ShortDateWithTime()
                    );
            }

            Spinner.StopSpinner();
        }
示例#27
0
        /// <summary>
        /// Fill the Data Grid View
        /// </summary>
        public async Task LoadLocationsAsync(string searchValue = null)
        {
            Spinner.InitSpinner();
            ;
            dgvLocations.Rows.Clear();

            IEnumerable <Location> locations = await AppServices.LocationService
                                               .GetAllAsync(searchValue);

            foreach (Location location in locations)
            {
                dgvLocations.Rows.Add(
                    location.LocationId,
                    location.Name,
                    location.ProductLocations.Count,
                    location.CreatedAt.ShortDateWithTime()
                    );
            }

            Spinner.StopSpinner();
        }
        /// <summary>
        /// Update button click
        /// </summary>
        private async void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Spinner.InitSpinner();

                await AppServices.UserService.ChangePasswordAsync(
                    Program.LoggedInUser.UserId,
                    tbCurrentPassword.Text,
                    tbNewPassword.Text
                    );

                Spinner.StopSpinner();
                btnCancel_Click(sender, e);
            }
            catch (OperationErrorException ex)
            {
                Spinner.StopSpinner();
                SetFormErrors(ex.Errors);
            }
        }
        private async void btnCreatePdf_Click(object sender, EventArgs e)
        {
            try
            {
                ICollection <ProductLocation> productLocations = (_product != null)
                    ? _product?.ProductLocations
                    : _location?.ProductLocations;

                if (!productLocations.Any())
                {
                    MessageBox.Show(Phrases.GlobalDialogExportWarningBody, Phrases.GlobalDialogWarningTitle,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (MessageBox.Show(Phrases.GlobalDialogExportBody, Phrases.GlobalDialogExportTitle,
                                         MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Spinner.InitSpinner();

                    if (_location != null)
                    {
                        await AppServices.ProductLocationService
                        .ExportProductLocationsFromLocationToPDFAsync(productLocations);
                    }
                    else
                    {
                        await AppServices.ProductLocationService
                        .ExportProductLocationsFromProductToPDFAsync(productLocations);
                    }

                    Spinner.StopSpinner();
                }
            }
            catch (ServiceErrorException ex)
            {
                Spinner.StopSpinner();

                MessageBox.Show($"{ex.Errors[0].Error}", Phrases.GlobalDialogErrorTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#30
0
        /// <summary>
        /// Create/Update button click
        /// </summary>
        private async void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                User user = new User
                {
                    Username = tbUsername.Text,
                    Password = tbPassword.Text,
                    RoleId   = int.Parse(cbRoles.SelectedValue.ToString())
                };

                Spinner.InitSpinner();

                if ((_userId != 0))
                {
                    user.UserId = _userId;
                    await AppServices.UserService.EditAsync(user);
                }
                else
                {
                    await AppServices.UserService.CreateAsync(user);
                }

                Spinner.StopSpinner();

                await _usersUserControl.LoadUsersAsync();

                Close();
            }
            catch (OperationErrorException ex)
            {
                Spinner.StopSpinner();

                if (ex.Errors.Any())
                {
                    ShowFormErrors(ex.Errors);
                }
            }
        }