Beispiel #1
0
        private void SetXLocParamAndModifyCellVisibilityInOccupantsGrid(DataGridViewRow changedRow,
                                                                        OccupantDistributionInfo dist, int colDistType, int colParamA, int colParamB)
        {
            var paramBCell = changedRow.Cells[colParamB];

            if (changedRow.Cells[colDistType].Value.Equals(EWorkerDistribution.Deterministic))
            {
                //Don't use the second parameter value for deterministic
                var paramBCellValue = GetDoubleCellValue(paramBCell.Value);

                if (paramBCellValue != 0D)
                {
                    var oldIgnore = _mCurrentlyIgnoringGridChangeEvents;
                    try
                    {
                        paramBCell.Value = 0D;
                    }
                    finally
                    {
                        _mCurrentlyIgnoringGridChangeEvents = oldIgnore;
                    }
                }

                MakeParamBCellReadOnly(paramBCell);
            }
            else
            {
                MakeParamBCellReadWrite(changedRow, paramBCell);
            }
        }
Beispiel #2
0
        private void HarvestOccupantDatagridRow(DataGridViewRow changedRow, int columnIndex)
        {
            var distributionNode = (OccupantDistributionInfo)changedRow.Tag;

            var descriptionNodeCell = changedRow.Cells[(int)OccupantGridColumnIdx.Description];
            var nrTargetsCell       =
                (DataGridViewTextBoxCell)changedRow.Cells[(int)OccupantGridColumnIdx.NumberOfTargets];

            var xLocDistTypeCell = changedRow.Cells[(int)OccupantGridColumnIdx.XLocDistType];
            var yLocDistTypeCell = changedRow.Cells[(int)OccupantGridColumnIdx.YLocDistType];
            var zLocDistTypeCell = changedRow.Cells[(int)OccupantGridColumnIdx.ZLocDistType];

            var xLocDistParmACell = changedRow.Cells[(int)OccupantGridColumnIdx.XLocDistParmA];
            var yLocDistParmACell = changedRow.Cells[(int)OccupantGridColumnIdx.YLocDistParmA];
            var zLocDistParmACell = changedRow.Cells[(int)OccupantGridColumnIdx.ZLocDistParmA];

            var xLocDistParmBCell = changedRow.Cells[(int)OccupantGridColumnIdx.XLocDistParmB];
            var yLocDistParmBCell = changedRow.Cells[(int)OccupantGridColumnIdx.YLocDistParmB];
            var zLocDistParmBCell = changedRow.Cells[(int)OccupantGridColumnIdx.ZLocDistParmB];

            if (distributionNode == null)
            {
                distributionNode = new OccupantDistributionInfo();
                changedRow.Tag   = distributionNode;
                QraStateContainer.Instance.OccupantDistributionInfoCollection.Add(distributionNode);
            }

            var numTargets = 0;

            if (nrTargetsCell.Value != null)
            {
                var changedRowNrTargetsValueString = nrTargetsCell.Value.ToString();
                if (changedRowNrTargetsValueString != distributionNode.NumTargets.ToString())
                {
                    numTargets = int.MinValue;
                    if (int.TryParse(changedRowNrTargetsValueString, out numTargets))
                    {
                        distributionNode.NumTargets = numTargets;
                    }
                    else
                    {
                        nrTargetsCell.Value = distributionNode.NumTargets;
                    }
                }

                if (descriptionNodeCell.Value != null)
                {
                    distributionNode.Desc = descriptionNodeCell.Value.ToString();
                }

                EnsureDistTypeValueValid(xLocDistTypeCell);
                EnsureDistTypeValueValid(yLocDistTypeCell);
                EnsureDistTypeValueValid(zLocDistTypeCell);

                distributionNode.XLocDistribution = (EWorkerDistribution)xLocDistTypeCell.Value;
                distributionNode.YLocDistribution = (EWorkerDistribution)yLocDistTypeCell.Value;
                distributionNode.ZLocDistribution = (EWorkerDistribution)zLocDistTypeCell.Value;

                distributionNode.XLocParamA = HarvestParamAFromCells(xLocDistParmACell, distributionNode.XLocParamA);
                distributionNode.YLocParamA = HarvestParamAFromCells(yLocDistParmACell, distributionNode.YLocParamA);
                distributionNode.ZLocParamA = HarvestParamAFromCells(zLocDistParmACell, distributionNode.ZLocParamA);

                distributionNode.XLocParamB = HarvestParamBFromCells(xLocDistParmBCell, distributionNode.XLocParamA,
                                                                     distributionNode.XLocParamB);
                distributionNode.YLocParamB = HarvestParamBFromCells(yLocDistParmBCell, distributionNode.YLocParamA,
                                                                     distributionNode.YLocParamB);
                distributionNode.ZLocParamB = HarvestParamBFromCells(zLocDistParmBCell, distributionNode.ZLocParamA,
                                                                     distributionNode.ZLocParamB);

                SetXLocParamAndModifyCellVisibilityInOccupantsGrid(changedRow, distributionNode,
                                                                   (int)OccupantGridColumnIdx.XLocDistType, (int)OccupantGridColumnIdx.XLocDistParmA,
                                                                   (int)OccupantGridColumnIdx.XLocDistParmB);
                SetXLocParamAndModifyCellVisibilityInOccupantsGrid(changedRow, distributionNode,
                                                                   (int)OccupantGridColumnIdx.YLocDistType, (int)OccupantGridColumnIdx.YLocDistParmA,
                                                                   (int)OccupantGridColumnIdx.YLocDistParmB);
                SetXLocParamAndModifyCellVisibilityInOccupantsGrid(changedRow, distributionNode,
                                                                   (int)OccupantGridColumnIdx.ZLocDistType, (int)OccupantGridColumnIdx.ZLocDistParmA,
                                                                   (int)OccupantGridColumnIdx.ZLocDistParmB);
                var distanceUnitCell = changedRow.Cells[(int)OccupantGridColumnIdx.Unit];
                if (distanceUnitCell.Value == null)
                {
                    distanceUnitCell.Value = DistanceUnit.Meter;
                }

                distributionNode.ParamUnitType = (DistanceUnit)distanceUnitCell.Value;

                var exposureHours     = double.NaN;
                var exposureHoursCell = changedRow.Cells[(int)OccupantGridColumnIdx.ExposureHours];

                if (Parsing.TryParseDouble((exposureHoursCell.Value ?? string.Empty).ToString(), out exposureHours))
                {
                    distributionNode.ExposureHours = exposureHours;
                }
                else
                {
                    exposureHoursCell.Value = distributionNode.ExposureHours;
                }
            }
        }
Beispiel #3
0
        private void HarvestOccupantDatagridRow(DataGridViewRow changedRow)
        {
            var dist = changedRow.Tag as OccupantDistributionInfo;

            if (dist == null)
            {
                dist           = new OccupantDistributionInfo();
                changedRow.Tag = dist;
            }

            var    intOutput    = 0;
            double doubleOutput = 0;

            if (int.TryParse((changedRow.Cells[0].Value ?? string.Empty).ToString(), out intOutput))
            {
                dist.NumTargets = intOutput;
            }

            changedRow.Cells[(int)OccupantGridColumnIdx.NumberOfTargets].Value = dist.NumTargets;

            if (changedRow.Cells[(int)OccupantGridColumnIdx.Description].Value != null)
            {
                dist.Desc = changedRow.Cells[(int)OccupantGridColumnIdx.Description].Value.ToString();
            }

            changedRow.Cells[(int)OccupantGridColumnIdx.Description].Value = dist.Desc;

            if (changedRow.Cells[(int)OccupantGridColumnIdx.XLocDistType].Value == null)
            {
                changedRow.Cells[(int)OccupantGridColumnIdx.XLocDistType].Value = EWorkerDistribution.Uniform;
            }

            dist.XLocDistribution =
                (EWorkerDistribution)changedRow.Cells[(int)OccupantGridColumnIdx.XLocDistType].Value;

            if (Parsing.TryParseDouble(
                    (changedRow.Cells[(int)OccupantGridColumnIdx.XLocDistParmA].Value ?? string.Empty).ToString(),
                    out doubleOutput))
            {
                dist.XLocParamA = doubleOutput;
            }

            if (!changedRow.Cells[(int)OccupantGridColumnIdx.XLocDistType].Value
                .Equals(EWorkerDistribution.Deterministic))
            {
                if (Parsing.TryParseDouble(
                        (changedRow.Cells[(int)OccupantGridColumnIdx.XLocDistParmB].Value ?? string.Empty).ToString(),
                        out doubleOutput))
                {
                    dist.XLocParamB = doubleOutput;
                }

                changedRow.Cells[(int)OccupantGridColumnIdx.XLocDistParmB].Style.BackColor =
                    changedRow.DataGridView.DefaultCellStyle.BackColor;
                changedRow.Cells[(int)OccupantGridColumnIdx.XLocDistParmB].Style.ForeColor =
                    changedRow.DataGridView.DefaultCellStyle.ForeColor;
                changedRow.Cells[(int)OccupantGridColumnIdx.XLocDistParmB].ReadOnly = false;
            }
            else
            {
                //Don't use the second parameter value for deterministic
                changedRow.Cells[(int)OccupantGridColumnIdx.XLocDistParmB].Value           = null;
                changedRow.Cells[(int)OccupantGridColumnIdx.XLocDistParmB].ReadOnly        = true;
                changedRow.Cells[(int)OccupantGridColumnIdx.XLocDistParmB].Style.BackColor = Color.LightGray;
                changedRow.Cells[(int)OccupantGridColumnIdx.XLocDistParmB].Style.ForeColor = Color.DarkGray;
            }

            if (changedRow.Cells[(int)OccupantGridColumnIdx.Unit].Value == null)
            {
                changedRow.Cells[(int)OccupantGridColumnIdx.Unit].Value = DistanceUnit.Meter;
            }

            dist.ParamUnitType = (DistanceUnit)changedRow.Cells[(int)OccupantGridColumnIdx.Unit].Value;
            changedRow.Cells[(int)OccupantGridColumnIdx.XLocDistParmA].Value = dist.XLocParamA;
            if (!changedRow.Cells[(int)OccupantGridColumnIdx.XLocDistType].Value
                .Equals(EWorkerDistribution.Deterministic))
            {
                changedRow.Cells[(int)OccupantGridColumnIdx.XLocDistParmB].Value = dist.XLocParamB;
            }

            if (int.TryParse(
                    (changedRow.Cells[(int)OccupantGridColumnIdx.ExposureHours].Value ?? string.Empty).ToString(),
                    out intOutput))
            {
                dist.ExposureHours = intOutput;
            }

            changedRow.Cells[(int)OccupantGridColumnIdx.ExposureHours].Value = dist.ExposureHours;
        }