예제 #1
0
        private void CalcGrid_GridTapped(object sender, GridTappedEventArgs e)
        {
            try
            {
                var rowIndex    = e.RowColumnIndex.RowIndex;
                var rowData     = e.RowData;
                var columnIndex = e.RowColumnIndex.ColumnIndex;

                VmEqVar vmEqCalcVariable = rowData as VmEqVar;

                if (columnIndex == 1)
                {
                    if (vmEqCalcVariable == null || vmEqCalcVariable.IsCalculated)
                    {
                        return;
                    }

                    calcGrid.EndEdit();                        // Finish previous edit if there was one.
                    calcGrid.BeginEdit(rowIndex, columnIndex); // Start new one.
                }
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
            }
        }
예제 #2
0
        private void CalcGrid_CurrentCellBeginEdit(object sender, GridCurrentCellBeginEditEventArgs e)
        {
            var rowIndex    = e.RowColumnIndex.RowIndex;
            var columnIndex = e.RowColumnIndex.ColumnIndex;

            if (e.RowColumnIndex.ColumnIndex == 1)       //Value column:
            {
                VmEqVar vmEqCalcVariable = calcGrid.GetRecordAtRowIndex(rowIndex) as VmEqVar;
                if (vmEqCalcVariable == null || vmEqCalcVariable.IsCalculated)
                {
                    e.Cancel = true;
                    return;
                }

                _vmEquations.ClearResults();     // Clear the current result in case it doesn't get refreshed properly after the edit
            }
        }
예제 #3
0
        void UpdateCalcInput(VmEqVar wmEqVar)
        {
            try
            {
                SingleValue singleValue = wmEqVar.GetSingleValue();
                KnownUOM    knownUOM    = wmEqVar.GetKnownUOM();

                if (singleValue == null)
                {
                    return;
                }
                if (singleValue is Constant)
                {
                    return;
                }
                if (singleValue is Literal)
                {
                    return;
                }

                // Check or update the calc UOM
                bool bUpdateCalcUom = false;
                if (knownUOM == null)
                {
                    singleValue.CalcQuantity.AnonUOM = null;
                }
                else if (singleValue.CalcQuantity.AnonUOM == null)
                {
                    bUpdateCalcUom = true;
                }
                else if (!knownUOM.Dimensions.Equals(singleValue.CalcQuantity.AnonUOM.Dimensions))
                {
                    bUpdateCalcUom = true;
                }

                if (bUpdateCalcUom)
                {
                    singleValue.CalcQuantity.AnonUOM = new AnonUOM(knownUOM.Dimensions, _uOMSet);
                }

                double dbl = (wmEqVar.Value ?? double.NaN);

                CalcStatus calcStatus;
                if (double.IsNaN(dbl) || double.IsInfinity(dbl))
                {
                    calcStatus = CalcStatus.Bad;
                }
                else
                {
                    calcStatus = CalcStatus.Good;
                }

                singleValue.CalcQuantity.CalcStatus = calcStatus;

                // Convert the input value to the calc UOM
                double convertedVal = dbl;

                if (knownUOM != null)
                {
                    convertedVal = UOM.Convert(dbl, fromUOM: knownUOM, anonToUOM: singleValue.CalcQuantity.AnonUOM);
                }

                singleValue.CalcQuantity.Value = convertedVal;

                SetMaxUOMLength();
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
                throw;
            }
        }