SCLS/SSWCS_JXDL(2019)/Model/CGetInfo.cs
2025-05-19 09:45:29 +08:00

460 lines
16 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DBFactory;
namespace Model
{
public static class CGetInfo
{
public static DBOperator dbo = new DBOperator();
public static DBOperator dboM = new DBOperator("ManConnString", "ManDBFactory");
static Dictionary<int, Model.MError> _DeviceErrors;
public static Dictionary<int, Model.MError> DeviceErrors
{
get { return _DeviceErrors; }
set { _DeviceErrors = value; }
}
/// <summary>
/// 初始化设备故障信息
/// </summary>
public static void AddDeviceErrors()
{
_DeviceErrors = new Dictionary<int, Model.MError>();
DataView dv = dbo.ExceSQL("SELECT F_ErrorIndex, F_DeviceKindIndex, F_DeviceErrorIndex, F_ErrorName, F_ErrorLevel, F_ManageStatus FROM T_Base_Device_State where F_DeviceErrorIndex>=30").Tables[0].DefaultView;
for (int i = 0; i < dv.Count; i++)
{
Model.MError errs = new Model.MError();
errs.ErrorIndex = Convert.ToInt32(dv[i]["F_ErrorIndex"]);
errs.DeviceErrorIndex = Convert.ToInt32(dv[i]["F_DeviceErrorIndex"]);
errs.DeviceKindIndex = Convert.ToInt32(dv[i]["F_DeviceKindIndex"]);
errs.DeviceErrorIndex = Convert.ToInt32(dv[i]["F_DeviceErrorIndex"]);
errs.ErrorName = dv[i]["F_ErrorName"].ToString();
errs.ErrorLevel = Convert.ToInt32(dv[i]["F_ErrorLevel"]);
errs.ManageStatus = Convert.ToInt32(dv[i]["F_ManageStatus"]);
_DeviceErrors.Add(Convert.ToInt32(errs.DeviceKindIndex.ToString() + errs.DeviceErrorIndex.ToString()), errs);
}
}
/// <summary>
/// 通过设备类型+设备故障代码获取故障信息
/// </summary>
/// <param name="errID">设备类型+设备故障代码</param>
/// <returns></returns>
public static Model.MError GetErrorInfo(int errID)
{//20110401
MError value;
if(false==_DeviceErrors.TryGetValue(errID,out value))
{
if (_DeviceErrors.ContainsKey(errID))
{
value = _DeviceErrors[errID];
}
else
{
value = null;
}
}
return value;
}
static Dictionary<int, Model.MDevice> _DeviceInfo;
/// <summary>
/// 加载到内存中的设备信息集合
/// </summary>
public static Dictionary<int, Model.MDevice> DeviceInfo
{
get { return _DeviceInfo; }
set { _DeviceInfo = value; }
}
/// <summary>
/// 向内中添加设备信息
/// </summary>
public static void AddDeviceInfo()
{
_DeviceInfo = new Dictionary<int, Model.MDevice>();
DataView dv = dbo.ExceSQL("select * from T_Base_Device ").Tables[0].DefaultView;
for (int i = 0; i < dv.Count; i++)
{
Model.MDevice devinfo = new Model.MDevice();
if (dv[i]["F_AppendBarcode"] == DBNull.Value)
{
devinfo.AppendBarcode = 0;
}
else
{
devinfo.AppendBarcode = (int)dv[i]["F_AppendBarcode"];
}
if (dv[i]["F_BeDetected"] == DBNull.Value)
{
devinfo.BeDetected = null;
}
else
{
devinfo.BeDetected = dv[i]["F_BeDetected"].ToString();
}
if (dv[i]["F_BindingDevice"] == DBNull.Value)
{
devinfo.BindingDevice = null;
}
else
{
devinfo.BindingDevice = dv[i]["F_BindingDevice"].ToString();
}
if (dv[i]["F_BindingDeviceOut"] == DBNull.Value)
{
devinfo.BindingDeviceOut = null;
}
else
{
devinfo.BindingDeviceOut = dv[i]["F_BindingDeviceOut"].ToString();
}
if (dv[i]["F_CommType"] == DBNull.Value)
{
devinfo.CommType = null;
}
else
{
devinfo.CommType = dv[i]["F_CommType"].ToString();
}
if (dv[i]["F_DBW1Address"] == DBNull.Value)
{
devinfo.Dbw1Address = -1;
}
else
{
devinfo.Dbw1Address = (int)(dv[i]["F_DBW1Address"]);
}
if (dv[i]["F_DBWSendLength"] == DBNull.Value)
{
devinfo.Dbw1SendLength = 0;
}
else
{
devinfo.Dbw1SendLength = (int)dv[i]["F_DBWSendLength"];
}
if (dv[i]["F_DBW2Address"] == DBNull.Value)
{
devinfo.Dbw2Address = -1;
}
else
{
devinfo.Dbw2Address = (int)dv[i]["F_DBW2Address"];
}
if (dv[i]["F_DBWGetLength"] == DBNull.Value)
{
devinfo.Dbw2Getlength = 0;
}
else
{
devinfo.Dbw2Getlength = (decimal)dv[i]["F_DBWGetLength"];
}
if (dv[i]["F_DeviceIndex"] == DBNull.Value)
{
devinfo.DeviceIndex = 0;
}
else
{
devinfo.DeviceIndex = (int)dv[i]["F_DeviceIndex"];
}
if (dv[i]["F_DeviceKindIndex"] == DBNull.Value)
{
devinfo.DeviceKind = 0;
}
else
{
devinfo.DeviceKind = (int)dv[i]["F_DeviceKindIndex"];
}
if (dv[i]["F_DeviceName"] == DBNull.Value)
{
devinfo.DeviceName = null;
}
else
{
devinfo.DeviceName = (string)dv[i]["F_DeviceName"];
}
if (dv[i]["F_DeviceVisual"] == DBNull.Value)
{
devinfo.DeviceVisual = 0;
}
else
{
devinfo.DeviceVisual = (int)dv[i]["F_DeviceVisual"];
}
if (dv[i]["F_KeyDevice"] == DBNull.Value)
{
devinfo.IfKeyDevice = '0';
}
else
{
devinfo.IfKeyDevice =Convert.ToChar (dv[i]["F_KeyDevice"]);
}
if (dv[i]["F_MaxSendCount"] == DBNull.Value)
{
devinfo.MaxSendCount = 0;
}
else
{
devinfo.MaxSendCount = (int)dv[i]["F_MaxSendCount"];
}
if (dv[i]["F_NeedOptimize"] == DBNull.Value)
{
devinfo.NeedOptimize = '0';
}
else
{
devinfo.NeedOptimize =Convert.ToChar(dv[i]["F_NeedOptimize"]);
}
if (dv[i]["F_SendInterval"] == DBNull.Value)
{
devinfo.SendInterval = 0;
}
else
{
devinfo.SendInterval = (int)dv[i]["F_SendInterval"];
}
if (dv[i]["F_LocalIP"] == DBNull.Value)
{
devinfo.LocalIP = "";
}
else
{
devinfo.LocalIP = (string)dv[i]["F_LocalIP"];
}
if (dv[i]["F_LocalPort"] == DBNull.Value)
{
devinfo.LocalPort = 0;
}
else
{
devinfo.LocalPort = (int)dv[i]["F_LocalPort"];
}
if (dv[i]["F_RemoteIP"] == DBNull.Value)
{
devinfo.RemoteIP = "";
}
else
{
devinfo.RemoteIP = (string)dv[i]["F_RemoteIP"];
}
if (dv[i]["F_RemotePort"] == DBNull.Value)
{
devinfo.RemotePort = 0;
}
else
{
devinfo.RemotePort = (int)dv[i]["F_RemotePort"];
}
if (dv[i]["F_OPCProgID"] == DBNull.Value)
{
devinfo.OPCProgID = "";
}
else
{
devinfo.OPCProgID = (string)dv[i]["F_OPCProgID"];
}
if (dv[i]["F_ErrorTaskNo"] == DBNull.Value)
{
devinfo.ErrorTaskNo = 0;
}
else
{
devinfo.ErrorTaskNo = (int)dv[i]["F_ErrorTaskNo"];
}
if (dv[i]["F_SendOutDetect"] == DBNull.Value)
{
devinfo.SendOutDetect ="0";
}
else
{
devinfo.SendOutDetect = dv[i]["F_SendOutDetect"].ToString();
}
//
if (dv[i]["F_OnlyDetectIO"] == DBNull.Value)
{
devinfo.OnlyDetectIO = "0";
}
else
{
devinfo.OnlyDetectIO = dv[i]["F_OnlyDetectIO"].ToString();
}
if (dv[i]["F_UseCommonDB"] == DBNull.Value)
{
devinfo.UseCommonDB = "0";
}
else
{
devinfo.UseCommonDB = dv[i]["F_UseCommonDB"].ToString();
}
if (dv[i]["F_IfCorrelDoubleFork"] == DBNull.Value)
{
devinfo.IfCorrelDoubleFork = "0";
}
else
{
devinfo.IfCorrelDoubleFork = dv[i]["F_IfCorrelDoubleFork"].ToString();
}
if (dv[i]["F_DoubleForkDetect"] == DBNull.Value)
{
devinfo.DoubleForkDetect = "0";
}
else
{
devinfo.DoubleForkDetect = dv[i]["F_DoubleForkDetect"].ToString();
}
if (dv[i]["F_DoubleFork"] == DBNull.Value)
{
devinfo.DoubleFork = "0";
}
else
{
devinfo.DoubleFork = dv[i]["F_DoubleFork"].ToString();
}
//20100609
if (dv[i]["F_SerialPort"] == DBNull.Value)
{
devinfo.SerialPort = 0;
}
else
{
devinfo.SerialPort =Convert.ToInt32( dv[i]["F_SerialPort"]);
}
//20100609
if (dv[i]["F_CommSettings"] == DBNull.Value)
{
devinfo.CommSettings = "0";
}
else
{
devinfo.CommSettings = dv[i]["F_CommSettings"].ToString();
}
//20100714
if (dv[i]["F_S7Connection"] == DBNull.Value)
{
devinfo.S7Connection = "S7:[S7 connection_1]";
}
else
{
devinfo.S7Connection = dv[i]["F_S7Connection"].ToString();
}
//20101118
if (dv[i]["F_SplitByte"] == DBNull.Value)
{
devinfo.SplitByte = -1;
}
else
{
devinfo.SplitByte =Convert.ToInt32( dv[i]["F_SplitByte"]);
}
_DeviceInfo.Add(devinfo.DeviceIndex, devinfo);
}
}
/// <summary>
/// 通过设备索引反馈设备信息
/// </summary>
/// <param name="DeviceIndex">设备索引</param>
/// <returns></returns>
public static Model.MDevice GetDeviceInfo(int DeviceIndex)
{
//20091102
if (_DeviceInfo.ContainsKey(DeviceIndex) == true)
{
return _DeviceInfo[DeviceIndex];
}
else
{
return null;
}
}
/// <summary>
/// 更新内存中的设备可变信息故障码是否有物运行状态任务号当前X、Y坐标控制方式
/// </summary>
/// <param name="deviceinfo"></param>
public static void SetDeviceInfo(Model.MDevice deviceinfo)
{
_DeviceInfo[deviceinfo.DeviceIndex].ErrorCode = deviceinfo.ErrorCode;
_DeviceInfo[deviceinfo.DeviceIndex].HaveGoods = deviceinfo.HaveGoods;
_DeviceInfo[deviceinfo.DeviceIndex].RunState = deviceinfo.RunState;
_DeviceInfo[deviceinfo.DeviceIndex].TaskNo = deviceinfo.TaskNo;
_DeviceInfo[deviceinfo.DeviceIndex].XCoor = deviceinfo.XCoor;
_DeviceInfo[deviceinfo.DeviceIndex].YCoor = deviceinfo.YCoor;
_DeviceInfo[deviceinfo.DeviceIndex].ControlMode = deviceinfo.ControlMode;
_DeviceInfo[deviceinfo.DeviceIndex].Barcode = deviceinfo.Barcode;
}
public static void SetDeviceMessage(Model.MDevice deviceinfo)
{
_DeviceInfo[deviceinfo.DeviceIndex].ReturnMessage = deviceinfo.ReturnMessage;
}
/// <summary>
///设备状态变化时更新设备上一次的状态
/// </summary>
/// <param name="deviceinfo"></param>
public static void SetDeviceLastRunState(Model.MDevice deviceinfo)
{
_DeviceInfo[deviceinfo.DeviceIndex].LastRunState = deviceinfo.LastRunState;
}
static Dictionary<string, Model.MIOControlStatus> _IOControlStatus;
/// <summary>
/// 加载到内存中的与管理任务交互的调度任务状态信息集合
/// </summary>
public static Dictionary<string, Model.MIOControlStatus> IOControlStatus
{
get { return CGetInfo._IOControlStatus; }
set { CGetInfo._IOControlStatus = value; }
}
public static void AddIOControlStatus()
{
_IOControlStatus = new Dictionary<string, Model.MIOControlStatus>();
DataView dv = dbo.ExceSQL("SELECT * FROM T_Base_IOControlStatus ").Tables[0].DefaultView;
for (int i = 0; i < dv.Count; i++)
{
Model.MIOControlStatus ioStatus = new Model.MIOControlStatus();
ioStatus.StatusCode = dv[i]["F_StatusCode"].ToString();
if (dv[i]["F_StatusID"] == DBNull.Value)
{
ioStatus.StatusID = 0;
}
else
{
ioStatus.StatusID = Convert.ToInt32(dv[i]["F_StatusID"]);
}
if (dv[i]["F_Remark"] == DBNull.Value)
{
ioStatus.Remark ="-";
}
else
{
ioStatus.Remark = dv[i]["F_Remark"].ToString();
}
_IOControlStatus.Add(ioStatus.StatusCode,ioStatus);
}
}
public static Model.MIOControlStatus GetIOControlStatus(string StatusCode)
{
if (_IOControlStatus.ContainsKey(StatusCode) == true)
{
return _IOControlStatus[StatusCode];
}
else
{
return null;
}
}
}
}