Example #1
0
        private bool InsertInclinationData(string tableName, Inclination_Data data)
        {
            string sqlStatement = "INSERT INTO " + tableName + "(Stamp,X,Y,DeltaX,DeltaY) VALUES(@stamp,@x,@y,@deltaX,@deltaY)";


            bool result = true;

            try
            {
                string stamp  = data.TimeStamp;
                string x      = data.X.ToString();
                string y      = data.Y.ToString();
                string deltaX = data.DeltaX.ToString();
                string deltaY = data.DeltaY.ToString();
                //string sqlStatement = $"INSERT INTO {tableName} VALUES('{stamp}',{x},{y},{deltaX},{deltaY})";

                using (SqlCommand cmd = new SqlCommand(sqlStatement, sqlConnection))
                {
                    cmd.Parameters.AddWithValue("@stamp", data.TimeStamp);
                    cmd.Parameters.AddWithValue("@x", data.X);
                    cmd.Parameters.AddWithValue("@y", data.Y);
                    cmd.Parameters.AddWithValue("@deltaX", data.DeltaX);
                    cmd.Parameters.AddWithValue("@deltaY", data.DeltaY);
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                result = false;
                form.AppendLog(ex.StackTrace.ToString() + "\r\n");
            }
            return(result);
        }
Example #2
0
        private bool HandleMessage(string routingKey, string msg)
        {
            string tableName  = "t_" + routingKey.Replace('.', '_');
            string deviceType = routingKey.Split('.')[1];
            bool   result     = false;

            switch (deviceType)
            {
            case "02":
                Temperature_Data td = JsonConvert.DeserializeObject <Temperature_Data>(msg);
                result = InsertTemperatureData(tableName, td);
                break;

            case "08":
                Strain_Data sd = JsonConvert.DeserializeObject <Strain_Data>(msg);
                result = InsertStrainData(tableName, sd);
                break;

            case "09":
                Settlement_Data obj = JsonConvert.DeserializeObject <Settlement_Data>(msg);
                result = InsertSettlementData(tableName, obj);
                break;

            case "11":
                Inclination_Data id = JsonConvert.DeserializeObject <Inclination_Data>(msg);
                result = InsertInclinationData(tableName, id);
                break;

            case "13":
                TemperatureHumidity_Data thd = JsonConvert.DeserializeObject <TemperatureHumidity_Data>(msg);
                result = InsertTemperatureHumidityData(tableName, thd);
                break;

            case "19":
                LaserRange_Data lrd = JsonConvert.DeserializeObject <LaserRange_Data>(msg);
                result = InsertLaserRangeData(tableName, lrd);
                break;

            default: break;
            }
            return(result);
        }