CNAS取数仪器端升级
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

SerialPortConfigInfoDAL.cs 5.9KB

hace 5 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using CnasLocalIDAL;
  2. using CnasSynchronousCommon;
  3. using CnasSynchrousModel;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data.SQLite;
  7. using System.Linq;
  8. using System.Text;
  9. namespace SyncLocalDAL
  10. {
  11. public class SerialPortConfigInfoDAL : LocalDBbase, ISerialPortConfigInfo
  12. {
  13. public SerialPortConfigInfo GetSerialPortConfigInfo()
  14. {
  15. SerialPortConfigInfo serialPortConfig = null;
  16. try
  17. {
  18. //构建数据库连接
  19. SQLiteHelper.SetConnectionString(ConnectString);
  20. string strSql = $"Select * From SercialPortConfig Limit 1";
  21. SQLiteDataReader reader = SQLiteHelper.ExecuteReader(strSql, new SQLiteParameter[] { });
  22. while (reader.Read())
  23. {
  24. serialPortConfig = new SerialPortConfigInfo();
  25. serialPortConfig.PortName = reader["PortName"].ToString();
  26. serialPortConfig.BaudRate = Convert.ToInt32(reader["BaudRate"]);
  27. serialPortConfig.DataBits = Convert.ToInt32(reader["DataBits"]);
  28. serialPortConfig.Handshake = reader["Handshake"].ToString();
  29. serialPortConfig.IfAutoWrap = Convert.ToBoolean(reader["IfAutoWrap"]);
  30. serialPortConfig.IfMuffleFurnace = Convert.ToBoolean(reader["IfMuffleFurnace"]);
  31. serialPortConfig.IfPeelingWeighing = Convert.ToBoolean(reader["IfPeelingWeighing"]);
  32. serialPortConfig.Parity = reader["Parity"].ToString();
  33. serialPortConfig.StopBits = reader["StopBits"].ToString();
  34. }
  35. reader.Close();
  36. }
  37. catch (Exception ex)
  38. {
  39. AppLog.Error("获取本地存储串口配置失败," + ex.Message.ToString());
  40. throw ex;
  41. }
  42. return serialPortConfig;
  43. }
  44. public int InsertSerialPortConfigInfo(SerialPortConfigInfo serialPortConfig)
  45. {
  46. int iReturn = 0;
  47. string strSql = @"INSERT INTO SercialPortConfig (PortName
  48. ,BaudRate
  49. ,DataBits
  50. ,Handshake
  51. ,IfAutoWrap
  52. ,IfMuffleFurnace
  53. ,IfPeelingWeighing
  54. ,Parity
  55. ,StopBits)
  56. VALUES(@PortName
  57. ,@BaudRate
  58. ,@DataBits
  59. ,@Handshake
  60. ,@IfAutoWrap
  61. ,@IfMuffleFurnace
  62. ,@IfPeelingWeighing
  63. ,@Parity
  64. ,@StopBits)";
  65. try
  66. {
  67. //构建数据库连接
  68. SQLiteHelper.SetConnectionString(ConnectString);
  69. SQLiteParameter[] parameters = new SQLiteParameter[serialPortConfig.GetType().GetProperties().Count()];
  70. for (int i = 0; i < serialPortConfig.GetType().GetProperties().Count(); i++)
  71. {
  72. parameters[i] = new SQLiteParameter(serialPortConfig.GetType().GetProperties()[i].Name, serialPortConfig.GetType().GetProperties()[i].GetValue(serialPortConfig, null));
  73. }
  74. //执行SQL语句
  75. iReturn += SQLiteHelper.ExecuteNonQuery(strSql, parameters);
  76. }
  77. catch (Exception ex)
  78. {
  79. AppLog.Error("插入本地存储串口配置失败," + ex.Message.ToString());
  80. throw ex;
  81. }
  82. return iReturn;
  83. }
  84. public int UpdateSerialPortConfigInfo(SerialPortConfigInfo serialPortConfig)
  85. {
  86. int iReturn = 0;
  87. string strSql = @"UPDATE SercialPortConfig SET PortName=@PortName
  88. ,BaudRate=@BaudRate
  89. ,DataBits=@DataBits
  90. ,Handshake=@Handshake
  91. ,IfAutoWrap=@IfAutoWrap
  92. ,IfMuffleFurnace=@IfMuffleFurnace
  93. ,IfPeelingWeighing=@IfPeelingWeighing
  94. ,Parity=@Parity
  95. ,StopBits=@StopBits";
  96. try
  97. {
  98. //构建数据库连接
  99. SQLiteHelper.SetConnectionString(ConnectString);
  100. SQLiteParameter[] parameters = new SQLiteParameter[serialPortConfig.GetType().GetProperties().Count()];
  101. for (int i = 0; i < serialPortConfig.GetType().GetProperties().Count(); i++)
  102. {
  103. parameters[i] = new SQLiteParameter(serialPortConfig.GetType().GetProperties()[i].Name, serialPortConfig.GetType().GetProperties()[i].GetValue(serialPortConfig, null));
  104. }
  105. //执行SQL语句
  106. iReturn += SQLiteHelper.ExecuteNonQuery(strSql, parameters);
  107. }
  108. catch (Exception ex)
  109. {
  110. AppLog.Error("更改本地存储串口配置失败," + ex.Message.ToString());
  111. throw ex;
  112. }
  113. return iReturn;
  114. }
  115. }
  116. }