Basf_TCC7/HJGL/FineUIPro.Web/Global.asax.cs

235 lines
9.3 KiB
C#
Raw Normal View History

2024-05-08 10:02:08 +08:00
namespace FineUIPro.Web
{
using System;
using System.Configuration;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using BLL;
public class Global : System.Web.HttpApplication
{
/// <summary>
/// 自动启用插件标志文件路径
/// </summary>
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.APPUrl = ConfigurationManager.AppSettings["APPUrl"];
Funs.UsingUnit = ConfigurationManager.AppSettings["UsingUnit"];
Funs.ConnString= ConfigurationManager.ConnectionStrings["HJGLDBConnectionString"].ConnectionString;
}
catch (Exception ex)
{
ErrLogInfo.WriteLog(ex);
AppDomain.Unload(AppDomain.CurrentDomain);
}
// 开启线程
System.Threading.Thread LoadServiceData = new System.Threading.Thread(new System.Threading.ThreadStart(ExpirePoint));
LoadServiceData.Start();
}
private void ExpirePoint()
{
//定义一个定时器,并开启和配置相关属性
System.Timers.Timer ExpirePoint = new System.Timers.Timer();
//执行任务的周期 ,60分钟
ExpirePoint.Interval = 1000 * 60 * 60;
ExpirePoint.Enabled = true;
ExpirePoint.Start();
ExpirePoint.Elapsed += new System.Timers.ElapsedEventHandler(ExpirePoint_Elapsed);
}
void ExpirePoint_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
int cycleDay = 15;
var project = from x in Funs.DB.Base_Project select x;
var set = BLL.Sys_SetService.GetSetById("4", project.First().ProjectId);
if (project != null && set != null && !string.IsNullOrEmpty(set.SetValue))
{
cycleDay = Convert.ToInt32(set.SetValue);
}
string strSql = @"SELECT jot.ProjectId, pItem.PointBatchId,jot.CoverWelderId
FROM dbo.Batch_PointBatchItem pItem
LEFT JOIN dbo.Pipeline_WeldJoint jot ON jot.WeldJointId = pItem.WeldJointId
WHERE DATEADD(DAY,@cycleDay,pItem.WeldingDate)<=GETDATE() AND pItem.IsCompletedPoint=0
GROUP BY jot.ProjectId, pItem.PointBatchId,jot.CoverWelderId";
List<SqlParameter> listStr = new List<SqlParameter>{};
listStr.Add(new SqlParameter("@cycleDay", cycleDay));
SqlParameter[] parameter = listStr.ToArray();
DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter);
if (dt.Rows.Count > 0)
{
foreach (DataRow r in dt.Rows)
{
var jotList = from x in Funs.DB.Batch_PointBatchItem
join y in Funs.DB.Pipeline_WeldJoint on x.WeldJointId equals y.WeldJointId
where x.PointBatchId == r["PointBatchId"].ToString()
&& y.CoverWelderId == r["CoverWelderId"].ToString()
&& (y.IsCancel == false || y.IsCancel == null)
select x;
var GJot = from x in Funs.DB.Batch_PointBatchItem
join y in Funs.DB.Pipeline_WeldJoint on x.WeldJointId equals y.WeldJointId
where x.PointBatchId == r["PointBatchId"].ToString()
&& y.CoverWelderId == r["CoverWelderId"].ToString()
&& (y.IsCancel == false || y.IsCancel == null)
&& y.JointAttribute == "固定F"
select x;
// 先查找固定口数量,如有固定口,则优先点
if (GJot.Count() > 0)
{
int Gnum = GJot.Count();
int rnum = Funs.GetRandomNum(1, Gnum);
int j = 1;
foreach (var g in GJot)
{
if (rnum == j)
{
BLL.Batch_PointBatchItemService.UpdatePointBatchItem(g.PointBatchItemId, "1", System.DateTime.Now, null);
}
j++;
}
}
else
{
2024-05-10 15:55:26 +08:00
if (jotList.Count() > 0)
2024-05-08 10:02:08 +08:00
{
2024-05-10 15:55:26 +08:00
int rnum = Funs.GetRandomNum(1, jotList.Count());
int j = 1;
foreach (var g in jotList)
2024-05-08 10:02:08 +08:00
{
2024-05-10 15:55:26 +08:00
if (rnum == j)
{
BLL.Batch_PointBatchItemService.UpdatePointBatchItem(g.PointBatchItemId, "1", System.DateTime.Now, null);
}
j++;
2024-05-08 10:02:08 +08:00
}
}
}
int batchOrder = BLL.Batch_PointBatchItemService.GetMaxBatchOrder(r["PointBatchId"].ToString());
// 点口后,更新该段批里的所有口为完成点口,并更新分段的顺序
foreach (var g in jotList)
{
BLL.Batch_PointBatchItemService.UpdateIsCompletedPoint(g.PointBatchItemId, true);
BLL.Batch_PointBatchItemService.UpdatePointBatchOrder(g.PointBatchItemId, batchOrder);
}
}
}
}
protected void Session_Start(object sender, EventArgs e)
{
Session.Timeout = 36000;
// 这种统计在线人数的做法会有一定的误差
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;
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));
if (Request.UserHostAddress != null)
{
errLog.Append(String.Format(CultureInfo.InvariantCulture, "IP地址:{0}\r\n", Request.UserHostAddress));
}
if (Session != null && Session["CurrUser"] != null)
{
errLog.Append(String.Format(CultureInfo.InvariantCulture, "操作人员:{0}\r\n", BLL.Sys_UserService.GetUsersByUserId(((Model.Sys_User)Session["CurrUser"]).UserId).UserName));
}
else
{
PageBase.ZXRefresh(Request.ApplicationPath + "/LogOff.aspx");
}
if (ex is HttpRequestValidationException)
{
PageBase.ZXRefresh(Request.ApplicationPath + "/Wrong.aspx?Message=0");
}
else if (ex is FriendlyException)
{
PageBase.ZXRefresh(Request.ApplicationPath + "/Wrong.aspx?MessageText=" + ex.Message);
}
}
catch
{
try
{
PageBase.ZXRefresh(Request.ApplicationPath + "/OperationError.aspx");
}
catch
{
}
}
finally
{
ErrLogInfo.WriteLog(ex, errLog == null ? null : errLog.ToString());
Server.ClearError();
PageBase.ZXRefresh(Request.ApplicationPath + "/OperationError.aspx");
}
}
protected void Session_End(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{
}
}
}