示例#1
0
 private void BtnProposeRule_Click(object sender, EventArgs e)
 {
     //If a Rule Form does not already exist, create one
     if (ruleForm == null)
     {
         ruleForm = new AddRuleStudent();
         ruleForm.Show();
     }
 }
示例#2
0
        //Checks if any complaints or rules where added
        private void UpdatesTick()
        {
            //If a rule has been added to the textbox in the Rule Form and
            //the Add button has been pressed, get the rule from that textbox
            if (AddRuleStudent.ruleName != "")
            {
                HouseRule houseRule = new HouseRule();
                houseRule.ApprovalState    = false;
                houseRule.ID               = houseRules.AllRules.Count;
                houseRule.Interval         = AddRuleStudent.repeatRule;
                houseRule.RuleText         = AddRuleStudent.ruleName;
                houseRule.LastCompleted    = DateTime.Now;
                houseRule.OnlyThisWeek     = false;
                houseRule.StudentsApproval = new Dictionary <int, bool>();

                for (int i = 0; i < student.TotalStudentNumber; i++)
                {
                    houseRule.StudentsApproval.Add(i + 1, false);

                    //The order of students is kept sorted by their ID
                    houseRule.OrderOfStudents.Add(i + 1);
                }

                houseRule.CurrentStudentId             = houseRule.OrderOfStudents[0];
                houseRule.StudentsApproval[student.ID] = true;

                houseRules.AllRules.Add(houseRule);

                AddRuleStudent.ruleName   = "";
                AddRuleStudent.repeatRule = 0;

                RulesUpdateTick();
                server.UpdateHouseRules(houseRules);
            }

            //If a complaint has been filed to the textbox in the Complaint Form and
            //the Add button has been pressed, get the complaint from that textbox
            if (AddComplainStudent.ruleBroken != "")
            {
                Complaint complaint = new Complaint();
                complaint.BrokenBy      = AddComplainStudent.IDOfRuleBreaker;
                complaint.ComplaintText = AddComplainStudent.ruleBroken;
                complaint.FiledBy       = AddComplainStudent.IDOfComplainer;
                complaint.FiledDate     = DateTime.Now;
                complaint.ID            = complaints.AllComplaints.Count;
                complaints.AllComplaints.Add(complaint);

                AddComplainStudent.ruleBroken      = "";
                AddComplainStudent.IDOfRuleBreaker = 0;
                AddComplainStudent.IDOfComplainer  = 0;

                //Updates form
                RulesUpdateTick();
                server.UpdateComplaints(complaints);
            }

            //If the rule form has been closed, revert ruleForm back to null
            if (ruleForm != null)
            {
                if (ruleForm.IsDisposed == true)
                {
                    ruleForm = null;
                }
            }

            //If the complaint Form has been closed, revert complaintForm back to null
            if (complaintForm != null)
            {
                if (complaintForm.IsDisposed == true)
                {
                    complaintForm = null;
                }
            }
        }