你的位置:首页 > ASP.net教程

[ASP.net教程]工作流待办事项消息提醒


    web页面提醒的缺点:不可能一直开着浏览器;邮件提醒的缺点:领导工作繁忙哪有时间看邮件,即便像我这样不忙的,也懒得看邮件,所以邮件提醒其实很鸡肋。所以需要做个桌面提醒,每个办公人员都有自己的电脑,只要电脑开着,就能收到提醒。

    所用到的技术:WebService、线程

    功能:1、桌面消息提醒器开机自动启动;2、根据设置的间隔自动提醒;3、点击消息,即可打开浏览器处理待办;4、首次使用需要登录一次,以后不需要每次登录,可以切换账号登录;

    主要代码:

using System;using System.Collections.Generic;using System.ComponentModel;using System.Configuration;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;using System.Web.Services.Protocols;using System.Windows.Forms;using Microsoft.Win32;using Utils;namespace MessageReminder{  /// <summary>  /// 桌面消息提醒器  /// </summary>  public partial class Form1 : Form  {    #region 变量    /// <summary>    /// 桌面消息提醒WebService    /// </summary>    private DesktopMsgService.Service m_DesktopMsgService = new DesktopMsgService.Service();    /// <summary>    /// 服务器url    /// </summary>    private string m_Url = ConfigurationManager.AppSettings["url"];    /// <summary>    /// 消息提醒框    /// </summary>    public MsgForm m_msgForm;    /// <summary>    /// 用户名    /// </summary>    public string m_UserName;    /// <summary>    /// 密码    /// </summary>    public string m_Pwd;    /// <summary>    /// 时间单位    /// </summary>    private int timeUnit = ConfigurationManager.AppSettings["testFlag"] == "1" ? 1000 : 1000 * 60;    /// <summary>    /// 待审阅    /// </summary>    private int m_dsyCount = 0;    /// <summary>    /// 待审阅辅审    /// </summary>    private int m_dsyFsCount = 0;    /// <summary>    /// 待审核    /// </summary>    private int m_dshCount = 0;    /// <summary>    /// 待审核辅审    /// </summary>    private int m_dshFsCount = 0;    /// <summary>    /// 待批准    /// </summary>    private int m_dpzCount = 0;    /// <summary>    /// 未通过    /// </summary>    private int m_wtgCount = 0;    /// <summary>    /// 是否可以退出    /// </summary>    private bool canExit = false;    #endregion    #region Form1    public Form1()    {      InitializeComponent();      #region 隐藏主窗体      //隐藏主窗体      this.ShowInTaskbar = false;      this.WindowState = FormWindowState.Minimized;      this.Visible = false;      #endregion      #region 开机自动启动      //开机自动启动      string path = Application.ExecutablePath;      RegistryKey rk = Registry.LocalMachine;      RegistryKey rk2 = rk.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);      if (rk2 == null)      {        rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");      }      if (rk2.GetValue("技术报告消息提醒器") == null        || rk2.GetValue("技术报告消息提醒器").ToString() != path)      {        rk2.SetValue("技术报告消息提醒器", path);      }      rk2.Close();      rk.Close();      #endregion      #region 记录用户名密码      //记录用户名密码      m_UserName = MessageReminder.Properties.Settings.Default.userName;      m_Pwd = MessageReminder.Properties.Settings.Default.pwd;      #endregion      #region 菜单显示      //菜单显示      if (MessageReminder.Properties.Settings.Default.userName != "")      {        this.登录ToolStripMenuItem.Text = "用户信息";      }      #endregion      #region 提醒间隔      if (Properties.Settings.Default.reminderInterval == timeUnit * 1)      {        this.reminderInterval1分钟.Checked = true;      }      else if (Properties.Settings.Default.reminderInterval == timeUnit * 2)      {        this.reminderInterval2分钟.Checked = true;      }      else if (Properties.Settings.Default.reminderInterval == timeUnit * 5)      {        this.reminderInterval5分钟.Checked = true;      }      else if (Properties.Settings.Default.reminderInterval == timeUnit * 10)      {        this.reminderInterval10分钟.Checked = true;      }      else if (Properties.Settings.Default.reminderInterval == timeUnit * 20)      {        this.reminderInterval20分钟.Checked = true;      }      else if (Properties.Settings.Default.reminderInterval == timeUnit * 30)      {        this.reminderInterval30分钟.Checked = true;      }      else if (Properties.Settings.Default.reminderInterval == timeUnit * 60 * 1)      {        this.reminderInterval1小时.Checked = true;      }      else if (Properties.Settings.Default.reminderInterval == timeUnit * 60 * 2)      {        this.reminderInterval2小时.Checked = true;      }      else if (Properties.Settings.Default.reminderInterval == timeUnit * 60 * 4)      {        this.reminderInterval4小时.Checked = true;      }      else if (Properties.Settings.Default.reminderInterval == timeUnit * 60 * 6)      {        this.reminderInterval6小时.Checked = true;      }      else if (Properties.Settings.Default.reminderInterval == timeUnit * 60 * 8)      {        this.reminderInterval8小时.Checked = true;      }      else if (Properties.Settings.Default.reminderInterval == timeUnit * 60 * 12)      {        this.reminderInterval12小时.Checked = true;      }      else if (Properties.Settings.Default.reminderInterval == timeUnit * 60 * 24)      {        this.reminderInterval24小时.Checked = true;      }      else      {        Properties.Settings.Default.reminderInterval = timeUnit * 10;        Properties.Settings.Default.Save();        this.reminderInterval10分钟.Checked = true;      }      #endregion    }    #endregion    #region Form1_Load    private void Form1_Load(object sender, EventArgs e)    {      if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.userName))      {        timerCheckReport.Interval = Properties.Settings.Default.reminderInterval;        timerCheckReport.Start();      }    }    #endregion    #region 登录服务器    private void 登录ToolStripMenuItem_Click(object sender, EventArgs e)    {      if (Properties.Settings.Default.userName == "")      {        Login login = new Login();        login.Show(this);      }      else      {        LoginInfo loginInfo = new LoginInfo();        loginInfo.Show(this);      }    }    #endregion    #region 关闭程序    private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)    {      if (MessageBox.Show("退出后无法接收到技术报告提醒消息,确定要退出桌面提醒吗?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)      {        canExit = true;        Application.Exit();      }    }    #endregion    #region GetMsgForm    /// <summary>    /// GetMsgForm    /// </summary>    private MsgForm GetMsgForm()    {      if (m_msgForm == null || m_msgForm.IsDisposed)      {        m_msgForm = new MsgForm();      }      return m_msgForm;    }    #endregion    #region 提醒间隔    //1分钟提示一次    private void 分钟提示一次ToolStripMenuItem_Click_1(object sender, EventArgs e)    {      Properties.Settings.Default.reminderInterval = timeUnit * 1;      UncheckReminder();      this.reminderInterval1分钟.Checked = true;      Properties.Settings.Default.Save();      timerCheckReport.Interval = Properties.Settings.Default.reminderInterval;      timerCheckReport.Stop();      timerCheckReport.Start();    }    //2分钟提示一次    private void 分钟提示一次ToolStripMenuItem1_Click_1(object sender, EventArgs e)    {      Properties.Settings.Default.reminderInterval = timeUnit * 2;      UncheckReminder();      this.reminderInterval2分钟.Checked = true;      Properties.Settings.Default.Save();      timerCheckReport.Interval = Properties.Settings.Default.reminderInterval;      timerCheckReport.Stop();      timerCheckReport.Start();    }    //5分钟提示一次    private void 分钟提示一次ToolStripMenuItem3_Click(object sender, EventArgs e)    {      Properties.Settings.Default.reminderInterval = timeUnit * 5;      UncheckReminder();      this.reminderInterval5分钟.Checked = true;      Properties.Settings.Default.Save();      timerCheckReport.Interval = Properties.Settings.Default.reminderInterval;      timerCheckReport.Stop();      timerCheckReport.Start();    }    //10分钟提示一次    private void 分钟提示一次ToolStripMenuItem_Click(object sender, EventArgs e)    {      Properties.Settings.Default.reminderInterval = timeUnit * 10;      UncheckReminder();      this.reminderInterval10分钟.Checked = true;      Properties.Settings.Default.Save();      timerCheckReport.Interval = Properties.Settings.Default.reminderInterval;      timerCheckReport.Stop();      timerCheckReport.Start();    }    //20分钟提示一次    private void 分钟提示一次ToolStripMenuItem1_Click(object sender, EventArgs e)    {      Properties.Settings.Default.reminderInterval = timeUnit * 20;      UncheckReminder();      this.reminderInterval20分钟.Checked = true;      Properties.Settings.Default.Save();      timerCheckReport.Interval = Properties.Settings.Default.reminderInterval;      timerCheckReport.Stop();      timerCheckReport.Start();    }    //30分钟提示一次    private void 分钟提示一次ToolStripMenuItem2_Click(object sender, EventArgs e)    {      Properties.Settings.Default.reminderInterval = timeUnit * 30;      UncheckReminder();      this.reminderInterval30分钟.Checked = true;      Properties.Settings.Default.Save();      timerCheckReport.Interval = Properties.Settings.Default.reminderInterval;      timerCheckReport.Stop();      timerCheckReport.Start();    }    //1小时提示一次    private void toolStripMenuItem2_Click(object sender, EventArgs e)    {      Properties.Settings.Default.reminderInterval = timeUnit * 60;      UncheckReminder();      this.reminderInterval1小时.Checked = true;      Properties.Settings.Default.Save();      timerCheckReport.Interval = Properties.Settings.Default.reminderInterval;      timerCheckReport.Stop();      timerCheckReport.Start();    }    //2小时提示一次    private void 小时提示一次ToolStripMenuItem_Click(object sender, EventArgs e)    {      Properties.Settings.Default.reminderInterval = timeUnit * 60 * 2;      UncheckReminder();      this.reminderInterval2小时.Checked = true;      Properties.Settings.Default.Save();      timerCheckReport.Interval = Properties.Settings.Default.reminderInterval;      timerCheckReport.Stop();      timerCheckReport.Start();    }    //4小时提示一次    private void 小时提示一次ToolStripMenuItem1_Click(object sender, EventArgs e)    {      Properties.Settings.Default.reminderInterval = timeUnit * 60 * 4;      UncheckReminder();      this.reminderInterval4小时.Checked = true;      Properties.Settings.Default.Save();      timerCheckReport.Interval = Properties.Settings.Default.reminderInterval;      timerCheckReport.Stop();      timerCheckReport.Start();    }    //6小时提示一次    private void 小时提示一次ToolStripMenuItem2_Click(object sender, EventArgs e)    {      Properties.Settings.Default.reminderInterval = timeUnit * 60 * 6;      UncheckReminder();      this.reminderInterval6小时.Checked = true;      Properties.Settings.Default.Save();      timerCheckReport.Interval = Properties.Settings.Default.reminderInterval;      timerCheckReport.Stop();      timerCheckReport.Start();    }    //8小时提示一次    private void 小时提示一次ToolStripMenuItem3_Click(object sender, EventArgs e)    {      Properties.Settings.Default.reminderInterval = timeUnit * 60 * 8;      UncheckReminder();      this.reminderInterval8小时.Checked = true;      Properties.Settings.Default.Save();      timerCheckReport.Interval = Properties.Settings.Default.reminderInterval;      timerCheckReport.Stop();      timerCheckReport.Start();    }    //12小时提示一次    private void 小时提示一次ToolStripMenuItem4_Click(object sender, EventArgs e)    {      Properties.Settings.Default.reminderInterval = timeUnit * 60 * 12;      UncheckReminder();      this.reminderInterval12小时.Checked = true;      Properties.Settings.Default.Save();      timerCheckReport.Interval = Properties.Settings.Default.reminderInterval;      timerCheckReport.Stop();      timerCheckReport.Start();    }    //24小时提示一次    private void 小时提示一次ToolStripMenuItem5_Click(object sender, EventArgs e)    {      Properties.Settings.Default.reminderInterval = timeUnit * 60 * 24;      UncheckReminder();      this.reminderInterval24小时.Checked = true;      Properties.Settings.Default.Save();      timerCheckReport.Interval = Properties.Settings.Default.reminderInterval;      timerCheckReport.Stop();      timerCheckReport.Start();    }    /// <summary>    /// 取消勾选    /// </summary>    private void UncheckReminder()    {      this.reminderInterval1分钟.Checked = false;      this.reminderInterval2分钟.Checked = false;      this.reminderInterval5分钟.Checked = false;      this.reminderInterval10分钟.Checked = false;      this.reminderInterval20分钟.Checked = false;      this.reminderInterval30分钟.Checked = false;      this.reminderInterval1小时.Checked = false;      this.reminderInterval2小时.Checked = false;      this.reminderInterval4小时.Checked = false;      this.reminderInterval6小时.Checked = false;      this.reminderInterval8小时.Checked = false;      this.reminderInterval12小时.Checked = false;      this.reminderInterval24小时.Checked = false;    }    #endregion    #region timerCheckReport_Tick 消息提醒间隔定时器    private void timerCheckReport_Tick(object sender, EventArgs e)    {      try      {        new Thread(new ThreadStart(delegate()        {          try          {            if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.userName)) //已登录            {              CheckReportCount();              ShowReminder();            }          }          catch (Exception ex)          {          }        })).Start();      }      catch (Exception ex)      {      }    }    #endregion    #region 立即检测    private void 立即检测ToolStripMenuItem_Click(object sender, EventArgs e)    {      new Thread(new ThreadStart(delegate()      {        try        {          if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.userName)) //已登录          {            CheckReportCount();            if (m_dsyCount + m_dsyFsCount + m_dshCount + m_dshFsCount + m_dpzCount + m_wtgCount > 0)            {              ShowReminder();              InvokeUtil.Invoke(this, new InvokeDelegate(delegate()              {                timerCheckReport.Stop();                timerCheckReport.Start();              }));            }            else            {              MessageBox.Show("没有待办工作!");            }          }          else          {            InvokeUtil.Invoke(this, new InvokeDelegate(delegate()            {              Login login = new Login();              login.Show(this);            }));          }        }        catch (SoapException ex)        {          MessageBox.Show("检测失败,请检查是否断网");        }        catch (Exception ex)        {          MessageBox.Show(ex.Message);        }      })).Start();    }    #endregion    #region CheckReportCount 检测报告    /// <summary>    /// 检测报告    /// </summary>    private void CheckReportCount()    {      if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.userName)) //已登录      {        m_dsyCount = m_DesktopMsgService.GetDsyReportCount(Properties.Settings.Default.deptCode);        m_dsyFsCount = m_DesktopMsgService.GetDsyFsReportCount(Properties.Settings.Default.userName);        m_dshCount = m_DesktopMsgService.GetDshReportCount(Properties.Settings.Default.userName);        m_dshFsCount = m_DesktopMsgService.GetDshFsReportCount(Properties.Settings.Default.userName);        m_dpzCount = m_DesktopMsgService.GetDpzReportCount(Properties.Settings.Default.userName);        m_wtgCount = m_DesktopMsgService.GetWtgReportCount(Properties.Settings.Default.userName);      }    }    #endregion    #region ShowReminder 弹出提醒    /// <summary>    /// 弹出提醒    /// </summary>    private void ShowReminder()    {      if (m_dsyCount + m_dsyFsCount + m_dshCount + m_dshFsCount + m_dpzCount + m_wtgCount > 0)      {        InvokeUtil.Invoke(this, new InvokeDelegate(delegate()        {          m_msgForm = GetMsgForm();          m_msgForm.Controls.Clear();          #region 加载link          //待审阅          if (m_dsyCount > 0)          {            string text = string.Format("您有 {0} 条待审阅报告", m_dsyCount);            CreateMsgLine("dsy", text, "/MultilevelAudit/CheckReport/Index");          }          //待审阅辅审          if (m_dsyFsCount > 0)          {            string text = string.Format("您有 {0} 条待审阅辅审报告", m_dsyFsCount);            CreateMsgLine("dsyfs", text, "/MultilevelAudit/AssistCheckReport/Index");          }          //待审核          if (m_dshCount > 0)          {            string text = string.Format("您有 {0} 条待审核报告", m_dshCount);            CreateMsgLine("dsh", text, "/MultilevelAudit/AuditingReport/Index");          }          //待审核辅审          if (m_dshFsCount > 0)          {            string text = string.Format("您有 {0} 条待审核辅审报告", m_dshFsCount);            CreateMsgLine("dshfs", text, "/MultilevelAudit/AssistAuditingReport/Index");          }          //待批准          if (m_dpzCount > 0)          {            string text = string.Format("您有 {0} 条待批准报告", m_dpzCount);            CreateMsgLine("dpz", text, "/MultilevelAudit/AuthorizeReport/Index");          }          //审批未通过          if (m_wtgCount > 0)          {            string text = string.Format("您有 {0} 条审批未通过报告", m_wtgCount);            CreateMsgLine("wtg", text, "/Tech/CompletedReportManage/Index?wtg=true");          }          #endregion          #region 显示消息窗体          m_msgForm.Height = m_msgForm.Controls.Count * 30 + 60;          m_msgForm.Left = Screen.PrimaryScreen.WorkingArea.Width - m_msgForm.Width;          m_msgForm.Top = Screen.PrimaryScreen.Bounds.Height;          m_msgForm.TopLevel = true;          m_msgForm.TopMost = true;          m_msgForm.ShowInTaskbar = false;          m_msgForm.Show();          new Thread(new ThreadStart(delegate()          {            while (m_msgForm.Top > Screen.PrimaryScreen.WorkingArea.Height - m_msgForm.Height)            {              InvokeUtil.Invoke(m_msgForm, new InvokeDelegate(delegate()              {                m_msgForm.Top = m_msgForm.Top - 1;                m_msgForm.Refresh();              }));              Thread.Sleep(10);            }          })).Start();          #endregion        }));      }    }    /// <summary>    /// 创建一条消息    /// </summary>    private void CreateMsgLine(string name, string text, string url)    {      LinkLabel link = CreateLink(name, text, 15 + m_msgForm.Controls.Count * 30);      byte[] bArr = ASCIIEncoding.UTF8.GetBytes(m_Url + url);      url = Convert.ToBase64String(bArr);      link.Links.Clear();      link.Links.Add(0, link.Text.Length,        string.Format("{0}/Auth/Account/MessageReminderLoginIn?userName={1}&pwd={2}&url={3}"        , m_Url, m_UserName, m_Pwd, url));      link.LinkClicked += new LinkLabelLinkClickedEventHandler(delegate(object obj, LinkLabelLinkClickedEventArgs ea)      {        System.Diagnostics.Process.Start(ea.Link.LinkData.ToString());      });    }    #endregion    #region CreateLink    /// <summary>    /// 创建Link    /// </summary>    /// <param name="name">name属性</param>    /// <param name="topPos">位置</param>    public LinkLabel CreateLink(string name, string text, int topPos)    {      Control[] ctrls = this.Controls.Find(name, false);      if (ctrls.Length > 0)      {        return ctrls[0] as LinkLabel;      }      else      {        LinkLabel link = new LinkLabel();        link.AutoSize = true;        link.LinkColor = System.Drawing.Color.Red;        link.Location = new System.Drawing.Point(12, topPos);        link.Name = name;        link.Size = new System.Drawing.Size(65, 12);        link.TabIndex = 0;        link.TabStop = true;        link.Text = text;        m_msgForm.Controls.Add(link);        return link;      }    }    #endregion    #region 关于    private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)    {      AboutBox aboutBox = new AboutBox();      aboutBox.ShowDialog();    }    #endregion    #region 双击托盘图标    private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)    {      立即检测ToolStripMenuItem_Click(sender, e);    }    #endregion    #region 阻止关闭窗体    private void Form1_FormClosing(object sender, FormClosingEventArgs e)    {      if (!canExit)      {        this.WindowState = FormWindowState.Minimized;        this.Visible = false;      }      e.Cancel = !canExit;    }    #endregion  }}

View Code

    代码下载:点击下载源代码

    截图: