Esempio n. 1
0
        // 添加新任务,打开添加新任务form
        private void button4_Click(object sender, EventArgs e)
        {
            this.add_task = new task_entity();
            this.add_task.clear();
            this.todayTime = this.monthCalendar1.SelectionStart.ToString("yyyyMMdd");
            // 获取当天的任务数量,并生成下一个taskid
            int    Count  = getTaskId(this.todayTime);
            string taskid = (Count + 1).ToString();

            this.addForm             = new Add_Form(this, taskid);
            this.addForm.ShowUpdate += new Add_Form.DisplayUpdateDelegate(addNewTask);
        }
Esempio n. 2
0
        // 修改任务记录
        private void button6_Click(object sender, EventArgs e)
        {
            this.modify_task = new task_entity();
            this.modify_task.clear();
            string taskid     = this.select_task.Task_id;
            string time       = this.select_task.Time;
            string topic      = this.select_task.Topic;
            string people     = this.select_task.People;
            string result     = this.select_task.Result;
            string reason     = this.select_task.Resaon;
            string dependence = this.select_task.Dependence;
            string isdelete   = "0";

            this.addForm             = new Add_Form(taskid, time, topic, people, dependence, result, reason);
            this.addForm.ShowUpdate += new Add_Form.DisplayUpdateDelegate(modifyTask);
        }
Esempio n. 3
0
 public Main_Form()
 {
     InitializeComponent();
     this.check_log();
     this.todayTime = this.monthCalendar1.SelectionStart.ToString("yyyyMMdd");
     this.ReadTasksFromXml(this.todayTime);
     this.toFillTasksToListView(this.todayTasks);
     this.select_task = new task_entity();
     Control.CheckForIllegalCrossThreadCalls = false;
     this.screenForm         = new ScreenForm(this);
     this.screenForm.Visible = false;
     tim = new System.Timers.Timer();
     //tim.Interval = 60000;
     tim.Elapsed += new System.Timers.ElapsedEventHandler(tim_Elapsed);
     //tim.Stop();
 }
Esempio n. 4
0
        // 根据日期从Xml获取tasks
        // today形如:20190810
        private void ReadTasksFromXml(string today)
        {
            XmlDocument myXmlDoc = new XmlDocument();                     // 初始化一个XML实例

            myXmlDoc.Load(@"../mylog.txt");                               // 通过文件路径加载日志文件
            XmlNode     rootNode     = myXmlDoc.SelectSingleNode("logs"); // 找到logs结点,即日志的根结点for
            string      innerXmlInfo = rootNode.InnerXml.ToString();
            string      outerXmlInfo = rootNode.OuterXml.ToString();
            XmlNodeList DateNodeList = rootNode.ChildNodes;   // 获取第一层子节点: date(日期)层

            foreach (XmlNode node in DateNodeList)
            {
                string date_id = node.Attributes[0].Value; // 取出每个日期的值
                if (date_id.Equals(today))                 // 如果给定的日期,与找到的日期匹配
                {
                    XmlNodeList tasks = node.ChildNodes;   // 获取当日的所有任务
                    int         num   = tasks.Count;
                    for (int i = 0; i < num; i++)          // 遍历今天所有的task
                    {
                        task_entity my_task = new task_entity();
                        XmlNodeList details = tasks[i].ChildNodes;  // 获取任务中的细节:time、topic、people、result、reason
                        for (int j = 0; j < details.Count; j++)
                        {
                            my_task.Time       = details[0].InnerText;
                            my_task.Topic      = details[1].InnerText;
                            my_task.People     = details[2].InnerText;
                            my_task.Result     = details[3].InnerText;
                            my_task.Resaon     = details[4].InnerText;
                            my_task.Dependence = details[5].InnerText;
                            my_task.Isdelete   = details[6].InnerText;
                        }
                        my_task.Task_id = tasks[i].Attributes[0].Value;
                        this.todayTasks.Add(my_task);
                    }
                }
            }
        }
Esempio n. 5
0
        // 添加任务到当天的任务中
        private void addTask_to_xml(task_entity tasks)
        {
            // 程序需要处理的情况
            // 1. 如果当天有任务   2. 如果当天没有任务
            // 3. 没有该天的日期   4. 有该天的日期
            XmlDocument myXmlDoc = new XmlDocument();

            myXmlDoc.Load(@"../mylog.txt");                           // 通过文件路径加载日志文件

            XmlNode rootNode = myXmlDoc.SelectSingleNode("logs");     // 找到logs结点,即日志的根结点

            XmlNodeList DateNodeList = rootNode.ChildNodes;           // 获取第一层子节点: date层

            XmlElement task_Element = myXmlDoc.CreateElement("task"); // 创建task

            XmlElement time_Node = myXmlDoc.CreateElement("time");

            time_Node.InnerText = tasks.Time;
            XmlElement topic_Node = myXmlDoc.CreateElement("topic");

            topic_Node.InnerText = tasks.Topic;
            XmlElement people_Node = myXmlDoc.CreateElement("people");

            people_Node.InnerText = tasks.People;
            XmlElement result_Node = myXmlDoc.CreateElement("result");

            result_Node.InnerText = tasks.Result;
            XmlElement reason_Node = myXmlDoc.CreateElement("reason");

            reason_Node.InnerText = tasks.Resaon;
            XmlElement dependence_Node = myXmlDoc.CreateElement("dependence");

            dependence_Node.InnerText = tasks.Dependence;
            XmlElement isdelete_Node = myXmlDoc.CreateElement("isdelete");

            isdelete_Node.InnerText = tasks.Isdelete;

            foreach (XmlNode node in DateNodeList)      // node即date结点
            {
                // 如果有没有日期,需要创建新的日期
                if (node.Attributes[0].Value == todayTime)     // 如果日期匹配需要添加任务的日期
                {
                    int    num     = node.ChildNodes.Count;    // num代表当天有多少个任务
                    string date_id = node.Attributes[0].Value; // 取出每个日期的值
                    if (num > 0)                               // 如果当天已经有了任务,需要取出最后的任务的号,用于添加任务的时候号码递增
                    {
                        string last_task_id   = node.LastChild.Attributes[0].Value;
                        int    last_task_id_n = 0;
                        int.TryParse(last_task_id, out last_task_id_n);     // 将当天的最后一次任务的task id转换成int型
                        task_Element.SetAttribute("id", (last_task_id_n + 1).ToString());
                        task_Element.AppendChild(time_Node);
                        task_Element.AppendChild(topic_Node);
                        task_Element.AppendChild(people_Node);
                        task_Element.AppendChild(result_Node);
                        task_Element.AppendChild(reason_Node);
                        task_Element.AppendChild(dependence_Node);
                        task_Element.AppendChild(isdelete_Node);
                        node.AppendChild(task_Element);
                        myXmlDoc.Save(@"../mylog.txt");
                        return;
                    }
                    else if (num == 0)
                    {     // 当前还没有任务
                        int last_task_id_n = 0;
                        task_Element.SetAttribute("id", (last_task_id_n + 1).ToString());
                        task_Element.AppendChild(time_Node);
                        task_Element.AppendChild(topic_Node);
                        task_Element.AppendChild(people_Node);
                        task_Element.AppendChild(result_Node);
                        task_Element.AppendChild(reason_Node);
                        task_Element.AppendChild(dependence_Node);
                        task_Element.AppendChild(isdelete_Node);
                        node.AppendChild(task_Element);
                        myXmlDoc.Save(@"../mylog.txt");
                        return;
                    }
                    else
                    {
                        // 异常,需要进行处理
                        return;
                    }
                }
                // 如果有日期没有任务,需要创建新的任务
                //string date_id = node.Attributes[0].Value;  // 取出每个日期的值
                // 如果有这个日期,则删除这个日期的结点,然后添加新结点
                //int num = node.ChildNodes.Count;    // num代表当天有多少个任务
            }
            XmlElement date_Element = myXmlDoc.CreateElement("date");   // 如果日期不匹配,需要添加日期结点

            date_Element.SetAttribute("id", this.todayTime.ToString());
            task_Element.SetAttribute("id", (1).ToString());
            task_Element.AppendChild(time_Node);
            task_Element.AppendChild(topic_Node);
            task_Element.AppendChild(people_Node);
            task_Element.AppendChild(result_Node);
            task_Element.AppendChild(reason_Node);
            task_Element.AppendChild(dependence_Node);
            task_Element.AppendChild(isdelete_Node);
            date_Element.AppendChild(task_Element);
            rootNode.AppendChild(date_Element);
            myXmlDoc.Save(@"../mylog.txt");
        }