一厂MES,含注塑,喷涂,冲孔
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

605 lines
30 KiB

using MESClassLibrary.BLL.Log;
using MESClassLibrary.EFModel;
using MESClassLibrary.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace MESClassLibrary.BLL.Inspection
{
public class CommonlyInspectionBLL
{
BasicBLL<tb_CommonlyInspection> db = new BasicBLL<tb_CommonlyInspection>();
/// <summary>
/// 查询信息
/// </summary>
/// <returns></returns>
public string SearchInfo(string versionID, string checkDate)
{
try
{
string jsonStr = "[]";
int total = 0;//总行数
List<tb_CommonlyInspection> list = null;
list = db.SearchInfoByKey("IsUseing", 1).Where(p => p.VersionID.Equals(versionID)).ToList();
if (list.Count > 0)
{
BasicBLL<tb_CheckItem> CheckItem_db = new BasicBLL<tb_CheckItem>();
var CheckItemList = CheckItem_db.SearchAllInfo().ToList();
List<CommonlyInspectionModel> CommonlyInspectionList = new List<CommonlyInspectionModel>();
foreach (var item in list)
{
CommonlyInspectionModel dm = Tool.Mapper<CommonlyInspectionModel, tb_CommonlyInspection>(item);
dm.InspectionContent = CheckItemList.FirstOrDefault(p => p.ID == item.InspectionContentID).CheckContent;
CommonlyInspectionList.Add(dm);
}
jsonStr = JSONTools.ScriptSerialize<List<CommonlyInspectionModel>>(CommonlyInspectionList);
}
return jsonStr;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return "";
}
}
/// <summary>
/// 添加信息
/// </summary>
/// <returns></returns>
public bool AddInfo(string CommonlyInspection, string CheckUserID, string ConfirmUserID, string UserID, string CheckDate, string CheckType, string ErrMes)
{
try
{
BasicBLL<tb_CommonlyInspectionRecord> Recorddb = new BasicBLL<tb_CommonlyInspectionRecord>();
DateTime dtime = DateTime.Now;
DateTime checktime = Convert.ToDateTime(CheckDate);
string[] arr = CommonlyInspection.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < arr.Length - 1; i++)
{
int index = arr[i].IndexOf(":");
tb_CommonlyInspectionRecord md = new tb_CommonlyInspectionRecord();
md.ID = Guid.NewGuid().ToString();
md.CommonlyInspectionID = arr[i].Substring(0, index);
md.CheckResult = arr[i].Substring(index + 1, arr[i].Length - index - 1);
md.CheckUser = CheckUserID;
md.ConfirmUser = CheckUserID;
md.CreateUserID = UserID;
md.CheckDate = checktime;
md.CheckType = CheckType;
md.ErrMes = ErrMes;
md.ConfirmUserDate = dtime;
md.CreateTime = dtime;
md.IsUseing = 1;
Recorddb.AddInfo(md);
}
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public bool UpdateInfo(string CommonlyInspection, string CheckUserID, string ConfirmUserID, string UserID, string CheckDate, string CheckType, string ErrMes)
{
try
{
string[] proNames = new string[9];
proNames[0] = "CheckResult";
proNames[1] = "CheckUser";
proNames[2] = "CheckDate";
proNames[3] = "ConfirmUser";
proNames[4] = "ConfirmUserDate";
proNames[5] = "UpdateUserID";
proNames[6] = "UpdateTime";
proNames[7] = "CheckType";
proNames[8] = "ErrMes";
BasicBLL<tb_CommonlyInspectionRecord> Recorddb = new BasicBLL<tb_CommonlyInspectionRecord>();
DateTime dtime = DateTime.Now;
DateTime checktime = Convert.ToDateTime(CheckDate);
string[] arr = CommonlyInspection.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < arr.Length - 3; i++)
{
int index = arr[i].IndexOf(":");
tb_CommonlyInspectionRecord md = new tb_CommonlyInspectionRecord();
md.ID = arr[i].Substring(0, index);
md.CheckResult = arr[i].Substring(index + 1, arr[i].Length - index - 1);
md.CheckUser = CheckUserID;
md.CheckDate = checktime;
md.CheckType = CheckType;
md.ErrMes = ErrMes;
md.ConfirmUser = ConfirmUserID;
md.ConfirmUserDate = dtime;
md.UpdateUserID = UserID;
md.UpdateTime = dtime;
//必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化
//如果没有初始化必填字段,更新会报错
md.CreateUserID = "";
md.CommonlyInspectionID = "";
Recorddb.UpdateInfo(md, proNames);
}
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public string GetDate(string VersionID, string CheckDate, string CheckType)
{
try
{
string str = "";
string CheckUserID = "";
string ConfirmUserID = "";
string ErrMes = "";
BasicBLL<tb_CommonlyInspection> db = new BasicBLL<tb_CommonlyInspection>();
string jsonStr = "[]";
List<tb_CommonlyInspection> list = null;
list = db.SearchInfoByKey("IsUseing", 1).Where(p => p.VersionID.Equals(VersionID)).ToList();
if (list.Count > 0)
{
BasicBLL<tb_CheckItem> CheckItem_db = new BasicBLL<tb_CheckItem>();
var CheckItemList = CheckItem_db.SearchAllInfo().ToList();
string[] arr_id = list.Select(s => s.ID).ToArray();
BasicBLL<tb_CommonlyInspectionRecord> CommonlyInspectionRecord_db = new BasicBLL<tb_CommonlyInspectionRecord>();
var _info = CommonlyInspectionRecord_db.SearchInfoByKey("CheckDate", Convert.ToDateTime(CheckDate)).Where(p => arr_id.Contains(p.CommonlyInspectionID) && p.CheckType.Equals(CheckType)).ToList();
if (_info.Count > 0)
{
#region 修改
List<CommonlyInspectionModel> CommonlyInspectionList = new List<CommonlyInspectionModel>();
foreach (var item in list)
{
CommonlyInspectionModel dm = Tool.Mapper<CommonlyInspectionModel, tb_CommonlyInspection>(item);
dm.InspectionContent = CheckItemList.FirstOrDefault(p => p.ID.Equals(item.InspectionContentID)).CheckContent;
CommonlyInspectionList.Add(dm);
}
str = "<table border='1' width='900' cellspacing='0' cellpadding='2' id='InspectionContentTable' name='1'>";
str += "<tr>";
str += "<td width='200'>点检内容</td>";
str += "<td width='200'>检查结果</td>";
str += "</tr>";
for (int j = 0; j < CommonlyInspectionList.Count; j++)
{
str += "<tr>";
str += "<td>" + CommonlyInspectionList[j].InspectionContent + "</td>";
var R_info = _info.FirstOrDefault(p => p.CommonlyInspectionID == CommonlyInspectionList[j].ID);
CheckUserID = R_info.CheckUser;
ConfirmUserID = R_info.ConfirmUser;
ErrMes = R_info.ErrMes;
switch (R_info.CheckResult)
{
case "0":
str += "<td><select class=\"easyui-combobox\" name='" + R_info.ID + "'><option value='1'>良好</option><option value='0' selected = 'selected'>故障</option><option value='2'>作业员调整后正常</option><option value='3'>需修理</option><option value='4'>确认修理完成</option></select></td>";
break;
case "1":
str += "<td><select class=\"easyui-combobox\" name='" + R_info.ID + "'><option value='1' selected = 'selected'>良好</option><option value='0'>故障</option><option value='2'>作业员调整后正常</option><option value='3'>需修理</option><option value='4'>确认修理完成</option></select></td>";
break;
case "2":
str += "<td><select class=\"easyui-combobox\" name='" + R_info.ID + "'><option value='1'>良好</option><option value='0'>故障</option><option value='2' selected = 'selected'>作业员调整后正常</option><option value='3'>需修理</option><option value='4'>确认修理完成</option></select></td>";
break;
case "3":
str += "<td><select class=\"easyui-combobox\" name='" + R_info.ID + "'><option value='1'>良好</option><option value='0'>故障</option><option value='2'>作业员调整后正常</option><option value='3' selected = 'selected'>需修理</option><option value='4'>确认修理完成</option></select></td>";
break;
case "4":
str += "<td><select class=\"easyui-combobox\" name='" + R_info.ID + "'><option value='1'>良好</option><option value='0'>故障</option><option value='2'>作业员调整后正常</option><option value='3'>需修理</option><option value='4' selected = 'selected'>确认修理完成</option></select></td>";
break;
}
str += "</tr>";
}
str += "<tr>";
str += "<td width='200'>异常情况描述</td>";
str += "<td><input class='easyui-textbox' id='ErrMes' value='" + ErrMes + "'/></td>";
str += "</tr>";
str += "</table>";
str += "<input id='CheckUserID' type='text' hidden='hidden' value='" + CheckUserID + "'/>";
str += "<input id='ConfirmUserID' type='text' hidden='hidden' value='" + ConfirmUserID + "'/>";
str += "<input id='InspectionContentFlag' type='text' hidden='hidden' value='1'/>";
#endregion
}
else
{
#region 新增
List<CommonlyInspectionModel> CommonlyInspectionList = new List<CommonlyInspectionModel>();
foreach (var item in list)
{
CommonlyInspectionModel dm = Tool.Mapper<CommonlyInspectionModel, tb_CommonlyInspection>(item);
dm.InspectionContent = CheckItemList.FirstOrDefault(p => p.ID.Equals(item.InspectionContentID)).CheckContent;
CommonlyInspectionList.Add(dm);
}
str = "<table border='1' width='900' cellspacing='0' cellpadding='2' id='InspectionContentTable' name='0'>";
str += "<tr>";
str += "<td width='200'>点检内容</td>";
str += "<td width='200'>检查结果</td>";
str += "</tr>";
for (int j = 0; j < CommonlyInspectionList.Count; j++)
{
str += "<tr>";
str += "<td>" + CommonlyInspectionList[j].InspectionContent + "</td>";
str += "<td><select class=\"easyui-combobox\" name='" + CommonlyInspectionList[j].ID + "'>" +
"<option value='1'>良好</option>" +
"<option value='0'>故障</option>" +
"<option value='2'>作业员调整后正常</option>" +
"<option value='3'>需修理</option>" +
"<option value='4'>确认修理完成</option>" +
"</select>" +
"</td>";
str += "</tr>";
}
str += "<tr>";
str += "<td width='200'>异常情况描述</td>";
str += "<td><input class='easyui-textbox' id='ErrMes' value=''/></td>";
str += "</tr>";
str += "</table>";
str += "<input id='InspectionContentFlag' type='text' hidden='hidden' value='0'/>";
#endregion
}
}
return str;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return "";
}
}
public string GetReportDate(string VersionID, string CheckDate)
{
try
{
string str = "";
List<String> ErrMesList = new List<String>();
BasicBLL<T_Sys_Users> dbUser = new BasicBLL<T_Sys_Users>();
BasicBLL<tb_CommonlyInspection> db = new BasicBLL<tb_CommonlyInspection>();
string jsonStr = "[]";
List<tb_CommonlyInspection> list = null;
list = db.SearchInfoByKey("IsUseing", 1).Where(p => p.VersionID.Equals(VersionID)).ToList();
if (list.Count > 0)
{
BasicBLL<tb_CheckItem> CheckItem_db = new BasicBLL<tb_CheckItem>();
var CheckItemList = CheckItem_db.SearchAllInfo().ToList();
string[] arr_id = list.Select(s => s.ID).ToArray();
BasicBLL<tb_CommonlyInspectionRecord> CommonlyInspectionRecord_db = new BasicBLL<tb_CommonlyInspectionRecord>();
DateTime StartTime = Convert.ToDateTime(CheckDate + "-01 00:00:00");
DateTime EndTime = StartTime.AddMonths(1);
int daynum = GetDays(Convert.ToInt32(CheckDate.Substring(0, 4)), Convert.ToInt32(CheckDate.Substring(5, 2)));
var _info = CommonlyInspectionRecord_db.SearchInfoByKey("IsUseing", 1).Where(p => p.CheckDate >= StartTime && p.CheckDate < EndTime && arr_id.Contains(p.CommonlyInspectionID)).ToList();
var userList = dbUser.SearchAllInfo().ToList();
if (_info.Count > 0)
{
#region 有记录
List<CommonlyInspectionModel> CommonlyInspectionList = new List<CommonlyInspectionModel>();
foreach (var item in list)
{
CommonlyInspectionModel dm = Tool.Mapper<CommonlyInspectionModel, tb_CommonlyInspection>(item);
var IC_info = CheckItemList.FirstOrDefault(p => p.ID.Equals(item.InspectionContentID));
if (IC_info != null)
{
dm.InspectionContent = IC_info.CheckContent;
dm.Standard = IC_info.Standard;
dm.Way = IC_info.Way;
dm.Cycle = IC_info.Cycle;
CommonlyInspectionList.Add(dm);
}
}
str = "<table border='1' cellspacing='0' cellpadding='5' id='InspectionContentTable' name='1' width='100%'>";
str += "<tr>";
str += "<td width='40'>序号</td>";
str += "<td width='250'>点检内容</td>";
str += "<td width='150'>点检标准</td>";
str += "<td width='150'>点检方法</td>";
str += "<td width='150'>点检周期</td>";
for (int i = 1; i <= daynum; i++)
{
str += "<td width='30'>" + i + "</td>";
}
str += "</tr>";
var info = CommonlyInspectionList.ToList();
for (int j = 0; j < info.Count; j++)
{
str += "<tr>";
str += "<td rowspan='2'>" + (j + 1).ToString() + "</td>";
str += "<td rowspan='2'>" + info[j].InspectionContent + "</td>";
str += "<td rowspan='2'>" + info[j].Standard + "</td>";
str += "<td rowspan='2'>" + info[j].Way + "</td>";
str += "<td rowspan='2'>" + info[j].Cycle + "</td>";
var R_info = _info.Where(p => p.CommonlyInspectionID == info[j].ID);
for (int k = 1; k <= daynum; k++)
{
DateTime dtime = StartTime.AddDays(k - 1);
var info_R = R_info.FirstOrDefault(p => p.CheckDate == dtime && p.CheckType.Equals("0"));
string CheckResult = "";
if (info_R != null)
{
if (!String.IsNullOrEmpty(info_R.ErrMes) && !ErrMesList.Contains(dtime.ToString("yyyy-MM-dd") + ":" + info_R.ErrMes))
{
ErrMesList.Add(dtime.ToString("yyyy-MM-dd") + ":" + info_R.ErrMes);
}
//select
switch (info_R.CheckResult)
{
case "0":
CheckResult = "▲";
break;
case "1":
CheckResult = "√";
break;
case "2":
CheckResult = "◎";
break;
case "3":
CheckResult = "X";
break;
case "4":
CheckResult = "☆";
break;
}
}
str += "<td width='30'>" + CheckResult + "</td>";
}
str += "</tr>";
str += "<tr>";
for (int k = 1; k <= daynum; k++)
{
DateTime dtime = StartTime.AddDays(k - 1);
var info_R = R_info.FirstOrDefault(p => p.CheckDate == dtime && p.CheckType.Equals("1"));
string CheckResult = "";
if (info_R != null)
{
//是否有异常记录并且没有加入到列表中
if (!String.IsNullOrEmpty(info_R.ErrMes) && !ErrMesList.Contains(dtime.ToString("yyyy-MM-dd") + ":" + info_R.ErrMes))
{
ErrMesList.Add(dtime.ToString("yyyy-MM-dd") + ":" + info_R.ErrMes);
}
switch (info_R.CheckResult)
{
case "0":
CheckResult = "▲";
break;
case "1":
CheckResult = "√";
break;
case "2":
CheckResult = "◎";
break;
case "3":
CheckResult = "X";
break;
case "4":
CheckResult = "☆";
break;
}
}
str += "<td width='30'>" + CheckResult + "</td>";
}
str += "</tr>";
}
str += "<tr>";
str += "<td rowspan='4'>日点检确认</td>";
str += "<td colspan='4'>点检人(白 班)确认签名</td>";
for (int i = 1; i <= daynum; i++)
{
DateTime dtime = StartTime.AddDays(i - 1);
var infoUser = _info.FirstOrDefault(p => p.CheckDate == dtime);
if (infoUser != null)
{
str += "<td width='30'>" + userList.FirstOrDefault(p => p.UserID.ToString().ToUpper().Equals(infoUser.CheckUser.ToUpper())).RealName + "</td>";
}
else
{
str += "<td width='30'></td>";
}
}
str += "</tr>";
str += "<tr>";
//str += "<td>日点检确认</td>";
str += "<td colspan='4'>点检人(夜 班)确认签名</td>";
for (int i = 1; i <= daynum; i++)
{
DateTime dtime = StartTime.AddDays(i - 1);
var infoUser = _info.FirstOrDefault(p => p.CheckDate == dtime);
if (infoUser != null)
{
str += "<td width='30'>" + userList.FirstOrDefault(p => p.UserID.ToString().ToUpper().Equals(infoUser.CheckUser.ToUpper())).RealName + "</td>";
}
else
{
str += "<td width='30'></td>";
}
}
str += "</tr>";
str += "<tr>";
//str += "<td>日点检确认</td>";
str += "<td colspan='4'>点检人(白班班长)确认签名</td>";
for (int i = 1; i <= daynum; i++)
{
DateTime dtime = StartTime.AddDays(i - 1);
var infoUser = _info.FirstOrDefault(p => p.CheckDate == dtime);
if (infoUser != null)
{
str += "<td width='30'>" + userList.FirstOrDefault(p => p.UserID.ToString().ToUpper().Equals(infoUser.ConfirmUser.ToUpper())).RealName + "</td>";
}
else
{
str += "<td width='30'></td>";
}
}
str += "</tr>";
str += "<tr>";
//str += "<td>日点检确认</td>";
str += "<td colspan='4'>点检人(夜班班长)确认签名</td>";
for (int i = 1; i <= daynum; i++)
{
DateTime dtime = StartTime.AddDays(i - 1);
var infoUser = _info.FirstOrDefault(p => p.CheckDate == dtime);
if (infoUser != null)
{
str += "<td width='30'>" + userList.FirstOrDefault(p => p.UserID.ToString().ToUpper().Equals(infoUser.ConfirmUser.ToUpper())).RealName + "</td>";
}
else
{
str += "<td width='30'></td>";
}
}
str += "</tr>";
str += "</table>";
if (ErrMesList.Count > 0)
{
#region 异常情况描述
str += "</table>";
str += "<table border='1' cellspacing='0' cellpadding='5' id='InspectionContentTable2' name='2' width='100%'>";
str += "<tr>";
str += "<td rowspan='" + ErrMesList.Count.ToString() + "' width='40'>异常情况描述</td>";
str += "<td>" + ErrMesList[0] + "</td>";
str += "</tr>";
for (int i = 1; i < ErrMesList.Count; i++)
{
str += "<tr>";
str += "<td>" + ErrMesList[i] + "</td>";
str += "</tr>";
}
str += "</table>";
#endregion
}
#endregion
}
else
{
#region 无记录
List<CommonlyInspectionModel> CommonlyInspectionList = new List<CommonlyInspectionModel>();
foreach (var item in list)
{
CommonlyInspectionModel dm = Tool.Mapper<CommonlyInspectionModel, tb_CommonlyInspection>(item);
var IC_info = CheckItemList.FirstOrDefault(p => p.ID.Equals(item.InspectionContentID));
if (IC_info != null)
{
dm.InspectionContent = IC_info.CheckContent;
CommonlyInspectionList.Add(dm);
}
}
str = "<table border='1' cellspacing='0' cellpadding='5' id='InspectionContentTable' name='1'>";
str += "<tr>";
str += "<td width='40'>序号</td>";
str += "<td width='250'>点检内容</td>";
for (int i = 1; i <= daynum; i++)
{
str += "<td width='30'>" + i + "</td>";
}
str += "</tr>";
var info = CommonlyInspectionList.ToList();
for (int j = 0; j < info.Count; j++)
{
str += "<tr>";
str += "<td rowspan='2'>" + (j + 1).ToString() + "</td>";
str += "<td rowspan='2'>" + info[j].InspectionContent + "</td>";
for (int k = 1; k <= daynum; k++)
{
str += "<td width='30'></td>";
}
str += "</tr>";
str += "<tr>";
for (int k = 1; k <= daynum; k++)
{
str += "<td width='30'></td>";
}
str += "</tr>";
}
#endregion
}
}
return str;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return "";
}
}
public static int GetDays(int year, int month)
{
int days = 0;
if (month != 2)
{
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days = 31;
break;
case 4:
case 6:
case 9:
case 11:
days = 30; break;
}
}
else
{
// 闰年
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
days = 29;
else
days = 28;
}
return days;
}
}
}