Beispiel #1
0
        // Constructor that sets some info on the object correct in the instance variables
        public ScheduleItem(UserInfo user, int index, HouseRules houseRules)
        {
            this.houseRules     = houseRules;
            this.houseRule      = houseRules.AllRules[index];
            this.dateTimeBuffer = this.houseRule.LastCompleted;

            this.index = index;
            int timesUntilNextAppointment;

            if (houseRules.AllRules[index].LastCompleted == DateTime.Today && user.ID != houseRules.AllRules[index].CurrentStudentId)
            {
                timesUntilNextAppointment = 0;
            }
            else if (user.ID == houseRules.AllRules[index].CurrentStudentId)
            {
                timesUntilNextAppointment = 1;
            }
            else
            {
                int current = houseRule.CurrentStudentId;

                timesUntilNextAppointment = Math.Abs(user.ID - current);

                if (timesUntilNextAppointment < 0)
                {
                    timesUntilNextAppointment += houseRule.OrderOfStudents.Count;
                }

                timesUntilNextAppointment += 1;
            }

            this.ID = houseRule.CurrentStudentId;
            span    = houseRule.LastCompleted.AddDays(timesUntilNextAppointment * houseRule.Interval).Subtract(DateTime.Today);
        }
Beispiel #2
0
        //Adds notification that a new rule is proposed
        private void AddHouseRule(HouseRule rule, int index, int textIndex)
        {
            // creates new labels and button
            Label  ruleLabel  = new Label();
            Label  ruleNumber = new Label();
            Button disapprove = new Button();

            disapprove.FlatStyle = FlatStyle.Flat;

            if (rule.Interval == 1)
            {
                ruleLabel.Text = rule.RuleText + " everyday";
            }
            else
            {
                ruleLabel.Text = rule.RuleText + " every " + rule.Interval.ToString() + " days";
            }
            ruleLabel.AutoSize = true;
            disapprove.Size    = new Size(25, 25);
            disapprove.Text    = "x";
            ruleNumber.Text    = (textIndex + 1).ToString();
            ruleNumber.Tag     = index + 1;

            AddHouseRuleRow(ruleNumber, ruleLabel, disapprove);
        }
        // Adds a House Rule
        private void AddHouseRule(HouseRule rule, int index)
        {
            Button removeRuleButton = new Button();
            Label  ruleLabel        = new Label();
            Label  ruleNumber       = new Label();

            ruleLabel.Text        = rule.RuleText;
            ruleLabel.AutoSize    = true;
            removeRuleButton.Size = new Size(30, 25);
            removeRuleButton.Text = "x";
            ruleNumber.Text       = (index + 1).ToString();
            AddHouseRuleRow(ruleNumber, ruleLabel, removeRuleButton);
        }
Beispiel #4
0
 public IActionResult AddHouseRule(Category category)
 {
     if (ModelState.IsValid)
     {
         var HouseRule = new HouseRule
         {
             Name = category.Name,
         };
         _db.AddHouseRules(HouseRule);
         return(RedirectToAction("Dashboard", "Admin"));
     }
     return(View("Views/Shared/AddNewHouseRulePartialView.cshtml", category));
 }
Beispiel #5
0
        //Adds notification that a new rule is proposed
        private void AddNotificationsRule(HouseRule rule, int index, int textIndex)
        {
            // creates labels and buttons to display
            Label  ruleLabel  = new Label();
            Label  ruleNumber = new Label();
            Button approve    = new Button();

            approve.FlatStyle = FlatStyle.Flat;
            Button disapprove = new Button();

            disapprove.FlatStyle = FlatStyle.Flat;

            ruleLabel.Text     = rule.RuleText + " every " + rule.Interval.ToString() + " days";
            ruleLabel.AutoSize = true;
            approve.Size       = new Size(25, 25);
            approve.Text       = "+";
            disapprove.Size    = new Size(25, 25);
            disapprove.Text    = "x";
            ruleNumber.Text    = (textIndex + 1).ToString();
            ruleNumber.Tag     = index + 1;

            AddNotificationsRuleRow(ruleNumber, ruleLabel, approve, disapprove);
        }
Beispiel #6
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;
                }
            }
        }
Beispiel #7
0
 public void AddHouseRules(HouseRule houseRule)
 {
     _db.HouseRules.Add(houseRule);
     _db.SaveChanges();
 }
Beispiel #8
0
 public HouseRuleTest()
 {
     _rule = new HouseRule();
 }