public Error InsertOrUpdateProductLocation(ProductLocationModel productLocation, UserModel user, string lockGuid) { Error error = ValidateModel(productLocation); if (!error.IsError) { // Check that the lock is still current if (!db.IsLockStillValid(typeof(ProductLocation).ToString(), productLocation.Id, lockGuid)) { error.SetError(EvolutionResources.errRecordChangedByAnotherUser, "LocationId"); } else { ProductLocation temp = null; if (productLocation.Id != 0) { temp = db.FindProductLocation(productLocation.Id); } if (temp == null) { temp = new ProductLocation(); } Mapper.Map <ProductLocationModel, ProductLocation>(productLocation, temp); db.InsertOrUpdateProductLocation(temp); productLocation.Id = temp.Id; } } return(error); }
/// <summary> /// Update the amount of stock shown as on_hand /// </summary> /// <param name="Product_Code">Value used to look up the item in the database</param> /// <param name="newStockLevel"></param> public void ModifyItemStock(int newStockLevel) { this.On_Hand = newStockLevel; ProductLocation.UpdateQuantity(this.Product_Location, newStockLevel); this.Save(); }
public async Task CreateAsync(Product product, int userId) { try { await ValidateProductFormData(product); await _repository.Products.AddAsync(product); await _repository.SaveChangesAsync(); // Get the main location Location mainLocation = await AppServices.LocationService.GetMainAsync(); ProductLocation plocation = new ProductLocation() { LocationId = mainLocation.LocationId, ProductId = product.ProductId, }; // Associate the product to the main location await AppServices.ProductLocationService.CreateAsync(plocation, userId); // When the product is created the stock is 0 by default, so we need to set an stock alert await AppServices.NotificationService.ToggleStockAlertsAsync(plocation, 0); // Save changes to save the association await _repository.SaveChangesAsync(); } catch (OperationErrorException operationErrorException) { throw operationErrorException; } }
private void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { string value = comboBox.SelectedItem.ToString(); ProductLocation x = ProductLocation.Get(value); Console.WriteLine(x.Product_Quantity); if (x.Product_Code == "Empty") { listBox.Items.Clear(); listBox.Items.Add("Product location : " + x.Product_Location); listBox.Items.Add("Product Code : " + x.Product_Code); listBox.Items.Add("Product Quantity : " + (x.Product_Quantity)); textBox.IsEnabled = false; button2.IsEnabled = false; } else { Inventory item = Inventory.Get(value); listBox.Items.Clear(); listBox.Items.Add("Product : " + item.Product); listBox.Items.Add("Product Code : " + item.Product_Code); listBox.Items.Add("On Hand : " + item.On_Hand); listBox.Items.Add("On Order : " + item.On_Order); listBox.Items.Add("Reorder Level : " + item.Reorder_Level); listBox.Items.Add("Reorder Quantity : " + item.Reorder_Quantity); textBox.IsEnabled = true; button2.IsEnabled = true; } }
private async Task ValidateProductLocationDataAsync(ProductLocation productLocation) { OperationErrorsList errorsList = new OperationErrorsList(); if (productLocation.LocationId <= 0) { errorsList.AddError("LocationId", Phrases.GlobalRequiredField); } if (errorsList.HasErrors()) { throw new OperationErrorException(errorsList); } // check if the product is already associated with the location ProductLocation pLocationCheck = await _repository.ProductLocations .FindOneAsync(pl => pl.ProductId == productLocation.ProductId && pl.LocationId == productLocation.LocationId); if (pLocationCheck != null) { errorsList.AddError("LocationId", Phrases.ProductLocationErrorAlreadyAssociated); } if (errorsList.HasErrors()) { throw new OperationErrorException(errorsList); } }
public inventoryInterface() { InitializeComponent(); comboBox.ItemsSource = ProductLocation.GetAll(); comboBox1.ItemsSource = Product.GetAllActiveItems(); }
public async Task ShouldCreateProductAndCheckIfTheAssociationWithMainLocationWasCreated() { // Arrange Product product = _mockProducts[1]; Location mainLocation = await AppServices.LocationService.GetMainAsync(); // Act await AppServices.ProductService.CreateAsync(product, _adminUser.UserId); ProductLocation productLocation = await AppServices.ProductLocationService .GetOneAsync(product.ProductId, mainLocation.LocationId); StockMovement stockMovement = await AppServices.StockMovementService .GetProductLastMovementAsync(product.ProductId); // Assert Assert.AreEqual(product.Reference, "mockRef2"); Assert.AreEqual(productLocation.LocationId, mainLocation.LocationId); Assert.AreEqual(productLocation.Stock, 0); Assert.AreEqual(productLocation.MinStock, 0); Assert.AreEqual(stockMovement.ProductId, product.ProductId); Assert.AreEqual(stockMovement.ToLocationId, mainLocation.LocationId); Assert.AreEqual(stockMovement.ToLocationName, mainLocation.Name); Assert.AreEqual(stockMovement.Qty, 0); Assert.AreEqual(stockMovement.Stock, 0); Assert.IsNull(stockMovement.FromLocationId); }
public LocationProductForm(ProductLocation productLocation, bool offlineMode) { InitializeComponent(); _offlineMode = offlineMode; if (_offlineMode) { ddlProductUnit.Enabled = false; } if (productLocation != null) { this.ProductLocation = productLocation; this.txtProductCodeOrBarcode.Text = productLocation.ProductBarcode; if (!_offlineMode) { this.BindData(); this.ddlProductUnit.SelectedValue = productLocation.ProductUnitCode; } this.txtPutLevel.Text = productLocation.PutLevel.ToString(); this.txtPutQty.Text = productLocation.PutQuantity.ToString(); this.chkRequestPrintLabel.Checked = productLocation.RequestPrintLabel; this.txtMaxStock.Text = productLocation.MaxStock.ToString(); } }
public static List <ProductLocation> GetAllEmpty() { using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = DBConnection.CONNECTION_STRING; conn.Open(); string sql; sql = "SELECT Locations_Id, Product_Location, Product_Quantity, Product_Code " + "FROM Product_Locations " + "WHERE Product_Code = 'Empty'"; SqlCommand command = new SqlCommand(sql, conn); using (SqlDataReader reader = command.ExecuteReader()) { List <ProductLocation> locationList = new List <ProductLocation>(); while (reader.Read()) { ProductLocation pl = new ProductLocation( reader.GetInt32(0), reader.GetString(1), reader.GetString(3), reader.GetInt32(2)); locationList.Add(pl); } return(locationList); } } }
public async Task ShouldCreateProductLocation() { // Arrange ProductLocation newProductLocation = new ProductLocation() { ProductId = _mockProduct.ProductId, LocationId = _mockLocation.LocationId, Stock = 10, MinStock = 0 }; // Act await AppServices.ProductLocationService .CreateAsync(newProductLocation, _mockUser.UserId); // Assert StockMovement stockMovement = await AppServices.StockMovementService .GetProductLastMovementAsync(newProductLocation.ProductId); Assert.IsNotNull(newProductLocation.ProductLocationId); Assert.IsNotNull(newProductLocation.CreatedAt); Assert.IsNotNull(newProductLocation.UpdatedAt); Assert.AreEqual(stockMovement.ToLocationId, newProductLocation.LocationId); Assert.IsNull(stockMovement.FromLocationId); Assert.AreEqual(stockMovement.UserId, _mockUser.UserId); Assert.AreEqual(stockMovement.Qty, newProductLocation.Stock); Assert.AreEqual(stockMovement.Stock, newProductLocation.Stock); }
public async Task ShouldDeleteProductLocation() { // Arrange ProductLocation newProductLocation = new ProductLocation() { ProductId = _mockProduct.ProductId, LocationId = _mockLocation.LocationId, Stock = 10, MinStock = 0 }; await AppServices.ProductLocationService .CreateAsync(newProductLocation, _mockUser.UserId); // Act await AppServices.ProductLocationService .DeleteAsyn(newProductLocation.ProductLocationId, _mockUser.UserId); // Assert StockMovement stockMovement = await AppServices.StockMovementService .GetProductLastMovementAsync(newProductLocation.ProductId); // Assert that the product stock is moved back to the main location Assert.AreEqual(stockMovement.FromLocationId, newProductLocation.LocationId); Assert.AreEqual(stockMovement.ToLocationId, _mockMainLocation.LocationId); Assert.AreEqual(stockMovement.UserId, _mockUser.UserId); Assert.AreEqual(stockMovement.Qty, newProductLocation.Stock); Assert.AreEqual(stockMovement.Stock, newProductLocation.Stock); }
public async Task ShouldFailCreateProductLocation_NoLocationId() { // Arrange ProductLocation newProductLocation = new ProductLocation() { ProductId = _mockProduct.ProductId, Stock = 10, MinStock = 5 }; try { // Act await AppServices.ProductLocationService .CreateAsync(newProductLocation, _mockUser.UserId); Assert.Fail("It should have thrown an OperationErrorExeption"); } catch (OperationErrorException ex) { // Assert Assert.AreEqual(ex.Errors.Count, 1); Assert.AreEqual(ex.Errors[0].Field, "LocationId"); Assert.AreEqual(ex.Errors[0].Error, Phrases.GlobalRequiredField); } }
public QualityCheck PostQualityCheck(ProductLocation product) { if (_db.QualityChecks.Any(d => d.EndDate == null)) { return(null); } // get correct object from database by id ProductLocation pr = _db.Locations.Find(product.Id); // initiate quality check object QualityCheck qualitycheck = new QualityCheck(); qualitycheck.StartDate = DateTime.Now; qualitycheck.ProductLocation = pr; qualitycheck.EndDate = null; _db.QualityChecks.Add(qualitycheck); _db.SaveChanges(); // create commands for quality check DroneCommandProcessor commands = createCommands(qualitycheck); // Execute quality check commands.Execute(); return(qualitycheck); }
public ActionResult CreateForProductInGameMakeGame([Bind(Include = "ProductLocationID,ProductInGameID,Address,DeliveryAgentName,DateInserted,DateUpdated,USR")] ProductLocation productLocation) { int GameID = db.ProductInGames.Find(productLocation.ProductInGameID).GameID; if (ModelState.IsValid) { productLocation.DateUpdated = DateTime.Now; productLocation.DateInserted = DateTime.Now; productLocation.USR = "******"; db.ProductLocations.Add(productLocation); try { db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException e) { var ee = e; } return(RedirectToAction("EditMakeGame", "Games", new { id = GameID })); } ViewBag.ProductInGameID = productLocation.ProductInGameID; return(View(productLocation)); }
public static ProductLocation Get(string Product_Location) { using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = DBConnection.CONNECTION_STRING; conn.Open(); string sql = "SELECT Locations_Id, Product_Location, Product_Quantity, Product_Code " + "FROM Product_Locations " + "WHERE Product_Location = @Product_Location"; SqlCommand command = new SqlCommand(sql, conn); command.Parameters.AddWithValue("Product_Location", Product_Location); using (SqlDataReader read = command.ExecuteReader()) { if (read.HasRows) { read.Read(); ProductLocation location = new ProductLocation( read.GetInt32(0), read.GetString(1), read.GetString(3), read.GetInt32(2)); return(location); } else { return(null); } } } }
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); } }
public ActionResult DeleteConfirmed(int id) { ProductLocation productLocation = db.ProductLocations.Find(id); db.ProductLocations.Remove(productLocation); db.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// Function to update the quantity of the item at the location /// </summary> /// <param name="Locations_Id"></param> /// <param name="Product_Quantity"></param> public static void UpdateQuantity(string Locations_Id, int Product_Quantity) { ProductLocation item = ProductLocation.Get(Locations_Id); item.Product_Quantity = Product_Quantity; item.Save(); }
public static void RemoveItemAtLocation(string Locations_Id) { ProductLocation item = ProductLocation.Get(Locations_Id); item.Product_Code = "Empty"; item.Save(); }
public async Task DeleteAsync(int[] locationIds, int userId) { OperationErrorsList errorsList = new OperationErrorsList(); try { for (int i = 0; i < locationIds.Length; i += 1) { int locationId = locationIds[i]; Location location = await _repository.Locations.GetByIdAsync(locationId); if (location != null) { // If it is the main location cannot be deleted if (location.IsMain) { errorsList.AddError( "MainLocation", Phrases.LocationErrorMainLocation ); throw new OperationErrorException(errorsList); } // Iterate through the productLocations and move the stock to the main // location before remove the location if ((location.ProductLocations != null) && location.ProductLocations.Any()) { while (location.ProductLocations.Any()) { ProductLocation producLocation = location.ProductLocations.ElementAt(0); // Remove the ProductLocation association and move the stock await AppServices.ProductLocationService .DeleteAsyn(producLocation.ProductLocationId, userId); } } _repository.Locations.Remove(location); } } await _repository.SaveChangesAsync(); } catch (OperationErrorException operationErrorException) { // Catch operation errors throw operationErrorException; } catch { // catch other errors and send a Service Error Exception errorsList.AddError("delete-location-db-error", Phrases.GlobalErrorOperationDB); throw new ServiceErrorException(errorsList); } }
/// <summary> /// Function to update what item is at a specific location /// </summary> /// <param name="Locations_Id">value to find the location in the database</param> /// <param name="Product_Code">new value for the item at the location</param> /// <param name="Product_Quantity">Quantity of the new item at the location</param> public static void ChangeItemAtLocation(string Locations_Id, string Product_Code, int Product_Quantity) { ProductLocation item = ProductLocation.Get(Locations_Id); item.Product_Code = Product_Code; item.Product_Quantity = Product_Quantity; item.Save(); }
// Method to create commands for the drone to execute private DroneCommandProcessor createCommands(QualityCheck qc) { // Get productLocation to take picture from ProductLocation pl = qc.ProductLocation; // Initiate CommandProcessor _droneCommandProcessor = new DroneCommandProcessor(); // Get Graph datastructure in pathfinder generated from selected warehouse IPathfinderFactory pathfinderFactory = new PathfinderFactory(); Pathfinder pathfinder = pathfinderFactory.GetPathfinderFromWarehouse(pl.District.Warehouse); // Initiate start position (start position is drone start location) Position startNode = new Position(pl.District.Warehouse.StartNode.X, pl.District.Warehouse.StartNode.Y); // Get path to take from startposition to nearest graphnode for the Productlocation by using dijkstra algoritm LinkedList <Position> path = pathfinder.GetPath(startNode, this.giveEndPosition(pl)); // save path to qualitycheck for webpage view List <Position> path2 = pathfinder.GetPathList(startNode, this.giveEndPosition(pl)); var s = JsonConvert.SerializeObject(path2, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); qc.JSONPath = s; _db.Entry(qc).State = EntityState.Modified; _db.SaveChanges(); // add start / takeoff command to the droneCommandProcessor _droneCommandProcessor.AddCommand(new Command { name = "Start" }); // add commands to the droneCommandProcessor from path, this generates the commands needed to move to the nearest graphnode to the productlocation IMovementCommandFactory mFactory = new MovementCommandFactory(); _droneCommandProcessor.AddListCommand(mFactory.GetMovementCommands(path)); // add commands to move from the nearest graphnode to the position in front of the productlocation IDistrictCommandFactory dFactory = new DistrictCommandFactory(); _droneCommandProcessor.AddListCommand(dFactory.GetCommands(giveEndPosition(pl), pl)); // add command to take picture, this also needs the current quality check id, needed for saving the pictures to the correct location _droneCommandProcessor.AddCommand(new Command { name = "TakePicture", value = qc.Id }); // add command to land the drone _droneCommandProcessor.AddCommand(new Command { name = "Land" }); return(_droneCommandProcessor); }
/// <summary> /// Function to update the location of the product /// </summary> /// <param name="Product_Id"></param> /// <param name="NewLocations_Id"></param> /// <param name="NewLocation"></param> public static void UpdateProductLocation(int Product_Id, string CurrLocations_Id, string NewLocations_Id, string NewLocation) { Inventory item = Inventory.Get(Product_Id); item.Product_Location = NewLocation; ProductLocation.ChangeItemAtLocation(NewLocations_Id, NewLocation, item.On_Hand); ProductLocation.RemoveItemAtLocation(CurrLocations_Id); item.Save(); }
public ActionResult CreateForProductInGameMakeGame(int productInGameID) { ViewBag.ProductInGame = db.ProductInGames.Find(productInGameID); ViewBag.ProductInGameID = productInGameID; ProductLocation model = new ProductLocation(); model = (ProductLocation)Helpers.TableTracker.TrackCreate(model, "USR"); return(View(model)); }
public inventoryInterface(Employee x) { InitializeComponent(); comboBox.ItemsSource = ProductLocation.GetAll(); comboBox1.ItemsSource = Product.GetAllActiveItems(); //This is to display the employee that is logged in k = x; }
private void VerifyIfHasStockAvailableToMove(ProductLocation plocation, float qty, string field = "qty") { OperationErrorsList errorsList = new OperationErrorsList(); if (plocation.Stock < qty) { errorsList.AddError(field, Phrases.StockMovementErrorQty); throw new OperationErrorException(errorsList); } }
public ActionResult Edit([Bind(Include = "ProductLocationID,ProductInGameID,Address,DeliveryAgentName,DateInserted,DateUpdated,USR")] ProductLocation productLocation) { if (ModelState.IsValid) { db.Entry(productLocation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProductInGameID = new SelectList(db.ProductInGames, "ProductInGameID", "Currency", productLocation.ProductInGameID); return(View(productLocation)); }
// method to determine wich graphnode is nearest to the productlocation and return its position private Position giveEndPosition(ProductLocation pl) { int half = pl.District.Columns / 2; Position result = new Position(pl.District.StartGraphNode.X, pl.District.StartGraphNode.Y); if (pl.Column > half) { result = new Position(pl.District.EndGraphNode.X, pl.District.EndGraphNode.Y); } return(result); }
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); }
private Models.ProductLocation toProductLocation(int productInGameId, string address) { ProductLocation pl = new ProductLocation(); pl.ProductInGameID = productInGameId; pl.Address = address; pl.DateInserted = DateTime.Now; pl.DateUpdated = DateTime.Now; pl.USR = "******"; return(pl); }