namespace FineUIPro.Web
{
using BLL;
using FineUIPro.Web.Score;
using Model;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Forms;
public class Global : System.Web.HttpApplication
{
///
/// 自动启用插件标志文件路径
///
//private static string applicationActiveFlagFilePhysicalPath = String.Empty;
protected void Application_Start(object sender, EventArgs e)
{
Application["OnlineUserCount"] = 0;
try
{
Funs.RootPath = Server.MapPath("~/");
// 日志文件所在目录
ErrLogInfo.DefaultErrLogFullPath = Server.MapPath("~/ErrLog.txt");
Funs.ConnString = ConfigurationManager.AppSettings["ConnectionString"];
Funs.SystemName = ConfigurationManager.AppSettings["SystemName"];
Funs.SGGLUrl = ConfigurationManager.AppSettings["SGGLUrl"];
Funs.RealNameApiUrl = ConfigurationManager.AppSettings["RealNameApiUrl"];
}
catch (Exception ex)
{
ErrLogInfo.WriteLog(string.Empty, ex);
//AppDomain.Unload(AppDomain.CurrentDomain);
}
//通用定时器
try
{
ErrLogInfo.WriteLog("通用定时器开启!");
QuartzServices.Init();
ErrLogInfo.WriteLog("通用定时器结束!");
}
catch (Exception ex)
{
ErrLogInfo.WriteLog("通用定时器!", ex);
}
// 开启线程
System.Threading.Thread LoadServiceData = new System.Threading.Thread(new System.Threading.ThreadStart(EduTrainAddScore));
LoadServiceData.Start();
}
private void EduTrainAddScore()
{
//定义一个定时器,并开启和配置相关属性
System.Timers.Timer Wtimer = new System.Timers.Timer();
//执行任务的周期 ,60分钟
Wtimer.Interval =1000 * 60 * 60; //120000;
Wtimer.Enabled = true;
Wtimer.Start();
Wtimer.Elapsed += new System.Timers.ElapsedEventHandler(Wtimer_Elapsed);
}
///
/// 培训考试加分
///
///
///
void Wtimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//考试大于等于80分通过,且没有加过分的记录,加分
var testRecordList = (from x in Funs.DB.View_Training_TestRecord where x.TestScores >= 80
&& !Funs.DB.ScoreFlowLog.Any(log => log.DataSourceId == x.TestRecordId)
orderby x.TestStartTime select x).ToList();
foreach (var item in testRecordList)
{
//查找最新一条积分记录
var flowLog = BLL.ScoreFlowLogService.GetScoreFlowLogByIdentityCard(item.IdentityCard, item.TestStartTime.Value.Year, DateTime.Now);
//作业人员考试加分
if (item.WorkPostType == "一般作业岗位" || item.WorkPostType == "特种作业人员")
{
//必修-岗位基本操作技能:一门专业课20分,最高20分;超过1门课程,多出的学习课程每门2分
if (item.CompanyTrainingId == BLL.Const.CompanyTrainingId3)
{
var scoreFlowLog = (from x in Funs.DB.ScoreFlowLog where x.Type == 1 && x.IdentityCard == item.IdentityCard && x.Year == item.TestStartTime.Value.Year && x.Item.Contains("考试【岗位基本操作技能】") orderby x.CompileDate descending select x).ToList();
//一个课程加分一次
var isExist = scoreFlowLog.Where(x => x.LogContent.Contains("岗位基本操作技能【" + item.CompanyTrainingItemName + "】")).FirstOrDefault();
if (isExist == null)//第一次加分
{
//人员记分流水日志表
Model.ScoreFlowLog newlog = new Model.ScoreFlowLog();
newlog.Id = SQLHelper.GetNewID();
newlog.Year = item.TestStartTime.Value.Year;
newlog.IdentityCard = item.IdentityCard;
newlog.UserName = item.PersonName;
newlog.PersonId = item.TestManId;
newlog.UnitId = item.UnitId;
newlog.ProjectId = item.ProjectId;
newlog.UnitName = item.UnitName;
newlog.ProjectName = item.ProjectName;
newlog.Type = 1;
newlog.Item = "考试【岗位基本操作技能】";
newlog.LogContent = "岗位基本操作技能【" + item.CompanyTrainingItemName + "】考试得分" + item.TestScores + "分后,加分";
newlog.CompileDate = DateTime.Now;
newlog.CompileManId = "";
newlog.CompileMan = "";
newlog.DataSourceId = item.TestRecordId;
newlog.CheckDate = item.TestStartTime;
if (scoreFlowLog.Count == 0)
{
newlog.Score = 20;
if (flowLog != null)
{
newlog.CurrentScore = flowLog.CurrentScore + 20;
}
else
{
newlog.CurrentScore = 120;
}
}
else
{
newlog.Score = 2;
if (flowLog != null)
{
newlog.CurrentScore = flowLog.CurrentScore + 2;
}
else
{
newlog.CurrentScore = 102;
}
}
BLL.ScoreFlowLogService.AddScoreFlowLog(newlog);
//人员记分情况
Model.ScoreUser newScoreUser = new ScoreUser();
newScoreUser.Id = SQLHelper.GetNewID();
newScoreUser.Year = newlog.Year;
newScoreUser.IdentityCard = item.IdentityCard;
newScoreUser.Score = newlog.CurrentScore;
newScoreUser.UserName = newlog.UserName;
newScoreUser.CompileDate = newlog.CompileDate;
newScoreUser.DataSourceId = newlog.DataSourceId;
newScoreUser.CheckDate = newlog.CheckDate;
BLL.ScoreUserService.AddScoreUser(newScoreUser);
}
}
//必修-通用安全知识:60分,每门10分,最高60分;超过6门课程,多出的学习课程每门2分
else if (item.CompanyTrainingId == BLL.Const.CompanyTrainingId1)
{
var scoreFlowLog = (from x in Funs.DB.ScoreFlowLog where x.Type == 1 && x.IdentityCard == item.IdentityCard && x.Year == item.TestStartTime.Value.Year && x.Item.Contains("考试【通用安全知识】") orderby x.CompileDate descending select x).ToList();
//一个课程加分一次
var isExist = scoreFlowLog.Where(x => x.LogContent.Contains("通用安全知识【" + item.CompanyTrainingItemName + "】")).FirstOrDefault();
if (isExist == null)//第一次加分
{
//人员记分流水日志表
Model.ScoreFlowLog newlog = new Model.ScoreFlowLog();
newlog.Id = SQLHelper.GetNewID();
newlog.Year = item.TestStartTime.Value.Year;
newlog.IdentityCard = item.IdentityCard;
newlog.UserName = item.PersonName;
newlog.PersonId = item.TestManId;
newlog.UnitId = item.UnitId;
newlog.ProjectId = item.ProjectId;
newlog.UnitName = item.UnitName;
newlog.ProjectName = item.ProjectName;
newlog.Type = 1;
newlog.Item = "考试【通用安全知识】";
newlog.LogContent = "通用安全知识【" + item.CompanyTrainingItemName + "】考试得分" + item.TestScores + "分后,加分";
newlog.CompileDate = DateTime.Now;
newlog.CompileManId = "";
newlog.CompileMan = "";
newlog.DataSourceId = item.TestRecordId;
newlog.CheckDate = item.TestStartTime;
if (scoreFlowLog.Count < 6)
{
newlog.Score = 10;
if (flowLog != null)
{
newlog.CurrentScore = flowLog.CurrentScore + 10;
}
else
{
newlog.CurrentScore = 110;
}
}
else
{
newlog.Score = 2;
if (flowLog != null)
{
newlog.CurrentScore = flowLog.CurrentScore + 2;
}
else
{
newlog.CurrentScore = 102;
}
}
BLL.ScoreFlowLogService.AddScoreFlowLog(newlog);
//人员记分情况
Model.ScoreUser newScoreUser = new ScoreUser();
newScoreUser.Id = SQLHelper.GetNewID();
newScoreUser.Year = newlog.Year;
newScoreUser.IdentityCard = item.IdentityCard;
newScoreUser.Score = newlog.CurrentScore;
newScoreUser.UserName = newlog.UserName;
newScoreUser.CompileDate = newlog.CompileDate;
newScoreUser.DataSourceId = newlog.DataSourceId;
newScoreUser.CheckDate = newlog.CheckDate;
BLL.ScoreUserService.AddScoreUser(newScoreUser);
}
}
//选修加分 每节课2分,加分上线不限制,以年度为节点
else
{
var isExist = (from x in Funs.DB.ScoreFlowLog
where x.Type == 1 && x.IdentityCard == item.IdentityCard && x.Year == item.TestStartTime.Value.Year
&& x.Item.Contains(item.CompanyTrainingName)
&& x.LogContent.Contains(item.CompanyTrainingName + "【" + item.CompanyTrainingItemName + "】")
orderby x.CompileDate descending
select x).FirstOrDefault();
if (isExist == null)
{
//人员记分流水日志表
Model.ScoreFlowLog newlog = new Model.ScoreFlowLog();
newlog.Id = SQLHelper.GetNewID();
newlog.Year = item.TestStartTime.Value.Year;
newlog.IdentityCard = item.IdentityCard;
newlog.UserName = item.PersonName;
newlog.PersonId = item.TestManId;
newlog.UnitId = item.UnitId;
newlog.ProjectId = item.ProjectId;
newlog.UnitName = item.UnitName;
newlog.ProjectName = item.ProjectName;
newlog.Type = 1;
newlog.Item = "考试【" + item.CompanyTrainingName + "】";
newlog.LogContent = item.CompanyTrainingName + "【" + item.CompanyTrainingItemName + "】考试得分" + item.TestScores + "分后,加分";
newlog.CompileDate = DateTime.Now;
newlog.CompileManId = "";
newlog.CompileMan = "";
newlog.DataSourceId = item.TestRecordId;
newlog.CheckDate = item.TestStartTime;
newlog.Score = 2;
if (flowLog != null)
{
newlog.CurrentScore = flowLog.CurrentScore + 2;
}
else
{
newlog.CurrentScore = 102;
}
BLL.ScoreFlowLogService.AddScoreFlowLog(newlog);
//人员记分情况
Model.ScoreUser newScoreUser = new ScoreUser();
newScoreUser.Id = SQLHelper.GetNewID();
newScoreUser.Year = newlog.Year;
newScoreUser.IdentityCard = item.IdentityCard;
newScoreUser.Score = newlog.CurrentScore;
newScoreUser.UserName = newlog.UserName;
newScoreUser.CompileDate = newlog.CompileDate;
newScoreUser.DataSourceId = newlog.DataSourceId;
newScoreUser.CheckDate = newlog.CheckDate;
BLL.ScoreUserService.AddScoreUser(newScoreUser);
}
}
}
//管理人员考试加分
else if (item.WorkPostType == "一般管理岗位" || item.WorkPostType == "特种管理人员")
{
//必修-知识方法工具,最少学习5门课程,一门5分;超过5门课程,多出的学习课程每门2分
if (item.CompanyTrainingId == BLL.Const.CompanyTrainingId2)
{
var scoreFlowLog = (from x in Funs.DB.ScoreFlowLog where x.Type == 1 && x.IdentityCard == item.IdentityCard && x.Year == item.TestStartTime.Value.Year && x.Item.Contains("考试【知识方法工具】") orderby x.CompileDate descending select x).ToList();
//一次考试加分一次
var isExist = scoreFlowLog.Where(x => x.LogContent.Contains("知识方法工具【" + item.CompanyTrainingItemName + "】")).FirstOrDefault();
if (isExist == null)//第一次加分
{
//人员记分流水日志表
Model.ScoreFlowLog newlog = new Model.ScoreFlowLog();
newlog.Id = SQLHelper.GetNewID();
newlog.Year = item.TestStartTime.Value.Year;
newlog.IdentityCard = item.IdentityCard;
newlog.UserName = item.PersonName;
newlog.PersonId = item.TestManId;
newlog.UnitId = item.UnitId;
newlog.ProjectId = item.ProjectId;
newlog.UnitName = item.UnitName;
newlog.ProjectName = item.ProjectName;
newlog.Type = 1;
newlog.Item = "考试【知识方法工具】";
newlog.LogContent = "知识方法工具【" + item.CompanyTrainingItemName + "】考试得分" + item.TestScores + "分后,加分";
newlog.CompileDate = DateTime.Now;
newlog.CompileManId = "";
newlog.CompileMan = "";
newlog.DataSourceId = item.TestRecordId;
newlog.CheckDate = item.TestStartTime;
if (scoreFlowLog.Count < 5)
{
newlog.Score = 5;
if (flowLog != null)
{
newlog.CurrentScore = flowLog.CurrentScore + 5;
}
else
{
newlog.CurrentScore = 105;
}
}
else
{
newlog.Score = 2;
if (flowLog != null)
{
newlog.CurrentScore = flowLog.CurrentScore + 2;
}
else
{
newlog.CurrentScore = 102;
}
}
BLL.ScoreFlowLogService.AddScoreFlowLog(newlog);
//人员记分情况
Model.ScoreUser newScoreUser = new ScoreUser();
newScoreUser.Id = SQLHelper.GetNewID();
newScoreUser.Year = newlog.Year;
newScoreUser.IdentityCard = item.IdentityCard;
newScoreUser.Score = newlog.CurrentScore;
newScoreUser.UserName = newlog.UserName;
newScoreUser.CompileDate = newlog.CompileDate;
newScoreUser.DataSourceId = newlog.DataSourceId;
newScoreUser.CheckDate = newlog.CheckDate;
BLL.ScoreUserService.AddScoreUser(newScoreUser);
}
}
//必修-生产受控管理,最少学习5门课程,一门5分;超过5门课程,多出的学习课程每门2分
else if (item.CompanyTrainingId == BLL.Const.CompanyTrainingId4)
{
var scoreFlowLog = (from x in Funs.DB.ScoreFlowLog where x.Type == 1 && x.IdentityCard == item.IdentityCard && x.Year == item.TestStartTime.Value.Year && x.Item.Contains("考试【生产受控管理】") orderby x.CompileDate descending select x).ToList();
//一次考试加分一次
var isExist = scoreFlowLog.Where(x => x.LogContent.Contains("生产受控管理【" + item.CompanyTrainingItemName + "】")).FirstOrDefault();
if (isExist == null)//第一次加分
{
//人员记分流水日志表
Model.ScoreFlowLog newlog = new Model.ScoreFlowLog();
newlog.Id = SQLHelper.GetNewID();
newlog.Year = item.TestStartTime.Value.Year;
newlog.IdentityCard = item.IdentityCard;
newlog.UserName = item.PersonName;
newlog.PersonId = item.TestManId;
newlog.UnitId = item.UnitId;
newlog.ProjectId = item.ProjectId;
newlog.UnitName = item.UnitName;
newlog.ProjectName = item.ProjectName;
newlog.Type = 1;
newlog.Item = "考试【生产受控管理】";
newlog.LogContent = "生产受控管理【" + item.CompanyTrainingItemName + "】考试得分" + item.TestScores + "分后,加分";
newlog.CompileDate = DateTime.Now;
newlog.CompileManId = "";
newlog.CompileMan = "";
newlog.DataSourceId = item.TestRecordId;
newlog.CheckDate = item.TestStartTime;
if (scoreFlowLog.Count < 5)
{
newlog.Score = 5;
if (flowLog != null)
{
newlog.CurrentScore = flowLog.CurrentScore + 5;
}
else
{
newlog.CurrentScore = 105;
}
}
else
{
newlog.Score = 2;
if (flowLog != null)
{
newlog.CurrentScore = flowLog.CurrentScore + 2;
}
else
{
newlog.CurrentScore = 102;
}
}
BLL.ScoreFlowLogService.AddScoreFlowLog(newlog);
//人员记分情况
Model.ScoreUser newScoreUser = new ScoreUser();
newScoreUser.Id = SQLHelper.GetNewID();
newScoreUser.Year = newlog.Year;
newScoreUser.IdentityCard = item.IdentityCard;
newScoreUser.Score = newlog.CurrentScore;
newScoreUser.UserName = newlog.UserName;
newScoreUser.CompileDate = newlog.CompileDate;
newScoreUser.DataSourceId = newlog.DataSourceId;
newScoreUser.CheckDate = newlog.CheckDate;
BLL.ScoreUserService.AddScoreUser(newScoreUser);
}
}
//必修-通用课程:通用安全知识:30分,每门10分,最高30分;超过3门课程,多出的学习课程每门2分
else if (item.CompanyTrainingId == BLL.Const.CompanyTrainingId1)
{
var scoreFlowLog = (from x in Funs.DB.ScoreFlowLog where x.Type == 1 && x.IdentityCard == item.IdentityCard && x.Year == item.TestStartTime.Value.Year && x.Item.Contains("考试【通用安全知识】") orderby x.CompileDate descending select x).ToList();
//一次考试加分一次
var isExist = scoreFlowLog.Where(x => x.LogContent.Contains("通用安全知识【" + item.CompanyTrainingItemName + "】")).FirstOrDefault();
if (isExist == null)//第一次加分
{
//人员记分流水日志表
Model.ScoreFlowLog newlog = new Model.ScoreFlowLog();
newlog.Id = SQLHelper.GetNewID();
newlog.Year = item.TestStartTime.Value.Year;
newlog.IdentityCard = item.IdentityCard;
newlog.UserName = item.PersonName;
newlog.PersonId = item.TestManId;
newlog.UnitId = item.UnitId;
newlog.ProjectId = item.ProjectId;
newlog.UnitName = item.UnitName;
newlog.ProjectName = item.ProjectName;
newlog.Type = 1;
newlog.Item = "考试【通用安全知识】";
newlog.LogContent = "通用安全知识【" + item.CompanyTrainingItemName + "】考试得分" + item.TestScores + "分后,加分";
newlog.CompileDate = DateTime.Now;
newlog.CompileManId = "";
newlog.CompileMan = "";
newlog.DataSourceId = item.TestRecordId;
newlog.CheckDate = item.TestStartTime;
if (scoreFlowLog.Count < 3)
{
newlog.Score = 10;
if (flowLog != null)
{
newlog.CurrentScore = flowLog.CurrentScore + 10;
}
else
{
newlog.CurrentScore = 110;
}
}
else
{
newlog.Score = 2;
if (flowLog != null)
{
newlog.CurrentScore = flowLog.CurrentScore + 2;
}
else
{
newlog.CurrentScore = 102;
}
}
BLL.ScoreFlowLogService.AddScoreFlowLog(newlog);
//人员记分情况
Model.ScoreUser newScoreUser = new ScoreUser();
newScoreUser.Id = SQLHelper.GetNewID();
newScoreUser.Year = newlog.Year;
newScoreUser.IdentityCard = item.IdentityCard;
newScoreUser.Score = newlog.CurrentScore;
newScoreUser.UserName = newlog.UserName;
newScoreUser.CompileDate = newlog.CompileDate;
newScoreUser.DataSourceId = newlog.DataSourceId;
newScoreUser.CheckDate = newlog.CheckDate;
BLL.ScoreUserService.AddScoreUser(newScoreUser);
}
}
else //选修加分 每节课2分,加分上线不限制,以年度为节点
{
var isExist = (from x in Funs.DB.ScoreFlowLog
where x.Type == 1 && x.IdentityCard == item.IdentityCard && x.Year == item.TestStartTime.Value.Year
&& x.Item.Contains(item.CompanyTrainingName)
&& x.LogContent.Contains(item.CompanyTrainingName + "【" + item.CompanyTrainingItemName + "】")
orderby x.CompileDate descending
select x).FirstOrDefault();
if (isExist == null)
{
//人员记分流水日志表
Model.ScoreFlowLog newlog = new Model.ScoreFlowLog();
newlog.Id = SQLHelper.GetNewID();
newlog.Year = item.TestStartTime.Value.Year;
newlog.IdentityCard = item.IdentityCard;
newlog.UserName = item.PersonName;
newlog.PersonId = item.TestManId;
newlog.UnitId = item.UnitId;
newlog.ProjectId = item.ProjectId;
newlog.UnitName = item.UnitName;
newlog.ProjectName = item.ProjectName;
newlog.Type = 1;
newlog.Item = "考试【" + item.CompanyTrainingName + "】";
newlog.LogContent = item.CompanyTrainingName + "【" + item.CompanyTrainingItemName + "】考试得分" + item.TestScores + "分后,加分";
newlog.CompileDate = DateTime.Now;
newlog.CompileManId = "";
newlog.CompileMan = "";
newlog.DataSourceId = item.TestRecordId;
newlog.CheckDate = item.TestStartTime;
newlog.Score = 2;
if (flowLog != null)
{
newlog.CurrentScore = flowLog.CurrentScore + 2;
}
else
{
newlog.CurrentScore = 102;
}
BLL.ScoreFlowLogService.AddScoreFlowLog(newlog);
//人员记分情况
Model.ScoreUser newScoreUser = new ScoreUser();
newScoreUser.Id = SQLHelper.GetNewID();
newScoreUser.Year = newlog.Year;
newScoreUser.IdentityCard = item.IdentityCard;
newScoreUser.Score = newlog.CurrentScore;
newScoreUser.UserName = newlog.UserName;
newScoreUser.CompileDate = newlog.CompileDate;
newScoreUser.DataSourceId = newlog.DataSourceId;
newScoreUser.CheckDate = newlog.CheckDate;
BLL.ScoreUserService.AddScoreUser(newScoreUser);
}
}
}
}
}
protected void Session_Start(object sender, EventArgs e)
{
Session.Timeout = 60;
// 这种统计在线人数的做法会有一定的误差
Application.Lock();
Application["OnlineUserCount"] = (int)Application["OnlineUserCount"] + 1;
Application.UnLock();
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
}
protected void Application_Error(object sender, EventArgs e)
{
StringBuilder errLog = null;
Exception ex = null;
using (Model.CNPCDB db = new Model.CNPCDB(Funs.ConnString))
{
Sys_ErrLogInfo newErr = new Sys_ErrLogInfo
{
ErrLogId = SQLHelper.GetNewID()
};
try
{
// 获取错误类
ex = Server.GetLastError().InnerException;
if (ex == null)
{
ex = Server.GetLastError().GetBaseException();
}
errLog = new StringBuilder();
errLog.Append(String.Format(CultureInfo.InvariantCulture, "出错文件:{0}\r\n", Request.Url.AbsoluteUri));
newErr.ErrUrl = Request.Url.AbsoluteUri;
if (Request.UserHostAddress != null)
{
errLog.Append(String.Format(CultureInfo.InvariantCulture, "IP地址:{0}\r\n", Request.UserHostAddress));
newErr.ErrIP = Request.UserHostAddress;
}
if (Session != null && Session["CurrUser"] != null)
{
errLog.Append(String.Format(CultureInfo.InvariantCulture, "操作人员:{0}\r\n", ((Model.Sys_User)Session["CurrUser"]).UserName));
newErr.UserName = ((Model.Sys_User)Session["CurrUser"]).UserId;
}
else
{
PageBase.PageRefresh(Request.ApplicationPath + "/LogOff.aspx");
}
}
catch
{
try
{
PageBase.PageRefresh(Request.ApplicationPath + "/LogOff.aspx");
}
catch
{
}
}
finally
{
if (errLog != null)
{
db.Sys_ErrLogInfo.InsertOnSubmit(newErr);
db.SubmitChanges();
}
ErrLogInfo.WriteLog(newErr.ErrLogId, ex, errLog == null ? null : errLog.ToString());
Server.ClearError();
//PageBase.PageRefresh(Request.ApplicationPath + "/LogOff.aspx");
}
}
}
///
/// 缓存结束
///
///
///
protected void Session_End(object sender, EventArgs e)
{
}
///
/// 活动结束
///
///
///
protected void Application_End(object sender, EventArgs e)
{
}
}
}