Beispiel #1
0
        private void btnAdjust_Click(object sender, EventArgs e)
        {
            if (dgvProducts1.Rows.Count == 0)
            {
                return;
            }

            ProductLocationService   locService    = new ProductLocationService();
            ProductAdjustmentService adjustServcie = new ProductAdjustmentService();
            ProductLocation          productLocation;
            ProductAdjustment        productAdjustment;

            try
            {
                for (int i = 0; i < dgvProducts1.Rows.Count; i++)
                {
                    productAdjustment = new ProductAdjustment();
                    productLocation   = new ProductLocation();

                    int prodLocID  = dgvProducts1.Rows[i].Cells["colProdLocID"].Value.ToInt();
                    int newqty     = dgvProducts1.Rows[i].Cells["colNewQty"].Value.ToInt();
                    int productID  = dgvProducts1.Rows[i].Cells["colProductID"].Value.ToInt();
                    int locationID = dgvProducts1.Rows[i].Cells["colLocationID"].Value.ToInt();
                    int currqty    = dgvProducts1.Rows[i].Cells["colCurrentQty"].Value.ToInt();
                    int diff       = dgvProducts1.Rows[i].Cells["colDifference"].Value.ToInt();

                    diff = diff < 0 ? diff * -1 : diff;

                    productLocation = locService.GetSingle(new ProductLocation {
                        Id = prodLocID
                    });
                    productLocation.Quantity = newqty;
                    productLocation.Id       = productLocation.Id;

                    locService.Update(productLocation);

                    adjustServcie.Add(new ProductAdjustment
                    {
                        ProductLocationID = prodLocID,
                        NewQty            = newqty,
                        ProductID         = productID,
                        LocationID        = locationID,
                        CurrentQty        = currqty,
                        Difference        = diff,
                        Remarks           = txtRemarks.Text,
                        AdjustmentDate    = DateTime.Now,
                        EmployeeID        = CurrentUser.User.EmployeeID
                    });
                }

                Helper.ShowMessage("Operation completed successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                dgvProducts1.Rows.Clear();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "An error occurred", "ucAdjustStock", "btnAdjustStock");
                Helper.ShowMessage("An error occured " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
 public static void ConfigureServices(IAppRepository repository)
 {
     // Instantiate our services
     AppSettingsService     = new AppSettingsService(repository);
     LocationService        = new LocationService(repository);
     NotificationService    = new NotificationService(repository);
     ProductLocationService = new ProductLocationService(repository);
     ProductService         = new ProductService(repository);
     RoleService            = new RoleService(repository);
     StockMovementService   = new StockMovementService(repository);
     UserService            = new UserService(repository);
 }
        public ucNewProduct()
        {
            InitializeComponent();
            InitEvents();

            PopulateCombo();
            LoadMeasurementCmb();

            _pruduct  = new ProductService();
            _prodLoc  = new ProductLocationService();
            _supplier = new SupplierService();
            _logger   = new ErrorLogService();

            lblRemoveimg.Visible = false;

            SetUpDefaults();
        }
Beispiel #4
0
        void AddProductsToGrid(List <Product> products)
        {
            try
            {
                ProductLocationService service = new ProductLocationService();
                Product  product;
                Location location = new Location();
                //ProductLocation prodLoc;

                foreach (Product item in products)
                {
                    IEnumerable <ProductLocation> locations = service.FindAll("ProductID = " + item.ProductID);

                    if (locations.Count() > 1)
                    {
                        foreach (var itm in locations)
                        {
                            product  = new Product();
                            product  = new ProductService().FindByID(itm.ProductID);
                            location = new LocationService().GetSingle(new Location {
                                Id = itm.LocationID
                            });

                            dgvProducts1.Rows.Add(product.ProductName, location.Name, itm.Quantity, 0, 0, product.ProductID, location.Id, itm.Id);
                        }

                        continue;
                    }

                    int    locationID   = locations.First().LocationID;
                    string locationName = new LocationService().GetSingle(new Location {
                        Id = locationID
                    }).Name;
                    string quantity = locations.First().Quantity.ToString();

                    dgvProducts1.Rows.Add(item.ProductName, locationName, quantity, 0, 0, item.ProductID, locationID, locations.First().Id);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "An error occurred", "ucAdjustStock", "AddProductsToGrid");
                Helper.ShowMessage("An error occured " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnTransfer_Click(object sender, EventArgs e)
        {
            if (dgvProductList.Rows.Count == 0)
            {
                return;
            }

            try
            {
                foreach (DataGridViewRow row in dgvProductList.Rows)
                {
                    string fromLoc = row.Cells["colFromLocation"] == null ? string.Empty : row.Cells["colFromLocation"].Value.ToString();
                    string toLoc   = row.Cells["colToLocation"].Value == null ? string.Empty : row.Cells["colToLocation"].Value.ToString();


                    if (fromLoc == toLoc)
                    {
                        row.DefaultCellStyle.BackColor = Color.Tomato;
                        Helper.ShowMessage("Stock cannot be tranfered to the same location",
                                           "Illegal Operation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                        return;
                    }
                    else
                    {
                        row.DefaultCellStyle.BackColor = Color.White;
                    }

                    if (string.IsNullOrEmpty(fromLoc) || string.IsNullOrEmpty(toLoc))
                    {
                        row.DefaultCellStyle.BackColor = Color.Tomato;
                        Helper.ShowMessage("Verify and set all locations involved in the current tranfer",
                                           "Illegal Operation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                        return;
                    }
                    else
                    {
                        row.DefaultCellStyle.BackColor = Color.White;
                    }

                    if (row.Cells["colProductID"].Value == null)
                    {
                        row.DefaultCellStyle.BackColor = Color.Tomato;
                        Helper.ShowMessage("Make sure a valid product is selected",
                                           "Illegal Operation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                        return;
                    }
                    else
                    {
                        row.DefaultCellStyle.BackColor = Color.White;
                    }

                    int oldqty     = row.Cells["colCurrQty"].Value == null ? 0 : row.Cells["colCurrQty"].Value.ToInt();
                    int currentqty = row.Cells["colQuantity"].Value.ToInt();
                    int productID  = row.Cells["colProductID"].Value.ToInt();

                    int newqty = oldqty - currentqty;

                    if (newqty < 0)
                    {
                        row.DefaultCellStyle.BackColor = Color.Tomato;
                        Helper.ShowMessage("Cannot transfer more stock than is currently at location",
                                           "Illegal Operation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                        return;
                    }
                    else
                    {
                        row.DefaultCellStyle.BackColor = Color.White;
                    }

                    ProductLocation prodloc = new ProductLocationService().GetSingle(new ProductLocation {
                        LocationID = toLoc.ToInt(), ProductID = productID
                    });

                    int fromLocQtyBeforeTransfer = 0;
                    int ToLocQtyBeforeTransfer   = 0;

                    if (prodloc != null)
                    {
                        fromLocQtyBeforeTransfer = prodloc.Quantity;
                        ToLocQtyBeforeTransfer   = prodloc == null ? 0 : prodloc.Quantity;

                        _productService.AddInventory(currentqty, productID, toLoc.ToInt());
                    }
                    else
                    {
                        new ProductLocationService().Add(new ProductLocation
                        {
                            ProductID  = productID,
                            LocationID = toLoc.ToInt(),
                            Quantity   = currentqty
                        });
                    }

                    _productService.ReduceInventory(currentqty, productID, fromLoc.ToInt());


                    new StockTranferService().Add(new StockTranfer
                    {
                        FromLocationID = fromLoc.ToInt(),
                        FromLocationQtyAfterTransfer = (fromLocQtyBeforeTransfer - currentqty),
                        FromLocationQtyBeforeTranfer = fromLocQtyBeforeTransfer,
                        ProductID = productID,
                        ToLocationAfterTranfer   = (ToLocQtyBeforeTransfer + currentqty),
                        ToLocationBeforeTransfer = ToLocQtyBeforeTransfer,
                        ToLocationID             = toLoc.ToInt(),
                        TransferDate             = DateTime.Now,
                        TransferQty = currentqty,
                        UserID      = 0
                    });
                }

                Helper.ShowMessage("Stock tranfer was completed succesfully ", "Tranfer Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
                UpdateRow = false;
                dgvProductList.Rows.Clear();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "An error occurred", "ucTransferStock", "btnTransfer_Click");
                Helper.ShowMessage("An error occured " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }