Beispiel #1
0
        public void batchInsertRows(List <CEntityWater> waters)
        {
            if (waters == null || waters.Count == 0)
            {
                return;
            }
            // 记录超过写入上线条,或者时间超过1分钟,就将当前的数据写入数据库
            CDBLog.Instance.AddInfo("batch insert的方式批量插入水位数据开始!");
            StringBuilder sql = new StringBuilder();

            foreach (CEntityWater water in waters)
            {
                sql.Append("insert INTO water(stationid,datatime,waterstage,waterflow,transtype,messagetype,recvdatatime,state) VALUES");
                sql.AppendFormat("({0},{1},{2},{3},{4},{5},{6},{7}),", "'" + water.StationID + "'", "'" + water.TimeCollect.ToString(CDBParams.GetInstance().DBDateTimeFormat) + "'", water.WaterStage,
                                 "null", CEnumHelper.ChannelTypeToDBStr(water.ChannelType).ToString(), CEnumHelper.MessageTypeToDBStr(water.MessageType).ToString(), "'" + water.TimeRecieved.ToString(CDBParams.GetInstance().DBDateTimeFormat) + "'", water.state.ToString());
                sql.Remove(sql.Length - 1, 1);
                sql.Append(";");
            }
            try
            {
                ExecuteSQLCommand(sql.ToString().Substring(0, sql.ToString().Length - 1));
            }catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        /// <summary>
        /// 插入数据到RG30表,流速1,流量1,流量2
        /// </summary>
        /// <param name="waterSpeedList"></param>
        public void batchInsertRows2(List <CEntityWaterSpeed> waterSpeedList)
        {
            if (waterSpeedList == null || waterSpeedList.Count == 0)
            {
                return;
            }
            // 记录超过写入上线条,或者时间超过1分钟,就将当前的数据写入数据库
            CDBLog.Instance.AddInfo("时差法流速数据:" + waterSpeedList.Count + "条");
            StringBuilder sql = new StringBuilder();

            foreach (CEntityWaterSpeed waterSpeed in waterSpeedList)
            {
                sql.Append("insert INTO RG30RawData(STCD,DT,AvgV1,AvgV2,AvgV3,AvgV4,W1,rawQ,Q,recvdatatime,transtype,messagetype) VALUES");
                sql.AppendFormat("({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}),", "'" + waterSpeed.STCD + "'", "'" + waterSpeed.DT.ToString(CDBParams.GetInstance().DBDateTimeFormat) + "'",
                                 waterSpeed.AvgV1, "NULL", "NULL", "NULL", "NULL", waterSpeed.rawQ, waterSpeed.Q,
                                 "'" + waterSpeed.RevtDT.ToString(CDBParams.GetInstance().DBDateTimeFormat) + "'",
                                 CEnumHelper.ChannelTypeToDBStr(waterSpeed.ChannelType).ToString(), CEnumHelper.MessageTypeToDBStr(waterSpeed.MessageType).ToString());
                sql.Remove(sql.Length - 1, 1);
                sql.Append(";");
            }
            try
            {
                string sql1 = sql.ToString().Substring(0, sql.ToString().Length - 1);
                //ExecuteSQLCommand(sql.ToString().Substring(0, sql.ToString().Length - 1));
                ExecuteSQLCommand(sql1);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #3
0
        // 添加新列
        public void AddNewRow(CEntityWater water)
        {
            // 记录超过1000条,或者时间超过1分钟,就将当前的数据写入数据库
            m_mutexDataTable.WaitOne(); //等待互斥量
            DataRow row = m_tableDataAdded.NewRow();

            row[CN_StationId]    = water.StationID;
            row[CN_DataTime]     = water.TimeCollect.ToString(CDBParams.GetInstance().DBDateTimeFormat);
            row[CN_WaterStage]   = water.WaterStage;
            row[CN_WaterFlow]    = water.WaterFlow;
            row[CN_MsgType]      = CEnumHelper.MessageTypeToDBStr(water.MessageType);
            row[CN_TransType]    = CEnumHelper.ChannelTypeToDBStr(water.ChannelType);
            row[CN_RecvDataTime] = water.TimeRecieved.ToString(CDBParams.GetInstance().DBDateTimeFormat);
            row[CN_State]        = water.state;
            m_tableDataAdded.Rows.Add(row);
            m_mutexDataTable.ReleaseMutex();

            // 判断是否需要创建新分区
            //CSQLPartitionMgr.Instance.MaintainWater(water.TimeCollect);
            if (m_tableDataAdded.Rows.Count >= CDBParams.GetInstance().AddBufferMax)
            {
                // 如果超过最大值,写入数据库
                //Task task = new Task(() => { AddDataToDB(); });
                //task.Start();
                NewTask(() => { AddDataToDB(); });
            }
            else
            {
                // 没有超过缓存最大值,开启定时器进行检测,多次调用Start()会导致重新计数
                m_addTimer.Start();
            }
        }
Beispiel #4
0
        public void AddNewRows_1(List <CEntityWater> waters)
        {
            // 记录超过写入上线条,或者时间超过1分钟,就将当前的数据写入数据库
            m_mutexDataTable.WaitOne(); //等待互斥量
            foreach (CEntityWater water in waters)
            {
                DataRow row = m_tableDataAdded.NewRow();
                row[CN_StationId]    = water.StationID;
                row[CN_DataTime]     = water.TimeCollect.ToString(CDBParams.GetInstance().DBDateTimeFormat);
                row[CN_WaterStage]   = water.WaterStage;
                row[CN_WaterFlow]    = water.WaterFlow;
                row[CN_MsgType]      = CEnumHelper.MessageTypeToDBStr(water.MessageType);
                row[CN_TransType]    = CEnumHelper.ChannelTypeToDBStr(water.ChannelType);
                row[CN_RecvDataTime] = water.TimeRecieved.ToString(CDBParams.GetInstance().DBDateTimeFormat);
                row[CN_State]        = water.state;
                m_tableDataAdded.Rows.Add(row);

                // 判断是否需要创建新分区
                //CSQLPartitionMgr.Instance.MaintainWater(water.TimeCollect);
            }

            // 直接写入数据库
            NewTask(() => { AddDataToDB(); });
            m_mutexDataTable.ReleaseMutex();
        }
Beispiel #5
0
 public void AddNewRows(List <CEntityVoltage> voltages)
 {
     // 记录超过1000条,或者时间超过1分钟,就将当前的数据写入数据库
     m_mutexDataTable.WaitOne(); //等待互斥量
     foreach (CEntityVoltage voltage in voltages)
     {
         DataRow row = m_tableDataAdded.NewRow();
         row[CN_StationId]    = voltage.StationID;
         row[CN_DataTime]     = voltage.TimeCollect.ToString(CDBParams.GetInstance().DBDateTimeFormat);
         row[CN_MsgType]      = CEnumHelper.MessageTypeToDBStr(voltage.MessageType);
         row[CN_TransType]    = CEnumHelper.ChannelTypeToDBStr(voltage.ChannelType);
         row[CN_RecvDataTime] = voltage.TimeRecieved.ToString(CDBParams.GetInstance().DBDateTimeFormat);
         row[CN_Voltage]      = voltage.Voltage;
         row[CN_State]        = voltage.state;
         m_tableDataAdded.Rows.Add(row);
         // 判断是否需要创建新分区
         //CSQLPartitionMgr.Instance.MaintainVoltage(voltage.TimeCollect);
     }
     if (m_tableDataAdded.Rows.Count >= CDBParams.GetInstance().AddBufferMax)
     {
         // 如果超过最大值,写入数据库
         // NewTask(() => { AddDataToDB(); });
         NewTask(() => { InsertSqlBulk(m_tableDataAdded); });
     }
     else
     {
         // 没有超过缓存最大值,开启定时器进行检测,多次调用Start()会导致重新计数
         m_addTimer_1.Start();
     }
     m_mutexDataTable.ReleaseMutex();
 }
Beispiel #6
0
        public void AddNewRows(List <CEntityOBS> obsDatas)
        {
            m_mutexDataTable.WaitOne(); //等待互斥量
            foreach (CEntityOBS obs in obsDatas)
            {
                DataRow row = m_tableDataAdded.NewRow();
                row[CN_StationId]    = obs.StationID;
                row[CN_DataTime]     = obs.TimeCollect.ToString(CDBParams.GetInstance().DBDateTimeFormat);
                row[CN_Depth]        = obs.Depth;
                row[CN_NTU]          = obs.NTU;
                row[CN_ppm]          = obs.ppm;
                row[CN_Temperature]  = obs.Temperature;
                row[CN_Conductivity] = obs.Conductivity;
                row[CN_Salinity]     = obs.Salinity;
                row[CN_Batt]         = obs.Batt;

                row[CN_transtype]   = CEnumHelper.ChannelTypeToDBStr(obs.ChannelType);
                row[CN_messagetype] = CEnumHelper.MessageTypeToDBStr(obs.MessageType);

                row[CN_recvdatatime] = obs.TimeRecieved;
                row[CN_State]        = obs.BState;
                m_tableDataAdded.Rows.Add(row);
            }
            NewTask(() => { InsertSqlBulk(m_tableDataAdded); });
            m_mutexDataTable.ReleaseMutex();
        }
Beispiel #7
0
        public void AddNewRow(CEntityTSRain rain)
        {
            m_mutexDataTable.WaitOne(); //等待互斥量
            DataRow row = m_tableDataAdded.NewRow();

            row[CN_StationId]    = rain.StationID;
            row[CN_DataTime]     = rain.TimeCollect.ToString(CDBParams.GetInstance().DBDateTimeFormat);
            row[CN_TotalRain]    = rain.TotalRain;
            row[CN_TransType]    = CEnumHelper.ChannelTypeToDBStr(rain.ChannelType);
            row[CN_MsgType]      = CEnumHelper.MessageTypeToDBStr(rain.MessageType);
            row[CN_RecvDataTime] = rain.TimeRecieved.ToString(CDBParams.GetInstance().DBDateTimeFormat);
            m_tableDataAdded.Rows.Add(row);
            m_mutexDataTable.ReleaseMutex();
            AddDataToDB();
        }
Beispiel #8
0
        public void AddNewRow(CEntityTSWater water)
        {
            // 记录超过1000条,或者时间超过1分钟,就将当前的数据写入数据库
            m_mutexDataTable.WaitOne(); //等待互斥量
            DataRow row = m_tableDataAdded.NewRow();

            row[CN_StationId]    = water.StationID;
            row[CN_DataTime]     = water.TimeCollect.ToString(CDBParams.GetInstance().DBDateTimeFormat);
            row[CN_WaterStage]   = water.WaterStage;
            row[CN_MsgType]      = CEnumHelper.MessageTypeToDBStr(water.MessageType);
            row[CN_TransType]    = CEnumHelper.ChannelTypeToDBStr(water.ChannelType);
            row[CN_RecvDataTime] = water.TimeRecieved.ToString(CDBParams.GetInstance().DBDateTimeFormat);
            m_tableDataAdded.Rows.Add(row);
            m_mutexDataTable.ReleaseMutex();
            AddDataToDB();
        }
Beispiel #9
0
        /// <summary>
        /// 异步添加一个数据记录
        /// </summary>
        /// <param name="entity"></param>
        public void AddNewRow(CEntitySoilData entity)
        {
            // 记录超过1000条,或者时间超过1分钟,就将当前的数据写入数据库
            m_mutexDataTable.WaitOne(); //等待互斥量
            DataRow row = m_tableDataAdded.NewRow();

            row[CN_StationId]   = entity.StationID;
            row[CN_DataTime]    = entity.DataTime.ToString(CDBParams.GetInstance().DBDateTimeFormat);
            row[CN_Voltage]     = entity.DVoltage;
            row[CN_MessageType] = CEnumHelper.MessageTypeToDBStr(entity.MessageType);
            row[CN_ChannelType] = CEnumHelper.ChannelTypeToDBStr(entity.ChannelType);

            row[CN_Voltage10]  = entity.Voltage10;
            row[CN_Moisture10] = entity.Moisture10;

            row[CN_Voltage20]  = entity.Voltage20;
            row[CN_Moisture20] = entity.Moisture20;

            row[CN_Voltage30]  = entity.Voltage30;
            row[CN_Moisture30] = entity.Moisture30;

            row[CN_Voltage40]  = entity.Voltage40;
            row[CN_Moisture40] = entity.Moisture40;

            row[CN_Voltage60]  = entity.Voltage60;
            row[CN_Moisture60] = entity.Moisture60;

            row[CN_RecvTime] = entity.reciveTime;
            row[CN_State]    = entity.state;

            m_tableDataAdded.Rows.Add(row);
            if (m_tableDataAdded.Rows.Count >= CDBParams.GetInstance().AddBufferMax)
            {
                // 如果超过最大值,写入数据库
                //Task task = new Task(() => { AddDataToDB(); });
                //task.Start();
                //m_mutexDataTable.ReleaseMutex();
                //Thread.Sleep(10 * 1000);
                NewTask(() => { AddDataToDB(); });
            }
            else
            {
                // 没有超过缓存最大值,开启定时器进行检测,多次调用Start()会导致重新计数
                m_addTimer.Start();
            }
            m_mutexDataTable.ReleaseMutex();
        }
Beispiel #10
0
 public void AddNewRows(List <CEntityTSWater> waters)
 {
     m_mutexDataTable.WaitOne(); //等待互斥量
     foreach (CEntityTSWater water in waters)
     {
         DataRow row = m_tableDataAdded.NewRow();
         row[CN_StationId]    = water.StationID;
         row[CN_DataTime]     = water.TimeCollect.ToString(CDBParams.GetInstance().DBDateTimeFormat);
         row[CN_WaterStage]   = water.WaterStage;
         row[CN_MsgType]      = CEnumHelper.MessageTypeToDBStr(water.MessageType);
         row[CN_TransType]    = CEnumHelper.ChannelTypeToDBStr(water.ChannelType);
         row[CN_RecvDataTime] = water.TimeRecieved.ToString(CDBParams.GetInstance().DBDateTimeFormat);
         m_tableDataAdded.Rows.Add(row);
     }
     AddDataToDB();
     m_mutexDataTable.ReleaseMutex();
 }
Beispiel #11
0
        public bool UpdateRows(List <CEntitySoilData> listData)
        {
            // 除主键外和站点外,其余信息随意修改
            StringBuilder sql = new StringBuilder();
            int           currentBatchCount = 0;

            for (int i = 0; i < listData.Count; i++)
            {
                ++currentBatchCount;
                sql.AppendFormat("update {0} set {1}={2},{3}={4},{5}={6},{7}='{8}',{9}={10},{11}={12},{13}={14},{15}={16},{17}={18}, {19}={20}, {21}={22} where {23}={24} and {25}='{26}';",
                                 CT_TableName,
                                 CN_Voltage, listData[i].DVoltage,
                                 CN_ChannelType, CEnumHelper.ChannelTypeToDBStr(listData[i].ChannelType),
                                 CN_MessageType, CEnumHelper.MessageTypeToDBStr(listData[i].MessageType),
                                 CN_RecvTime, listData[i].reciveTime.ToString(),
                                 CN_Moisture10, listData[i].Moisture10,
                                 CN_Moisture20, listData[i].Moisture20,
                                 CN_Moisture40, listData[i].Moisture40,
                                 CN_Voltage10, listData[i].Voltage10,
                                 CN_Voltage20, listData[i].Voltage20,
                                 CN_Voltage40, listData[i].Voltage40,
                                 CN_State, listData[i].state,
                                 CN_StationId, listData[i].StationID,
                                 CN_DataTime, listData[i].DataTime.ToString()
                                 //    CN_VoltageID, voltages[i].VoltageID
                                 );
                //if (currentBatchCount >= CDBParams.GetInstance().UpdateBufferMax)
                //{
                // 更新数据库
                //if (!this.ExecuteSQLCommand(sql.ToString()))
                //{
                //    // 保存失败
                //    return false;
                //}

                //currentBatchCount = 0;
            }
            // 更新数据库
            if (!this.ExecuteSQLCommand(sql.ToString()))
            {
                return(false);
            }
            sql.Clear(); //清除以前的所有命令
            ResetAll();
            return(true);
        }
Beispiel #12
0
        public bool UpdateRows(List <CEntityRealTime> realtimes)
        {
            // 除主键和站点信息外,其余信息随意修改
            StringBuilder sql = new StringBuilder();
            int           currentBatchCount = 0;

            for (int i = 0; i < realtimes.Count; i++)
            {
                ++currentBatchCount;
                sql.AppendFormat("update {0} set {1}={2},{3}={4},{5}={6},{7}={8},{9}={10},{11}={12},{13}={14},{15}={16},{17}={18},{19}={20} where {21}={22} and {23}='{24}';",
                                 CT_TableName,
                                 CN_YesterdayRain, realtimes[i].LastDayRainFall,
                                 CN_TodayRain, realtimes[i].DDayRainFall,
                                 CN_PeriodRain, realtimes[i].DPeriodRain,
                                 CN_WaterStage, realtimes[i].DWaterYield,
                                 CN_WaterFlow, realtimes[i].DWaterFlowActual,
                                 CN_Voltage, realtimes[i].Dvoltage,
                                 CN_TransType, CEnumHelper.ChannelTypeToDBStr(realtimes[i].EIChannelType),
                                 CN_MsgType, CEnumHelper.MessageTypeToDBStr(realtimes[i].EIMessageType),
                                 CN_DataTime, realtimes[i].TimeDeviceGained,
                                 CN_DataState, realtimes[i].EIStationType,
                                 CN_StationId, realtimes[i].StrStationID,
                                 CN_CName, realtimes[i].StrStationName.ToString()
                                 //    CN_VoltageID, voltages[i].VoltageID
                                 );
                //if (currentBatchCount >= CDBParams.GetInstance().UpdateBufferMax)
                //{
                //    // 更新数据库
                //    if (!this.ExecuteSQLCommand(sql.ToString()))
                //    {
                //        // 保存失败
                //        return false;
                //    }
                //    sql.Clear(); //清除以前的所有命令
                //    currentBatchCount = 0;
                //}
            }
            // 更新数据库
            if (!this.ExecuteSQLCommand(sql.ToString()))
            {
                return(false);
            }
            sql.Clear(); //清除以前的所有命令
            ResetAll();
            return(true);
        }
Beispiel #13
0
        public void AddOrUpdate(List <CEntityWater> listWaters)
        {
            m_mutexDataTable.WaitOne(); //等待互斥量
            foreach (CEntityWater water in listWaters)
            {
                StringBuilder sql = new StringBuilder();
                try
                {
                    DataRow row = m_tableDataAdded.NewRow();
                    row[CN_StationId]    = water.StationID;
                    row[CN_DataTime]     = water.TimeCollect.ToString(CDBParams.GetInstance().DBDateTimeFormat);
                    row[CN_WaterStage]   = water.WaterStage;
                    row[CN_WaterFlow]    = water.WaterFlow;
                    row[CN_MsgType]      = CEnumHelper.MessageTypeToDBStr(water.MessageType);
                    row[CN_TransType]    = CEnumHelper.ChannelTypeToDBStr(water.ChannelType);
                    row[CN_RecvDataTime] = water.TimeRecieved.ToString(CDBParams.GetInstance().DBDateTimeFormat);
                    m_tableDataAdded.Rows.Add(row);

                    // 判断是否需要创建新分区
                    //CSQLPartitionMgr.Instance.MaintainWater(water.TimeCollect);
                    NewTask(() => { AddDataToDB(); });
                }
#pragma warning disable CS0168 // 声明了变量“e”,但从未使用过
                catch (Exception e)
#pragma warning restore CS0168 // 声明了变量“e”,但从未使用过
                {
                    sql.AppendFormat("update {0} set {1}={2},{3}={4},{5}={6},{7}={8},{9}={10} where {11}={12} and {13}='{14}';",
                                     CT_TableName,
                                     CN_WaterStage, water.WaterStage,
                                     CN_WaterFlow, (water.WaterFlow.HasValue ? water.WaterFlow.Value.ToString() : "null"),
                                     CN_TransType, CEnumHelper.ChannelTypeToDBStr(water.ChannelType),
                                     CN_MsgType, CEnumHelper.MessageTypeToDBStr(water.MessageType),
                                     CN_RecvDataTime, DateTimeToDBStr(water.TimeRecieved),
                                     CN_StationId, water.StationID,
                                     CN_DataTime, water.TimeCollect.ToString()
                                     );
                    if (!this.ExecuteSQLCommand(sql.ToString()))
                    {
                        return;
                    }
                    sql.Clear(); //清除以前的所有命令
                }
                ResetAll();
            }
            m_mutexDataTable.ReleaseMutex();
        }
Beispiel #14
0
        /// <summary>
        /// 异步添加数据到数据库
        /// </summary>
        /// <param name="listData"></param>
        public void AddSoilDataRange(List <CEntitySoilData> listData)
        {
            m_mutexDataTable.WaitOne(); //等待互斥量
            foreach (CEntitySoilData entity in listData)
            {
                DataRow row = m_tableDataAdded.NewRow();
                row[CN_StationId]   = entity.StationID;
                row[CN_DataTime]    = entity.DataTime.ToString(CDBParams.GetInstance().DBDateTimeFormat);
                row[CN_Voltage]     = entity.DVoltage;
                row[CN_MessageType] = CEnumHelper.MessageTypeToDBStr(entity.MessageType);
                row[CN_ChannelType] = CEnumHelper.ChannelTypeToDBStr(entity.ChannelType);

                row[CN_Voltage10]  = entity.Voltage10;
                row[CN_Moisture10] = entity.Moisture10;

                row[CN_Voltage20]  = entity.Voltage20;
                row[CN_Moisture20] = entity.Moisture20;

                row[CN_Voltage30]  = entity.Voltage30;
                row[CN_Moisture30] = entity.Moisture30;

                row[CN_Voltage40]  = entity.Voltage40;
                row[CN_Moisture40] = entity.Moisture40;

                row[CN_Voltage60]  = entity.Voltage60;
                row[CN_Moisture60] = entity.Moisture60;

                row[CN_RecvTime] = entity.reciveTime;
                row[CN_State]    = entity.state;

                m_tableDataAdded.Rows.Add(row);
            }
            if (m_tableDataAdded.Rows.Count >= CDBParams.GetInstance().AddBufferMax)
            {
                // 超过最大缓存,开线程写入数据库
                NewTask(() => { AddDataToDB(); });
            }
            else
            {
                // 没有超过缓存最大值,开启定时器进行检测,多次调用Start()会导致重新计数
                m_addTimer.Start();
            }
            m_mutexDataTable.ReleaseMutex();
        }
Beispiel #15
0
 public void AddNewRows(List <PWDData> pwdDatas)
 {
     m_mutexDataTable.WaitOne(); //等待互斥量
     foreach (PWDData pwd in pwdDatas)
     {
         DataRow row = m_tableDataAdded.NewRow();
         row[CN_StationId]    = pwd.StationID;
         row[CN_DataTime]     = pwd.TimeCollect.ToString(CDBParams.GetInstance().DBDateTimeFormat);
         row[CN_Visi1min]     = pwd.Visi1min;
         row[CN_Visi10min]    = pwd.Visi10min;
         row[CN_transtype]    = CEnumHelper.ChannelTypeToDBStr(pwd.ChannelType);
         row[CN_messagetype]  = CEnumHelper.MessageTypeToDBStr(pwd.MessageType);
         row[CN_recvdatatime] = pwd.TimeRecieved;
         row[CN_State]        = pwd.BState;
         m_tableDataAdded.Rows.Add(row);
     }
     NewTask(() => { InsertSqlBulk(m_tableDataAdded); });
     m_mutexDataTable.ReleaseMutex();
 }
Beispiel #16
0
        public bool UpdateRows(List <CEntityVoltage> voltages)
        {
            // 除主键外和站点外,其余信息随意修改
            StringBuilder sql = new StringBuilder();
            int           currentBatchCount = 0;

            for (int i = 0; i < voltages.Count; i++)
            {
                ++currentBatchCount;
                CTF_TableName = "voltage" + voltages[i].TimeCollect.Year.ToString() + voltages[i].TimeCollect.Month.ToString() + (voltages[i].TimeCollect.Day < 15 ? "A" : "B");
                sql.AppendFormat("update {0} set {1}={2},{3}={4},{5}={6},{7}={8},{9}={10} where {11}={12} and {13}='{14}';",
                                 CTF_TableName,
                                 CN_Voltage, voltages[i].Voltage,
                                 CN_TransType, CEnumHelper.ChannelTypeToDBStr(voltages[i].ChannelType),
                                 CN_MsgType, CEnumHelper.MessageTypeToDBStr(voltages[i].MessageType),
                                 CN_State, voltages[i].state,
                                 CN_RecvDataTime, DateTimeToDBStr(voltages[i].TimeRecieved),
                                 CN_StationId, voltages[i].StationID,
                                 CN_DataTime, voltages[i].TimeCollect.ToString()
                                 //    CN_VoltageID, voltages[i].VoltageID
                                 );
                //if (currentBatchCount >= CDBParams.GetInstance().UpdateBufferMax)
                //{
                //    // 更新数据库
                //    if (!this.ExecuteSQLCommand(sql.ToString()))
                //    {
                //        // 保存失败
                //        return false;
                //    }
                //    sql.Clear(); //清除以前的所有命令
                //    currentBatchCount = 0;
                //}
            }
            // 更新数据库
            if (!this.ExecuteSQLCommand(sql.ToString()))
            {
                return(false);
            }
            sql.Clear(); //清除以前的所有命令
            ResetAll();
            return(true);
        }
Beispiel #17
0
        public bool UpdateRows(List <Hydrology.Entity.CEntityWater> waters)
        {
            // 除主键外,其余信息随意修改
            StringBuilder sql = new StringBuilder();
            int           currentBatchCount = 0;

            for (int i = 0; i < waters.Count; i++)
            {
                ++currentBatchCount;
                CTF_TableName = "water" + waters[i].TimeCollect.Year.ToString() + waters[i].TimeCollect.Month.ToString() + (waters[i].TimeCollect.Day > 15 ? "B" : "A");
                sql.AppendFormat("update {0} set {1}={2},{3}={4},{5}={6},{7}={8},{9}={10},{11}={12} where {13}={14} and {15}='{16}';",
                                 CTF_TableName,
                                 CN_WaterStage, waters[i].WaterStage,
                                 CN_WaterFlow, (waters[i].WaterFlow.HasValue ? waters[i].WaterFlow.Value.ToString() : "null"),
                                 CN_TransType, CEnumHelper.ChannelTypeToDBStr(waters[i].ChannelType),
                                 CN_MsgType, CEnumHelper.MessageTypeToDBStr(waters[i].MessageType),
                                 CN_State, waters[i].state,
                                 CN_RecvDataTime, DateTimeToDBStr(waters[i].TimeRecieved),
                                 CN_StationId, waters[i].StationID,
                                 CN_DataTime, waters[i].TimeCollect.ToString()
                                 //   CN_WaterID, waters[i].WaterID
                                 );
                //if (currentBatchCount >= CDBParams.GetInstance().UpdateBufferMax)
                //{
                //    // 更新数据库
                //    if (!this.ExecuteSQLCommand(sql.ToString()))
                //    {
                //        return false;
                //    }
                //    sql.Clear(); //清除以前的所有命令
                //    currentBatchCount = 0;
                //}
            }
            // 更新数据库
            if (!this.ExecuteSQLCommand(sql.ToString()))
            {
                return(false);
            }
            sql.Clear(); //清除以前的所有命令
            ResetAll();
            return(true);
        }
Beispiel #18
0
        public void AddNewRows(List <CEntityWater> waters)
        {
            // 记录超过写入上线条,或者时间超过1分钟,就将当前的数据写入数据库
            m_mutexDataTable.WaitOne(); //等待互斥量
            string id = "";

            foreach (CEntityWater water in waters)
            {
                DataRow row = m_tableDataAdded.NewRow();
                row[CN_StationId]    = water.StationID;
                row[CN_DataTime]     = water.TimeCollect.ToString(CDBParams.GetInstance().DBDateTimeFormat);
                row[CN_WaterStage]   = water.WaterStage;
                row[CN_WaterFlow]    = water.WaterFlow;
                row[CN_MsgType]      = CEnumHelper.MessageTypeToDBStr(water.MessageType);
                row[CN_TransType]    = CEnumHelper.ChannelTypeToDBStr(water.ChannelType);
                row[CN_RecvDataTime] = water.TimeRecieved.ToString(CDBParams.GetInstance().DBDateTimeFormat);
                row[CN_State]        = water.state;
                m_tableDataAdded.Rows.Add(row);

                // 用于中游局Debug
                if (id != water.StationID)
                {
                    id = water.StationID;
                    CDBLog.Instance.AddInfo(string.Format("写入站点{0}数据到水位表", id));
                }
                // 判断是否需要创建新分区
                //CSQLPartitionMgr.Instance.MaintainWater(water.TimeCollect);
            }
            if (m_tableDataAdded.Rows.Count >= CDBParams.GetInstance().AddBufferMax)
            {
                // 如果超过最大值,写入数据库
                // NewTask(() => { AddDataToDB(); });
                NewTask(() => { InsertSqlBulk(m_tableDataAdded); });
            }
            else
            {
                // 没有超过缓存最大值,开启定时器进行检测,多次调用Start()会导致重新计数
                m_addTimer_1.Start();
            }
            m_mutexDataTable.ReleaseMutex();
        }
Beispiel #19
0
 public void AddNewRows(List <CEntityRealTime> realtimes)
 {
     // 记录超过1000条,或者时间超过1分钟,就将当前的数据写入数据库
     m_mutexDataTable.WaitOne(); //等待互斥量
     foreach (CEntityRealTime realtime in realtimes)
     {
         if (realtime.TimeDeviceGained != DateTime.MinValue)
         {
             DataRow row = m_tableDataAdded.NewRow();
             row[CN_CName]         = realtime.StrStationName;
             row[CN_StationId]     = realtime.StrStationID;
             row[CN_StationType]   = realtime.EIStationType;
             row[CN_DataTime]      = realtime.TimeDeviceGained.ToString(CDBParams.GetInstance().DBDateTimeFormat);
             row[CN_YesterdayRain] = realtime.LastDayRainFall;
             row[CN_TodayRain]     = realtime.DDayRainFall;
             row[CN_PeriodRain]    = realtime.DPeriodRain;
             row[CN_WaterStage]    = realtime.DWaterYield;
             row[CN_WaterFlow]     = realtime.DWaterFlowActual;
             row[CN_Voltage]       = realtime.Dvoltage;
             row[CN_DataState]     = realtime.ERTDState;
             row[CN_MsgType]       = CEnumHelper.MessageTypeToDBStr(realtime.EIMessageType);
             row[CN_TransType]     = CEnumHelper.ChannelTypeToDBStr(realtime.EIChannelType);
             m_tableDataAdded.Rows.Add(row);
         }
         // 判断是否需要创建新分区
         //CSQLPartitionMgr.Instance.MaintainVoltage(voltage.TimeCollect);
     }
     if (m_tableDataAdded.Rows.Count >= CDBParams.GetInstance().AddBufferMax)
     {
         // 如果超过最大值,写入数据库
         // NewTask(() => { AddDataToDB(); });
         NewTask(() => { InsertSqlBulk(m_tableDataAdded); });
     }
     else
     {
         // 没有超过缓存最大值,开启定时器进行检测,多次调用Start()会导致重新计数
         m_addTimer_1.Start();
     }
     m_mutexDataTable.ReleaseMutex();
 }
Beispiel #20
0
        public void AddNewRows(List <CEntityWater> waters)
        {
            // 记录超过写入上线条,或者时间超过1分钟,就将当前的数据写入数据库
            m_mutexDataTable.WaitOne(); //等待互斥量
                                        //string id = "";

            foreach (CEntityWater water in waters)
            {
                DataRow row = m_tableDataAdded.NewRow();
                row[CN_StationId]    = water.StationID;
                row[CN_DataTime]     = water.TimeCollect.ToString(CDBParams.GetInstance().DBDateTimeFormat);
                row[CN_WaterStage]   = water.WaterStage;
                row[CN_WaterFlow]    = water.WaterFlow;
                row[CN_MsgType]      = CEnumHelper.MessageTypeToDBStr(water.MessageType);
                row[CN_TransType]    = CEnumHelper.ChannelTypeToDBStr(water.ChannelType);
                row[CN_RecvDataTime] = water.TimeRecieved.ToString(CDBParams.GetInstance().DBDateTimeFormat);
                row[CN_State]        = water.state;
                m_tableDataAdded.Rows.Add(row);
            }
            NewTask(() => { InsertSqlBulk(m_tableDataAdded); });
            m_mutexDataTable.ReleaseMutex();
        }
Beispiel #21
0
        public void AddNewRows_1(List <CEntityVoltage> voltages)
        {
            // 记录超过1000条,或者时间超过1分钟,就将当前的数据写入数据库
            m_mutexDataTable.WaitOne(); //等待互斥量
            foreach (CEntityVoltage voltage in voltages)
            {
                DataRow row = m_tableDataAdded.NewRow();
                row[CN_StationId]    = voltage.StationID;
                row[CN_DataTime]     = voltage.TimeCollect.ToString(CDBParams.GetInstance().DBDateTimeFormat);
                row[CN_MsgType]      = CEnumHelper.MessageTypeToDBStr(voltage.MessageType);
                row[CN_TransType]    = CEnumHelper.ChannelTypeToDBStr(voltage.ChannelType);
                row[CN_RecvDataTime] = voltage.TimeRecieved.ToString(CDBParams.GetInstance().DBDateTimeFormat);
                row[CN_Voltage]      = voltage.Voltage;
                row[CN_Voltage]      = voltage.state;
                m_tableDataAdded.Rows.Add(row);
                // 判断是否需要创建新分区
                //CSQLPartitionMgr.Instance.MaintainVoltage(voltage.TimeCollect);
            }

            // 如果超过最大值,写入数据库
            NewTask(() => { AddDataToDB(); });

            m_mutexDataTable.ReleaseMutex();
        }
Beispiel #22
0
        public void AddNewRow_2(CEntityRealTime realtime)
        {
            if (IsInDB(realtime))
            {
                // 如果数据库中有,就判断是否为最新数据
                //if (IsNew(realtime))
                //{

                //}
                m_mutexDataTable.WaitOne(); //等待互斥量

                DataRow row = m_tableDataUpdated.NewRow();
                row[CN_CName]         = realtime.StrStationName;
                row[CN_StationId]     = realtime.StrStationID;
                row[CN_StationType]   = realtime.EIStationType;
                row[CN_DataTime]      = realtime.TimeDeviceGained.ToString(CDBParams.GetInstance().DBDateTimeFormat);
                row[CN_YesterdayRain] = realtime.LastDayRainFall;
                row[CN_TodayRain]     = realtime.DDayRainFall;
                row[CN_PeriodRain]    = realtime.DPeriodRain;
                row[CN_WaterStage]    = realtime.DWaterYield;
                row[CN_WaterFlow]     = realtime.DWaterFlowActual;
                row[CN_Voltage]       = realtime.Dvoltage;
                row[CN_DataState]     = realtime.ERTDState;
                row[CN_MsgType]       = CEnumHelper.MessageTypeToDBStr(realtime.EIMessageType);
                row[CN_TransType]     = CEnumHelper.ChannelTypeToDBStr(realtime.EIChannelType);
                m_tableDataUpdated.Rows.Add(row);

                m_mutexDataTable.ReleaseMutex();

                // 判断是否需要创建新分区
                //CSQLPartitionMgr.Instance.MaintainVoltage(voltage.TimeCollect);
                if (m_tableDataUpdated.Rows.Count >= CDBParams.GetInstance().AddBufferMax)
                {
                    // 如果超过最大值,写入数据库
                    NewTask(() => { AddDataToDB(); });
                }
                else
                {
                    // 没有超过缓存最大值,开启定时器进行检测,多次调用Start()会导致重新计数
                    m_updateTimer.Start();
                }
            }
            else
            {
                // 如果数据库中没有,就将当前的数据写入数据库
                m_mutexDataTable.WaitOne(); //等待互斥量
                DataRow row = m_tableDataAdded.NewRow();
                row[CN_CName]         = realtime.StrStationName;
                row[CN_StationId]     = realtime.StrStationID;
                row[CN_StationType]   = realtime.EIStationType;
                row[CN_DataTime]      = realtime.TimeDeviceGained.ToString(CDBParams.GetInstance().DBDateTimeFormat);
                row[CN_YesterdayRain] = realtime.LastDayRainFall;
                row[CN_TodayRain]     = realtime.DDayRainFall;
                row[CN_PeriodRain]    = realtime.DPeriodRain;
                row[CN_WaterStage]    = realtime.DWaterYield;
                row[CN_WaterFlow]     = realtime.DWaterFlowActual;
                row[CN_Voltage]       = realtime.Dvoltage;
                row[CN_DataState]     = realtime.ERTDState;
                row[CN_MsgType]       = CEnumHelper.MessageTypeToDBStr(realtime.EIMessageType);
                row[CN_TransType]     = CEnumHelper.ChannelTypeToDBStr(realtime.EIChannelType);
                m_tableDataAdded.Rows.Add(row);

                m_mutexDataTable.ReleaseMutex();

                // 判断是否需要创建新分区
                //CSQLPartitionMgr.Instance.MaintainVoltage(voltage.TimeCollect);
                if (m_tableDataAdded.Rows.Count >= CDBParams.GetInstance().AddBufferMax)
                {
                    // 如果超过最大值,写入数据库
                    NewTask(() => { AddDataToDB(); });
                }
                else
                {
                    // 没有超过缓存最大值,开启定时器进行检测,多次调用Start()会导致重新计数
                    m_addTimer.Start();
                }
            }
        }