示例#1
0
        public static DBOperation GetDbOperation()
        {
            if (mDbInstence == null)
            {
                mDbInstence = new DBOperation();
            }

            if (!bIsOpen)
            {
                if (OpenDB() != 0)
                {
                    Program.Logger.Info("Failed to open database!");
                    return(null);
                }
            }

            return(mDbInstence);
        }
示例#2
0
        /// <summary>
        /// LH:土壤数据存入数据库
        /// </summary>
        private void DataProcessListLH()
        {
            while (true)
            {
                if (0 == listLH.Count)
                {
                    Thread.Sleep(100);
                    //   Console.WriteLine("+++++++++++none");
                    continue;
                }

                DataClassLH dclh   = (DataClassLH)listLH.Last();
                string      strOut = "CO2:" + 0 + " 环境温度:" + dclh.dAirTemperature + " 环境湿度:" + dclh.dAirMoisture + " 光照:" + dclh.dSunshine + " 土壤PH:" + dclh.dSoilPH + " 土壤温度:" + dclh.dSoilTempture + " 土壤湿度:" + dclh.dSoilMoisture + " 土壤湿度30:" + dclh.dSoilMoisture30;
                Console.WriteLine(System.DateTime.Now + ":" + strOut);

                Dictionary <string, double> dct = new Dictionary <string, double>();
                dct.Add("SOIL_TEMPERATURE", dclh.dSoilTempture);
                dct.Add("SOIL_MOISTURE", dclh.dSoilMoisture);
                dct.Add("SUNSHINE", dclh.dSunshine);
                dct.Add("AIR_TEMPERATURE", dclh.dAirTemperature);
                dct.Add("AIR_MOISTURE", dclh.dAirMoisture);
                dct.Add("SOIL_MOISTURE30", dclh.dSoilMoisture30);
                dct.Add("SOIL_PH", dclh.dSoilPH);

                ///将数据插入数据库
                ///
                DBOperation db = DBOperation.GetDbOperation();
                if (db != null)
                {
                    count++;
                    if (count > 20000)
                    {
                        count = 0;
                    }
                    db.updateSoilData(dclh.ID, dct);
                    Console.WriteLine(System.DateTime.Now + ":insert to soil database ok!!:" + count);
                }
                else
                {
                    Program.Logger.Debug("database open failed!!!");
                }
                listLH.RemoveLast();
            }
        }