示例#1
0
 private void AddSubPoints(bool neg)
 {
     if (ErrorChecking.TextIsType("double", TextBoxPE.Text) && ErrorChecking.TextIsType("double", TextBoxPP.Text))
     {
         string PE = TextBoxPE.Text;
         string PP = TextBoxPP.Text;
         main.SaveIndexToMem(Index, PE, PP, neg);
         main.DisplayPage(main.currentPage);
     }
 }
        private void SaveDataInForm()
        {
            if (VerifyData())
            {
                Assignment temp = new Assignment();
                temp.name       = TextBoxName.Text;
                temp.catIndex   = GetCatIndex(ComboBoxCats.Text);
                temp.points     = Convert.ToDouble(TextBoxPoints.Text);
                temp.outOf      = Convert.ToDouble(TextBoxOutOf.Text);
                temp.real       = RadioButtonReal.Checked;
                temp.active     = CheckBoxActive.Checked;
                temp.meanPoints = 0.0;
                if (ErrorChecking.TextIsType("double", TextBoxMeanPoints.Text))
                {
                    temp.meanPoints = Convert.ToDouble(TextBoxMeanPoints.Text);
                }

                //simple edit of the same assignment
                if (_currentAssignment != null && _currentAssignment.name.Equals(temp.name))
                {
                    XMLHandler.SaveAssignmentToFile(_schoolClass, temp, false);
                }
                else
                {
                    //this assignment name already exists, and it is NOT the one we are editing
                    if (XMLHandler.AssignmentFileExists(_schoolClass, temp))
                    {
                        XMLHandler.SaveAssignmentToFile(_schoolClass, temp);
                        var result = DialogResult.Yes;
                        if (!Settings.AlwaysDeleteOldAssignment)
                        {
                            result = MessageBox.Show("Would you like to delete the assignment with the old name?",
                                                     "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        }

                        if (result == DialogResult.Yes)
                        {
                            XMLHandler.DeleteAssignment(_schoolClass, _currentAssignment);
                        }
                    }
                    else
                    {
                        XMLHandler.SaveAssignmentToFile(_schoolClass, temp, warning: false);
                    }
                }
                _currentAssignment = temp;
                FillDataView();
                DisplayCellDataInEdit(temp);
            }
        }
        private bool VerifyData(bool warning = true)
        {
            if (TextBoxName.Text.Equals(""))
            {
                if (warning)
                {
                    MessageBox.Show(@"Name is invalid", @"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return(false);
            }
            if (ComboBoxCats.Text.Equals(""))
            {
                if (warning)
                {
                    MessageBox.Show(@"No category selected", @"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return(false);
            }
            if (!ErrorChecking.TextIsType("double", TextBoxPoints.Text))
            {
                if (warning)
                {
                    MessageBox.Show(@"Points earned is invalid", @"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return(false);
            }
            if (!ErrorChecking.TextIsType("double", TextBoxOutOf.Text))
            {
                if (warning)
                {
                    MessageBox.Show(@"Out of is invalid", @"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return(false);
            }

            if (!ErrorChecking.TextIsType("double", TextBoxMeanPoints.Text))
            {
                if (!TextBoxMeanPoints.Text.Equals("") && warning)
                {
                    MessageBox.Show(@"Mean points earned is invalid, continuing anyway", @"Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            return(true);
        }
示例#4
0
        public static Curve[] ReadCurves(SchoolClass schoolClass)
        {
            if (!Directory.Exists(DIRECTORY + CURVE_DIR))
            {
                Directory.CreateDirectory(DIRECTORY + CURVE_DIR);
            }
            string fullDirPath = DIRECTORY + CURVE_DIR + schoolClass.className + "/";

            if (!Directory.Exists(fullDirPath))
            {
                Directory.CreateDirectory(fullDirPath);
            }

            bool flag_needsUpdate = false;
            bool flag_error       = false;
            int  updated          = 0;

            Curve[]  curves       = new Curve[0];
            string[] GC3Files     = Directory.GetFiles(fullDirPath, "*" + C_FILE_EXT);
            string[] useableFiles = new string[0];
            foreach (string file in GC3Files)
            {
                XElement workingXE;
                try
                {
                    workingXE = XElement.Load(file); //<GC3_Data>
                }
                catch
                {
                    flag_error = true;
                    continue;
                }
                var temp = workingXE.Element("SCHEMA_VER").Value;
                if (temp == null)
                {
                    continue;
                }
                if (!ErrorChecking.TextIsType("int", temp))
                {
                    flag_error = true;
                    continue;
                }
                int fileSchemaVer = Convert.ToInt32(temp);
                if (fileSchemaVer > C_SCHEMA_VER)
                {
                    flag_needsUpdate = true;
                    continue;
                }
                else if (fileSchemaVer < C_SCHEMA_VER)
                {
                    //implement a way to update curve schema versions
                }

                //the file is good, add it to the list to be imported
                Array.Resize(ref useableFiles, useableFiles.Length + 1);
                useableFiles[useableFiles.Length - 1] = file;
            }
            if (updated > 0)
            {
                curves = ReadCurves(schoolClass);
            }

            //error notifications
            if (flag_error)
            {
                MessageBox.Show("At least one " + C_FILE_EXT + " file was not in a readable format!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            if (flag_needsUpdate)
            {
                MessageBox.Show("At least one " + C_FILE_EXT + " file was made for a newer version of Grade Calculator 3 than is installed. There may be an update.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            if (useableFiles.Length == 0)
            {
                return(null);
            }

            //continue on to converting the XML to <Assignment> type
            bool flag_invalidEntryInFile = false;

            foreach (string file in useableFiles)
            {
                try
                {
                    XElement XE = XElement.Load(file);
                    XE = XE.Element("CurveData");
                    Curve curve = new Curve(XE.Element("Name").Value);
                    curve.active = Convert.ToBoolean(XE.Element("Active").Value);
                    curve.ignoreUserInactives = Convert.ToBoolean(XE.Element("IgnoreUserActives").Value);
                    curve.appliedCatIndexes   = XCurveCatIndexesToInt(XE.Element("CatIndexes"));
                    curve.appliedAssgnNames   = XCurveAssgnNamesToString(XE.Element("AssgnNames"));
                    curve.kept                  = Convert.ToInt32(XE.Element("Kept").Value);
                    curve.conDropPercent        = Convert.ToDouble(XE.Element("ConDropPercent").Value);
                    curve.conDropPoints         = Convert.ToDouble(XE.Element("ConDropPoints").Value);
                    curve.additive              = Convert.ToDouble(XE.Element("Additive").Value);
                    curve.multiplicative        = Convert.ToDouble(XE.Element("Multiplicative").Value);
                    curve.additivePercent       = Convert.ToDouble(XE.Element("AdditivePercent").Value);
                    curve.goalMeanPercent       = Convert.ToDouble(XE.Element("GoalMeanPercent").Value);
                    curve.goalMeanPercentMethod = Convert.ToInt32(XE.Element("GoalMeanPercentMethod").Value);

                    Array.Resize(ref curves, curves.Length + 1);
                    curves[curves.Length - 1] = curve;
                }
                catch
                {
                    flag_invalidEntryInFile = true;
                    continue;
                }
            }
            if (flag_invalidEntryInFile)
            {
                MessageBox.Show(@"At least one " + C_FILE_EXT + @" file had an invalid entry!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (Settings.DebugMsg)
            {
                MessageBox.Show(@"Loaded " + Convert.ToString(curves.Length) + @" curves successfully!",
                                @"Success!",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            return(curves);
        }
示例#5
0
        public static Assignment[] ReadAssignments(SchoolClass schoolClass)
        {
            //checks to make sure DirectoryNotFoundException does not occur
            if (!Directory.Exists(DIRECTORY + ASSGN_DIR))
            {
                Directory.CreateDirectory(DIRECTORY + ASSGN_DIR);
            }
            string fullDirPath = DIRECTORY + ASSGN_DIR + schoolClass.className + "/";

            if (!Directory.Exists(fullDirPath))
            {
                Directory.CreateDirectory(fullDirPath);
            }

            bool flag_needsUpdate = false;
            bool flag_error       = false;
            int  updated          = 0;

            Assignment[] assignments  = new Assignment[0];
            string[]     GC3Files     = Directory.GetFiles(fullDirPath, "*" + A_FILE_EXT);
            string[]     useableFiles = new string[0];
            foreach (string file in GC3Files)
            {
                XElement workingXE;
                try
                {
                    workingXE = XElement.Load(file); //<GC3_Data>
                }
                catch
                {
                    flag_error = true;
                    continue;
                }
                var temp = workingXE.Element("SCHEMA_VER").Value;
                if (temp == null)
                {
                    continue;
                }
                if (!ErrorChecking.TextIsType("int", temp))
                {
                    flag_error = true;
                    continue;
                }
                int fileSchemaVer = Convert.ToInt32(temp);
                if (fileSchemaVer > A_SCHEMA_VER)
                {
                    flag_needsUpdate = true;
                    continue;
                }
                else if (fileSchemaVer < A_SCHEMA_VER)
                {
                    //implement a way to update Assignment schema versions
                }

                //the file is good, add it to the list to be imported
                Array.Resize(ref useableFiles, useableFiles.Length + 1);
                useableFiles[useableFiles.Length - 1] = file;
            }
            if (updated > 0)
            {
                assignments = ReadAssignments(schoolClass);
            }

            //error notifications
            if (flag_error)
            {
                MessageBox.Show("At least one " + A_FILE_EXT + " file was not in a readable format!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            if (flag_needsUpdate)
            {
                MessageBox.Show("At least one " + A_FILE_EXT + " file was made for a newer version of Grade Calculator 3 than is installed. There may be an update.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            if (useableFiles.Length == 0)
            {
                return(null);
            }

            //continue on to converting the XML to <Assignment> type
            bool flag_invalidEntryInFile = false;

            foreach (string file in useableFiles)
            {
                try
                {
                    XElement XE = XElement.Load(file);
                    XE = XE.Element("AssignmentData");
                    Assignment assgn = new Assignment();
                    assgn.name       = XE.Element("Name").Value;
                    assgn.catIndex   = Convert.ToInt32(XE.Element("CatIndex").Value);
                    assgn.real       = Convert.ToBoolean(XE.Element("Real").Value);
                    assgn.active     = Convert.ToBoolean(XE.Element("Active").Value);
                    assgn.points     = Convert.ToDouble(XE.Element("Points").Value);
                    assgn.outOf      = Convert.ToDouble(XE.Element("OutOf").Value);
                    assgn.meanPoints = Convert.ToDouble(XE.Element("MeanPoints").Value);
                    Array.Resize(ref assignments, assignments.Length + 1);
                    assignments[assignments.Length - 1] = assgn;
                }
                catch
                {
                    flag_invalidEntryInFile = true;
                    continue;
                }
            }
            if (flag_invalidEntryInFile)
            {
                MessageBox.Show(@"At least one " + A_FILE_EXT + @" file had an invalid entry!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (Settings.DebugMsg)
            {
                MessageBox.Show(@"Loaded " + Convert.ToString(assignments.Length) + @" assignments successfully!",
                                @"Success!",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            return(assignments);
        }
示例#6
0
        /*
         *  Schema version history:
         *      D_SCHEMA_VER:
         *          1 : v0.1-v0.3.2
         *          2 : v0.4-Present
         *      A_SCHEMA_VER:
         *          1 : v0.3-Present
         *      C_SCHEMA_VER:
         *          1 : v0.4-Present
         *      S_SCHEMA_VER:
         *          1 : v0.5-Present
         */

        public static SchoolClass[] ReadSchoolClasses()
        {
            if (!Directory.Exists(DIRECTORY + CLASS_DIR))
            {
                Directory.CreateDirectory(DIRECTORY + CLASS_DIR);
            }

            bool flag_needsUpdate = false;
            bool flag_error       = false;
            int  updated          = 0;

            SchoolClass[] schoolClasses = new SchoolClass[0];
            string[]      GC3Files      = Directory.GetFiles(DIRECTORY + CLASS_DIR, "*" + D_FILE_EXT);
            string[]      useableFiles  = new string[0];
            foreach (string file in GC3Files)
            {
                XElement workingXE;
                try
                {
                    workingXE = XElement.Load(file); //<GC3_Data>
                }
                catch
                {
                    flag_error = true;
                    continue;
                }
                var temp = workingXE.Element("SCHEMA_VER").Value;
                if (temp == null)
                {
                    continue;
                }
                if (!ErrorChecking.TextIsType("int", temp))
                {
                    flag_error = true;
                    continue;
                }
                int fileSchemaVer = Convert.ToInt32(temp);
                if (fileSchemaVer > D_SCHEMA_VER)
                {
                    flag_needsUpdate = true;
                    continue;
                }
                else if (fileSchemaVer < D_SCHEMA_VER)
                {
                    //the following line should be used for non-backwards compatible schema changes
                    updated += UpdateSchema(fileSchemaVer, file);
                }

                //the file is good, add it to the list to be imported
                Array.Resize(ref useableFiles, useableFiles.Length + 1);
                useableFiles[useableFiles.Length - 1] = file;
            }
            if (updated > 0)
            {
                schoolClasses = ReadSchoolClasses();
            }

            //error notifications
            if (flag_error)
            {
                MessageBox.Show("At least one " + D_FILE_EXT + " file was not in a readable format!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            if (flag_needsUpdate)
            {
                MessageBox.Show("At least one " + D_FILE_EXT + " file was made for a newer version of Grade Calculator 3 than is installed. There may be an update.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            if (useableFiles.Length == 0)
            {
                return(null);
            }

            //continue on to converting the XML to SchoolClass type
            bool flag_invalidEntryInFile = false;

            foreach (string file in useableFiles)
            {
                try
                {
                    XElement XE          = XElement.Load(file);
                    XElement xCanvasData = XE.Element("CanvasData");
                    XE = XE.Element("ClassData");
                    SchoolClass CC = new SchoolClass();
                    CC.className = XE.Element("ClassName").Value;
                    CC.professor = XE.Element("Professor").Value;
                    XElement XETerm = XE.Element("Term");
                    CC.termSeason               = XETerm.Element("Season").Value;
                    CC.termYear                 = Convert.ToInt32(XETerm.Element("Year").Value);
                    CC.credits                  = Convert.ToInt32(XE.Element("Credits").Value);
                    CC.gradeScaleFormat         = Convert.ToInt32(XE.Element("GradeScaleFormat").Value);
                    CC.gradeScale               = XGradeScaleToDouble(CC.gradeScaleFormat, XE.Element("GradeScale"));
                    (CC.catNames, CC.catWorths) = XCatsToArray(XE.Element("Categories"));
                    CC.enrolled                 = Convert.ToInt32(XE.Element("Enrolled").Value);


                    if (xCanvasData != null)
                    {
                        CC.canvasData = XElementToCanvasData(xCanvasData);
                    }

                    Array.Resize(ref schoolClasses, schoolClasses.Length + 1);
                    schoolClasses[schoolClasses.Length - 1] = CC;
                }
                catch
                {
                    flag_invalidEntryInFile = true;
                    continue;
                }
            }
            if (flag_invalidEntryInFile)
            {
                MessageBox.Show("At least one " + D_FILE_EXT + " file had an invalid entry!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            //MessageBox.Show("Loaded " + Convert.ToString(schoolClasses.Length)+ " classes successfully!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            return(schoolClasses);
        }
示例#7
0
        public void SaveCurrentData()
        {
            SchoolClass schoolClass = new SchoolClass();

            Double[] gradeScaleValues;

            //Class Information
            //Class Name
            if ((textBoxClassName.Text != "") && (textBoxClassName.Text != @"(None)"))
            {
                schoolClass.className = textBoxClassName.Text;
            }
            else
            {
                MessageBox.Show("Class Name is invalid", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //Professor
            if (textBoxProfessor.Text != "")
            {
                schoolClass.professor = textBoxProfessor.Text;
            }
            else
            {
                schoolClass.professor = null;
            }

            //Term
            if (comboBoxTermSeason.Text != "")
            {
                schoolClass.termSeason = comboBoxTermSeason.Text;
                schoolClass.termYear   = (int)numericUpDownTermYear.Value;
            }
            else
            {
                schoolClass.termSeason = null;
                schoolClass.termYear   = -1;
            }

            //Credits
            schoolClass.credits = (int)numericUpDownCredits.Value;

            //Students
            schoolClass.enrolled = (int)numericUpDownEnrolled.Value;

            //Grade Scale
            //Grade Scale Format
            if (radioButtonAF.Checked == true)
            {
                schoolClass.gradeScaleFormat = 1;
            }
            else if (radioButtonSN.Checked == true)
            {
                schoolClass.gradeScaleFormat = 2;
            }
            else //note: this should never happen as radio buttons are being used.
            {
                MessageBox.Show("Grade Scale Format is invalid. (This should never happen)", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //Grade Scale Values
            //A-F
            int c = 0;

            if (schoolClass.gradeScaleFormat == 1)
            {
                TextBox[]  gradeScaleTextBoxes  = new TextBox[11];
                CheckBox[] gradeScaleCheckBoxes = new CheckBox[11];
                bool[]     gradeScaleEnableds   = new bool[11];

                gradeScaleTextBoxes[0]  = TextBoxA;
                gradeScaleTextBoxes[1]  = TextBoxAM;
                gradeScaleTextBoxes[2]  = TextBoxBP;
                gradeScaleTextBoxes[3]  = TextBoxB;
                gradeScaleTextBoxes[4]  = TextBoxBM;
                gradeScaleTextBoxes[5]  = TextBoxCP;
                gradeScaleTextBoxes[6]  = TextBoxC;
                gradeScaleTextBoxes[7]  = TextBoxCM;
                gradeScaleTextBoxes[8]  = TextBoxDP;
                gradeScaleTextBoxes[9]  = TextBoxD;
                gradeScaleTextBoxes[10] = TextBoxDM;

                /*
                 * gradeScaleCheckBoxes[0] = checkBoxA;
                 * gradeScaleCheckBoxes[1] = checkBoxAM;
                 * gradeScaleCheckBoxes[2] = checkBoxBP;
                 * gradeScaleCheckBoxes[3] = checkBoxB;
                 * gradeScaleCheckBoxes[4] = checkBoxBM;
                 * gradeScaleCheckBoxes[5] = checkBoxCP;
                 * gradeScaleCheckBoxes[6] = checkBoxC;
                 * gradeScaleCheckBoxes[7] = checkBoxCM;
                 * gradeScaleCheckBoxes[8] = checkBoxDP;
                 * gradeScaleCheckBoxes[9] = checkBoxD;
                 * gradeScaleCheckBoxes[10] = checkBoxDM;
                 */

                for (int i = 0; i < 11; i++)
                {
                    gradeScaleEnableds[c] = gradeScaleTextBoxes[i].Text != "";
                    c++;
                }

                gradeScaleValues = new double[11];

                c = 0;
                Double  prevVal = Double.MaxValue;
                Boolean flag    = false; //if no checkbox is enabled (other than F)
                foreach (Double element in gradeScaleValues)
                {
                    if (gradeScaleEnableds[c])
                    {
                        flag = true;
                        if (ErrorChecking.TextIsType("Double", gradeScaleTextBoxes[c].Text))
                        {
                            Double currentGradeScaleValue = Convert.ToDouble(gradeScaleTextBoxes[c].Text);
                            if (prevVal > currentGradeScaleValue)
                            {
                                gradeScaleValues[c] = currentGradeScaleValue;
                                prevVal             = currentGradeScaleValue;
                            }
                            else
                            {
                                MessageBox.Show("Grade scale has impossible values!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                        else
                        {
                            MessageBox.Show("Non-numeric value entered in grade scale!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                    else
                    {
                        gradeScaleValues[c] = -1; //if this grade value is disabled
                    }
                    c++;
                }
                if (!flag)
                {
                    MessageBox.Show("At least one grade must be enabled!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                schoolClass.gradeScale = gradeScaleValues;
            }

            //S/N (TODO)
            else
            {
                return;
            }

            //Categories
            SaveCurrentCatData();
            schoolClass.catNames = categoryNames;
            foreach (string cat in schoolClass.catNames)
            {
                if (cat.Equals(""))
                {
                    MessageBox.Show("One or more categories have no name!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            schoolClass.catWorths = new double[categoryWorthsS.Length];
            c = 0;
            Double total = 0;

            foreach (string worthString in categoryWorthsS)
            {
                if (ErrorChecking.TextIsType("Double", worthString))
                {
                    schoolClass.catWorths[c] = Convert.ToDouble(worthString);
                    total += schoolClass.catWorths[c];
                    c++;
                }
                else
                {
                    MessageBox.Show("Category total percentage contains non-numeric value!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            if ((int)Math.Round(total) != 100)
            {
                var result = MessageBox.Show("% of total adds to " + total.ToString() + ". Continue?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (result == DialogResult.No)
                {
                    return;
                }
            }
            if (!schoolClass.IsParseable())
            {
                MessageBox.Show("An entry contains an illegal XML character! Try removing any symbols entered.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //Data has been verified and is ready to be written to a file!
            _oldClass?.RemapAssignments(schoolClass, true);
            _oldClass?.RemapCurves(schoolClass);
            if (_oldClass != null && !_oldClass.className.Equals(schoolClass.className))
            {
                XMLHandler.ChangeAssignmentDirName(schoolClass, _oldClass);
                XMLHandler.DeleteClass(_oldClass.className, false);
            }

            if (XMLHandler.SaveSchoolClassToFile(schoolClass, XMLHandler.D_SCHEMA_VER))
            {
                main.InitialSetup();
                this.Close();
            }
            else
            {
                MessageBox.Show("An entry contains an illegal XML character! Try removing any symbols entered.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }