示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            var MarksandWeightingTable = new Marks_and_Weighting_Table(subjectnamearray, datatablesubjectnamearray, numofsubjects, MarksWeightingRecordDataTable, subjectMarks, totalMarks);

            MarksandWeightingTable.Closed += (s, args) => this.Close();
            MarksandWeightingTable.Show();
            MarksandWeightingTable.StartPosition = FormStartPosition.Manual;
            MarksandWeightingTable.Location      = new Point(this.Location.X, this.Location.Y);
        }
示例#2
0
        private void TaskPageNextBtn_Click(object sender, EventArgs e)
        {
            NumOfTasks.Enabled = false;
            int NumberOfTasks = NumOfTasks.SelectedIndex + 2;

            var EmptyErrorMsg         = false;
            var TotalWeightageMsg     = false;
            var TotalPercentageageMsg = false;

            for (int i = 0; i < NumOfSubjects; i++)
            {
                double SubjectWeightage = 0;

                for (int j = 0; j < NumberOfTasks; j++)
                {
                    double parsedValue;
                    if (!double.TryParse(weightages[j, i].Text, out parsedValue) || !double.TryParse(marks[j, i].Text, out parsedValue))
                    {
                        MessageBox.Show("This is a number only field", "Error Message");
                        return;
                    }

                    if (weightages[j, i].Text.Trim() == string.Empty || marks[j, i].Text.Trim() == string.Empty)
                    {
                        EmptyErrorMsg = true;
                        i             = NumOfSubjects;
                        break;
                    }

                    if (Convert.ToDouble(weightages[j, i].Text) < 0 || Convert.ToDouble(weightages[j, i].Text) > 1)
                    {
                        TotalWeightageMsg = true;
                        i = NumOfSubjects;
                        break;
                    }

                    if (Convert.ToDouble(marks[j, i].Text) < 0 || Convert.ToDouble(marks[j, i].Text) > 100)
                    {
                        TotalPercentageageMsg = true;
                        i = NumOfSubjects;
                        break;
                    }

                    SubjectWeightage += Convert.ToDouble(weightages[j, i].Text);
                }

                if (SubjectWeightage != Convert.ToDouble(1))
                {
                    TotalWeightageMsg = true;
                    break;
                }
            }

            if (EmptyErrorMsg == true)
            {
                MessageBox.Show("Please fill out all textboxes or select a valid input.", "Error Message");
                return;
                /*https://www.codeproject.com/Questions/496674/EmptyplusTextboxplusValidationplusinplusC*/
            }

            if (TotalWeightageMsg == true)
            {
                MessageBox.Show("Please enter a total weightage of 1 for each subject.", "Error Message");
                return;
            }

            if (TotalPercentageageMsg == true)
            {
                MessageBox.Show("Please enter a total percentage of 1 for each task.", "Error Message");
                return;
            }

            /* Marks and Weighting Table */

            DataTable MarksWeightingRecordDataTable = new DataTable();

            MarksWeightingRecordDataTable.Clear();

            foreach (string DatatableSubjectName in DatatableSubjectNameArray)
            {
                MarksWeightingRecordDataTable.Columns.Add(DatatableSubjectName);
            }

            for (int i = 0; i < NumberOfTasks; i += 1)
            {
                DataRow newRow = MarksWeightingRecordDataTable.NewRow();

                for (int j = 0, k = 0; k < NumOfSubjects; j += 2, k++)
                {
                    newRow[j]     = weightages[i, k].Text;
                    newRow[j + 1] = marks[i, k].Text;
                }

                MarksWeightingRecordDataTable.Rows.Add(newRow);
            }

            double[] Subjectmarks = new double[NumOfSubjects];
            for (int i = 0; i < NumOfSubjects; i += 1)
            {
                double sum = 0;
                for (int k = 0; k < NumberOfTasks; k++)
                {
                    double temp = Convert.ToDouble(weightages[k, i].Text) * Convert.ToDouble(marks[k, i].Text);
                    sum += temp;
                }

                Subjectmarks[i] = sum;
            }

            double totalMarks = 0;

            for (int i = 0; i < NumOfSubjects; i++)
            {
                totalMarks += Subjectmarks[i];
            }

            totalMarks /= NumOfSubjects;

            this.Hide();
            var MarksandWeightingTable = new Marks_and_Weighting_Table(SubjectNameArray, DatatableSubjectNameArray, NumOfSubjects, MarksWeightingRecordDataTable, Subjectmarks, totalMarks);

            MarksandWeightingTable.Closed += (s, args) => this.Close();
            MarksandWeightingTable.Show();
            MarksandWeightingTable.StartPosition = FormStartPosition.Manual;
            MarksandWeightingTable.Location      = new Point(this.Location.X, this.Location.Y);
        }