DalPlcInfo.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using ProjectBase.Data.BaseDAL.BaseDatabase;
  2. using ProjectBase.Data.Pager;
  3. using ProjectBase.Util;
  4. using SIMDP.DAL.IDALSQL;
  5. using SIMDP.Model;
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace SIMDP.DAL.DALSQL
  14. {
  15. /// <summary>
  16. /// PLC 配置摘要说明
  17. /// </summary>
  18. public class DalPlcInfo: BaseDALSQL<MoPlcInfo>, IDalPlcInfo
  19. {
  20. #region 对象实例及构造函数
  21. public static DalPlcInfo Instance
  22. {
  23. get
  24. {
  25. return new DalPlcInfo();
  26. }
  27. }
  28. public DalPlcInfo() : base("plc_info", "plc_id")
  29. {
  30. this.sortField = "plc_id";
  31. this.isDescending = false;
  32. }
  33. #endregion
  34. /// <summary>
  35. /// 将DataReader的属性值转化为实体类的属性值,返回实体类
  36. /// </summary>
  37. /// <param name="dr">有效的DataReader对象</param>
  38. /// <returns>实体类对象</returns>
  39. protected override MoPlcInfo DataReaderToEntity(IDataReader dataReader)
  40. {
  41. MoPlcInfo info = new MoPlcInfo();
  42. SmartDataReader reader = new SmartDataReader(dataReader);
  43. info.PlcId = reader.GetInt64("plc_id");
  44. info.PlcName = reader.GetString("plc_name");
  45. info.LinkType = reader.GetInt64("link_type");
  46. info.LinkConfig = reader.GetString("link_config");
  47. return info;
  48. }
  49. /// <summary>
  50. /// 将实体对象的属性值转化为Hashtable对应的键值
  51. /// </summary>
  52. /// <param name="obj">有效的实体对象</param>
  53. /// <returns>包含键值映射的Hashtable</returns>
  54. protected override Hashtable GetHashByEntity(MoPlcInfo obj)
  55. {
  56. MoPlcInfo info = obj as MoPlcInfo;
  57. Hashtable hash = new Hashtable();
  58. //hash.Add("plc_id", info.PlcId);
  59. hash.Add("plc_name", info.PlcName);
  60. hash.Add("link_type", info.LinkType);
  61. hash.Add("link_config", info.LinkConfig);
  62. return hash;
  63. }
  64. /// <summary>
  65. /// 获取字段中文别名(用于界面显示)的字典集合
  66. /// </summary>
  67. /// <returns></returns>
  68. public override Dictionary<string, string> GetColumnNameAlias()
  69. {
  70. Dictionary<string, string> dict = new Dictionary<string, string>();
  71. #region 添加别名解析
  72. dict.Add("plc_id", "PLC编号");
  73. dict.Add("plc_name", "PLC名称");
  74. dict.Add("link_type", "连接类型");
  75. dict.Add("link_config", "连接信息");
  76. #endregion
  77. return dict;
  78. }
  79. /// <summary>
  80. /// 获取PLC配置信息
  81. /// </summary>
  82. /// <param name="id">plc id</param>
  83. /// <param name="name">plc名称</param>
  84. /// <returns></returns>
  85. public List<MoPlcInfo> GetAllPlcInfo()
  86. {
  87. string sql = string.Format("SELECT * FROM plc_info ");
  88. return this.GetList(sql, null);
  89. }
  90. /// <summary>
  91. /// 以分页的方式获取PLC配置信息
  92. /// </summary>
  93. /// <param name="id"></param>
  94. /// <param name="name"></param>
  95. /// <param name="info">分页信息</param>
  96. /// <returns></returns>
  97. public List<MoPlcInfo> GetPlcInfoWithPager(long id, string name, PagerInfo info)
  98. {
  99. string sql = string.Format(" plc_id = {0} and plc_name = '{1}' ", id, name);
  100. return this.FindWithPager(sql, info);
  101. }
  102. /// <summary>
  103. /// 插入一条PLC配置信息
  104. /// </summary>
  105. /// <param name="obj"></param>
  106. /// <returns></returns>
  107. public bool InsetPlcInfo(MoPlcInfo obj)
  108. {
  109. return this.Insert(GetHashByEntity(obj), null);
  110. }
  111. /// <summary>
  112. /// 删除记录
  113. /// </summary>
  114. /// <param name="id"></param>
  115. /// <returns></returns>
  116. public bool DeleteWithId(long id, string userId)
  117. {
  118. return this.Delete(id, userId);
  119. }
  120. /// <summary>
  121. /// 更新信息
  122. /// </summary>
  123. /// <param name="id"></param>
  124. /// <param name="newoObj"></param>
  125. /// <returns></returns>
  126. public bool UpdateWithId(long id, MoPlcInfo newoObj)
  127. {
  128. return this.InsertUpdate(newoObj, id);
  129. }
  130. }
  131. }