예제 #1
0
        /// <summary>
        /// 更新SQLLite数据库的遥测/遥信数据
        /// </summary>
        /// <param name="theRemoteData"></param>
        /// <param name="list">设备地址</param>
        /// <param name="name">遥测/遥信</param>
        /// <returns></returns>
        internal ReadSqlLiteData toReadSqlLiteData(TheRemoteData theRemoteData, List <byte> list, string name)
        {
            ReadSqlLiteData theReadSqlLiteData = new ReadSqlLiteData();

            switch (name)
            {
            case "遥测":
                theReadSqlLiteData.theAddress     = ByteWithString.byteToHexStr(list.ToArray());//设备地址
                theReadSqlLiteData.theDataAddress = ByteWithString.byteToHexStr(theRemoteData.RemoteAddress).ToLower();
                theReadSqlLiteData.theNumber      = ((theRemoteData.RemoteValue[1] << 8) | theRemoteData.RemoteValue[0]).ToString();
                theReadSqlLiteData.theValue       = theRemoteData.quility.ToString("X2").ToLower();
                break;

            case "遥信":
                theReadSqlLiteData.theAddress     = ByteWithString.byteToHexStr(list.ToArray());            //设备地址
                theReadSqlLiteData.theDataAddress = ByteWithString.byteToHexStr(theRemoteData.RemoteAddress);
                theReadSqlLiteData.theNumber      = ByteWithString.byteToHexStr(theRemoteData.RemoteValue); //值
                if (theRemoteData.LastestModify != null && theRemoteData.LastestModify.Length > 0)
                {
                    theReadSqlLiteData.theValue = ByteWithString.ConvertCP56TIME2aToDateTime(theRemoteData.LastestModify).ToString("yyyy-MM-dd HH:mm:ss");
                }
                else
                {
                    theReadSqlLiteData.theValue = "";
                }
                break;

            default: break;
            }
            return(theReadSqlLiteData);
        }
예제 #2
0
        internal void SaveDataAddOrUpdate(object obj)
        {
            try
            {
                ThreadData theThreadData = obj as ThreadData;
                //DataGridView dt, string deviceAddress, string name
                ReadSqlLiteData theReadData = new ReadSqlLiteData();
                for (int i = 0; i < theThreadData.THE_DATA_GRID_VIEW.Rows.Count; i++)
                {
                    switch (theThreadData.THE_NAME)
                    {
                    case "遥信":
                        theReadData.theAddress     = theThreadData.THE_DEVICE_ADDRESS;
                        theReadData.theDataAddress = theThreadData.THE_DATA_GRID_VIEW.Rows[i].Cells["RemoteName"].Tag.ToString();        //名称
                        theReadData.theNumber      = theThreadData.THE_DATA_GRID_VIEW.Rows[i].Cells["RemoteValueStr"].Value.ToString();  //数值
                        theReadData.theValue       = theThreadData.THE_DATA_GRID_VIEW.Rows[i].Cells["LastestModifStr"].Value.ToString(); //时标
                        UpdataOrAddNowData(theReadData, "遥信");
                        break;

                    case "遥测":
                        theReadData.theAddress     = theThreadData.THE_DEVICE_ADDRESS;
                        theReadData.theDataAddress = theThreadData.THE_DATA_GRID_VIEW.Rows[i].Cells["TRemoteName"].Tag.ToString();        //名称
                        theReadData.theNumber      = theThreadData.THE_DATA_GRID_VIEW.Rows[i].Cells["TRemoteValueStr"].Value.ToString();  //数值
                        theReadData.theValue       = theThreadData.THE_DATA_GRID_VIEW.Rows[i].Cells["TLastestModifStr"].Value.ToString(); //描述
                        UpdataOrAddNowData(theReadData, "遥测");
                        break;

                    default: break;
                    }
                }
            }
            catch
            {
            }
        }
예제 #3
0
        public static List <ReadSqlLiteData> returnTelemeteringArray(string deviceDataID, string str)
        {
            SQLiteHelper           theSQLiteHelper      = new SQLiteHelper();
            string                 sql                  = string.Format("select * from Telemetering where deviceAddress=\"{0}\" and belongLine=\"{1}\"", deviceDataID, str);
            List <ReadSqlLiteData> readSqlLiteDataArray = new List <ReadSqlLiteData>();
            DataTable              dt = theSQLiteHelper.ExecuteDataTable(sql, null);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ReadSqlLiteData theReadSqlLiteData = new ReadSqlLiteData();
                theReadSqlLiteData.theAddress     = dt.Rows[i]["deviceAddress"].ToString();
                theReadSqlLiteData.theDataAddress = dt.Rows[i]["telemeteringAddress"].ToString();
                theReadSqlLiteData.theBelong      = dt.Rows[i]["belongLine"].ToString();
                theReadSqlLiteData.theNumber      = dt.Rows[i]["numberValue"].ToString();
                theReadSqlLiteData.theValue       = dt.Rows[i]["theDescribe"].ToString();
                readSqlLiteDataArray.Add(theReadSqlLiteData);
            }
            return(readSqlLiteDataArray);
        }
예제 #4
0
        public void UpdataOrAddNowData(ReadSqlLiteData theReadData, string name)
        {
            string line = "";
            string sql  = "";

            switch (name)
            {
            case "遥测":
                line = BelongTelemeteringLine(theReadData.theDataAddress);
                sql  = string.Format("SELECT count (*) FROM Telemetering WHERE deviceAddress = \"{0}\" AND telemeteringAddress = \"{1}\"", theReadData.theAddress, theReadData.theDataAddress);
                if (int.Parse(theSQLiteHelper.ExecuteScalar(sql, null).ToString()) > 0)
                {
                    sql = string.Format("update Telemetering set numberValue=\"{0}\",theDescribe=\"{1}\" WHERE deviceAddress = \"{2}\" AND telemeteringAddress = \"{3}\"", theReadData.theNumber, theReadData.theValue, theReadData.theAddress, theReadData.theDataAddress);
                }
                else
                {
                    sql = string.Format("insert into Telemetering(deviceAddress,telemeteringAddress,belongLine,numberValue,theDescribe) values (\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\")", theReadData.theAddress, theReadData.theDataAddress, line, theReadData.theNumber, theReadData.theValue);
                }
                break;

            case "遥信":
                line = BelongRemoteLine(theReadData.theDataAddress);
                sql  = string.Format("SELECT count (*) FROM Remote WHERE deviceAddress = \"{0}\" AND remoteAddress = \"{1}\"", theReadData.theAddress, theReadData.theDataAddress);
                if (int.Parse(theSQLiteHelper.ExecuteScalar(sql, null).ToString()) > 0)
                {
                    sql = string.Format("update Remote set numberValue=\"{0}\",theCharacteristic=\"{1}\" WHERE deviceAddress = \"{2}\" AND remoteAddress = \"{3}\"", theReadData.theNumber, theReadData.theValue, theReadData.theAddress, theReadData.theDataAddress);
                }
                else
                {
                    sql = string.Format("insert into Remote(deviceAddress,remoteAddress,belongLine,numberValue,theCharacteristic) values (\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\")", theReadData.theAddress, theReadData.theDataAddress, line, theReadData.theNumber, theReadData.theValue);
                }
                break;

            default: break;
            }
            theSQLiteHelper.ExecuteNonQuery(sql, null);
        }