//This thing will throw all sorts of exceptions, make sure to catch them... //It also returns null if basically anything goes wrong? Probably... public static GenericRule newFromIO(string[] lines) { GenericRule schRule = null; if (Int32.Parse(lines[1]) == 0) //5 lines for TimeRule { byte type = Byte.Parse(lines[0]); string[] blockTheseApps = lines[1].Split(new string[] { ",", " " }, StringSplitOptions.RemoveEmptyEntries); string[] stringBool = lines[2].Split(new string[] { ",", " " }, StringSplitOptions.RemoveEmptyEntries); bool[] blockTheseComparts = new bool[stringBool.Length]; for (byte i = 0; i < blockTheseComparts.Length; i++) { blockTheseComparts[i] = Convert.ToBoolean(stringBool[i]); } switch (type) { case 0: default: DateTime startTime = DateTime.Parse(lines[3]); DateTime endTime = DateTime.Parse(lines[4]); schRule = new TimeRule(startTime, endTime, blockTheseComparts, blockTheseApps); break; } } return(schRule); }
private void btnOk_Click(object sender, EventArgs e) { //Converts dialog input into two DatTime objects. DateTime startDateTime = RemoveTimeVars(startDatePicker.Value); double hours = startHourPicker.SelectedIndex; if (startAMPMPicker.SelectedIndex == 1) { hours += 12; //check if p.m. } startDateTime = startDateTime.AddHours(hours).AddMinutes(startMinutePicker.SelectedIndex); DateTime endDateTime = RemoveTimeVars(endDatePicker.Value); hours = endHourPicker.SelectedIndex; if (endAMPMPicker.SelectedIndex == 1) { hours += 12; } endDateTime = endDateTime.AddHours(hours).AddMinutes(endMinutePicker.SelectedIndex); if (startDateTime.CompareTo(endDateTime) > 0) { MessageBox.Show("End date cannot be before start date.", "Error"); return; } string[] split = new string[] { " ", "," }; userSelectedAppBlocks = appsBlockedInput.Text.Split(split, StringSplitOptions.RemoveEmptyEntries); userSelectedCompartBlocks = new bool[] { checkBox1.Checked, checkBox2.Checked, checkBox3.Checked, checkBox4.Checked, checkBox5.Checked, checkBox6.Checked, checkBox7.Checked, checkBox8.Checked, checkBox9.Checked, }; //TODO: catch blank or invalid DateTimes. //TODO: fields do not complete correctly. rule = new TimeRule(startDateTime, endDateTime, userSelectedCompartBlocks, userSelectedAppBlocks); if (rule.namedAppsBlocked.Equals("none") && rule.namedCompartsBlocked.Equals("none")) { MessageBox.Show("Please enter compartment(s) and/or app(s) to block", "Error"); return; } var confirmResult = MessageBox.Show("Set " + rule.ToString() + " rule from " + rule.RuleDesc() + "?", "Confirm Adding Rule", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { this.DialogResult = DialogResult.OK; this.Close(); } }
private void timeIntervalToolStripMenuItem_Click(object sender, EventArgs e) { SchedulerTime sch = new SchedulerTime(); sch.ShowDialog(); GenericRule schRule = sch.GetRule(); if (sch.DialogResult == DialogResult.OK) { rules.Add(schRule); updateGridView(); Debug.WriteLine("Ruled added."); System.IO.File.AppendAllLines(comDirectory + "\\hitman.txt", schRule.Hire()); } else if (sch.DialogResult == DialogResult.Cancel) { Debug.WriteLine("Canceled."); } else { Debug.WriteLine("Dialog Result Unknown!"); } updateLocks(); }