Exemplo n.º 1
0
        /// <summary>
        /// Pre-fill control from existing pie tier
        /// </summary>
        public void Prefill(PieTask.PieTier tier)
        {
            Tier = tier;
            if (Tier != null)
            {
                tbGoalNumber.Text     = Tier.GoalNumber.ToString();
                tbRadius.Text         = Math.Round(Tier.Radius, 3, MidpointRounding.AwayFromZero).ToString();
                rbRadiusMeter.Checked = true;
                //rbInnerRadiusFeet.Checked = false;
                cbIsReetranceAllowed.Checked = Tier.IsReentranceAllowed;
                tbMultiplier.Text            = Tier.Multiplier.ToString();

                if (!double.IsNaN(Tier.LowerBoundary))
                {
                    tbLowerBoundary.Text         = Math.Round(Tier.LowerBoundary, 3, MidpointRounding.AwayFromZero).ToString();
                    rbLowerBoundaryMeter.Checked = true;
                    //rbLowerBoundaryFeet.Checked = false;
                }
                if (!double.IsNaN(Tier.UpperBoundary))
                {
                    tbUpperBoundary.Text         = Math.Round(Tier.UpperBoundary, 3, MidpointRounding.AwayFromZero).ToString();
                    rbUpperBoundaryMeter.Checked = true;
                    rbUpperBoundaryFeet.Checked  = false;
                }
                foreach (IDeclarationValidationRules rule in Tier.DeclarationValidationRules)
                {
                    lbRules.Items.Add(rule);
                }
                IsExisting = true;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Adds a new pie tier to the tier list box, when the pie tier user controls fires the DataVaild event
 /// </summary>
 private void PieTierControl1_DataValid()
 {
     PieTask.PieTier tier = (Controls["pieTierControl1"] as PieTierControl).Tier;
     if (!lbPieTiers.Items.Contains(tier))
     {
         lbPieTiers.Items.Add(tier);
     }
     Log(LogSeverityType.Info, $"{tier} created/modified");
 }
Exemplo n.º 3
0
        /// <summary>
        /// Validates user input and creates a new pie tier / modifies the existing pie tier
        /// </summary>
        /// <param name="sender">sender of the event</param>
        /// <param name="e">event arguments</param>
        private void btCreate_Click(object sender, EventArgs e)
        {
            bool   isDataValid          = true;
            string functionErrorMessage = "Failed to create/modify pie tier: ";
            int    goalNumber;

            if (!int.TryParse(tbGoalNumber.Text, out goalNumber))
            {
                Log(LogSeverityType.Error, functionErrorMessage + $"Failed to parse Goal No. '{tbGoalNumber.Text}' as integer");
                isDataValid = false;
            }
            if (goalNumber <= 0)
            {
                Log(LogSeverityType.Error, functionErrorMessage + $"Goal No. must be greater than 0");
                isDataValid = false;
            }
            double radius;

            if (!double.TryParse(tbRadius.Text, out radius))
            {
                Log(LogSeverityType.Error, functionErrorMessage + $"Failed to parse Radius '{tbRadius.Text}' as double");
                isDataValid = false;
            }
            if (rbRadiusFeet.Checked)
            {
                radius = CoordinateHelpers.ConvertToMeter(radius);
            }
            bool   isReentranceAllowed = cbIsReetranceAllowed.Checked;
            double multiplier;

            if (!double.TryParse(tbMultiplier.Text, out multiplier))
            {
                Log(LogSeverityType.Error, functionErrorMessage + $"Failed to parse Multiplier '{tbMultiplier.Text}' as double");
                isDataValid = false;
            }

            double lowerBoundary = double.NaN;

            if (!string.IsNullOrWhiteSpace(tbLowerBoundary.Text))
            {
                if (!double.TryParse(tbLowerBoundary.Text, out lowerBoundary))
                {
                    Log(LogSeverityType.Error, functionErrorMessage + $"Failed to parse Lower Boundary '{tbLowerBoundary.Text}' as double");
                    isDataValid = false;
                }
                if (!double.IsNaN(lowerBoundary))
                {
                    if (rbLowerBoundaryFeet.Checked)
                    {
                        lowerBoundary = CoordinateHelpers.ConvertToMeter(lowerBoundary);
                    }
                }
            }
            double upperBoundary = double.NaN;

            if (!string.IsNullOrWhiteSpace(tbUpperBoundary.Text))
            {
                if (!double.TryParse(tbUpperBoundary.Text, out upperBoundary))
                {
                    Log(LogSeverityType.Error, functionErrorMessage + $"Failed to parse Upper Boundary '{tbUpperBoundary.Text}' as double");
                    isDataValid = false;
                }
                if (!double.IsNaN(upperBoundary))
                {
                    if (rbUpperBoundaryFeet.Checked)
                    {
                        upperBoundary = CoordinateHelpers.ConvertToMeter(upperBoundary);
                    }
                }
            }
            if (!double.IsNaN(lowerBoundary) && double.IsNaN(upperBoundary))
            {
                if (lowerBoundary >= upperBoundary)
                {
                    Log(LogSeverityType.Error, functionErrorMessage + $"Lower Boundary '{lowerBoundary}[m]' must be smaller than Upper Boundary '{upperBoundary}[m]'");
                    isDataValid = false;
                }
            }
            //TODO add goal validations;
            if (isDataValid)
            {
                if (!IsExisting)
                {
                    Tier = new PieTask.PieTier();
                }
                List <IDeclarationValidationRules> declarationValidationRules = new List <IDeclarationValidationRules>();
                foreach (object item in lbRules.Items)
                {
                    if (item is IDeclarationValidationRules)
                    {
                        if (!Tier.DeclarationValidationRules.Contains(item as IDeclarationValidationRules))
                        {
                            declarationValidationRules.Add(item as IDeclarationValidationRules);
                        }
                    }
                }
                Tier.SetupPieTier(goalNumber, radius, isReentranceAllowed, multiplier, lowerBoundary, upperBoundary, declarationValidationRules);
                IsExisting           = false;
                tbGoalNumber.Text    = "";
                tbRadius.Text        = "";
                tbMultiplier.Text    = "";
                tbLowerBoundary.Text = "";
                tbUpperBoundary.Text = "";
                lbRules.Items.Clear();
                OnDataValid();
            }
        }