Exemplo n.º 1
0
 private void FillCurvesCheckedListBox()
 {
     CheckedListBoxCurves.Items.Clear();
     if (_schoolClass.curves is null)
     {
         return;
     }
     foreach (Curve curve in _schoolClass.curves)
     {
         CheckedListBoxCurves.Items.Add(curve.name);
         CheckedListBoxCurves.SetItemChecked(CheckedListBoxCurves.Items.IndexOf(curve.name), curve.active);
     }
 }
Exemplo n.º 2
0
        private void ClearCurvedForm(bool clearName = true, bool deselect = true)
        {
            TextBox[] textBoxes =
            {
                TextBoxConDropPercent, TextBoxConDropPoints, TextBoxCurveToMean, TextBoxAdditivePercent,
                TextBoxAdditivePoints, TextBoxMultiplicative
            };
            RadioButton[] radioButtons =
            {
                RadioButtonDrop,        RadioButtonKeep,            RadioButtonConDropPercent, RadioButtonConDropPoints,
                RadioButtonCurveToMean, RadioButtonAdditivePercent, RadioButtonAdditivePoints, RadioButtonMultiplicative
            };
            NumericUpDown[] numericUpDowns = { NumericUpDownDrop, NumericUpDownKeep };

            foreach (TextBox tb in textBoxes)
            {
                tb.Text = "";
            }
            foreach (RadioButton rb in radioButtons)
            {
                rb.Checked = false;
            }
            foreach (NumericUpDown nUD in numericUpDowns)
            {
                nUD.Value = 0;
            }
            if (clearName)
            {
                TextBoxCurveName.Text       = "";
                CheckBoxCurveActive.Checked = true;
            }
            if (deselect)
            {
                CheckedListBoxCurves.ClearSelected();
            }
        }
Exemplo n.º 3
0
        private void SaveCurve(bool warning = true)
        {
            //everything in the required group box
            if (TextBoxCurveName.Text.StartsWith("$$$ADJUST$$$"))
            {
                MessageBox.Show(
                    "You sly dog! You can't start a curve with \"$$$ADJUST$$$\" because it has a special meaning" +
                    " in this program.", "Someone read the code!", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }

            Curve newCurve = new Curve(TextBoxCurveName.Text);

            newCurve.active = CheckBoxCurveActive.Checked;
            List <int> enabledCatIndexes = new List <int>();

            foreach (var item in CheckedListBoxCategories.CheckedIndices)
            {
                enabledCatIndexes.Add(Convert.ToInt32(item));
            }
            newCurve.appliedCatIndexes = enabledCatIndexes.ToArray();
            List <string> enabledAssgns = new List <string>();

            foreach (var item in CheckedListBoxAssignments.CheckedItems)
            {
                enabledAssgns.Add(item.ToString());
            }
            newCurve.appliedAssgnNames = enabledAssgns.ToArray();

            //the actual curve method
            if (RadioButtonDrop.Checked)
            {
                newCurve.kept = -1 * (int)NumericUpDownDrop.Value;
                if (!Settings.unrestrictedCurves)
                {
                    if (enabledCatIndexes.Count > 1)
                    {
                        MessageBox.Show("This curve can only be applied to 1 category. Cannot apply/save curve.", "Error!", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return;
                    }
                }
            }
            else if (RadioButtonKeep.Checked)
            {
                newCurve.kept = (int)NumericUpDownKeep.Value;
                if (!Settings.unrestrictedCurves)
                {
                    if (enabledCatIndexes.Count > 1)
                    {
                        MessageBox.Show("This curve can only be applied to 1 category. Cannot apply/save curve.", "Error!", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return;
                    }
                }
            }
            else if (RadioButtonConDropPercent.Checked)
            {
                double val;
                if (Double.TryParse(TextBoxConDropPercent.Text, out val))
                {
                    newCurve.conDropPercent = val;
                }
                else
                {
                    MessageBox.Show("Value entered for drop if below % is invalid.", "Error!", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
            }
            else if (RadioButtonConDropPoints.Checked)
            {
                double val;
                if (double.TryParse(TextBoxConDropPoints.Text, out val))
                {
                    newCurve.conDropPoints = val;
                }
                else
                {
                    MessageBox.Show("Value entered for drop if below x points is invalid.", "Error!", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
            }
            else if (RadioButtonCurveToMean.Checked)
            {
                double val;
                if (double.TryParse(TextBoxCurveToMean.Text, out val))
                {
                    newCurve.goalMeanPercent = val;
                }
                else
                {
                    MessageBox.Show("Value entered for curve to mean % is invalid.", "Error!", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }

                if (!Settings.unrestrictedCurves)
                {
                    if (enabledCatIndexes.Count > 1)
                    {
                        MessageBox.Show("This curve can only be applied to 1 category. Cannot apply/save curve.", "Error!", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return;
                    }
                }
            }
            else if (RadioButtonAdditivePercent.Checked)
            {
                double val;
                if (double.TryParse(TextBoxAdditivePercent.Text, out val))
                {
                    newCurve.additivePercent = val / 100;
                }
                else
                {
                    MessageBox.Show("Value entered for add x % is invalid.", "Error!", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
            }
            else if (RadioButtonAdditivePoints.Checked)
            {
                double val;
                if (double.TryParse(TextBoxAdditivePoints.Text, out val))
                {
                    newCurve.additive = val;
                }
                else
                {
                    MessageBox.Show("Value entered for add x points is invalid.", "Error!", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
            }
            else if (RadioButtonMultiplicative.Checked)
            {
                double val;
                if (double.TryParse(TextBoxMultiplicative.Text, out val))
                {
                    newCurve.multiplicative = val;
                }
                else
                {
                    MessageBox.Show("Value entered for multiply by x is invalid.", "Error!", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
            }
            else if (!Settings.unrestrictedCurves)
            {
                MessageBox.Show("No curve method selected. Cannot save.", "Error!", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            if (_schoolClass.CurveExists(newCurve.name) != -1)  //if the curve will be overwritten
            {
                var result = DialogResult.Yes;
                if (warning)
                {
                    result = MessageBox.Show("Data already exists for " + newCurve.name + ". Overwrite the file?",
                                             "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                }
                if (result == DialogResult.Yes)
                {
                    XMLHandler.DeleteCurve(_schoolClass, newCurve);
                }
                else
                {
                    return;
                }
            }
            try
            {
                XMLHandler.SaveCurveToFile(_schoolClass, newCurve, true);
            }
            catch
            {
                if (warning)
                {
                    MessageBox.Show("Curve name is not valid.", "Error!", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                return;
            }
            _schoolClass.LoadCurves();
            DisplayCurvedData();
            FillCurvesCheckedListBox();
            CheckedListBoxCurves.SetSelected(CheckedListBoxCurves.Items.IndexOf(newCurve.name), true);
        }