Ejemplo n.º 1
0
        private void btApply_Click(object sender, EventArgs e)
        {
            ScheduledAction saTmp, saCurr = new ScheduledAction();
            DateTime        dt;
            ListViewItem    lvi;
            int             i;
            string          lastfirst;
            int             dow;

            if (checkBox1.Checked && rbWeek.Checked && btWeekdays.Text.Contains(">>"))
            {
                dt = new DateTime(monthCalendar1.SelectionEnd.Ticks);
            }
            else
            {
                dt = new DateTime(monthCalendar1.SelectionStart.Ticks);
            }
            dt            = dt.AddHours(Convert.ToDouble(udHours.Value));
            dt            = dt.AddMinutes(Convert.ToDouble(udMinutes.Value));
            saCurr.repeat = checkBox1.Checked;
            if (checkBox1.Checked)
            {
                if (udKeer.Value == 0)
                {
                    MessageBox.Show("Nul keer herhalen kan niet.", "Fout", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (rbTijd.Checked)
                {
                    if (mtbDMJ.Text.Contains(" ") || mtbDMJ.Text.Length != 8 || mtbUM.Text.Contains(" ") || mtbUM.Text.Length != 5 || mtbDMJ.Text.Equals("00-00-00") && mtbUM.Text.Equals("00:00"))
                    {
                        MessageBox.Show("De tussenliggende tijd mag geen underscores bevatten en moet minimaal een minuut zijn.", "Fout", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    saCurr.repeattype = "period";
                    saCurr.period     = mtbDMJ.Text + " " + mtbUM.Text;
                }
                else if (rbWeek.Checked)
                {
                    if (mtbMJ.Text.Contains(" ") || mtbMJ.Text.Length != 5 || mtbMJ.Text.Equals("00-00"))
                    {
                        MessageBox.Show("De tussenliggende tijd mag geen underscores bevatten en moet minimaal een maand zijn.", "Fout", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    if (Convert.ToInt32(mtbDaysBefore.Text) >= 32)
                    {
                        MessageBox.Show("Dagen ervoor moet kleiner gelijk 31 zijn.", "Fout", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    saCurr.repeattype = "weekday";
                    dow = 0x0000;
                    if (miMa.Checked)
                    {
                        dow |= 0x0001;
                    }
                    if (miDi.Checked)
                    {
                        dow |= 0x0002;
                    }
                    if (miWo.Checked)
                    {
                        dow |= 0x0004;
                    }
                    if (miDo.Checked)
                    {
                        dow |= 0x0008;
                    }
                    if (miVr.Checked)
                    {
                        dow |= 0x0010;
                    }
                    if (miZa.Checked)
                    {
                        dow |= 0x0020;
                    }
                    if (miZo.Checked)
                    {
                        dow |= 0x0040;
                    }
                    if (btWeekdays.Text.Equals("...") || dow == 0)
                    {
                        MessageBox.Show("Trek een periode vanaf begin/eind van de maand en kies 1 of meer weekdagen via contextmenu van de knop.", "Fout", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    if (btWeekdays.Text.Contains("<<"))
                    {
                        lastfirst  = "last ";
                        lastfirst += btWeekdays.Text.Substring(0, 1);
                    }
                    else
                    {
                        lastfirst  = "first ";
                        lastfirst += btWeekdays.Text.Substring(btWeekdays.Text.Length - 1);
                    }
                    saCurr.period = lastfirst + " " + dow.ToString() + " " + mtbMJ.Text + " " + mtbDaysBefore.Text;
                    dt            = dt.AddDays(-1 * Convert.ToInt32(mtbDaysBefore.Text));
                }
                saCurr.times = Convert.ToInt32(udKeer.Value);
            }
            saCurr.fire     = dt.Ticks;
            saCurr.alertmsg = tbAlertmsg.Text;
            if (lvActions.SelectedItems.Count == 0)
            {
                // new alert
                saCurr.sGUID = Guid.NewGuid().ToString();

                int    k = 1;
                string key;
                do
                {
                    key = saCurr.fire.ToString() + "_" + k.ToString();
                    k++;
                } while (m_scheduledActions.ContainsKey(key));

                m_scheduledActions.Add(key, saCurr);
                lvi     = new ListViewItem(tbAlertmsg.Text);
                lvi.Tag = key;
                lvActions.Items.Add(lvi);
                lvi.Selected = true;
            }
            else
            {
                // update of existing alert
                lvActions.Items[lvActions.SelectedIndices[0]].Text = tbAlertmsg.Text;
                string key = (string)lvActions.SelectedItems[0].Tag;
                //saTmp = m_scheduledActions[key];
                //saCurr.sGUID = saTmp.sGUID;
                m_scheduledActions[key] = saCurr;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// load configuration from XML
        /// </summary>
        private void OpenConfig()
        {
            TreeNode        tnNew;
            XmlNodeList     nodes, tnodes, dnodes;
            XmlDocument     ActReg = new XmlDocument();
            Activiteit      actCurr;
            ScheduledAction saCurr;
            ICollection     coll;
            XmlNode         tmpNode;
            bool            loadCompleted;

            RegistryKey regKey;

            regKey = Registry.CurrentUser.OpenSubKey(@"Software\ToDo");
            if (regKey == null)
            {
                regKey = Registry.CurrentUser.CreateSubKey(@"Software\ToDo", RegistryKeyPermissionCheck.ReadWriteSubTree);
                regKey.SetValue("LoadCompleted", "False");
            }
            loadCompleted = Convert.ToBoolean(regKey.GetValue("LoadCompleted"));

            try
            {
                ActReg.Load(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\ActivityRegistration.xml");
            }
            catch
            {
                return;
            }

            tcActLijst.ContextMenuStrip = cmActiviteit;

            nodes = ActReg.SelectNodes("/ACTIVITIES/ACTIVITY");
            foreach (XmlNode node in nodes)
            {
                actCurr         = new Activiteit();
                actCurr.sGUID   = node.Attributes["id"].Value;
                actCurr.m_sDesc = node.SelectSingleNode("DESCRIPTION").InnerText;

                tmpNode = node.SelectSingleNode("AVAILABLETIME");
                if (tmpNode != null)
                {
                    actCurr.totalAvailable = Convert.ToInt64(tmpNode.InnerText);
                }

                coll   = actCurr.m_Hash.Keys;
                dnodes = node.SelectNodes("TIMESPENT/DAY");

                foreach (XmlNode dnode in dnodes)
                {
                    actCurr.m_Hash.Add(dnode.Attributes["day"].Value, System.Convert.ToInt64(dnode.InnerText));
                }

                string  str   = actCurr.m_sDesc;
                TabPage tpNew = new TabPage(str.Substring(0, Math.Min(str.Length, nchars)));
                tpNew.ToolTipText = str;

                if (node.Attributes["visible"] != null)
                {
                    actCurr.visible = Convert.ToBoolean(node.Attributes["visible"].Value);
                }
                else
                {
                    actCurr.visible = true;
                }
                if (actCurr.visible)
                {
                    tcActLijst.TabPages.Add(tpNew);
                }
                else
                {
                    m_invisTabPages.Insert(m_invisTabPages.Count, tpNew);
                }

                tpNew.Tag = actCurr;
                // tpNew.ContextMenuStrip = cmActiviteit;
                // tcActLijst.ContextMenuStrip = cmActiviteit;

                TreeView tvNew = new TreeView();
                tpNew.Controls.Add(tvNew);

                tvNew.CheckBoxes      = true;
                tvNew.LabelEdit       = true;
                tvNew.AfterLabelEdit += new System.Windows.Forms.NodeLabelEditEventHandler(this.tvTaskLijst_RenameAct);
                tvNew.MouseDown      += new System.Windows.Forms.MouseEventHandler(this.tvActLijst_MouseDown);

                tnodes = node.SelectNodes("TASKS/TASK");
                foreach (XmlNode tnode in tnodes)
                {
                    if (loadCompleted || !System.Convert.ToBoolean(tnode.Attributes["completed"].Value))
                    {
                        tnNew = new TreeNode(tnode.Attributes["description"].Value);
                        tvNew.Nodes.Add(tnNew);
                        tnNew.ContextMenuStrip = cmTaak;
                        tnNew.Checked          = System.Convert.ToBoolean(tnode.Attributes["completed"].Value);
                    }
                }
                tnNew = new TreeNode("*");
                tvNew.Nodes.Add(tnNew);
                btPausestart.Enabled = true;
            }

            nodes = ActReg.SelectNodes("/ACTIVITIES/SCHEDULEDACTION");
            foreach (XmlNode node in nodes)
            {
                saCurr              = new ScheduledAction();
                saCurr.sGUID        = node.Attributes["id"].Value;
                saCurr.hasbeenfired = Convert.ToBoolean(node.Attributes["hasbeenfired"].Value);
                saCurr.fire         = Convert.ToInt64(node.SelectSingleNode("FIRE").InnerText);
                saCurr.alertmsg     = node.SelectSingleNode("ALERTMSG").InnerText;
                tmpNode             = node.SelectSingleNode("REPEAT");
                if (tmpNode != null)
                {
                    saCurr.repeat     = true;
                    saCurr.repeattype = tmpNode.Attributes["type"].Value;
                    saCurr.times      = Convert.ToInt32(tmpNode.Attributes["times"].Value);
                    saCurr.period     = tmpNode.InnerText;
                }
                else
                {
                    saCurr.repeat = false;
                }

                int    k = 1;
                string key;
                do
                {
                    key = saCurr.fire.ToString() + "_" + k.ToString();
                    k++;
                } while (m_frmScheduledAction.m_scheduledActions.ContainsKey(key));
                m_frmScheduledAction.m_scheduledActions.Add(key, saCurr);
            }

            resizeInner();
        }