工作流待办事项消息提醒

    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>
        public DesktopMsgService.Service m_DesktopMsgService = new DesktopMsgService.Service();
        /// <summary>
        /// 服务器url
        /// </summary>
        public 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

            #region 设置WebService地址
            m_DesktopMsgService.Url = m_Url + "/WebService/DesktopMsgService/Service.asmx";
            #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 登录服务器
        /// <summary>
        /// 登录窗体
        /// </summary>
        private Login m_Login;
        /// <summary>
        /// 登录窗体
        /// </summary>
        private void CreateLogin()
        {
            if (m_Login == null || m_Login.IsDisposed)
            {
                m_Login = new Login();
                m_Login.Show(this);
            }
            else
            {
                m_Login.Focus();
            }
        }
        /// <summary>
        /// 用户信息窗体
        /// </summary>
        private LoginInfo m_LoginInfo;
        /// <summary>
        /// 用户信息窗体
        /// </summary>
        private void CreateLoginInfo()
        {
            if (m_LoginInfo == null || m_LoginInfo.IsDisposed)
            {
                m_LoginInfo = new LoginInfo();
                m_LoginInfo.Show(this);
            }
            else
            {
                m_LoginInfo.Focus();
            }
        }
        private void 登录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Properties.Settings.Default.userName == "")
            {
                CreateLogin();
            }
            else
            {
                CreateLoginInfo();
            }
        }
        #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()
                        {
                            CreateLogin();
                        }));
                    }
                }
                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 关于
        /// <summary>
        /// 关于窗体
        /// </summary>
        private AboutBox m_AboutBox;
        /// <summary>
        /// 关于窗体
        /// </summary>
        private void CreateAboutBox()
        {
            if (m_AboutBox == null || m_AboutBox.IsDisposed)
            {
                m_AboutBox = new AboutBox();
                m_AboutBox.Show(this);
            }
            else
            {
                m_AboutBox.Focus();
            }
        }
        private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CreateAboutBox();
        }
        #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

        #region 设置
        /// <summary>
        /// 设置窗体
        /// </summary>
        private SettingsForm m_SettingsForm;
        /// <summary>
        /// 设置窗体
        /// </summary>
        private void CreateSettingsForm()
        {
            if (m_SettingsForm == null || m_SettingsForm.IsDisposed)
            {
                m_SettingsForm = new SettingsForm();
                m_SettingsForm.Show(this);
            }
            else
            {
                m_SettingsForm.Focus();
            }
        }

        private void 设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CreateSettingsForm();
        }
        #endregion

    }
}
View Code

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

    截图:

    WebService代码:

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Services;
using DAL;
using DBHelper;
using Models;

namespace TechReport.Web.WebService.DesktopMsg
{
    /// <summary>
    /// 桌面消息提醒WebService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class Service : System.Web.Services.WebService
    {
        #region 变量
        private OracleHelper dbHelper = new OracleHelper();
        #endregion

        #region HelloWorld
        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
        #endregion

        #region 获取待审阅报告
        /// <summary>
        /// 获取待审阅报告
        /// </summary>
        [WebMethod]
        public int GetDsyReportCount(string deptCode)
        {
            string sql = string.Format(@"
                select count(1)
                from REPORT,REPORTSTATE,sys_user 
                where report.reportstateid=reportstate.reportstateid 
                and report.empcode=sys_user.empcode
                and REPORT.REPORTSTATEID in({1}) 
                and report.DEPTCODE='{0}'"
                , deptCode, (int)Enums.ReportState.待审阅报告);

            return Convert.ToInt32(dbHelper.GetSingle(sql));
        }
        #endregion

        #region 获取待审阅辅审报告
        /// <summary>
        /// 获取待审阅辅审报告
        /// </summary>
        [WebMethod]
        public int GetDsyFsReportCount(string userName)
        {
            string sql = string.Format(@"
                select count(1)
                from report,reportaudit,sys_user 
                where report.reportcode=reportaudit.reportcode 
                and report.empcode=sys_user.empcode 
                and reportaudit.isfinished=0 
                and reportaudit.audittype={1} 
                and reportaudit.auditusername='{0}'"
                , userName, (int)Enums.AuditType.审阅辅审);

            return Convert.ToInt32(dbHelper.GetSingle(sql));
        }
        #endregion

        #region 获取待审核报告
        /// <summary>
        /// 获取待审核报告
        /// </summary>
        [WebMethod]
        public int GetDshReportCount(string userName)
        {
            string sql = string.Format(@"
                select count(1)
                from report,reportaudit,sys_user,reportstate 
                where report.reportcode=reportaudit.reportcode 
                and report.empcode=sys_user.empcode 
                and reportaudit.isfinished=0 
                and report.reportstateid=reportstate.reportstateid 
                and reportaudit.audittype={2} 
                and reportaudit.auditusername='{0}' 
                and report.reportstateid in({1}) 
                and report.reportTypeId in(1,2)"
                , userName, (int)Enums.ReportState.待审核报告, (int)Enums.AuditType.审核);

            return Convert.ToInt32(dbHelper.GetSingle(sql));
        }
        #endregion

        #region 获取待审核辅审报告
        /// <summary>
        /// 获取待审核辅审报告
        /// </summary>
        [WebMethod]
        public int GetDshFsReportCount(string userName)
        {
            string sql = string.Format(@"
                select count(1)
                from report,reportaudit,sys_user 
                where report.reportcode=reportaudit.reportcode 
                and report.empcode=sys_user.empcode 
                and reportaudit.isfinished=0 
                and reportaudit.audittype={1} 
                and reportaudit.auditusername='{0}'"
                , userName, (int)Enums.AuditType.审核辅审);

            return Convert.ToInt32(dbHelper.GetSingle(sql));
        }
        #endregion

        #region 获取待批准报告
        /// <summary>
        /// 获取待批准报告
        /// </summary>
        [WebMethod]
        public int GetDpzReportCount(string userName)
        {
            string sql = string.Format(@"
                select count(1)
                from report,reportaudit,sys_user 
                where report.reportcode=reportaudit.reportcode 
                and report.empcode=sys_user.empcode 
                and reportaudit.isfinished=0 
                and reportaudit.audittype={2} 
                and reportaudit.auditusername='{0}' 
                and report.reportstateid={1} 
                and report.reportTypeId in (1,2)"
                , userName, (int)Enums.ReportState.待批准报告, (int)Enums.AuditType.批准);

            return Convert.ToInt32(dbHelper.GetSingle(sql));
        }
        #endregion

        #region 获取未通过报告
        /// <summary>
        /// 获取未通过报告
        /// </summary>
        [WebMethod]
        public int GetWtgReportCount(string userName)
        {
            string sql = string.Format(@"
                select count(1)
                from REPORT,sys_user 
                where report.empcode=sys_user.empcode
                and sys_user.username='{3}'
                and REPORT.REPORTSTATEID in({0},{1},{2})"
                , (int)Enums.ReportState.审阅未通过报告, (int)Enums.ReportState.审核未通过报告
                , (int)Enums.ReportState.批准未通过报告, userName);

            return Convert.ToInt32(dbHelper.GetSingle(sql));
        }
        #endregion

    }
}
View Code

    与用户登录相关的代码:

#region 消息提醒器登录
/// <summary>
/// 消息提醒器登录
/// </summary>
/// <param name="userName">用户名</param>
/// <param name="pwd">密码(加密状态)</param>
[AuthIgnore]
public ActionResult MsgReminderLoginIn(string userName, string pwd)
{
    SYS_USER empDetail = m_UserDal.Get(userName);
    if (empDetail != null && empDetail.PASSWORD == pwd)
    {
        Session["_sysAuth"] = userName;
        return Content("OK|" + empDetail.EMPNAME + "|" + empDetail.DEPTCODE);
    }
    return Content("登录失败!");
}
/// <summary>
/// 消息提醒器登录
/// </summary>
/// <param name="userName">用户名</param>
/// <param name="pwd">密码(加密状态)</param>
/// <param name="url">跳转url</param>
[AuthIgnore]
public ActionResult MessageReminderLoginIn(string userName, string pwd, string url)
{
    SYS_USER empDetail = m_UserDal.Get(userName);
    if (empDetail != null && empDetail.PASSWORD == pwd)
    {
        Session["_sysAuth"] = userName;
        return new RedirectResult(ASCIIEncoding.UTF8.GetString(Convert.FromBase64String(url)));
    }
    return Content("登录失败,没有权限!");
}
View Code

 

转载于:https://www.cnblogs.com/s0611163/p/5091723.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值