private void SaveLine() { try { if (SelectedPi == null || SelectedItem == null || SelectedPi.Status != PhysicalInventoryStatus.Draft) { MessageBox.Show("Can't add item, try again later...."); return; } var newObject = SelectedPi.Id; if (_isEdit == false) { SelectedPiLine = new PhysicalInventoryLineDTO() { PhysicalInventory = SelectedPi, PhysicalInventoryLineType = PhysicalInventoryLineTypes.AfterPi } } ; SelectedPiLine.ItemId = TransactionLine.Item.Id; SelectedPiLine.CountedQty = TransactionLine.ItemCountedQuantity; SelectedPiLine.ExpectedQty = TransactionLine.ItemCurrentQuantity; var stat = _piHeaderService.InsertOrUpdateChild(SelectedPiLine); if (stat == string.Empty) { if (newObject == 0) { PhysicalInventories.Insert(0, SelectedPi); } _isEdit = false; GetSummary(); SelectedPi = SelectedPi; } else { MessageBox.Show("Problem adding physical Inventory item, please try again..." + Environment.NewLine + stat); } } catch (Exception exception) { MessageBox.Show("Problem adding item, please try again..." + Environment.NewLine + exception.Message + Environment.NewLine + exception.InnerException); } }
public bool ObjectExistsChild(PhysicalInventoryLineDTO piLine) { var objectExists = false; //var iDbContext = DbContextUtil.GetDbContextInstance(); //try //{ // var catRepository = new Repository<PhysicalInventoryLineDTO>(iDbContext); // var catExists = catRepository.GetAll() // .FirstOrDefault(bp => bp.PhysicalInventoryId == piLine.PhysicalInventoryId && bp.ItemId == piLine.ItemId && bp.Id != piLine.Id); // if (catExists != null) // objectExists = true; //} //finally //{ // iDbContext.Dispose(); //} return(objectExists); }
public string DisableChild(PhysicalInventoryLineDTO piLine) { if (piLine == null || piLine.Id == 0 || piLine.PhysicalInventory == null || piLine.PhysicalInventory.Status != PhysicalInventoryStatus.Draft) { return("First choose Item to delete..."); } string stat; try { _piLineRepository.Update(piLine); _unitOfWork.Commit(); stat = string.Empty; } catch (Exception exception) { stat = exception.Message; } return(stat); }
public PhysicalInventoryLineDTO GetNewPiLine(int warehouseId, int itemId, decimal countedQty, PhysicalInventoryLineTypes lineType) { var line = new PhysicalInventoryLineDTO(); try { var selectedItemQuantity = new ItemQuantityService(false).GetByCriteria(warehouseId, itemId); //var selectedPhysicalInventory = GetListOf(false) //.FirstOrDefault(pi => pi.WarehouseId == warehouseId && // pi.PhysicalInventoryDate.Date == DateTime.Now.Date) ?? var selectedPhysicalInventory = new PhysicalInventoryHeaderDTO { PhysicalInventoryDate = DateTime.Now, Status = PhysicalInventoryStatus.Posted, WarehouseId = warehouseId, PhysicalInventoryNumber = GetNewPhysicalInventoryNumber(warehouseId, false) }; line.PhysicalInventory = selectedPhysicalInventory; line.ItemId = itemId; line.CountedQty = countedQty; line.ExpectedQty = selectedItemQuantity != null ? selectedItemQuantity.QuantityOnHand : 0; line.PhysicalInventoryLineType = lineType; } catch { MessageBox.Show("Problem getting new pi, try again..."); return(null); } finally { //_unitOfWork.Dispose(); } return(line); }
public string ValidateChild(PhysicalInventoryLineDTO piLine) { if (null == piLine) { return(GenericMessages.ObjectIsNull); } if (piLine.PhysicalInventory == null) { return("PhysicalInventory " + GenericMessages.ObjectIsNull); } if (piLine.ItemId == 0) { return("No item is found in the physical inventory line"); } if (piLine.CountedQty < 0) { return(piLine.CountedQty + " can not be less than 0 "); } return(string.Empty); }
public string InsertOrUpdateChild(PhysicalInventoryLineDTO piLine) { try { var validate = ValidateChild(piLine); if (!string.IsNullOrEmpty(validate)) { return(validate); } if (ObjectExistsChild(piLine)) { return(GenericMessages.DatabaseErrorRecordAlreadyExists); } _piLineRepository.InsertUpdate(piLine); _unitOfWork.Commit(); return(string.Empty); } catch (Exception exception) { return(exception.Message); } }