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.
364 lines
14 KiB
364 lines
14 KiB
using RS.DBUtility;
|
|
using RS.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace RS.SQLServerDAL
|
|
{
|
|
public class SOperateLog
|
|
{
|
|
|
|
/// <summary>
|
|
/// 查询作业日志 默认显示当天
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public DataTable SelJobLog()
|
|
{
|
|
DataTable dtResult = null;
|
|
try
|
|
{
|
|
DataTable dtJobOrderInfo = new DataTable();
|
|
StringBuilder selectString = new StringBuilder();
|
|
selectString.AppendLine("SELECT job_log_num,recipe,batch,production_id," + " ");
|
|
selectString.AppendLine("operator_num,pieces,finish_state,start_time,end_time" + " ");
|
|
selectString.AppendLine("FROM `tb_operate_job_log`" + " ");
|
|
selectString.AppendLine("WHERE pieces!=26" + " ");
|
|
selectString.AppendLine("order by id desc" + " ");
|
|
MySqlHelper sHelper = new MySqlHelper();
|
|
dtJobOrderInfo = sHelper.QuerySql(selectString.ToString());
|
|
if (dtJobOrderInfo != null)
|
|
{
|
|
if (dtJobOrderInfo.Rows.Count > 0)
|
|
{
|
|
DataView dv = dtJobOrderInfo.DefaultView;
|
|
dtResult = dv.ToTable();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.ToString();
|
|
}
|
|
return dtResult;
|
|
}
|
|
/// <summary>
|
|
/// 查询报警日志
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public DataTable SelAlarmLog()
|
|
{
|
|
DataTable dtResult = null;
|
|
try
|
|
{
|
|
DataTable dtJobOrderInfo = new DataTable();
|
|
StringBuilder selectString = new StringBuilder();
|
|
selectString.AppendLine("SELECT alarm_log_num,alarm_content,alarm_start_time,alarm_restore_time" + " ");
|
|
selectString.AppendLine("FROM `tb_operate_alarm_log`" + " ");
|
|
selectString.AppendLine("order by id desc" + " ");
|
|
MySqlHelper sHelper = new MySqlHelper();
|
|
dtJobOrderInfo = sHelper.QuerySql(selectString.ToString());
|
|
if (dtJobOrderInfo != null)
|
|
{
|
|
if (dtJobOrderInfo.Rows.Count > 0)
|
|
{
|
|
DataView dv = dtJobOrderInfo.DefaultView;
|
|
dtResult = dv.ToTable();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.ToString();
|
|
}
|
|
return dtResult;
|
|
}
|
|
/// <summary>
|
|
/// 保存报警日志
|
|
/// </summary>
|
|
/// <param name="recipeWork"></param>
|
|
/// <returns></returns>
|
|
public bool SaveAlarmLog(OperateAlarmLog operateAlarmLog)
|
|
{
|
|
bool bResult = false;
|
|
try
|
|
{
|
|
StringBuilder selectString = new StringBuilder();
|
|
selectString.AppendLine("INSERT INTO tb_operate_alarm_log" + " ");
|
|
selectString.AppendLine("(alarm_log_num,alarm_content,alarm_name,alarm_start_time,alarm_restore_time,alarm_decive_name)" + " ");
|
|
selectString.AppendLine("VALUES(" + " ");
|
|
selectString.AppendLine(" '" + operateAlarmLog.alarmLogNum + "', ");
|
|
selectString.AppendLine(" '" + operateAlarmLog.alarmContent + "', ");
|
|
selectString.AppendLine(" '" + operateAlarmLog.alarmName + "', ");
|
|
selectString.AppendLine(" '" + operateAlarmLog.alarmStartTime + "', ");
|
|
selectString.AppendLine(" '" + operateAlarmLog.alarmRestoreTime + "', ");
|
|
selectString.AppendLine(" '" + operateAlarmLog.alarmDeciveName + "'");
|
|
selectString.AppendLine(" " + ")");
|
|
MySqlHelper sHelper = new MySqlHelper();
|
|
bResult = sHelper.ExecuteBNonQuerySQL(selectString.ToString());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.ToString();
|
|
}
|
|
return bResult;
|
|
}
|
|
public bool SaveOperatorLog(OperateOperationLog operateOperationLog)
|
|
{
|
|
bool bResult = false;
|
|
try
|
|
{
|
|
StringBuilder selectString = new StringBuilder();
|
|
selectString.AppendLine("INSERT INTO tb_operate_operation_log" + " ");
|
|
selectString.AppendLine("(operation_start_time,user_group,operation_info)" + " ");
|
|
selectString.AppendLine("VALUES(" + " ");
|
|
selectString.AppendLine(" '" + operateOperationLog.operationStartTime + "', ");
|
|
selectString.AppendLine(" '" + operateOperationLog.userGroup + "', ");
|
|
selectString.AppendLine(" '" + operateOperationLog.operationInfo + "'");
|
|
selectString.AppendLine(" " + ")");
|
|
MySqlHelper sHelper = new MySqlHelper();
|
|
bResult = sHelper.ExecuteBNonQuerySQL(selectString.ToString());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.ToString();
|
|
}
|
|
return bResult;
|
|
}
|
|
public bool UpdateAlarmLog(string alarmName, string dateTime)
|
|
{
|
|
bool bResult = false;
|
|
try
|
|
{
|
|
StringBuilder selectString = new StringBuilder();
|
|
selectString.AppendLine("UPDATE `tb_operate_alarm_log`" + " ");
|
|
selectString.AppendLine("set alarm_restore_time ='" + dateTime + "' ");
|
|
selectString.AppendLine("WHERE alarm_name = '" + alarmName + "' ");
|
|
MySqlHelper sHelper = new MySqlHelper();
|
|
bResult = sHelper.ExecuteBNonQuerySQL(selectString.ToString());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.ToString();
|
|
}
|
|
return bResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询操作信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public DataTable SelOperationLog()
|
|
{
|
|
DataTable dtResult = null;
|
|
try
|
|
{
|
|
DataTable dtJobOrderInfo = new DataTable();
|
|
StringBuilder selectString = new StringBuilder();
|
|
selectString.AppendLine("SELECT user_group,operation_info,operation_start_time" + " ");
|
|
selectString.AppendLine("FROM `tb_operate_operation_log`" + " ");
|
|
selectString.AppendLine("order by id desc" + " ");
|
|
MySqlHelper sHelper = new MySqlHelper();
|
|
dtJobOrderInfo = sHelper.QuerySql(selectString.ToString());
|
|
if (dtJobOrderInfo != null)
|
|
{
|
|
if (dtJobOrderInfo.Rows.Count > 0)
|
|
{
|
|
DataView dv = dtJobOrderInfo.DefaultView;
|
|
dtResult = dv.ToTable();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.ToString();
|
|
}
|
|
return dtResult;
|
|
}
|
|
/// <summary>
|
|
/// 查询 当前报警(尚未恢复)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public DataTable SelNoResetAlarm(out int length)
|
|
{
|
|
int len = 0;
|
|
DataTable dtResult = null;
|
|
try
|
|
{
|
|
DataTable dtJobOrderInfo = new DataTable();
|
|
StringBuilder selectString = new StringBuilder();
|
|
selectString.AppendLine("SELECT alarm_log_num,alarm_name,alarm_content,alarm_start_time,alarm_restore_time" + " ");
|
|
selectString.AppendLine("FROM `tb_operate_alarm_log`" + " ");
|
|
selectString.AppendLine("WHERE alarm_start_time=alarm_restore_time" + " ");
|
|
MySqlHelper sHelper = new MySqlHelper();
|
|
dtJobOrderInfo = sHelper.QuerySql(selectString.ToString());
|
|
if (dtJobOrderInfo != null)
|
|
{
|
|
len = dtJobOrderInfo.Rows.Count;
|
|
if (dtJobOrderInfo.Rows.Count > 0)
|
|
{
|
|
DataView dv = dtJobOrderInfo.DefaultView;
|
|
dtResult = dv.ToTable();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.ToString();
|
|
}
|
|
length = len;
|
|
return dtResult;
|
|
}
|
|
/// <summary>
|
|
/// 按时间 查询作业日志
|
|
/// </summary>
|
|
/// <param name="startTime"></param>
|
|
/// <param name="endTime"></param>
|
|
/// <returns></returns>
|
|
public DataTable SelJobLogByDay(string startTime, string endTime)
|
|
{
|
|
DataTable dtResult = null;
|
|
try
|
|
{
|
|
DataTable dtJobOrderInfo = new DataTable();
|
|
StringBuilder selectString = new StringBuilder();
|
|
selectString.AppendLine("SELECT job_log_num,recipe,batch,production_id," + " ");
|
|
selectString.AppendLine("operator_num,pieces,finish_state,start_time,end_time" + " ");
|
|
selectString.AppendLine("FROM `tb_operate_job_log`" + " ");
|
|
selectString.AppendLine("WHERE start_time>='" + startTime + "'" + " ");
|
|
selectString.AppendLine("AND start_time<='" + endTime + "'" + " ");
|
|
MySqlHelper sHelper = new MySqlHelper();
|
|
dtJobOrderInfo = sHelper.QuerySql(selectString.ToString());
|
|
if (dtJobOrderInfo != null)
|
|
{
|
|
if (dtJobOrderInfo.Rows.Count > 0)
|
|
{
|
|
DataView dv = dtJobOrderInfo.DefaultView;
|
|
dtResult = dv.ToTable();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.ToString();
|
|
}
|
|
return dtResult;
|
|
}
|
|
/// <summary>
|
|
/// 按时间 查询报警日志
|
|
/// </summary>
|
|
/// <param name="startTime"></param>
|
|
/// <param name="endTime"></param>
|
|
/// <returns></returns>
|
|
public DataTable SelAlarmLogByDay(string startTime, string endTime)
|
|
{
|
|
DataTable dtResult = null;
|
|
try
|
|
{
|
|
DataTable dtJobOrderInfo = new DataTable();
|
|
StringBuilder selectString = new StringBuilder();
|
|
selectString.AppendLine("SELECT alarm_log_num,alarm_content,alarm_start_time,alarm_restore_time" + " ");
|
|
selectString.AppendLine("FROM `tb_operate_alarm_log`" + " ");
|
|
selectString.AppendLine("WHERE alarm_start_time>='" + startTime + "'" + " ");
|
|
selectString.AppendLine("AND alarm_start_time<='" + endTime + "'" + " ");
|
|
MySqlHelper sHelper = new MySqlHelper();
|
|
dtJobOrderInfo = sHelper.QuerySql(selectString.ToString());
|
|
if (dtJobOrderInfo != null)
|
|
{
|
|
if (dtJobOrderInfo.Rows.Count > 0)
|
|
{
|
|
DataView dv = dtJobOrderInfo.DefaultView;
|
|
dtResult = dv.ToTable();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.ToString();
|
|
}
|
|
return dtResult;
|
|
}
|
|
/// <summary>
|
|
/// 按时间 查询操作日志
|
|
/// </summary>
|
|
/// <param name="startTime"></param>
|
|
/// <param name="endTime"></param>
|
|
/// <returns></returns>
|
|
public DataTable ControlsLogByDay(string startTime, string endTime)
|
|
{
|
|
DataTable dtResult = null;
|
|
try
|
|
{
|
|
try
|
|
{
|
|
DataTable dtJobOrderInfo = new DataTable();
|
|
StringBuilder selectString = new StringBuilder();
|
|
selectString.AppendLine("SELECT * FROM tb_operate_operation_log" + " ");
|
|
selectString.AppendLine("WHERE operation_start_time>='" + startTime + "'" + " ");
|
|
selectString.AppendLine("and operation_start_time<='" + endTime + "'" + " ");
|
|
MySqlHelper sHelper = new MySqlHelper();
|
|
dtJobOrderInfo = sHelper.QuerySql(selectString.ToString());
|
|
if (dtJobOrderInfo != null)
|
|
{
|
|
if (dtJobOrderInfo.Rows.Count > 0)
|
|
{
|
|
DataView dv = dtJobOrderInfo.DefaultView;
|
|
dtResult = dv.ToTable();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.ToString();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.ToString();
|
|
}
|
|
return dtResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除90天前的日志
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool DeleteLog()
|
|
{
|
|
bool bResult1 = false;
|
|
bool bResult2 = false;
|
|
bool bResult3 = false;
|
|
MySqlHelper sHelper = new MySqlHelper();
|
|
try
|
|
{
|
|
{
|
|
StringBuilder selectString = new StringBuilder();
|
|
selectString.AppendLine("DELETE FROM `tb_operate_alarm_log`" + " ");
|
|
selectString.AppendLine("WHERE alarm_start_time<'" + DateTime.Now.AddDays(-90) + "'" + " ");
|
|
bResult1 = sHelper.ExecuteBNonQuerySQL(selectString.ToString());
|
|
}
|
|
{
|
|
StringBuilder selectString = new StringBuilder();
|
|
selectString.AppendLine("DELETE FROM `tb_operate_job_log`" + " ");
|
|
selectString.AppendLine("WHERE start_time<'" + DateTime.Now.AddDays(-90) + "'" + " ");
|
|
bResult2 = sHelper.ExecuteBNonQuerySQL(selectString.ToString());
|
|
}
|
|
{
|
|
StringBuilder selectString = new StringBuilder();
|
|
selectString.AppendLine("DELETE FROM `tb_operate_operation_log`" + " ");
|
|
selectString.AppendLine("WHERE operation_start_time<'" + DateTime.Now.AddDays(-90) + "'" + " ");
|
|
bResult3 = sHelper.ExecuteBNonQuerySQL(selectString.ToString());
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.ToString();
|
|
}
|
|
return bResult1 & bResult2 & bResult3;
|
|
}
|
|
}
|
|
}
|