一厂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.

414 lines
17 KiB

3 months ago
using DBUtility;
using PaintingScreen.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Web;
namespace PaintingScreen.Handler
{
public class FiveScreenFunction
{
public static FiveScreenModel getFiveScreenModel(string reportName, string type)
{
string sql_month = GetMonthStr();
string sql_date = GetDateStr();
FiveScreenModel model = new FiveScreenModel();
List<string> data1 = new List<string>(); //原值
List<string> data2 = new List<string>(); //基准值
List<string> data3 = new List<string>(); //置空之后的值
model.data1 = data1;
model.data2 = data2;
model.data3 = data3;
try
{
if (type == "月报")
{
// string sql = @"
// SELECT TOP 1
// [LastYear]
// ,[Jan]
// ,[Feb]
// ,[Mar]
// ,[Apr]
// ,[May]
// ,[Jun]
// ,[Jul]
// ,[Aug]
// ,[Sept]
// ,[Oct]
// ,[Nov]
// ,[Dec]
// FROM tb_Report_FiveScreen
// WHERE Name = '" + reportName + @"'
// ORDER BY CreateTime DESC
// ";
string sql = @"
SELECT TOP 1
" + sql_month + @"
FROM tb_Report_FiveScreen
WHERE Name like '" + reportName + @"%'
ORDER BY CreateTime DESC
";
DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
if (dt != null && dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Columns.Count; i++)
{
string res = dt.Rows[0][i].ToString().Trim();
string resKong = CompareMinValue(res, reportName);
if (res.Length > 4)
{
res = res.Remove(res.IndexOf('.'));
}
if (resKong.Length > 4)
{
resKong = resKong.Remove(resKong.IndexOf('.'));
}
data1.Add(res);
data3.Add(resKong);
}
}
// string sql2 = @"
// SELECT TOP 1
// [LastYear]
// ,[Jan]
// ,[Feb]
// ,[Mar]
// ,[Apr]
// ,[May]
// ,[Jun]
// ,[Jul]
// ,[Aug]
// ,[Sept]
// ,[Oct]
// ,[Nov]
// ,[Dec]
// ,[CreateTime]
// FROM tb_Report_FiveScreenStandard
// WHERE Name = '" + reportName + @"'
// ORDER BY CreateTime DESC
// ";
string sql2 = @"
SELECT TOP 1
" + sql_month + @"
FROM tb_Report_FiveScreenStandard
WHERE Name like '" + reportName + @"%'
ORDER BY CreateTime DESC
";
DataTable dt2 = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql2, null);
if (dt2 != null && dt2.Rows.Count > 0)
{
for (int i = 0; i < dt2.Columns.Count; i++)
{
string res = dt2.Rows[0][i].ToString().Trim();
if (res.Length > 4)
{
res = res.Remove(res.IndexOf('.'));
}
data2.Add(res);
}
}
model.data1 = data1;
model.data2 = data2;
model.data3 = data3;
}
else if (type == "日报")
{
// string sql = @"
// SELECT TOP 1
// [day1]
// ,[day2]
// ,[day3]
// ,[day4]
// ,[day5]
// ,[day6]
// ,[day7]
// ,[day8]
// ,[day9]
// ,[day10]
// ,[day11]
// ,[day12]
// ,[day13]
// ,[day14]
// ,[day15]
// ,[day16]
// ,[day17]
// ,[day18]
// ,[day19]
// ,[day20]
// ,[day21]
// ,[day22]
// ,[day23]
// ,[day24]
// ,[day25]
// ,[day26]
// ,[day27]
// ,[day28]
// ,[day29]
// ,[day30]
// ,[day31]
// FROM tb_Report_FiveScreen
// WHERE Name = '" + reportName + @"'
// ORDER BY CreateTime DESC
// ";
string sql = @"
SELECT TOP 1
" + sql_date + @"
FROM tb_Report_FiveScreen
WHERE Name like '" + reportName + @"%'
ORDER BY CreateTime DESC
";
DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
if (dt != null && dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Columns.Count; i++)
{
string res = dt.Rows[0][i].ToString().Trim();
string resKong = CompareMinValue(res, reportName);
if (res.Length > 4)
{
res = res.Remove(res.IndexOf('.'));
}
if (resKong.Length > 4)
{
resKong = resKong.Remove(resKong.IndexOf('.'));
}
data1.Add(res);
data3.Add(resKong);
}
}
#region 根据当前的月份,取数据库的列
string columnName = "";
string month = DateTime.Now.Month.ToString();
switch (month)
{
case "1":
columnName = "Jan";
break;
case "2":
columnName = "Feb";
break;
case "3":
columnName = "Mar";
break;
case "4":
columnName = "Apr";
break;
case "5":
columnName = "May";
break;
case "6":
columnName = "Jun";
break;
case "7":
columnName = "Jul";
break;
case "8":
columnName = "Aug";
break;
case "9":
columnName = "Sept";
break;
case "10":
columnName = "Oct";
break;
case "11":
columnName = "Nov";
break;
case "12":
columnName = "Dec";
break;
}
#endregion
string sql2 = @"
SELECT TOP 1
"+ columnName +@"
FROM tb_Report_FiveScreenStandard
WHERE Name like '" + reportName + @"%'
ORDER BY CreateTime DESC
";
DataTable dt2 = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql2, null);
if (dt2 != null && dt2.Rows.Count > 0)
{
for (int i = 0; i < 31; i++)
{
string res = dt2.Rows[0][0].ToString().Trim();
if (res.Length > 4)
{
res = res.Remove(res.IndexOf('.'));
}
data2.Add(res);
}
}
model.data1 = data1;
model.data2 = data2;
model.data3 = data3;
}
return model;
}
catch (Exception ex)
{
LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
return model;
}
}
public static string GetMonthStr()
{
string res = "";
try
{
string[] monthString = {"","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec"};
int now_month = DateTime.Now.Month;
List<string> small = new List<string>();
List<string> big = new List<string>();
for (int i = 1; i <= 12; i++)
{
if (i <= now_month)
{
small.Add(monthString[i]);
}
else
{
big.Add(monthString[i]);
}
}
big.AddRange(small);
foreach (string str in big)
{
res += str + ",";
}
res = res.Remove(res.Length - 1);
return res;
}
catch (Exception ex)
{
LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
return res;
}
}
public static string GetDateStr()
{
string res = "";
try
{
string[] dateString = { "", "day1", "day2", "day3", "day4", "day5", "day6", "day7", "day8", "day9", "day10"
, "day11", "day12", "day13", "day14", "day15", "day16", "day17", "day18", "day19"
, "day20", "day21", "day22", "day23", "day24", "day25", "day26", "day27", "day28", "day29", "day30", "day31" };
int now_date = DateTime.Now.Day;
List<string> small = new List<string>();
List<string> big = new List<string>();
for (int i = 1; i <= 31; i++)
{
if (i <= now_date)
{
small.Add(dateString[i]);
}
else
{
big.Add(dateString[i]);
}
}
big.AddRange(small);
foreach (string str in big)
{
res += str + ",";
}
res = res.Remove(res.Length - 1);
return res;
}
catch (Exception ex)
{
LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
return res;
}
}
public static string CompareMinValue(string num, string reportName)
{
string res = num;
double number = 0;
double.TryParse(num, out number);
if (reportName.Contains("注塑合格率"))
{
reportName = "注塑合格率";
}
else if (reportName.Contains("注塑设备利用率"))
{
reportName = "注塑设备利用率";
}
else if (reportName.Contains("喷涂设备利用率"))
{
reportName = "喷涂设备利用率";
}
else if (reportName.Contains("运行滑撬数"))
{
reportName = "运行滑撬数";
}
else if (reportName.Contains("喷涂入库套数"))
{
reportName = "喷涂入库套数";
}
else if (reportName.Contains("喷涂一次合格率"))
{
reportName = "喷涂一次合格率";
}
else if (reportName.Contains("喷涂总合格率"))
{
reportName = "喷涂总合格率";
}
switch (reportName)
{
case "注塑合格率":
if (number < 90)
res = "";
break;
case "注塑设备利用率":
if (number < 90)
res = "";
break;
case "喷涂设备利用率":
if (number < 80)
res = "";
break;
case "运行滑撬数":
if (number < 1200)
res = "";
break;
case "喷涂入库套数":
if (number < 2600)
res = "";
break;
case "喷涂一次合格率":
if (number < 50)
res = "";
break;
case "喷涂总合格率":
if (number < 80)
res = "";
break;
}
return res;
}
}
}