예제 #1
0
        private void AddTask_UI(TaskInformation task)
        {
            //UI界面
            Grid grid = System.Windows.Markup.XamlReader.Parse(xaml) as Grid;

            grid.Margin     = new Thickness(0, grid.Height * (grid_Tasks.Children.Count), 0, 0);
            grid.Background = new SolidColorBrush(color_Background * (1 - grid_Tasks.Children.Count * 0.75f / list_Tasks.Count));
            foreach (UIElement UIele in grid.Children)
            {
                if (UIele is Label && (UIele as Label).Name == "lab_TaskName")
                {
                    Label tx = (UIele as Label);
                    tx.Content = task.Name;

                    if (task.Name.Length > 15)
                    {
                        tx.FontSize -= 3;
                    }
                    tx.Foreground = new SolidColorBrush(Colors.White);
                    tx.Tag        = task;

                    tx.MouseDoubleClick += this.lab_TaskName_MouseDoubleClick;
                }
                if (UIele is Label && (UIele as Label).Name == "lab_Date")
                {
                    Label tx = (UIele as Label);
                    if (task.Time == DateTime.Today.ToLongDateString())
                    {
                        tx.Visibility = Visibility.Hidden;
                    }
                    tx.Content    = task.Time;
                    tx.Foreground = new SolidColorBrush(Colors.White);
                    tx.Tag        = task;
                }
                if (UIele is Button && (UIele as Button).Name == "btn_Setting")
                {
                    Button btn = UIele as Button;
                    btn.Tag = task;
                    if (task.IsFinish)
                    {
                        btn.Content = "√";
                    }
                    btn.Click += btn_Setting_Click;
                }
            }

            grid_Tasks.Height = ItemHeight * (grid_Tasks.Children.Count + 1);
            grid_Main.Height  = grid_Title.ActualHeight + grid_Tasks.Height;
            this.Height       = grid_Main.Height;
            grid_Tasks.Children.Add(grid);
        }
예제 #2
0
        private void lab_TaskName_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            TaskInformation task = (TaskInformation)(sender as Label).Tag;

            if (e.RightButton == MouseButtonState.Pressed)
            {
                TaskSetting dig = new TaskSetting(task);
                dig.ShowDialog();
            }
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load("TaskSetting.xml");
                XmlNode    root = xmlDoc.FirstChild;
                XmlElement xe   = null;
                foreach (XmlElement ele in root.ChildNodes)
                {
                    if (task.Name.Contains(ele.GetAttribute("Name")) &&
                        (xe == null ||
                         xe.GetAttribute("Name").Length < ele.GetAttribute("Name").Length))
                    {
                        xe = ele;
                    }
                }
                if (xe != null)
                {
                    string strAim = xe.GetAttribute("AimSource");
                    if (Regex.IsMatch(strAim, @"\w+://.+") || Regex.IsMatch(strAim, @"\w:\\.+"))
                    {
                        try
                        {
                            Process p = Process.Start(strAim);
                        }
                        catch (Exception ex)
                        {
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show(strAim);
                    }
                }
            }
        }
예제 #3
0
        private void btn_Confirm_Click(object sender, RoutedEventArgs e)
        {
            XmlNode         root = xmlDoc.FirstChild;
            TaskInformation task = new TaskInformation()
            {
                Name = txt_Name.Text
            };
            XmlElement ele = (XmlElement)root.SelectSingleNode(string.Format("//SETTING[@Name='{0}']", txt_Name.Text));

            if (ele == null)//如果不在XML表
            {
                ele = xmlDoc.CreateElement("SETTING");
            }
            ele.SetAttribute("Name", txt_Name.Text);
            ele.SetAttribute("AimSource", txt_AimSource.Text);
            root.AppendChild(ele);
            xmlDoc.Save("TaskSetting.xml");
            this.Close();
        }
예제 #4
0
        public TaskSetting(TaskInformation Task)
        {
            InitializeComponent();
            Expend.LoadImage(btn_Open, @"Texture\pic_File.png");

            this.Title = string.Format("{0} - TaskSettings", Task.Name);

            xmlDoc.Load("TaskSetting.xml");
            XmlNode root = xmlDoc.FirstChild;

            txt_Name.Text = Task.Name;
            XmlElement ele = null;

            foreach (XmlElement xe in root.ChildNodes)
            {
                if (Task.Name.Contains(xe.GetAttribute("Name")))
                {
                    if (ele == null || xe.GetAttribute("Name").Length > ele.GetAttribute("Name").Length)
                    {
                        ele = xe;
                    }
                }
            }
            if (ele == null)//如果不在XML表
            {
                ele = xmlDoc.CreateElement("SETTING");
                ele.SetAttribute("Name", Task.Name);
                ele.SetAttribute("AimSource", "");
                root.AppendChild(ele);
            }
            else
            {
                txt_Name.Text      = ele.GetAttribute("Name");
                txt_AimSource.Text = ele.GetAttribute("AimSource");
            }
        }
예제 #5
0
        private void LoadTaskFromDatabase()
        {
            list_Tasks.Clear();
            grid_Tasks.Children.Clear();

            DataTable data = null;

            try
            {
                data = ExcelToDataTable(setting.SourcePath, setting.ChoosenSheet);
            }
            catch
            {
                return;
            }
            //XML
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load("Data.xml");
            string  strToday = DateTime.Today.ToLongDateString().ToString();
            XmlNode root     = xmlDoc.SelectSingleNode("Datas");

            //添加未完成任务
            foreach (XmlElement ele in root.SelectNodes("//TASK[@IsFinish=\"False\"]"))
            {
                TaskInformation task = new TaskInformation()
                {
                    Name     = ele.GetAttribute("Name"),
                    Time     = ele.GetAttribute("Time"),
                    IsFinish = false
                };
                if (setting.isLoadHistory)
                {
                    list_Tasks.Add(task);
                }
                else
                {
                    if (task.Time == strToday)
                    {
                        list_Tasks.Add(task);
                    }
                }
            }

            //添加今日任务
            foreach (DataRow row in data.Rows)
            {
                if (Regex.IsMatch(row[0].ToString(), string.Format(@"{0}/{1}/{2} 0:00:00", DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day)) ||
                    Regex.IsMatch(row[0].ToString(), string.Format("({0})?年?{1}月{2}日", DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day)))
                {
                    for (int index = 1; index < row.ItemArray.Count(); index++)
                    {
                        if (row[index].ToString() != "")
                        {
                            //获得今日任务
                            TaskInformation task = new TaskInformation()
                            {
                                Name     = row[index].ToString(),
                                Time     = DateTime.Today.ToLongDateString(),
                                IsFinish = false
                            };

                            XmlElement ele = (XmlElement)root.SelectSingleNode(string.Format("//TASK[@Name='{0}'][@Time ='{1}']", task.Name, task.Time));
                            if (ele == null)//如果不在XML表
                            {
                                ele = xmlDoc.CreateElement("TASK");
                                ele.SetAttribute("Name", task.Name);
                                ele.SetAttribute("Time", task.Time);
                                ele.SetAttribute("IsFinish", task.IsFinish.ToString());
                                root.AppendChild(ele);
                                task.IsFinish = false;
                                //计入结构
                                list_Tasks.Add(task);
                            }
                            else//如果在表中获取是否完成
                            {
                                task.IsFinish = ele.GetAttribute("IsFinish") == "True" ? true : false;
                                if (task.IsFinish)
                                {
                                    //计入结构
                                    list_Tasks.Add(task);
                                }
                            }
                        }
                    }
                }
            }
            xmlDoc.Save("Data.xml");

            sortTaskList(list_Tasks);

            //UI
            foreach (TaskInformation t in list_Tasks)
            {
                AddTask_UI(t);
            }
            AddLastTaskRow();
        }