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

450 lines
19 KiB
C#

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;
using FineUIPro.Web.common;
using System.Threading.Tasks;
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();
// 开启超焊信息提取
System.Threading.Thread LoadServiceSuperQue = new System.Threading.Thread(new System.Threading.ThreadStart(SuperQueWelding));
LoadServiceSuperQue.Start();
// 开启WPS可焊焊工提取
System.Threading.Thread LoadServiceWPSWelder = new System.Threading.Thread(new System.Threading.ThreadStart(WPSWelder));
LoadServiceWPSWelder.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
{
if (jotList.Count() > 0)
{
int rnum = Funs.GetRandomNum(1, jotList.Count());
int j = 1;
foreach (var g in jotList)
{
if (rnum == j)
{
BLL.Batch_PointBatchItemService.UpdatePointBatchItem(g.PointBatchItemId, "1", System.DateTime.Now, null);
}
j++;
}
}
}
//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);
}
}
}
}
private void SuperQueWelding()
{
//定义一个定时器,并开启和配置相关属性
System.Timers.Timer ExpirePoint = new System.Timers.Timer();
//执行任务的周期 ,3小时
ExpirePoint.Interval = 1000 * 60 * 60 * 3;
ExpirePoint.Enabled = true;
ExpirePoint.Start();
ExpirePoint.Elapsed += new System.Timers.ElapsedEventHandler(SuperQueWelding_Elapsed);
}
void SuperQueWelding_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
var jotList = (from x in Funs.DB.Pipeline_WeldJoint where x.WeldingDailyId != null && x.WeldingMethodId != null select x).ToList();
foreach (var jot in jotList)
{
var wps = BLL.WPQListServiceService.GetWPQById(jot.WPQId);
string floorWelder = jot.BackingWelderId;
string cellWelder = jot.CoverWelderId;
bool canWPS = true;
if (wps != null)
{
// 验证焊工WPS资质
if (floorWelder == cellWelder)
{
if (!wps.WelderIds.Contains(floorWelder))
{
canWPS = false;
}
}
else
{
if (!wps.WelderIds.Contains(floorWelder))
{
canWPS = false;
}
if (!wps.WelderIds.Contains(cellWelder))
{
canWPS = false;
}
}
}
// 验证焊工合格项目资质
bool canSave = false;
var joty = BLL.Base_WeldTypeService.GetWeldTypeByWeldTypeId(jot.WeldTypeId);
var mat = BLL.Base_WeldingMethodService.GetWeldingMethodByWeldingMethodId(jot.WeldingMethodId);
var loc = BLL.Base_WeldingLocationServie.GetWeldingLocationById(jot.WeldingLocationId);
string weldTypeGroup = joty.Flag;
string weldTypeCode = joty.WeldTypeCode;
decimal? dia = jot.Dia;
decimal? sch = jot.Thickness;
string[] wmeCodes = mat.WeldingMethodCode.Split('+');
string location = string.Empty;
if (loc != null)
{
location = loc.WeldingLocationCode;
}
string ste = jot.Material1Id;
List<Model.Welder_WelderQualify> floorWelderQualifys = (from x in Funs.DB.Welder_WelderQualify
where x.WelderId == floorWelder && x.WeldingMethodId != null
&& x.WeldingLocationId != null && x.MaterialType != null
&& x.WeldType != null
&& x.ThicknessMax != null && x.SizesMin != null
select x).ToList();
List<Model.Welder_WelderQualify> cellWelderQualifys = (from x in Funs.DB.Welder_WelderQualify
where x.WelderId == cellWelder && x.WeldingMethodId != null
&& x.WeldingLocationId != null && x.MaterialType != null
&& x.WeldType != null
&& x.ThicknessMax != null && x.SizesMin != null
select x).ToList();
// 打底和盖面同一焊工
if (floorWelder == cellWelder)
{
if (floorWelderQualifys != null && floorWelderQualifys.Count() > 0)
{
if (wmeCodes.Count() <= 1) // 一种焊接方法
{
canSave = BLL.WelderQualifiedService.IsOK(floorWelderQualifys, wmeCodes[0], location, weldTypeGroup, ste, dia, sch);
}
else // 大于一种焊接方法,如氩电联焊
{
canSave = BLL.WelderQualifiedService.TwoWmeIsOK(floorWelderQualifys, cellWelderQualifys, wmeCodes[0], wmeCodes[1], location, weldTypeGroup, ste, dia, sch);
}
}
}
// 打底和盖面焊工不同
else
{
bool isok1 = false;
bool isok2 = false;
if (wmeCodes.Count() <= 1) // 一种焊接方法
{
if (floorWelderQualifys != null && floorWelderQualifys.Count() > 0)
{
isok1 = BLL.WelderQualifiedService.IsOK(floorWelderQualifys, wmeCodes[0], location, weldTypeGroup, ste, dia, sch);
}
if (cellWelderQualifys != null && cellWelderQualifys.Count() > 0)
{
isok2 = BLL.WelderQualifiedService.IsOK(cellWelderQualifys, wmeCodes[0], location, weldTypeGroup, ste, dia, sch);
}
if (isok1 && isok2)
{
canSave = true;
}
}
else
{
canSave = BLL.WelderQualifiedService.TwoWmeIsOK(floorWelderQualifys, cellWelderQualifys, wmeCodes[0], wmeCodes[1], location, weldTypeGroup, ste, dia, sch);
}
}
if (canWPS == false || canSave == false)
{
jot.IsSuperQueWelding = true;
}
else
{
jot.IsSuperQueWelding = null;
}
}
Funs.DB.SubmitChanges();
}
private void WPSWelder()
{
//定义一个定时器,并开启和配置相关属性
System.Timers.Timer WPSWelder = new System.Timers.Timer();
//执行任务的周期 ,60分钟
WPSWelder.Interval = 1000 * 60 * 60;
WPSWelder.Enabled = true;
WPSWelder.Start();
WPSWelder.Elapsed += new System.Timers.ElapsedEventHandler(WPSWelder_Elapsed);
}
void WPSWelder_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
var wpsList = from x in Funs.DB.WPQ_WPQList where x.ProjectId == ((Model.Sys_User)Session["CurrUser"]).LoginProjectId select x;
var welderList = from x in Funs.DB.Welder_ProjectWelder where x.ProjectId == ((Model.Sys_User)Session["CurrUser"]).LoginProjectId select x;
if (wpsList==null)
{
return;
}
foreach (var wps in
wpsList)
{
string testWelder = string.Empty;
string materialStr = string.Empty;
if (wps.MaterialId1 != null)
{
string[] matList = wps.MaterialId1.Split('|');
foreach (var matId in matList)
{
var mat = from x in Funs.DB.Base_Material where x.MaterialId == matId select x;
if (mat.Count() > 0 && !materialStr.Contains(mat.First().MaterialType))
{
materialStr += mat.First().MaterialType + ",";
}
}
}
if (materialStr != null)
{
materialStr = materialStr.Substring(0, materialStr.Length - 1);
}
string[] wpsMaterial = materialStr.Split(',');
// 焊工考试情况
foreach (var welder in welderList)
{
var welderTestList = from x in Funs.DB.Welder_TestInfo where x.WelderId == welder.WelderId select x;
if (welderTestList.Count() > 0)
{
foreach (var t in welderTestList)
{
if (t.MaterialId != null && wps.WeldingMethodId != null)
{
string[] testMaterial = t.MaterialId.Split(',');
if (wpsMaterial.All(x => testMaterial.Contains(x)) && wps.WeldingMethodId.Contains(t.WeldMethodId) && t.IsPass == true)
{
testWelder += welder.WelderId + "|";
break;
}
}
}
}
}
if (testWelder != string.Empty)
{
testWelder = testWelder.Substring(0, testWelder.Length - 1);
wps.WelderIds = testWelder;
Funs.DB.SubmitChanges();
}
}
}
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)
{
}
}
}