private long InsertDevice(DeviceLocalItem localItem)
        {
            var groupId = GetOrMakeGroupId(localItem.GroupName);

            var devInsertCommand = new SQLiteCommand("INSERT INTO DEVICES(DEV_ID, GROUP_ID, PROFILE_ID, CODE, SIL_N_1, SIL_N_2, TS, USR, POS, IsSendedToServer, MmeCode) VALUES(NULL, @GROUP_ID, @PROFILE_ID, @CODE, @SIL_N_1, @SIL_N_2, @TS, @USR, @POS, 1, @MmeCode)", _connection);

            devInsertCommand.Parameters.Add("@GROUP_ID", DbType.Int64);
            devInsertCommand.Parameters.Add("@PROFILE_ID", DbType.Guid);
            devInsertCommand.Parameters.Add("@CODE", DbType.String);
            devInsertCommand.Parameters.Add("@SIL_N_1", DbType.String);
            devInsertCommand.Parameters.Add("@SIL_N_2", DbType.String);
            devInsertCommand.Parameters.Add("@TS", DbType.String);
            devInsertCommand.Parameters.Add("@USR", DbType.StringFixedLength);
            devInsertCommand.Parameters.Add("@POS", DbType.Boolean);
            devInsertCommand.Parameters.Add("@MmeCode", DbType.String);
            devInsertCommand.Prepare();

            devInsertCommand.Parameters["@GROUP_ID"].Value   = groupId;
            devInsertCommand.Parameters["@PROFILE_ID"].Value = localItem.ProfileKey;
            devInsertCommand.Parameters["@CODE"].Value       = localItem.Code;
            devInsertCommand.Parameters["@SIL_N_1"].Value    = localItem.StructureOrd;
            devInsertCommand.Parameters["@SIL_N_2"].Value    = localItem.StructureId;
            devInsertCommand.Parameters["@TS"].Value         = DateTime.Now.ToString(@"yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
            devInsertCommand.Parameters["@USR"].Value        = localItem.UserName;
            devInsertCommand.Parameters["@POS"].Value        = (localItem.Position == 2);
            devInsertCommand.Parameters["@MmeCode"].Value    = localItem.MmeCode;
            devInsertCommand.ExecuteNonQuery();

            return(_connection.LastInsertRowId);
        }
 public bool SaveResults(DeviceLocalItem localDevice)
 {
     try
     {
         var deviceId = InsertDevice(localDevice);
         InsertErrors(localDevice.ErrorCodes, deviceId);
         InsertParameters(localDevice.DeviceParameters, deviceId);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 3
0
        private long InsertDevice(DeviceLocalItem localItem, SqlTransaction trans)
        {
            var groupId = GetOrMakeGroupId(localItem.GroupName, trans);

            _deviceSelectCmd.Parameters["@CODE"].Value     = localItem.Code;
            _deviceSelectCmd.Parameters["@GROUP_ID"].Value = groupId;
            _deviceSelectCmd.Parameters["@POS"].Value      = (localItem.Position == 2);
            _deviceSelectCmd.Parameters["@PROF_ID"].Value  = localItem.ProfileKey;
            _deviceSelectCmd.Transaction = trans;
            var devId = _deviceSelectCmd.ExecuteScalar();

            if (devId != null)
            {
                _deviceDeleteCmd.Transaction = trans;
                _deviceDeleteCmd.Parameters["@DEV_ID"].Value = devId;
                _deviceDeleteCmd.ExecuteNonQuery();
            }

            _devInsertCommand.Parameters["@GROUP_ID"].Value   = groupId;
            _devInsertCommand.Parameters["@PROFILE_ID"].Value = localItem.ProfileKey;
            _devInsertCommand.Parameters["@CODE"].Value       = localItem.Code;

            if (localItem.StructureOrd != null)
            {
                _devInsertCommand.Parameters["@SIL_N_1"].Value = localItem.StructureOrd;
            }
            else
            {
                _devInsertCommand.Parameters["@SIL_N_1"].Value = DBNull.Value;
            }

            if (localItem.StructureId != null)
            {
                _devInsertCommand.Parameters["@SIL_N_2"].Value = localItem.StructureId;
            }
            else
            {
                _devInsertCommand.Parameters["@SIL_N_2"].Value = DBNull.Value;
            }

            _devInsertCommand.Parameters["@TS"].Value       = localItem.Timestamp;
            _devInsertCommand.Parameters["@USR"].Value      = localItem.UserName;
            _devInsertCommand.Parameters["@POS"].Value      = (localItem.Position == 2);
            _devInsertCommand.Parameters["@MME_CODE"].Value = localItem.MmeCode;
            _devInsertCommand.Transaction = trans;

            return((int)_devInsertCommand.ExecuteScalar());
        }
Esempio n. 4
0
        public bool SaveResults(DeviceLocalItem localDevice)
        {
            var trans = _connection.BeginTransaction();

            try
            {
                var deviceId = InsertDevice(localDevice, trans);
                InsertErrors(localDevice.ErrorCodes, deviceId, trans);
                InsertParameters(localDevice.DeviceParameters, deviceId, trans);

                trans.Commit();
                return(true);
            }
            catch (Exception)
            {
                trans.Rollback();
                return(false);
            }
        }
Esempio n. 5
0
 public bool SendResultToServer(DeviceLocalItem localDevice)
 {
     return(_resultsService.SaveResults(localDevice));
 }
 public bool SendResultToServer(DeviceLocalItem localDevice)
 {
     return(Channel.SendResultToServer(localDevice));
 }