|
- using CnasLocalIDAL;
- using CnasSynchronousCommon;
- using CnasSynchrousModel;
- using SyncLocalDAL;
- using System;
- using System.Collections.Generic;
- using System.Data.SQLite;
- using System.Linq;
- using System.Text;
-
- namespace CNAS_SerialPort
- {
- public class SerialPortConfigInfoDAL : LocalDBbase, ISerialPortConfigInfo
- {
- public SerialPortConfigInfo GetSerialPortConfigInfo()
- {
- SerialPortConfigInfo serialPortConfig = null;
- try
- {
- //构建数据库连接
- SQLiteHelper.SetConnectionString(ConnectString);
-
- string strSql = $"Select * From SercialPortConfig Limit 1";
- SQLiteDataReader reader = SQLiteHelper.ExecuteReader(strSql, new SQLiteParameter[] { });
- while (reader.Read())
- {
- serialPortConfig = new SerialPortConfigInfo();
-
- serialPortConfig.PortName = reader["PortName"].ToString();
- serialPortConfig.BaudRate = Convert.ToInt32(reader["BaudRate"]);
- serialPortConfig.DataBits = Convert.ToInt32(reader["DataBits"]);
- serialPortConfig.Handshake = reader["Handshake"].ToString();
- serialPortConfig.IfAutoWrap = Convert.ToBoolean(reader["IfAutoWrap"]);
- serialPortConfig.IfMuffleFurnace = Convert.ToBoolean(reader["IfMuffleFurnace"]);
- serialPortConfig.IfPeelingWeighing = Convert.ToBoolean(reader["IfPeelingWeighing"]);
- serialPortConfig.Parity = reader["Parity"].ToString();
- serialPortConfig.StopBits = reader["StopBits"].ToString();
-
- }
- reader.Close();
- }
- catch (Exception ex)
- {
- AppLog.Error("获取本地存储串口配置失败," + ex.Message.ToString());
- throw ex;
- }
- return serialPortConfig;
- }
-
-
-
- public int InsertSerialPortConfigInfo(SerialPortConfigInfo serialPortConfig)
- {
- int iReturn = 0;
- string strSql = @"INSERT INTO SercialPortConfig (PortName
- ,BaudRate
- ,DataBits
- ,Handshake
- ,IfAutoWrap
- ,IfMuffleFurnace
- ,IfPeelingWeighing
- ,Parity
- ,StopBits)
- VALUES(@PortName
- ,@BaudRate
- ,@DataBits
- ,@Handshake
- ,@IfAutoWrap
- ,@IfMuffleFurnace
- ,@IfPeelingWeighing
- ,@Parity
- ,@StopBits)";
- try
- {
- //构建数据库连接
- SQLiteHelper.SetConnectionString(ConnectString);
-
- SQLiteParameter[] parameters = new SQLiteParameter[serialPortConfig.GetType().GetProperties().Count()];
- for (int i = 0; i < serialPortConfig.GetType().GetProperties().Count(); i++)
- {
- parameters[i] = new SQLiteParameter(serialPortConfig.GetType().GetProperties()[i].Name, serialPortConfig.GetType().GetProperties()[i].GetValue(serialPortConfig, null));
- }
-
- //执行SQL语句
- iReturn += SQLiteHelper.ExecuteNonQuery(strSql, parameters);
- }
- catch (Exception ex)
- {
- AppLog.Error("插入本地存储串口配置失败," + ex.Message.ToString());
- throw ex;
- }
- return iReturn;
- }
-
- public int UpdateSerialPortConfigInfo(SerialPortConfigInfo serialPortConfig)
- {
- int iReturn = 0;
- string strSql = @"UPDATE SercialPortConfig SET PortName=@PortName
- ,BaudRate=@BaudRate
- ,DataBits=@DataBits
- ,Handshake=@Handshake
- ,IfAutoWrap=@IfAutoWrap
- ,IfMuffleFurnace=@IfMuffleFurnace
- ,IfPeelingWeighing=@IfPeelingWeighing
- ,Parity=@Parity
- ,StopBits=@StopBits";
- try
- {
- //构建数据库连接
- SQLiteHelper.SetConnectionString(ConnectString);
-
- SQLiteParameter[] parameters = new SQLiteParameter[serialPortConfig.GetType().GetProperties().Count()];
- for (int i = 0; i < serialPortConfig.GetType().GetProperties().Count(); i++)
- {
- parameters[i] = new SQLiteParameter(serialPortConfig.GetType().GetProperties()[i].Name, serialPortConfig.GetType().GetProperties()[i].GetValue(serialPortConfig, null));
- }
-
- //执行SQL语句
- iReturn += SQLiteHelper.ExecuteNonQuery(strSql, parameters);
- }
- catch (Exception ex)
- {
- AppLog.Error("更改本地存储串口配置失败," + ex.Message.ToString());
- throw ex;
- }
- return iReturn;
- }
- }
- }
|