You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Report/LjLogControl.cs

158 lines
5.3 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Mesnac.Action.ChemicalWeighing.FreeDb;
using Mesnac.Action.ChemicalWeighing.LjMaterial;
using Mesnac.Action.ChemicalWeighing.Report.Entity;
using Mesnac.Action.ChemicalWeighing.Util;
using Mesnac.Basic;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mesnac.Action.ChemicalWeighing.Report
{
/// <summary>
/// 配料日志
/// </summary>
public class LjLogControl
{
/// <summary>
/// 通过内容查询日志
/// </summary>
/// <param name="txt">查询关键字</param>
public static DataTable ManualLogSelect(string txt)
{
string sql;
if (!string.IsNullOrEmpty(txt))
{
sql = BaseSelect($"where logtext like '%{txt}%'");
}
else
{
sql = BaseSelect("");
}
return DBHelp.GetTable(sql);
}
/// <summary>
/// 通过内容和机台号查询日志
/// </summary>
/// <param name="txt">查询关键字</param>
public static DataTable ManualLogSelect(string txt, int deviceNo)
{
string sql;
if (deviceNo == 0)
{
return ManualLogSelect(txt);
}
else
{
sql = BaseSelect($"where deviceNo = {deviceNo} and logtext like '%{txt}%'");
return DBHelp.GetTable(sql);
}
}
/// <summary>
/// 通过时间查询日志
/// </summary>
/// <param name="txt">查询关键字</param>
public static DataTable ManualLogSelect(string startTime, string endTime)
{
string sql = BaseSelect($"where logtime BETWEEN '{startTime}' AND '{endTime}'");
return DBHelp.GetTable(sql);
}
/// <summary>
/// 去年数据的转移
/// </summary>
public static void LastYearDataCut()
{
int nowYear = DateTime.Now.Year;
string sql = $"insert into Manual_Log_{nowYear - 1} " +
$"select logtext, logtime, userid, value, valuekind, deviceno, devicekind, createdate " +
$"from Manual_Log where logtime < '{nowYear}-01-01 00:00:00'";
DBHelp.ExecuteNonQuery(sql);
sql = $"delete from Manual_Log where logtime < '{nowYear}-01-01 00:00:00'";
DBHelp.ExecuteNonQuery(sql);
}
private static string BaseSelect(string sql)
{
string s = "select top 500 id, logtext, logtime, value, deviceno from Manual_Log " + sql +
" order by id desc";
return s;
}
/// <summary>
/// 完整手动日志插入
/// </summary>
/// <param name="logName">日志内容</param>
/// <param name="value">值</param>
/// <param name="valuekind">值类型 0无 1水称设定值 2水称称量值 3螺旋设定值 4螺旋称量值</param>
/// <param name="deviceno">设备编号</param>
/// <param name="devicekind">设备类型 0无 1水称 2螺旋湿混 3糊化 4干混</param>
public static void ManualLogControl(string logName, int value, int valuekind, int deviceno, int devicekind)
{
var Log = new LjLogEntity()
{
logtext = logName,
logtime = DateTime.Now,
userid = UserJudge.IsEdit() ? "Edit" : UserInfo.Instance.UserName,
value = value,
deviceno = deviceno,
devicekind = devicekind,
valuekind = valuekind,
createdate = DateTime.Now.ToString("yyyyMMdd")
};
FreeSqlUnit.Instance.Insert(Log).ExecuteIdentity();
}
/// <summary>
/// 无数值 有设备 日志记录
/// </summary>
/// <param name="logName">日志内容</param>
/// <param name="deviceno">设备编号</param>
/// <param name="devicekind">设备类型</param>
public static void ManualLogControl(string logName, int deviceno, int devicekind)
{
var Log = new LjLogEntity()
{
logtext = logName,
logtime = DateTime.Now,
userid = UserJudge.IsEdit() ? "Edit" : UserInfo.Instance.UserName,
value = 0,
deviceno = deviceno,
devicekind = devicekind,
valuekind = 0,
createdate = DateTime.Now.ToString("yyyyMMdd")
};
FreeSqlUnit.Instance.Insert(Log).ExecuteIdentity();
}
/// <summary>
/// 无数值 无设备 日志记录
/// </summary>
/// <param name="logName"></param>
public static void ManualLogControl(string logName)
{
var Log = new LjLogEntity()
{
logtext = logName,
logtime = DateTime.Now,
userid = UserJudge.IsEdit() ? "Edit" : UserInfo.Instance.UserName,
value = 0,
deviceno = 0,
devicekind = 0,
valuekind = 0,
createdate = DateTime.Now.ToString("yyyyMMdd")
};
FreeSqlUnit.Instance.Insert(Log).ExecuteIdentity();
}
}
}