private void GetOk() { var row = MatComboBox.GetSelectedDataRow() as make_det; if (row != null) { var plan_weighing = Math.Round(Convert.ToDecimal((row.AmountByRecipe * _iw.Amount) / row.TotalWeightByRecipe), 2); ByRecipeEdit.EditValue = row.AmountByRecipe; IntermediateWeighingEdit.EditValue = row.AmountIntermediateWeighing; TotalEdit.EditValue = row.AmountByRecipe - (row.AmountIntermediateWeighing ?? 0); var deviation = _db.MatRecDet.FirstOrDefault(w => w.MatId == row.MatId && w.RecId == row.RecId)?.Deviation ?? 1000000; var vizok = (dynamic)TareMatEdit.GetSelectedDataRow(); var netto_amount = AmountEdit.Value - TaraCalcEdit.Value - (vizok != null ? vizok.Weight : 0); CalcAmount.EditValue = plan_weighing + TaraCalcEdit.Value + (vizok != null ? vizok.Weight : 0); OkButton.Enabled = !String.IsNullOrEmpty(MatComboBox.Text) && ((plan_weighing + deviation) >= netto_amount && (plan_weighing - deviation) <= netto_amount); // && (TotalEdit.Value + deviation) >= netto_amount; } else { OkButton.Enabled = false; } }
private void OkButton_Click(object sender, EventArgs e) { var vizok = (dynamic)TareMatEdit.GetSelectedDataRow(); det.Total = det.Amount - det.TaraAmount - (vizok != null ? (decimal)vizok.Weight : 0); det.TaraTotal = det.TaraAmount + (vizok != null ? (decimal)vizok.Weight : 0); if (_db.Entry <IntermediateWeighingDet>(det).State == EntityState.Detached) { _db.IntermediateWeighingDet.Add(det); } _db.SaveChanges(); }