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.
163 lines
5.7 KiB
C#
163 lines
5.7 KiB
C#
using NPOI.SS.UserModel;
|
|
using NPOI.XSSF.UserModel;
|
|
using Rs.Framework;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Rs.MotionPlat.Entitys
|
|
{
|
|
public static class AlarmCollection
|
|
{
|
|
private static Dictionary<int,AlarmEntity> alarmDic = new Dictionary<int,AlarmEntity>();
|
|
private static Dictionary<string, int> names2id2 = new Dictionary<string, int>();
|
|
static AlarmCollection()
|
|
{
|
|
Load();
|
|
}
|
|
|
|
public static void Load()
|
|
{
|
|
alarmDic.Clear();
|
|
XSSFWorkbook book;
|
|
FileStream fs = File.Open("Dorxx 报警文本(中英韩).xlsx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
|
book = new XSSFWorkbook(fs);
|
|
fs.Close();
|
|
if(book!=null)
|
|
{
|
|
ISheet sheet = book.GetSheetAt(0);
|
|
if(sheet!=null)
|
|
{
|
|
int rowNum = sheet.LastRowNum+1;
|
|
if(rowNum>2)
|
|
{
|
|
for(int i=1;i<rowNum; i++)
|
|
{
|
|
try
|
|
{
|
|
AlarmEntity entity = new AlarmEntity();
|
|
IRow row = sheet.GetRow(i);
|
|
if(row!=null)
|
|
{
|
|
ICell cell = row.GetCell(0);
|
|
if (cell != null)
|
|
{
|
|
if (cell.CellType == CellType.Numeric)
|
|
{
|
|
entity.AlarmID = int.Parse(cell.NumericCellValue.ToString().Trim());
|
|
}
|
|
else if (cell.CellType == CellType.String)
|
|
{
|
|
entity.AlarmID = int.Parse(cell.StringCellValue.ToString().Trim());
|
|
}
|
|
cell = row.GetCell(1);
|
|
if (cell != null)
|
|
entity.Titile = cell.StringCellValue;
|
|
cell = row.GetCell(2);
|
|
if (cell != null)
|
|
entity.CN = cell.StringCellValue;
|
|
cell = row.GetCell(3);
|
|
if (cell != null)
|
|
entity.EN = cell.StringCellValue;
|
|
cell = row.GetCell(4);
|
|
if (cell != null)
|
|
entity.KO = cell.StringCellValue;
|
|
if (!alarmDic.ContainsKey(entity.AlarmID))
|
|
{
|
|
alarmDic.Add(entity.AlarmID, entity);
|
|
if(!names2id2.ContainsKey(entity.Titile))
|
|
{
|
|
names2id2.Add(entity.Titile, entity.AlarmID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static AlarmEntity Get(int _alarmID)
|
|
{
|
|
if(alarmDic.Count>0 && alarmDic.ContainsKey(_alarmID))
|
|
return alarmDic[_alarmID];
|
|
return null;
|
|
}
|
|
|
|
public static AlarmEntity Get(string _alarmName)
|
|
{
|
|
if(names2id2.ContainsKey(_alarmName))
|
|
{
|
|
return Get(names2id2[_alarmName]);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static string GetAlarm(int _alarmID)
|
|
{
|
|
StringBuilder content = new StringBuilder();
|
|
AlarmEntity alarm = Get(_alarmID);
|
|
if(alarm!=null)
|
|
{
|
|
if(GlobalVar.MsgShowCn)
|
|
{
|
|
content.Append(alarm.CN).Append("\r\n\r\n");
|
|
}
|
|
if (GlobalVar.MsgShowEn)
|
|
{
|
|
content.Append(alarm.EN).Append("\r\n\r\n");
|
|
}
|
|
if (GlobalVar.MsgShowKo)
|
|
{
|
|
content.Append(alarm.KO);
|
|
}
|
|
return content.ToString();
|
|
}
|
|
return "";
|
|
}
|
|
}
|
|
public class AlarmEntity
|
|
{
|
|
/// <summary>
|
|
/// 报警编号
|
|
/// </summary>
|
|
public int AlarmID { get; set; }
|
|
|
|
public string Titile { get; set; }
|
|
/// <summary>
|
|
/// 中文
|
|
/// </summary>
|
|
public string CN { get; set; }
|
|
/// <summary>
|
|
/// 英文
|
|
/// </summary>
|
|
public string EN { get; set; }
|
|
/// <summary>
|
|
/// 韩文
|
|
/// </summary>
|
|
public string KO { get; set; }
|
|
|
|
public AlarmEntity Transform(params object[] args)
|
|
{
|
|
AlarmEntity entity = new AlarmEntity();
|
|
entity.AlarmID = AlarmID;
|
|
entity.CN = string.Format(CN, args);
|
|
entity.EN = string.Format(EN, args);
|
|
entity.KO = string.Format(KO, args);
|
|
return entity;
|
|
}
|
|
}
|
|
}
|