zoukankan      html  css  js  c++  java
  • TaskListManager

    介绍 TaskManager是一个个人信息管理器(PIM)。它是一个用于管理任务、事件、联系人、收藏夹和web链接等任何类型的个人信息的工具,这些信息都可以在同一个表单上浏览。它可以作为一种思维刺激器,一种自我分析和自我提升的工具。 在TaskManager中,不使用数据库;所有相关信息都存储在XML文件中。它可以是两个XML文件互操作性的最佳示例之一。 我们不需要安装数据库来使用这个应用程序。 主要有三个部分: 任务管理:对挂起的任务发出警报。添加,删除,编辑和导出任务列表作为HTML或Excel文件。要添加或编辑任务列表,需要单击左侧窗格中的任务按钮。 所有挂起的任务都将在托盘图标中显示为工具提示。单击工具提示,用户可以显示主表单。 联系人管理:以树状视图查看联系人,导航方便,添加和删除联系人。为所有联系人创建组。 Internet收藏夹:从Internet Explorer收藏夹列表中获取所有文件夹和链接,并将其显示为树状视图。导航喜爱的节点并在相同表单的web浏览器中显示该页面。一旦安装了应用程序,它将在运行时获取收藏夹。 使用的代码 我试着让它不言自明,等级分明。主要类是:TreeViewSerializer。ContactForm cs。cs, TaskManagerForm.cs。 下面的方法将负责在TaskList XML文件的任务表中添加一个任务。 隐藏,收缩,复制Code

    /// <summary>
    /// Utility method to update the visual representation of
    /// the tasks (the CheckedListBox) with a new or updated row.
    /// </summary>
    /// <paramname="rowIndex">Index of modifed row, or -1 for new row</param>
    /// <paramname="row">Row object from the DataTable</param>
    private void UpdateDisplayWithRow(int rowIndex, TasksDataSet.TasksRow row)
    {
        string title, format = "{0} - Due: {1:d}";
    
        title = string.Format(format, row.TaskTitle, row.TaskDueDate);
    
        if (rowIndex == -1)
        {
            tasksCheckedListBox.Items.Add(title, row.TaskComplete);
        }
        else
        {
            // Remove the old value, add a new one, set the checkbox
            tasksCheckedListBox.Items.RemoveAt(rowIndex);
            tasksCheckedListBox.Items.Insert(rowIndex, title);
            tasksCheckedListBox.SetItemChecked(rowIndex, row.TaskComplete);
        }
    }
    
    /// <summary>
    /// Loads the entries using XML deserialization
    /// </summary>
    public void LoadEntries()
    {
        try
        {
            XmlSerializer s = new XmlSerializer(typeof(TasksDataSet));
            TextReader r = new StreamReader("TaskList.xml");
            ds = (TasksDataSet)s.Deserialize(r);
            r.Close();
    
        }
        catch
        {
            ds = new TasksDataSet();
        }
    
        foreach (TasksDataSet.TasksRow row in ds.Tasks)
        {
            UpdateDisplayWithRow(-1, row);
        }
    }
    
    /// <summary>
    /// Saves the entries using XML serialization
    /// </summary>
    public void SaveEntries()
    {
        try
        {
            XmlSerializer s = new XmlSerializer(typeof(TasksDataSet));
            TextWriter w = new StreamWriter("TaskList.xml");
            s.Serialize(w, ds);
            w.Close();
        }
        catch( Exception x )
        {
            appNotifyIcon.ShowBalloonTip(8000,
                "Bh@nu's - Task Manager",
                "Tasks could not be saved.
    " + x.Message, ToolTipIcon.Error);
        }
    }

    checktaskdate()方法将检查任务列表中任务的到期时间。所有悬而未决的任务每分钟都会以工具提示的形式显示在托盘图标上。 隐藏,收缩,复制Code

    /// <summary>
    /// Scans the list of tasks. Any incomplete tasks due
    /// yesterday or earlier are appended to a buffer for
    /// display in the tooltip.
    /// </summary>
    private void CheckTaskDates()
    {
        // StringBuilder is more efficient than string concatentation
        StringBuilder buffer = new StringBuilder();
    
        // Iterate over each task in the DataSet
        foreach (TasksDataSet.TasksRow row in ds.Tasks)
        {
            // Compare date and completed flag
            if ((DateTime.Now.Date > row.TaskDueDate) && !row.TaskComplete)
            {
                buffer.Append(row.TaskTitle).Append(", Due: ");
                buffer.AppendFormat("{0:d}", row.TaskDueDate).Append('
    ');
            }
        }
    
        // If the buffer is not empty, there is at least one
        // task to display
        if (buffer.Length > 0)
        {
            // Display an Info balloon tip for 8 seconds
            appNotifyIcon.ShowBalloonTip(8000, 
                "bh@nu's - Task Manager", 
                buffer.ToString(), ToolTipIcon.Info);
        }
    }

    ContactForm类中还有另一个重要的方法。这个方法将负责在两个XML文件中添加新的联系人及其惟一的组和ID。一个XML文件将包含treeview数据,另一个文件将包含详细信息。为了便于显示treeview,我创建了这两个XML文件。 隐藏,收缩,复制Code

    private void btnUpdate_Click(object sender, System.EventArgs e)
    {
        TreeViewSerialization.TreeViewSerializer objTreeViewSerializer = 
                        new TreeViewSerialization.TreeViewSerializer();
        //objTreeViewSerializer.SerializeTreeView(this.treeView_Contacts,
        //       Application.StartupPath + "\..\..\bhanu.xml");
        objTreeViewSerializer.SerializeTreeView(this.treeView_Contacts, 
                              Application.StartupPath + "\bhanu.xml");
    
        bool bAddNew = (m_iContactID == 0) ? true : false;
    
        bool bContinue = true;
    
        try
        {
            string sFullName = txt_Name.Text;
            string sCellPhone = txt_Cell.Text;
            string sHomePhone = txt_Home.Text;
            string sEmail = txt_Email.Text;
            string sEmail2 = txt_Email2.Text;
            string sAddress = txt_Address.Text;
            string sCity = txt_City.Text;
            string sState = cmb_State.Text;
            string sZip = txt_Zip.Text;
            string sBDay = dt_DateTimePicker.Value.ToLongDateString();
    
            if( sFullName == "" || sCellPhone == "" || 
                sHomePhone == "" || sEmail == "" || 
                sEmail2 == "" || sAddress == "" || 
                sCity == "" || sState == "" ||
                sZip == "" || sBDay == "" )
            {
                MessageBox.Show( "You must have valid data in each field before" + 
                                 " you may
    add this contact to your contact's list.", 
                                 "Validation Error...", MessageBoxButtons.OK, 
                                 MessageBoxIcon.Exclamation );
                bContinue = false;
            }
    
            if( bContinue )
            {
                if( bAddNew == true )
                {
                    AddContact( m_XmlDocument, m_iNextID, sFullName, 
                        sCellPhone, sHomePhone, sEmail, sEmail2, sAddress,
                        sCity, sState, sZip, sBDay );
              
                    AddContactToCombo( m_iNextID, sFullName );
              
                    m_iNextID++;
                }
                else
                {
                    UpdateContact( m_XmlDocument, m_iNextID, sFullName, 
                        sCellPhone, sHomePhone, sEmail, sEmail2, sAddress,
                        sCity, sState, sZip, sBDay );
                }
        
                m_XmlDocument.Save( m_sXmlFileName );
            }
        }
        catch( Exception exception )
        {
            MessageBox.Show( exception.Message );
        }
    }
    
    private void treeView_Contacts_AfterSelect(object sender, TreeViewEventArgs e)
    {
        AddNewContact();
        if (treeView_Contacts.SelectedNode.Text == "Friends" || 
            treeView_Contacts.SelectedNode.Text == "Work")
        {
            return;
        }
        else
        {
            this.txt_Name.Text = this.treeView_Contacts.SelectedNode.Text;
    
            string strEmail = string.Empty;
            XmlDocument xmlContacts = new XmlDocument();
    
            xmlContacts.Load(Application.StartupPath +"\My_Contacts.xml");
                    
            foreach (XmlNode xmlItem in xmlContacts)
            {
                foreach (XmlNode newnode in xmlItem)
                {
                    if (newnode["FullName"].InnerText == 
                        this.treeView_Contacts.SelectedNode.Text)
                    {
                        this.txt_Email.Text = newnode["Email"].InnerText;
                        this.txt_City.Text = newnode["City"].InnerText;
                        this.txt_Home.Text = newnode["HomePhone"].InnerText;
                        this.txt_Zip.Text = newnode["ZipCode"].InnerText;
                        this.txt_Email2.Text = newnode["Email2"].InnerText;
                        this.txt_Address.Text = newnode["StreetAddress"].InnerText;
                        this.cmb_State.Text = newnode["State"].InnerText;
                        this.dt_DateTimePicker.Text = newnode["BDay"].InnerText;
                        this.txt_Cell.Text = newnode["CellPhone"].InnerText;
    
                    }
                }
            }
        }
    }

    显示互联网收藏夹是相当简单的,只有几个方法来显示整个东西。这些方法就是这样写的。 隐藏,收缩,复制Code

    private bool LoadWebSitesTree()
    {
        bool result = false;
        try
        {
            Cursor = Cursors.WaitCursor;
            string favFolderPath = 
              Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
    
            // Disables any redrawing of the tree view till we are done
            tvWebSites.BeginUpdate();
    
            LoadFavFromFolder(new DirectoryInfo(favFolderPath), webSitesRootNode);
            LoadFavFromPath(favFolderPath, webSitesRootNode);
    
            result = true;
        }
        catch (Exception exp) 
        {
            //DebugLog.Instance.REPORT(exp); 
        }
        finally
        {
            Cursor = Cursors.Default;
            tvWebSites.EndUpdate();
        }
    
        return result;
    }
    
    private void LoadFavFromFolder(DirectoryInfo curDirInfo, TreeNode curNode)
    {
        try
        {
            TreeNode newNode;
    
            foreach (DirectoryInfo dirInfo in curDirInfo.GetDirectories())
            {
                if (curNode == null)
                    newNode = tvWebSites.Nodes.Add(dirInfo.Name);
                else
                    newNode = curNode.Nodes.Add(dirInfo.Name);
    
                if (dirInfo.GetDirectories().Length == 0)
                    LoadFavFromPath(dirInfo.FullName, newNode);
                else
                    LoadFavFromFolder(dirInfo, newNode);
            }
        }
        catch (Exception exp) 
        { 
            //DebugLog.Instance.REPORT(exp); 
        }
    }
    
    private void LoadFavFromPath(string curPath, TreeNode curNode)
    {
        try
        {
            DirectoryInfo curDirInfo = new DirectoryInfo(curPath);
    
            foreach (FileInfo objFile in curDirInfo.GetFiles("*.url"))
            {
                TreeNode newNode = new TreeNode();
    
                string fileName = objFile.FullName;
                newNode.Tag = GetURLValue(fileName);
                newNode.Text = Path.GetFileNameWithoutExtension(fileName);
                newNode.ImageIndex = 2;
                newNode.SelectedImageIndex = 2;
    
                if (curNode == null)
                    tvWebSites.Nodes.Add(newNode);
                else
                    curNode.Nodes.Add(newNode);
            }
        }
        catch (Exception exp) 
        { 
            //DebugLog.Instance.REPORT(exp); 
        }
    }
    
    //    Reading favorites file as INI file getting the value of URL=
    private string GetURLValue(string fileName)
    {
        string strURL = null;
        StreamReader reader = null;
        try
        {
            reader = new StreamReader(fileName);
            string fileLine;
            int iIndex = -1;
            while ((fileLine = reader.ReadLine()) != null)
            {
                if (fileLine != null)
                {
                    if ((iIndex = fileLine.IndexOf("URL=")) >= 0)
                    {
                        strURL = fileLine.Substring(iIndex + 4);
                        break;
                    }
                }
            }
        }
        catch (Exception exp) 
        { 
            //DebugLog.Instance.REPORT(exp); 
        }
        finally
        {
            try { if (reader != null) reader.Close(); }
            catch (Exception exp) 
            { 
                //DebugLog.Instance.REPORT(exp);
            }
        }
    
        return strURL;
    }

    待办事项 任务网格中的打印支持。身份验证后收集用户名和密码。文字装饰。 干杯! ! 本文转载于:http://www.diyabc.com/frontweb/news439.html

  • 相关阅读:
    MySQL分区性能初探
    FastDFS开源的轻量级分布式文件系统
    MySQL数据类型之数值类型,对理解类型定义中的“位”有莫大的帮助
    空密码引发共享打印机拒绝访问
    利用Myxls导出并下载Excel
    StyleCop SA0102
    Spring AOP介绍
    大学英语一下重修听力考试范围.doc 听力原文 及MP3
    Eclipse中文版
    飞鱼秀下载
  • 原文地址:https://www.cnblogs.com/Dincat/p/13450074.html
Copyright © 2011-2022 走看看