|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using ICSharpCode.Core;
|
|
|
|
|
using Mesnac.Codd.Session;
|
|
|
|
|
using Mesnac.Action.ChemicalWeighing.Entity;
|
|
|
|
|
using DevExpress.Office.Utils;
|
|
|
|
|
using Mesnac.Action.ChemicalWeighing.Entity.PptPlan;
|
|
|
|
|
|
|
|
|
|
namespace Mesnac.Action.ChemicalWeighing.Alarm
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 报警管理辅助类
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class AlarmHelper
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#region 报警参数
|
|
|
|
|
|
|
|
|
|
#region 判断报警代码是否存在
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 判断报警代码是否存在
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="alarmPLC">要判断的报警PLC</param>
|
|
|
|
|
/// <param name="alarmcode">要判断的报警代码</param>
|
|
|
|
|
/// <returns>如果存在返回true,否则返回false</returns>
|
|
|
|
|
public static bool IsExistsAlarmCode(string alarmcode)
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
string sqlstr = "select count(Alarm_ID) from Pmt_Alarm where Alarm_ID = @AlarmCode";
|
|
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
dbHelper.AddParameter("@AlarmCode", alarmcode);
|
|
|
|
|
object result = dbHelper.ToScalar();
|
|
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
|
|
{
|
|
|
|
|
int intResult = 0;
|
|
|
|
|
if (int.TryParse(result.ToString(), out intResult))
|
|
|
|
|
{
|
|
|
|
|
if (intResult > 0)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 判断报警名称是否存在
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 判断报警名称是否存在
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="alarmPLC">要判断的报警PLC</param>
|
|
|
|
|
/// <param name="alarmName">要判断的报警名称</param>
|
|
|
|
|
/// <returns>如果存在返回true,否则返回false</returns>
|
|
|
|
|
public static bool IsExistsAlarmName(string alarmPLC, string alarmName)
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
string sqlstr = "select count(Alarm_ID) from Pmt_Alarm where Alarm_PLC = @AlarmPLC and Alarm_Cn_Info = @AlarmName";
|
|
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
dbHelper.AddParameter("@AlarmPLC", alarmPLC);
|
|
|
|
|
dbHelper.AddParameter("@AlarmName", alarmName);
|
|
|
|
|
object result = dbHelper.ToScalar();
|
|
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
|
|
{
|
|
|
|
|
int intResult = 0;
|
|
|
|
|
if (int.TryParse(result.ToString(), out intResult))
|
|
|
|
|
{
|
|
|
|
|
if (intResult > 0)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 判断报警数据块是否存在
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 判断报警数据块是否存在
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="alarmblock">要判断的报警数据块</param>
|
|
|
|
|
/// <returns>如果存在返回true,否则返回false</returns>
|
|
|
|
|
public static bool IsExistsAlarmBlock(string alarmblock)
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
string sqlstr = "select count(Alarm_ID) from Pmt_Alarm where Alarm_Block = @AlarmBlock";
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
|
|
dbHelper.AddParameter("@AlarmBlock", alarmblock);
|
|
|
|
|
object result = dbHelper.ToScalar();
|
|
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
|
|
{
|
|
|
|
|
int intResult = 0;
|
|
|
|
|
if (int.TryParse(result.ToString(), out intResult))
|
|
|
|
|
{
|
|
|
|
|
if (intResult > 0)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 判断对应的报警地址和位是否存在
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 判断对应的报警地址和位是否存在
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="alarmAddress">报警地址</param>
|
|
|
|
|
/// <param name="alarmBit">报警位</param>
|
|
|
|
|
/// <returns>存在返回true,否则返回false</returns>
|
|
|
|
|
public static bool IsExistsAlarmAddressAndBit(string alarmAddress, string alarmBit)
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
string sqlstr = "select count(Alarm_ID) from Pmt_Alarm where Alarm_Alias = @Alarm_Alias";
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
|
|
dbHelper.AddParameter("@AlarmAddress", alarmAddress);
|
|
|
|
|
dbHelper.AddParameter("@AlarmBit", alarmBit);
|
|
|
|
|
object result = dbHelper.ToScalar();
|
|
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
|
|
{
|
|
|
|
|
int intResult = 0;
|
|
|
|
|
if (int.TryParse(result.ToString(), out intResult))
|
|
|
|
|
{
|
|
|
|
|
if (intResult > 0)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 判断对应的报警参数是否存在
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 判断对应的报警参数是否存在
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="alarmPLC">报警PLC</param>
|
|
|
|
|
/// <param name="alarmBlock">报警地址块</param>
|
|
|
|
|
/// <param name="alarmAddress">报警地址字</param>
|
|
|
|
|
/// <param name="alarmBit">报警地址位</param>
|
|
|
|
|
/// <returns>存在返回true,不存在返回false</returns>
|
|
|
|
|
public static bool IsExists(int ID,string alarmPLC, string alarmBlock, string alarm_Alias)
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
string sqlstr = "select count(ID) from Pmt_Alarm where ID<>@ID and Alarm_PLC = @AlarmPLC and Alarm_Block = @AlarmBlock and Alarm_Alias = @Alarm_Alias";
|
|
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
dbHelper.AddParameter("@ID", ID);
|
|
|
|
|
dbHelper.AddParameter("@AlarmPLC", alarmPLC);
|
|
|
|
|
dbHelper.AddParameter("@AlarmBlock", alarmBlock);
|
|
|
|
|
dbHelper.AddParameter("@Alarm_Alias", alarm_Alias);
|
|
|
|
|
object result = dbHelper.ToScalar();
|
|
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
|
|
{
|
|
|
|
|
int intResult = 0;
|
|
|
|
|
if (int.TryParse(result.ToString(), out intResult))
|
|
|
|
|
{
|
|
|
|
|
if (intResult > 0)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 根据报警参数数据块、报警参数地址字和报警参数数据位查询报警参数
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据报警参数数据块、报警参数地址字和报警参数数据位查询报警参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="alarmBlock">报警参数PLC</param>
|
|
|
|
|
/// <param name="alarmBlock">报警参数数据块</param>
|
|
|
|
|
/// <param name="alarmAddress">报警参数地址字</param>
|
|
|
|
|
/// <param name="alarmBit">报警参数位</param>
|
|
|
|
|
/// <returns>返回对应的报警参数数据行</returns>
|
|
|
|
|
public static DataRow GetAlarmInfoDataRow(string alarmPLC, string alarmBlock, int Alarm_Alias)
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
string sqlstr = "select * from Pmt_Alarm where Alarm_PLC = @AlarmPLC and Alarm_Alias = @Alarm_Alias";
|
|
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
dbHelper.AddParameter("@AlarmPLC", alarmPLC);
|
|
|
|
|
dbHelper.AddParameter("@AlarmBlock", alarmBlock);
|
|
|
|
|
dbHelper.AddParameter("@Alarm_Alias", Alarm_Alias);
|
|
|
|
|
DataTable dt = dbHelper.ToDataTable();
|
|
|
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
return dt.Rows[0];
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据报警参数数据块、报警参数地址字和报警参数数据位查询报警参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="alarmPLC">报警参数PLC</param>
|
|
|
|
|
/// <param name="alarmBlock">报警参数数据块</param>
|
|
|
|
|
/// <param name="alarmAddress">报警参数地址字</param>
|
|
|
|
|
/// <param name="alarmBit">报警参数位</param>
|
|
|
|
|
/// <returns>返回对应的报警参数实体</returns>
|
|
|
|
|
public static Entity.PmtAlarmInfo GetAlarmInfoEntity(string alarmPLC, string alarmBlock, int Alarm_Alias)
|
|
|
|
|
{
|
|
|
|
|
DataRow dr = GetAlarmInfoDataRow(alarmPLC, alarmBlock, Alarm_Alias);
|
|
|
|
|
Entity.PmtAlarmInfo entity = ConvertDataRowToPmtAlarmInfo(dr);
|
|
|
|
|
return entity;
|
|
|
|
|
}
|
|
|
|
|
public static Entity.PmtAlarmInfo GetAlarmInfoEntity(string ID)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
string sqlstr = "select * from Pmt_Alarm where ID = @ID";
|
|
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
dbHelper.AddParameter("@ID", ID);
|
|
|
|
|
DataTable dt = dbHelper.ToDataTable();
|
|
|
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
return ConvertDataRowToPmtAlarmInfo(dt.Rows[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 查询所有报警参数
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询所有报警参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>返回报警参数数据表</returns>
|
|
|
|
|
public static DataTable GetPmtAlarmInfoTable()
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
string sqlstr = "select * from Pmt_Alarm order by Alarm_PLC, Alarm_Block, Alarm_Alias";
|
|
|
|
|
DataTable dt = dbHelper.GetDataTableBySql(sqlstr);
|
|
|
|
|
return dt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询所有报警参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>返回报警参数实体类列表</returns>
|
|
|
|
|
public static List<Entity.PmtAlarmInfo> GetPmtAlarmInfoList()
|
|
|
|
|
{
|
|
|
|
|
List<Entity.PmtAlarmInfo> lst = new List<Entity.PmtAlarmInfo>();
|
|
|
|
|
DataTable dt = GetPmtAlarmInfoTable();
|
|
|
|
|
if (dt != null)
|
|
|
|
|
{
|
|
|
|
|
foreach(DataRow dr in dt.Rows)
|
|
|
|
|
{
|
|
|
|
|
Entity.PmtAlarmInfo entity = ConvertDataRowToPmtAlarmInfo(dr);
|
|
|
|
|
lst.Add(entity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return lst;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 分类查询
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分类查询
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>返回分类查询数据表</returns>
|
|
|
|
|
public static DataTable GetBlockStartLengthTable()
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
string sqlstr = "select Alarm_PLC, Alarm_Block, MIN(Alarm_Word) as Start, (MAX(Alarm_Word) - MIN(Alarm_Word) + 1) as Length from Pmt_Alarm group by Alarm_PLC, Alarm_Block";
|
|
|
|
|
DataTable dt = dbHelper.GetDataTableBySql(sqlstr);
|
|
|
|
|
return dt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分类查询
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>返回分类查询实体列表</returns>
|
|
|
|
|
public static List<Entity.AlarmInfo> GetBlockStartLengthList()
|
|
|
|
|
{
|
|
|
|
|
List<Entity.AlarmInfo> list = new List<AlarmInfo>();
|
|
|
|
|
DataTable dt = GetBlockStartLengthTable();
|
|
|
|
|
if (dt != null)
|
|
|
|
|
{
|
|
|
|
|
foreach(DataRow dr in dt.Rows)
|
|
|
|
|
{
|
|
|
|
|
Entity.AlarmInfo entity = ConvertDataRowToAlarmInfo(dr);
|
|
|
|
|
list.Add(entity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 把数据行转换为报警参数实体对象
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 把数据行转换为报警参数实体对象
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dr">报警参数数据行</param>
|
|
|
|
|
/// <returns>返回对应的报警参数实体对象</returns>
|
|
|
|
|
public static Entity.PmtAlarmInfo ConvertDataRowToPmtAlarmInfo(DataRow dr)
|
|
|
|
|
{
|
|
|
|
|
if (dr != null)
|
|
|
|
|
{
|
|
|
|
|
Entity.PmtAlarmInfo entity = new Entity.PmtAlarmInfo();
|
|
|
|
|
entity.ID = Mesnac.Basic.DataProcessor.RowValue(dr, "ID", 0);
|
|
|
|
|
entity.Equip_Code = Mesnac.Basic.DataProcessor.RowValue(dr, "Equip_Code", String.Empty);
|
|
|
|
|
entity.Alarm_ID = Mesnac.Basic.DataProcessor.RowValue(dr, "Alarm_ID", 0);
|
|
|
|
|
entity.AlarmPLC = Mesnac.Basic.DataProcessor.RowValue(dr, "Alarm_PLC", String.Empty);
|
|
|
|
|
entity.AlarmBlock = Mesnac.Basic.DataProcessor.RowValue(dr, "Alarm_Block", String.Empty);
|
|
|
|
|
entity.AlarmAlias = Mesnac.Basic.DataProcessor.RowValue(dr, "Alarm_Alias", String.Empty);
|
|
|
|
|
entity.Alarm_Cn_Info = Mesnac.Basic.DataProcessor.RowValue(dr, "Alarm_Cn_Info", String.Empty);
|
|
|
|
|
|
|
|
|
|
return entity;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 把数据行转换为报警参数扩展实体对象
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dr">数据行</param>
|
|
|
|
|
/// <returns>返回对应的报警参数实体对象</returns>
|
|
|
|
|
public static Entity.AlarmInfo ConvertDataRowToAlarmInfo(DataRow dr)
|
|
|
|
|
{
|
|
|
|
|
if (dr != null)
|
|
|
|
|
{
|
|
|
|
|
Entity.AlarmInfo entity = new AlarmInfo();
|
|
|
|
|
entity.AlarmPLC = Mesnac.Basic.DataProcessor.RowValue(dr, "Alarm_PLC", String.Empty);
|
|
|
|
|
entity.AlarmBlock = Mesnac.Basic.DataProcessor.RowValue(dr, "Alarm_Block", String.Empty);
|
|
|
|
|
entity.Start = Mesnac.Basic.DataProcessor.RowValue(dr, "Start", 0);
|
|
|
|
|
entity.Length = Mesnac.Basic.DataProcessor.RowValue(dr, "Length", 0);
|
|
|
|
|
return entity;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 报警记录
|
|
|
|
|
|
|
|
|
|
#region 查询报警记录
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询报警记录
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="alarmData">报警记录实体数据</param>
|
|
|
|
|
public static DataTable QueryAlarmLogData()
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
string sqlstr = @"select * from LR_Alarmlog where Alarm_Status=1";
|
|
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
DataTable table = dbHelper.ToDataTable();
|
|
|
|
|
if (table != null && table.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
return table;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询报警记录
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="alarmData">报警记录实体数据</param>
|
|
|
|
|
public static List<SimpleAlarmInfo> QueryAlarmLog()
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
List<SimpleAlarmInfo> list = new List<SimpleAlarmInfo>();
|
|
|
|
|
|
|
|
|
|
string sqlstr = @"select a.Alarm_PLC,a.Alarm_Block,a.Alarm_Alias,a.Alarm_Cn_Info,l.Alarm_OccurTime from Pmt_Alarm a inner join LR_Alarmlog l on a.Alarm_ID=l.Alarm_ID where Alarm_Status=1";
|
|
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
DataTable table = dbHelper.ToDataTable();
|
|
|
|
|
if (table != null && table.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
SimpleAlarmInfo entity = new SimpleAlarmInfo();
|
|
|
|
|
foreach (DataRow row in table.Rows)
|
|
|
|
|
{
|
|
|
|
|
entity = ConvertDataRowToAlarm(row);
|
|
|
|
|
list.Add(entity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static DataTable QueryAlarmLogDataTable()
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string sqlstr = @"select ROW_NUMBER() over(order by a.Alarm_ID) Alarm_ID,a.Alarm_PLC,a.Alarm_Block,a.Alarm_Alias,a.Alarm_Cn_Info,l.Alarm_OccurTime from Pmt_Alarm a inner join LR_Alarmlog l on a.Alarm_ID=l.Alarm_ID where Alarm_Status=1";
|
|
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
DataTable table = dbHelper.ToDataTable();
|
|
|
|
|
if (table != null && table.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
return table;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
public static bool IsExist(int ID)
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
SimpleAlarmInfo entity = new SimpleAlarmInfo();
|
|
|
|
|
|
|
|
|
|
string sqlstr = @"select a.Alarm_PLC,a.Alarm_Block,a.Alarm_Alias,a.Alarm_Cn_Info,l.Alarm_OccurTime from Pmt_Alarm a inner join LR_Alarmlog l on a.Alarm_ID=l.Alarm_ID where a.Alarm_ID=@ID";
|
|
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
dbHelper.AddParameter("@ID", ID);
|
|
|
|
|
DataTable table = dbHelper.ToDataTable();
|
|
|
|
|
if (table != null && table.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
foreach (DataRow row in table.Rows)
|
|
|
|
|
{
|
|
|
|
|
entity = ConvertDataRowToAlarm(row);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
private static SimpleAlarmInfo ConvertDataRowToAlarm(DataRow dr)
|
|
|
|
|
{
|
|
|
|
|
if (dr != null)
|
|
|
|
|
{
|
|
|
|
|
SimpleAlarmInfo alarm = new SimpleAlarmInfo();
|
|
|
|
|
|
|
|
|
|
alarm.Alarm_ID = Mesnac.Basic.DataProcessor.RowValue(dr, "Alarm_ID",0);
|
|
|
|
|
alarm.AlramPLC = Mesnac.Basic.DataProcessor.RowValue(dr, "Alarm_PLC", String.Empty);
|
|
|
|
|
alarm.AlarmBlock = Mesnac.Basic.DataProcessor.RowValue(dr, "Alarm_Block", String.Empty);
|
|
|
|
|
alarm.Alarm_Alias = Mesnac.Basic.DataProcessor.RowValue(dr, "Alarm_Alias", String.Empty);
|
|
|
|
|
alarm.Alarm_Cn = Mesnac.Basic.DataProcessor.RowValue(dr, "Alarm_Cn_Info", String.Empty);
|
|
|
|
|
|
|
|
|
|
return alarm;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 添加报警记录
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加报警记录
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="alarmData">报警记录实体数据</param>
|
|
|
|
|
public static void InsertAlarmLogData(Entity.LR_Alarmlog alarmData)
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
string sqlstr = @"insert into LR_Alarmlog(Equip_Code,Alarm_ID,Alarm_OccurTime,Alarm_ClearTime,Alarm_Status,Alarm_GUID)
|
|
|
|
|
values(@Equip_Code,@Alarm_ID,@Alarm_OccurTime,@Alarm_ClearTime,@Alarm_Status,@Alarm_GUID)";
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
|
|
dbHelper.AddParameter("@Equip_Code", alarmData.Equip_Code);
|
|
|
|
|
dbHelper.AddParameter("@Alarm_ID", alarmData.Alarm_ID);
|
|
|
|
|
dbHelper.AddParameter("@Alarm_OccurTime", alarmData.Alarm_OccurTime);
|
|
|
|
|
dbHelper.AddParameter("@Alarm_ClearTime", alarmData.Alarm_ClearTime);
|
|
|
|
|
dbHelper.AddParameter("@Alarm_Status", alarmData.Alarm_Status);
|
|
|
|
|
dbHelper.AddParameter("@Alarm_GUID", alarmData.Alarm_GUID);
|
|
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 更新报警记录
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新报警记录
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="alarmID">报警记录ID</param>
|
|
|
|
|
/// <param name="clearTime">报警清除时间</param>
|
|
|
|
|
public static void UpdateAlarmLogData(int alarmID,string clearTime)
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
string sqlstr = @"update LR_Alarmlog set Alarm_Status = 0,Alarm_ClearTime = @Alarm_ClearTime where ID = @Alarm_ID";
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
|
|
dbHelper.AddParameter("@Alarm_ID", alarmID);
|
|
|
|
|
dbHelper.AddParameter("@Alarm_ClearTime", clearTime);
|
|
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 更新报警设置
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新报警记录
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="alarmID">报警记录ID</param>
|
|
|
|
|
/// <param name="clearTime">报警清除时间</param>
|
|
|
|
|
public static void UpdateAlarmData(PmtAlarmInfo alarm)
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
string sqlstr = @"update Pmt_Alarm set Alarm_PLC = @Alarm_PLC,Alarm_Block = @Alarm_Block,Alarm_Alias=@Alarm_Alias,Alarm_Cn_Info=@Alarm_Cn_Info where ID = @ID";
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
|
|
dbHelper.AddParameter("@Alarm_PLC", alarm.AlarmPLC);
|
|
|
|
|
dbHelper.AddParameter("@Alarm_Block", alarm.AlarmBlock);
|
|
|
|
|
dbHelper.AddParameter("@Alarm_Alias", alarm.AlarmAlias);
|
|
|
|
|
dbHelper.AddParameter("@Alarm_Cn_Info", alarm.Alarm_Cn_Info);
|
|
|
|
|
dbHelper.AddParameter("@ID", alarm.ID);
|
|
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|