zoukankan      html  css  js  c++  java
  • Global

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.SessionState;
    using System.Text.RegularExpressions;
    using System.Data;
    namespace Web
    {
        public class Global : System.Web.HttpApplication
        {
                    protected void Application_Start(object sender, EventArgs e)
            {
                DataTable dtS = DBUtility.DbHelperSQL.Query("select * from 表名").Tables[0];
                DataTable dtT = DBUtility.DbHelperSQL.Query("select * from 表名").Tables[0];
                int count = dtS.Rows.Count + dtT.Rows.Count;
                Application.Add("total", count);
                Application.Add("online", 0);
            }
    
            protected void Session_Start(object sender, EventArgs e)
            {
                Application.Lock();//关闭会话,解决同时发生的情况
                Application["total"] = (int)Application["total"] + 1;//总的访问量加1
                Application["online"] = (int)Application["online"] + 1;//当前在线人数加1
                Application.UnLock();
            }
    
            protected void Application_BeginRequest(object sender, EventArgs e)
            {
                // 非法字符过滤
                Security.FilterModule.Filter(Request);
            }
    
            protected void Application_AuthenticateRequest(object sender, EventArgs e)
            {
    
            }
    
            protected void Application_Error(object sender, EventArgs e)
            {
    
            }
    
            protected void Session_End(object sender, EventArgs e)
            {
                Application.Lock();//锁
                Application["online"] = (int)Application["online"] - 1;//当前在线人数减1
                if(Session["usertype"].ToString()=="student")
                {
                    DataTable dt = DBUtility.DbHelperSQL.Query("select * from 表名 where  Day(CreateTime)=Day(getdate()) and UserName='" + Session["username"] + "'").Tables[0];
                    if (dt.Rows.Count > 0)
                    {
                        smodel = sbll.GetModel(int.Parse(dt.Rows[0]["Id"].ToString()));
                        smodel.Online = false;
                        smodel.ExitTime = DateTime.Now;
                        smodel.UpdateTime = DateTime.Now;
                        sbll.Update(smodel);
                    }
                }
                if (Session["usertype"].ToString() == "teacher")
                {
                    DataTable dt = DBUtility.DbHelperSQL.Query("select * from 表名 where Day(CreateTime)=Day(getdate()) and UserName='" + Session["username"] + "'").Tables[0];
                    if (dt.Rows.Count > 0)
                    {
                        tmodel = tbll.GetModel(int.Parse(dt.Rows[0]["Id"].ToString()));
                        tmodel.Online = false;
                        tmodel.ExitTime = DateTime.Now;
                        tmodel.UpdateTime = DateTime.Now;
                        tbll.Update(tmodel);
                    }
                }
                Application.UnLock();//解锁
            }
    
            protected void Application_End(object sender, EventArgs e)
            {
    
            }
        }
    }
    
    本人声明: 个人主页:沐海(http://www.cnblogs.com/mahaisong) 以上文章都是经过本人设计实践和阅读其他文档得出。如果需要探讨或指教可以留言或加我QQ!欢迎交流!
  • 相关阅读:
    Angular14 Angular相关命令
    Angular14 Visual Studio Code作为Angular开发工具常用插件安装、json-server安装与使用、angular/cli安装失败问题、emmet安装
    Material使用03 MdCardModule模块、MdInputModule模块
    Material使用02 图标MdIconModule、矢量图作为图标使用及改进
    Material使用01 侧边栏MdSidenavModule、工具栏MdTollbarModule
    阿里巴巴Druid数据库连接池的使用
    利用generator自动生成model(实体)、dao(接口)、mapper(映射)
    c++拷贝函数详解(转)
    c++友元函数友元类
    c++中虚函数与纯虚函数的区别(转)
  • 原文地址:https://www.cnblogs.com/mahaisong/p/2017842.html
Copyright © 2011-2022 走看看