public void UpdateAccumulatedWeight(AccumulatedWeight accumulatedWeight) { using (var db = new WeighrContext()) { db.AccumulatedWeights.Update(accumulatedWeight); db.SaveChanges(); } }
public void LogFinalValues() { //display filling status _checkWeightProcess = false; if (_calc_result > ((_currentProduct.TargetWeight) + (_currentProduct.UpperLimit / 1000))) //if overpacked { GpioUtility.switchOnOverWeightLight(); } else if (_calc_result < ((_currentProduct.TargetWeight) - (_currentProduct.LowerLimit / 1000))) //if underpacke { GpioUtility.switchOnUnderWeightLight(); } else { GpioUtility.switchOnNormalWeightLight(); } Decimal percDiffFillTime = 0; if (_currentProduct.ExpectedFillTime == 0) { percDiffFillTime = 0; } else { percDiffFillTime = (_currentProduct.ExpectedFillTime - _ActualFillTime) / 100; } Decimal weightDiff = Convert.ToDecimal(_calc_result) - _currentProduct.TargetWeight; int weightStatus = 0; if (weightDiff > 0) { weightStatus = 1; } else if (weightDiff < 0) { weightStatus = -1; } string batchCode = ""; batchCode = (_currentBatch == null) ? "b001" : _currentBatch.BatchCode; TransactionLog trans_log = new TransactionLog() { ProductId = _currentProduct.ProductId, ProductCode = _currentProduct.ProductCode, BatchCode = batchCode, OrderNumber = "", ProductDensity = _currentProduct.Density, ShiftId = 1, TargetWeight = _currentProduct.TargetWeight, UpperLimit = _currentProduct.UpperLimit, LowerLimit = _currentProduct.LowerLimit, ActualWeight = Convert.ToDecimal(_calc_result), TransactionDate = DateTime.Now.ToUniversalTime(), WeightDifference = weightDiff, Units = "Kgs", WeightStatus = weightStatus, // -1=UnderWeight , 0=Normal , 1=OverWeight WeightType = "NET", persistedServer = false, DeviceId = DeviceInfoHelper.Instance.Id, SerialNumber = _deviceInfo.SerialNumber, ClientId = _deviceInfo.ClientId, PlantId = _deviceInfo.PlantId, MachineName = _deviceInfo.MachineName, ProductName = _currentProduct.Name, ExpectedFillTime = _currentProduct.ExpectedFillTime, ActualFillTime = _ActualFillTime, PercDiffFillTime = percDiffFillTime, BaseUnitOfMeasure = "Kgs", Uploaded = false, rowguid = Guid.NewGuid(), ModifiedDate = DateTime.Now.ToUniversalTime(), }; _transactionLogComp.AddTransactionLog(trans_log); LogTransactionRemote(trans_log); LastWeightTextblock.Text = "Last Weight : " + _calc_result.ToString("0.00"); var accumWeight = _accumulatedWeightComp.GetAccumulatedWeight(); if (accumWeight != null) { accumWeight.Weight = accumWeight.Weight + trans_log.ActualWeight; accumWeight.CurrentDate = DateTime.Now.ToUniversalTime(); _accumulatedWeightComp.UpdateAccumulatedWeight(accumWeight); TotalAccumulatedWeightTextblock.Text = "Total Accum : " + accumWeight.Weight.ToString("0.00"); } else { AccumulatedWeight accumulatedWeight = new AccumulatedWeight { Weight = trans_log.ActualWeight, StartDate = DateTime.Now.ToUniversalTime(), CurrentDate = DateTime.Now.ToUniversalTime(), }; _accumulatedWeightComp.AddAccumulatedWeight(accumulatedWeight); TotalAccumulatedWeightTextblock.Text = "Total Accum : " + accumulatedWeight.Weight.ToString("0.00"); } // AccumulatedWeightTextbox.Text = accumWeight.Weight.ToString(); tblWeigherStatus.Text = "Status: Ready To Fill"; }