public CDataGridViewSoilData()
            : base()
        {
            // 设定标题栏,默认有个隐藏列
            this.Header = new string[]
            {
                CS_StationID, CS_StationName, CS_TimeCollected, CS_Depth,
                CS_NTU, CS_ppm, CS_Temperature, CS_Conductivity, CS_Salinity, CS_Batt,
                CS_ReciveTime
            };
            //base.HideColomns = new int[] { 8, 9, 12, 13, 15 };
            //11.12
            // this.BPartionPageEnable = false;

            // 设置一页的数量
            this.PageRowCount = CDBParams.GetInstance().UIPageRowCount;

            // 初始化成员变量
            m_bIsEditable                     = false;
            m_listAdded                       = new List <CEntitySoilData>();
            m_listUpdated                     = new List <CEntitySoilData>();
            m_listDeleteSoilData              = new List <long>();
            m_listDeleteSoilDatas_StationId   = new List <String>();
            m_listDeleteSoilDatas_StationDate = new List <String>();
            //this.Columns[2].Width = 125;
            //this.Columns[2].Width = 125;
        }
        //public bool DeleteRange(List<long> listIds)
        //{
        //// 删除多行数据
        //StringBuilder sql = new StringBuilder();
        //int currentBatchCount = 0;
        //for (int i = 0; i < listIds.Count; i++)
        //{
        //    ++currentBatchCount;
        //    sql.AppendFormat("delete from {0} where {1}={2};",
        //        CT_TableName,
        //        CN_RecordID, listIds[i].ToString()
        //    );
        //    if (currentBatchCount >= CDBParams.GetInstance().UpdateBufferMax)
        //    {
        //        // 更新数据库
        //        if (!this.ExecuteSQLCommand(sql.ToString()))
        //        {
        //            return false;
        //        }
        //        sql.Clear(); //清除以前的所有命令
        //        currentBatchCount = 0;
        //    }
        //} // end of for
        //// 如何考虑线程同异步
        //return ExecuteSQLCommand(sql.ToString());
        //}

        public bool DeleteRange(List <CEntityWaterFlowMap> listEntity)
        {
            // 删除多行数据
            StringBuilder sql = new StringBuilder();
            int           currentBatchCount = 0;

            for (int i = 0; i < listEntity.Count; i++)
            {
                ++currentBatchCount;
                sql.AppendFormat("delete from {0} where {1}={2} and {3}='{4}' and {5}={6};",
                                 CT_TableName,
                                 CN_StationID, listEntity[i].StationID,
                                 CN_BGTM, listEntity[i].BGTM,
                                 CN_PTNO, listEntity[i].PTNO
                                 );
                if (currentBatchCount >= CDBParams.GetInstance().UpdateBufferMax)
                {
                    // 更新数据库
                    if (!this.ExecuteSQLCommand(sql.ToString()))
                    {
                        return(false);
                    }
                    sql.Clear(); //清除以前的所有命令
                    currentBatchCount = 0;
                }
            } // end of for
            // 如何考虑线程同异步
            return(ExecuteSQLCommand(sql.ToString()));
        }
        public bool DeleteLine(CEntityWaterFlowMap Entity)
        {
            // 删除多行数据
            StringBuilder sql = new StringBuilder();
            int           currentBatchCount = 0;

            //for (int i = 0; i < Entity.Count; i++)
            //{
            ++currentBatchCount;
            //   sql.AppendFormat("delete from {0} where {1}={2} and {3}='{4}';",
            sql.AppendFormat("delete from {0} where {1}={2};",
                             CT_TableName,
                             CN_StationID, Entity.StationID
                             //CN_BGTM, Entity.BGTM
                             );
            if (currentBatchCount >= CDBParams.GetInstance().UpdateBufferMax)
            {
                // 更新数据库
                if (!this.ExecuteSQLCommand(sql.ToString()))
                {
                    return(false);
                }
                sql.Clear(); //清除以前的所有命令
                currentBatchCount = 0;
            }
            //} // end of for
            // 如何考虑线程同异步
            return(ExecuteSQLCommand(sql.ToString()));
        }
Пример #4
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();
        }
Пример #5
0
        private List <CEntitySoilData> m_listEntityRTD; //与表格内容一致的RTD内容
        #endregion

        public CDataGridViewSoilRTD()
            : base()
        {
            m_listEntityRTD = new List <CEntitySoilData>();
            // 设定标题栏,默认有个隐藏列
            this.Header = new string[]
            {
                CS_StationID, CS_StationName, CS_StationType, CS_TimeCollected, CS_MessageType,
                CS_ChannelType, CS_V10, CS_M10, CS_V20, CS_M20, CS_V30, CS_M30, CS_V40, CS_M40, CS_V60, CS_M60
            };
            // 隐藏延迟列,串口列
            base.HideColomns = new int[] { 4, 10, 11, 14, 15 };
            // 设置一页的数量
            this.PageRowCount = CDBParams.GetInstance().UIPageRowCount;
            //this.PageRowCount = 300;   //  默认一页显示数量

            //DataGridViewNumericUpDownColumn stationId = new DataGridViewNumericUpDownColumn()
            //{
            //    Minimum = 0,
            //    Maximum = 65537,
            //    DecimalPlaces = 0 /*好像是设置小数点后面的位数*/

            //};
            //this.SetColumnEditStyle(1, stationId);

            // 绑定消息,用于按照ID排序
            //this.SortCompare += new DataGridViewSortCompareEventHandler(this.EHSortCompare);
            //this.CellValueNeeded += new DataGridViewCellValueEventHandler(this.EHCellValueNeeded);
            //this.sort

            // 设置数据类型
            //this.Columns[CS_StationId].ValueType = typeof(int);
            // m_dataTable.Columns[CS_StationId].DataType = System.Type.GetType("System.Int32");
        }
        /// <summary>
        /// 删除站点的
        /// </summary>
        /// <param name="listStationId"></param>
        /// <returns></returns>
        public bool DeleteSoilStationRange(List <string> listStationId)
        {
            if (listStationId.Count <= 0)
            {
                return(true);
            }
            // 删除某条雨量记录
            StringBuilder sql = new StringBuilder();
            int           currentBatchCount = 0;

            for (int i = 0; i < listStationId.Count; i++)
            {
                ++currentBatchCount;
                sql.AppendFormat("delete from {0} where {1}={2};",
                                 CT_TableName,
                                 CN_StationId, listStationId[i]
                                 );
                if (currentBatchCount >= CDBParams.GetInstance().UpdateBufferMax)
                {
                    // 更新数据库
                    if (!this.ExecuteSQLCommand(sql.ToString()))
                    {
                        // 保存失败
                        return(false);
                    }
                    sql.Clear(); //清除以前的所有命令
                    currentBatchCount = 0;
                }
            }
            if (!ExecuteSQLCommand(sql.ToString()))
            {
                return(false);
            }
            return(true);
        }
Пример #7
0
        public bool DeleteRows(List <String> waters_StationId, List <String> waters_StationDate)
        {
            // 删除某条水位记录
            StringBuilder sql = new StringBuilder();
            int           currentBatchCount = 0;

            for (int i = 0; i < waters_StationId.Count; i++)
            {
                ++currentBatchCount;
                CTF_TableName = "water" + DateTime.Parse(waters_StationDate[i]).Year.ToString() + DateTime.Parse(waters_StationDate[i]).Month.ToString() + (DateTime.Parse(waters_StationDate[i]).Day > 15 ? "B" : "A");
                sql.AppendFormat("delete from {0} where {1}={2} and {3} = '{4}';",
                                 CTF_TableName,
                                 CN_StationId, waters_StationId[i].ToString(),
                                 CN_DataTime, waters_StationDate[i].ToString()
                                 );
                if (currentBatchCount >= CDBParams.GetInstance().UpdateBufferMax)
                {
                    // 更新数据库
                    if (!this.ExecuteSQLCommand(sql.ToString()))
                    {
                        return(false);
                    }
                    sql.Clear(); //清除以前的所有命令
                    currentBatchCount = 0;
                }
            }
            if (!ExecuteSQLCommand(sql.ToString()))
            {
                return(false);
            }
            ResetAll();
            // 如何考虑线程同异步
            return(true);
        }
Пример #8
0
        public CSQLFsfx() : base()
        {
            // 为数据表添加列
            m_tableDataAdded.Columns.Add(CN_StationId);
            m_tableDataAdded.Columns.Add(CN_DataTime);


            m_tableDataAdded.Columns.Add(CN_shfx);
            m_tableDataAdded.Columns.Add(CN_shfs);
            m_tableDataAdded.Columns.Add(CN_yxszdshfx);
            m_tableDataAdded.Columns.Add(CN_yxszdshfs);
            m_tableDataAdded.Columns.Add(CN_maxTime);
            m_tableDataAdded.Columns.Add(CN_avg2fx);
            m_tableDataAdded.Columns.Add(CN_avg2fs);
            m_tableDataAdded.Columns.Add(CN_avg10fx);
            m_tableDataAdded.Columns.Add(CN_avg10fs);
            m_tableDataAdded.Columns.Add(CN_max10fx);
            m_tableDataAdded.Columns.Add(CN_max10fs);
            m_tableDataAdded.Columns.Add(CN_max10tm);



            m_mutexWriteToDB      = CDBMutex.Mutex_TB_FSFX;
            m_addTimer_1          = new System.Timers.Timer();
            m_addTimer_1.Elapsed += new System.Timers.ElapsedEventHandler(EHTimer_1);
            m_addTimer_1.Enabled  = false;
            m_addTimer_1.Interval = CDBParams.GetInstance().AddToDbDelay;
        }
Пример #9
0
        public CDataGridViewRTD()
            : base()
        {
            m_listEntityRTD = new List <CEntityRealTime>();
            // 设定标题栏,默认有个隐藏列
            this.Header = new string[]
            {
                CS_StationName, CS_StationId, CS_TimeCollected, CS_SHFX, CS_DelayTime, CS_SHFS, CS_avg10fx,
                CS_avg10fs, CS_Visi1min, CS_Visi10min, CS_Depth, CS_Tmp, CS_Ntu, CS_Cndcty, CS_Salinity,
                CS_Volatage
            };
            // 隐藏延迟列,串口列
            //base.ColumnHeadersHeight = 50;
            base.HideColomns = new int[] { 4 };
            // 设置一页的数量
            this.PageRowCount = CDBParams.GetInstance().UIPageRowCount;
            string path = string.Empty;

            time1 = 90;
            time2 = 150;
            TimeXmlHelper.ReadFromXML(out time1, out time2);

            this.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

            //RecalculateHeaderSize();
        }
Пример #10
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();
 }
Пример #11
0
 public void AddNewRows(List <FSFXData> fsfxDatas)
 {
     m_mutexDataTable.WaitOne(); //等待互斥量
     foreach (FSFXData fsfx in fsfxDatas)
     {
         DataRow row = m_tableDataAdded.NewRow();
         row[CN_StationId] = fsfx.StationID;
         row[CN_DataTime]  = fsfx.TimeCollect.ToString(CDBParams.GetInstance().DBDateTimeFormat);
         row[CN_shfx]      = fsfx.shfx;
         row[CN_shfs]      = fsfx.shfs;
         row[CN_yxszdshfx] = fsfx.yxszdshfx;
         row[CN_yxszdshfs] = fsfx.yxszdshfs;
         row[CN_maxTime]   = fsfx.maxTime;
         row[CN_avg2fx]    = fsfx.avg2fx;
         row[CN_avg2fs]    = fsfx.avg2fs;
         row[CN_avg10fx]   = fsfx.avg10fx;
         row[CN_avg10fs]   = fsfx.avg10fs;
         row[CN_max10fx]   = fsfx.max10fx;
         row[CN_max10fs]   = fsfx.max10fs;
         row[CN_max10tm]   = fsfx.max10tm;
         m_tableDataAdded.Rows.Add(row);
     }
     NewTask(() => { InsertSqlBulk(m_tableDataAdded); });
     m_mutexDataTable.ReleaseMutex();
 }
Пример #12
0
        // 将Map中由key指定的DataTable,从startRow开始返回界面最大行数的集合
        private List <CEntityEva> CopyDataToList(int key, int startRow)
        {
            List <CEntityEva> result = new List <CEntityEva>();
            // 取最小值 ,保证不越界
            int       endRow = Math.Min(m_mapDataTable[key].Rows.Count, startRow + CDBParams.GetInstance().UIPageRowCount);
            DataTable table  = m_mapDataTable[key];

            for (; startRow < endRow; ++startRow)
            {
                CEntityEva Eva = new CEntityEva();
                Eva.StationID   = table.Rows[startRow][CN_StationId].ToString();
                Eva.TimeCollect = DateTime.Parse(table.Rows[startRow][CN_DataTime].ToString());
                if (!table.Rows[startRow][CN_Temp].ToString().Equals(""))
                {
                    Eva.Temperature = Decimal.Parse(table.Rows[startRow][CN_Temp].ToString());
                }
                if (!table.Rows[startRow][CN_Eva].ToString().Equals(""))
                {
                    Eva.Eva = Decimal.Parse(table.Rows[startRow][CN_Eva].ToString());
                }
                if (!table.Rows[startRow][CN_Voltage].ToString().Equals(""))
                {
                    Eva.Voltage = Decimal.Parse(table.Rows[startRow][CN_Voltage].ToString());
                }
                if (!table.Rows[startRow][CN_Rain].ToString().Equals(""))
                {
                    Eva.Rain = Decimal.Parse(table.Rows[startRow][CN_Rain].ToString());
                }
                Eva.type = table.Rows[startRow][CN_ACT].ToString();
                Eva.act  = table.Rows[startRow][CN_ACT].ToString();
                result.Add(Eva);
            }
            return(result);
        }
Пример #13
0
        public CSQLWater()
            : base()
        {
            m_listDelRows    = new List <long>();
            m_listUpdateRows = new List <CEntityWater>();
            // 为数据表添加列
            m_tableDataAdded.Columns.Add(CN_StationId);
            //  m_tableDataAdded.Columns.Add(CN_WaterID);
            m_tableDataAdded.Columns.Add(CN_DataTime);
            m_tableDataAdded.Columns.Add(CN_RecvDataTime);
            m_tableDataAdded.Columns.Add(CN_WaterStage);
            m_tableDataAdded.Columns.Add(CN_WaterFlow);
            m_tableDataAdded.Columns.Add(CN_TransType);
            m_tableDataAdded.Columns.Add(CN_MsgType);
            m_tableDataAdded.Columns.Add(CN_State);

            // 初始化互斥量
            m_mutexWriteToDB = CDBMutex.Mutex_TB_Water;

            m_addTimer_1          = new System.Timers.Timer();
            m_addTimer_1.Elapsed += new System.Timers.ElapsedEventHandler(EHTimer_1);
            m_addTimer_1.Enabled  = false;
            m_addTimer_1.Interval = CDBParams.GetInstance().AddToDbDelay;
            if (XmlHelper.urlDic == null || XmlHelper.urlDic.Count == 0)
            {
                XmlHelper.getXMLInfo();
            }

            urlPrefix = XmlHelper.urlDic["ip"];
        }
Пример #14
0
        /// <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);
            }
        }
        public bool AddRange(List <CEntityWaterFlowMap> listEntitys)
        {
            m_mutexDataTable.WaitOne(); //等待互斥量
            foreach (CEntityWaterFlowMap entity in listEntitys)
            {
                DataRow row = m_tableDataAdded.NewRow();
                //row[CN_StationID] = entity.StationID;
                //row[]=
                //row[CN_WaterStage] = entity.WaterStage;
                //row[CN_WaterFlow] = entity.WaterFlow;
                row[CN_StationID] = entity.StationID;
                // entity.BGTM = Convert.ToDateTime("2010-06-06");
                row[CN_BGTM]  = entity.BGTM.ToString(CDBParams.GetInstance().DBDateTimeFormat);
                row[CN_PTNO]  = entity.PTNO;
                row[CN_ZR]    = entity.ZR;
                row[CN_Q1]    = entity.Q1;
                row[CN_Q2]    = entity.Q2;
                row[CN_Q3]    = entity.Q3;
                row[CN_Q4]    = entity.Q4;
                row[CN_Q5]    = entity.Q5;
                row[CN_Q6]    = entity.Q6;
                row[CN_currQ] = entity.currQ;

                m_tableDataAdded.Rows.Add(row);
                if (m_tableDataAdded.Rows.Count >= CDBParams.GetInstance().AddBufferMax)
                {
                    // 如果超过最大值,写入数据库
                    m_mutexDataTable.ReleaseMutex();
                    AddDataToDB();
                    m_mutexDataTable.WaitOne();
                }
            }
            m_mutexDataTable.ReleaseMutex();
            return(AddDataToDB());
        }
        // 添加新列
        public void AddNewRow(CEntityWaterFlowMap entity)
        {
            // 记录超过1000条,或者时间超过1分钟,就将当前的数据写入数据库
            m_mutexDataTable.WaitOne(); //等待互斥量
            DataRow row = m_tableDataAdded.NewRow();

            //row[CN_StationID] = entity.StationID;
            //row[CN_WaterStage] = entity.WaterStage;
            //row[CN_WaterFlow] = entity.WaterFlow;
            row[CN_StationID] = entity.StationID;
            row[CN_BGTM]      = entity.BGTM.ToString(CDBParams.GetInstance().DBDateTimeFormat);
            row[CN_PTNO]      = entity.PTNO;
            row[CN_ZR]        = entity.ZR;
            row[CN_Q1]        = entity.Q1;
            row[CN_Q2]        = entity.Q2;
            row[CN_Q3]        = entity.Q3;
            row[CN_Q4]        = entity.Q4;
            row[CN_Q5]        = entity.Q5;
            row[CN_Q6]        = entity.Q6;
            row[CN_currQ]     = entity.currQ;
            m_tableDataAdded.Rows.Add(row);
            if (m_tableDataAdded.Rows.Count >= CDBParams.GetInstance().AddBufferMax)
            {
                // 如果超过最大值,写入数据库
                Task task = new Task(() => { AddDataToDB(); });
                task.Start();
            }
            else
            {
                // 没有超过缓存最大值,开启定时器进行检测,多次调用Start()会导致重新计数
                m_addTimer.Start();
            }
            m_mutexDataTable.ReleaseMutex();
        }
Пример #17
0
        private List <CEntityTSWater> CopyDataToList(int key, int startRow)
        {
            List <CEntityTSWater> result = new List <CEntityTSWater>();
            // 取最小值 ,保证不越界
            int       endRow = Math.Min(m_mapDataTable[key].Rows.Count, startRow + CDBParams.GetInstance().UIPageRowCount);
            DataTable table  = m_mapDataTable[key];

            for (; startRow < endRow; ++startRow)
            {
                CEntityTSWater water = new CEntityTSWater();
                // water.WaterID = long.Parse(table.Rows[startRow][CN_WaterID].ToString());
                water.StationID   = table.Rows[startRow][CN_StationId].ToString();
                water.TimeCollect = DateTime.Parse(table.Rows[startRow][CN_DataTime].ToString());
                //水位
                if (!table.Rows[startRow][CN_WaterStage].ToString().Equals(""))
                {
                    water.WaterStage = Decimal.Parse(table.Rows[startRow][CN_WaterStage].ToString());
                }
                else
                {
                    //11.12
                    water.WaterStage = -9999;
                }
                //流量
                water.TimeRecieved = DateTime.Parse(table.Rows[startRow][CN_RecvDataTime].ToString());
                water.ChannelType  = CEnumHelper.DBStrToChannelType(table.Rows[startRow][CN_TransType].ToString());
                water.MessageType  = CEnumHelper.DBStrToMessageType(table.Rows[startRow][CN_MsgType].ToString());
                result.Add(water);
            }
            return(result);
        }
        // 添加新列
        public void AddNewRow(CEntityWarningInfo entity)
        {
            // 记录超过1000条,或者时间超过1分钟,就将当前的数据写入数据库
            m_mutexDataTable.WaitOne(); //等待互斥量
            DataRow row = m_tableDataAdded.NewRow();

            row[CN_DataTime]   = entity.DataTime;
            row[CN_InfoDetail] = entity.InfoDetail;
            row[CN_InfoDetail] = entity.InfoDetail;
            if (entity.WarningInfoCodeType.HasValue)
            {
                row[CN_ErroCode] = CEnumHelper.WarningCodeTypeToDBStr(entity.WarningInfoCodeType.Value);
            }
            else
            {
                row[CN_ErroCode] = null;
            }
            row[CN_StationID] = entity.StrStationId.ToString();
            m_tableDataAdded.Rows.Add(row);
            if (m_tableDataAdded.Rows.Count >= CDBParams.GetInstance().AddBufferMax)
            {
                // 如果超过最大值,写入数据库
                base.NewTask(() => { AddDataToDB(); });
            }
            else
            {
                // 没有超过缓存最大值,开启定时器进行检测,多次调用Start()会导致重新计数
                m_addTimer.Start();
            }
            m_mutexDataTable.ReleaseMutex();
        }
        public CDataGridViewSoilData()
            : base()
        {
            // 设定标题栏,默认有个隐藏列
            this.Header = new string[]
            {
                CS_StationID, CS_StationName, CS_TimeCollected, CS_Voltage,
                CS_V10, CS_M10, CS_V20, CS_M20, CS_V30, CS_M30,
                CS_V40, CS_M40, CS_V60, CS_M60,
                CS_MsgType, CS_ChannelType, CS_ReciveTime
            };
            base.HideColomns = new int[] { 8, 9, 12, 13, 15 };
            //11.12
            // this.BPartionPageEnable = false;

            // 设置一页的数量
            this.PageRowCount = CDBParams.GetInstance().UIPageRowCount;

            // 初始化成员变量
            m_bIsEditable                     = false;
            m_listAdded                       = new List <CEntitySoilData>();
            m_listUpdated                     = new List <CEntitySoilData>();
            m_listDeleteSoilData              = new List <long>();
            m_listDeleteSoilDatas_StationId   = new List <String>();
            m_listDeleteSoilDatas_StationDate = new List <String>();
            //this.Columns[2].Width = 125;
            //this.Columns[2].Width = 125;
        }
Пример #20
0
        public CSQLDEva()
            : base()
        {
            m_listDelRows    = new List <long>();
            m_listUpdateRows = new List <CEntityEva>();
            // 为数据表添加列
            m_tableDataAdded.Columns.Add(CN_StationId);
            m_tableDataAdded.Columns.Add(CN_DataTime);

            m_tableDataAdded.Columns.Add(CN_Temp);
            m_tableDataAdded.Columns.Add(CN_Eva);
            m_tableDataAdded.Columns.Add(CN_Rain);
            m_tableDataAdded.Columns.Add(CN_Rain8);
            m_tableDataAdded.Columns.Add(CN_Rain20);

            //m_tableDataAdded.Columns.Add(CN_TransType);

            // 分页查询相关
            m_strStaionId = null;

            // 初始化互斥量
            m_mutexWriteToDB = CDBMutex.Mutex_TB_DEva;

            m_addTimer_1          = new System.Timers.Timer();
            m_addTimer_1.Elapsed += new System.Timers.ElapsedEventHandler(EHTimer_1);
            m_addTimer_1.Enabled  = false;
            m_addTimer_1.Interval = CDBParams.GetInstance().AddToDbDelay;
        }
Пример #21
0
        public bool DeleteRows(List <CEntityRealTime> realtimes)
        {
            // 删除某条实时记录
            StringBuilder sql = new StringBuilder();
            int           currentBatchCount = 0;

            foreach (CEntityRealTime realtime in realtimes)
            {
                ++currentBatchCount;
                sql.AppendFormat("delete from {0} where {1}={2} and {3}='{4}';",
                                 CT_TableName,
                                 CN_StationId, realtime.StrStationID,
                                 CN_CName, realtime.StrStationName
                                 );
                if (currentBatchCount >= CDBParams.GetInstance().UpdateBufferMax)
                {
                    // 更新数据库
                    if (!this.ExecuteSQLCommand(sql.ToString()))
                    {
                        // 保存失败
                        return(false);
                    }
                    sql.Clear(); //清除以前的所有命令
                    currentBatchCount = 0;
                }
            }
            // 如何考虑线程同异步
            if (!ExecuteSQLCommand(sql.ToString()))
            {
                return(false);
            }
            ResetAll();
            return(true);
        }
Пример #22
0
        public List <CEntityEva> GetPageData(int pageIndex, bool irefresh)
        {
            if (pageIndex <= 0 || m_startTime == null || m_endTime == null || m_strStaionId == null)
            {
                return(new List <CEntityEva>());
            }
            // 获取某一页的数据,判断所需页面是否在内存中有值
            int startIndex = (pageIndex - 1) * CDBParams.GetInstance().UIPageRowCount + 1;
            int key        = (int)(startIndex / CDBParams.GetInstance().DBPageRowCount) + 1; //对应于数据库中的索引
            int startRow   = startIndex - (key - 1) * CDBParams.GetInstance().DBPageRowCount - 1;

            Debug.WriteLine("Eva startIndex;{0} key:{1} startRow:{2}", startIndex, key, startRow);
            // 判断MAP中是否有值
            if (m_mapDataTable.ContainsKey(key) && !irefresh)
            {
                // 从内存中读取
                return(CopyDataToList(key, startRow));
            }
            else if (m_mapDataTable.ContainsKey(key) && irefresh)
            {
                m_mapDataTable.Remove(key);
                // 从数据库中查询
                int    topcount = key * CDBParams.GetInstance().DBPageRowCount;
                int    rowidmim = topcount - CDBParams.GetInstance().DBPageRowCount;
                string sql      = " select * from ( " +
                                  "select top " + topcount.ToString() + " row_number() over( order by " + CN_DataTime + " ) as " + CN_RowId + ",* " +
                                  "from " + CT_TableName + " " +
                                  "where " + CN_StationId + "=" + m_strStaionId.ToString() + " " +
                                  "and " + TimeSelectString + CN_DataTime + " between " + DateTimeToDBStr(m_startTime) +
                                  "and " + DateTimeToDBStr(m_endTime) +
                                  ") as tmp1 " +
                                  "where " + CN_RowId + ">" + rowidmim.ToString() +
                                  " order by " + CN_DataTime + " DESC";
                SqlDataAdapter adapter      = new SqlDataAdapter(sql, CDBManager.GetInstacne().GetConnection());
                DataTable      dataTableTmp = new DataTable();
                adapter.Fill(dataTableTmp);
                m_mapDataTable.Add(key, dataTableTmp);
                return(CopyDataToList(key, startRow));
            }
            else
            {
                // 从数据库中查询
                int    topcount = key * CDBParams.GetInstance().DBPageRowCount;
                int    rowidmim = topcount - CDBParams.GetInstance().DBPageRowCount;
                string sql      = " select * from ( " +
                                  "select top " + topcount.ToString() + " row_number() over( order by " + CN_DataTime + " ) as " + CN_RowId + ",* " +
                                  "from " + CT_TableName + " " +
                                  "where " + CN_StationId + "=" + m_strStaionId.ToString() + " " +
                                  "and " + TimeSelectString + CN_DataTime + " between " + DateTimeToDBStr(m_startTime) +
                                  "and " + DateTimeToDBStr(m_endTime) +
                                  ") as tmp1 " +
                                  "where " + CN_RowId + ">" + rowidmim.ToString() +
                                  " order by " + CN_DataTime + " DESC";
                SqlDataAdapter adapter      = new SqlDataAdapter(sql, CDBManager.GetInstacne().GetConnection());
                DataTable      dataTableTmp = new DataTable();
                adapter.Fill(dataTableTmp);
                m_mapDataTable.Add(key, dataTableTmp);
                return(CopyDataToList(key, startRow));
            }
        }
Пример #23
0
        public bool DeleteRows(List <String> Evas_StationId, List <String> Evas_StationDate)
        {
            // 删除某条雨量记录
            StringBuilder sql = new StringBuilder();
            int           currentBatchCount = 0;

            for (int i = 0; i < Evas_StationId.Count; i++)
            {
                ++currentBatchCount;
                sql.AppendFormat("delete from {0} where {1}={2} and {3}='{4}';",
                                 CT_TableName,
                                 CN_StationId, Evas_StationId[i].ToString(),
                                 CN_DataTime, Evas_StationDate[i].ToString()
                                 );
                if (currentBatchCount >= CDBParams.GetInstance().UpdateBufferMax)
                {
                    // 更新数据库
                    if (!this.ExecuteSQLCommand(sql.ToString()))
                    {
                        // 保存失败
                        return(false);
                    }
                    sql.Clear(); //清除以前的所有命令
                    currentBatchCount = 0;
                }
            }
            // 如何考虑线程同异步
            if (!ExecuteSQLCommand(sql.ToString()))
            {
                return(false);
            }
            ResetAll();
            return(true);
        }
Пример #24
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();
        }
Пример #25
0
 public void AddNewRows(List <CEntityEva> sanilities)
 {
     // 记录超过1000条,或者时间超过1分钟,就将当前的数据写入数据库
     m_mutexDataTable.WaitOne(); //等待互斥量
     foreach (CEntityEva Eva in sanilities)
     {
         DataRow row = m_tableDataAdded.NewRow();
         row[CN_StationId] = Eva.StationID;
         row[CN_DataTime]  = Eva.TimeCollect.ToString(CDBParams.GetInstance().DBDateTimeFormat);
         row[CN_Temp]      = Eva.Temperature;
         row[CN_Eva]       = Eva.Eva;
         row[CN_Rain]      = Eva.Rain;
         row[CN_Rain8]     = Eva.P8;
         row[CN_Rain20]    = Eva.P20;
         m_tableDataAdded.Rows.Add(row);
     }
     if (m_tableDataAdded.Rows.Count >= CDBParams.GetInstance().AddBufferMax)
     {
         // 如果超过最大值,写入数据库
         NewTask(() => { InsertSqlBulk(m_tableDataAdded); });
     }
     else
     {
         // 没有超过缓存最大值,开启定时器进行检测,多次调用Start()会导致重新计数
         m_addTimer_1.Start();
     }
     m_mutexDataTable.ReleaseMutex();
 }
Пример #26
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();
            }
        }
Пример #27
0
        public CSQLCurrenData() : base()
        {
            m_listDelRows    = new List <long>();
            m_listUpdateRows = new List <CEntityRealTime>();
            // 为数据表添加列
            m_tableDataAdded.Columns.Add(CN_CName);
            m_tableDataAdded.Columns.Add(CN_StationId);
            m_tableDataAdded.Columns.Add(CN_StationType);
            m_tableDataAdded.Columns.Add(CN_YesterdayRain);
            m_tableDataAdded.Columns.Add(CN_TodayRain);
            m_tableDataAdded.Columns.Add(CN_PeriodRain);
            m_tableDataAdded.Columns.Add(CN_WaterStage);
            m_tableDataAdded.Columns.Add(CN_WaterFlow);
            m_tableDataAdded.Columns.Add(CN_Voltage);
            m_tableDataAdded.Columns.Add(CN_DataState);
            m_tableDataAdded.Columns.Add(CN_MsgType);
            m_tableDataAdded.Columns.Add(CN_TransType);
            m_tableDataAdded.Columns.Add(CN_DataTime);

            // 初始化互斥量
            m_mutexWriteToDB = CDBMutex.Mutex_TB_CurrentData;

            m_addTimer_1          = new System.Timers.Timer();
            m_addTimer_1.Elapsed += new System.Timers.ElapsedEventHandler(EHTimer_1);
            m_addTimer_1.Enabled  = false;
            m_addTimer_1.Interval = CDBParams.GetInstance().AddToDbDelay;
        }
Пример #28
0
        // 添加新列
        public void AddNewRow(CEntitySerialPort entity)
        {
            // 记录超过1000条,或者时间超过1分钟,就将当前的数据写入数据库
            m_mutexDataTable.WaitOne(); //等待互斥量
            DataRow row = m_tableDataAdded.NewRow();

            row[CN_PortNumber] = entity.PortNumber;
            row[CN_TransType]  = CEnumHelper.SerialTransTypeToDBStr(entity.TransType);
            row[CN_Baudrate]   = entity.Baudrate;
            row[CN_Databit]    = entity.DataBit;
            row[CN_Stopbit]    = entity.StopBit;
            row[CN_Parity]     = CEnumHelper.PortParityTypeToDBChar(entity.ParityType);
            row[CN_Stream]     = CEnumHelper.SerialPortStreamTypeToDBStr(entity.Stream);
            row[CN_Break]      = entity.Break;
            row[CN_Open]       = entity.SwitchSatus;
            m_tableDataAdded.Rows.Add(row);
            if (m_tableDataAdded.Rows.Count >= CDBParams.GetInstance().AddBufferMax)
            {
                // 如果超过最大值,写入数据库
                Task task = new Task(() => { AddDataToDB(); });
                task.Start();
            }
            else
            {
                // 没有超过缓存最大值,开启定时器进行检测,多次调用Start()会导致重新计数
                m_addTimer.Start();
            }
            m_mutexDataTable.ReleaseMutex();
        }
Пример #29
0
        // 将Map中由key指定的DataTable,从startRow开始返回界面最大行数的集合
        private List <CEntityWater> CopyDataToList(int key, int startRow)
        {
            List <CEntityWater> result = new List <CEntityWater>();
            // 取最小值 ,保证不越界
            int       endRow = Math.Min(m_mapDataTable[key].Rows.Count, startRow + CDBParams.GetInstance().UIPageRowCount);
            DataTable table  = m_mapDataTable[key];

            for (; startRow < endRow; ++startRow)
            {
                CEntityWater water = new CEntityWater();
                // water.WaterID = long.Parse(table.Rows[startRow][CN_WaterID].ToString());
                water.StationID   = table.Rows[startRow][CN_StationId].ToString();
                water.TimeCollect = DateTime.Parse(table.Rows[startRow][CN_DataTime].ToString());
                //水位
                if (!table.Rows[startRow][CN_WaterStage].ToString().Equals(""))
                {
                    water.WaterStage = Decimal.Parse(table.Rows[startRow][CN_WaterStage].ToString());
                }
                else
                {
                    //11.12
                    water.WaterStage = -9999;
                }
                //流量
                string tmp = table.Rows[startRow][CN_WaterFlow].ToString();
                if (!tmp.Equals(""))
                {
                    water.WaterFlow = Decimal.Parse(table.Rows[startRow][CN_WaterFlow].ToString());
                }
                else
                {
                    //11.12
                    water.WaterFlow = -9999;
                }
                if (table.Rows[startRow][CN_State].ToString() != "")
                {
                    try
                    {
                        water.state = int.Parse(table.Rows[startRow][CN_State].ToString());
                    }
#pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过
                    catch (Exception ex) { }
#pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过
                }
                else
                {
                    water.state = 1;
                }
                water.TimeRecieved = DateTime.Parse(table.Rows[startRow][CN_RecvDataTime].ToString());
                water.ChannelType  = CEnumHelper.DBStrToChannelType(table.Rows[startRow][CN_TransType].ToString());
                water.MessageType  = CEnumHelper.DBStrToMessageType(table.Rows[startRow][CN_MsgType].ToString());
                result.Add(water);
            }
            return(result);
        }
        private DateTime m_dateTimeEnd;     //查询的起点日期

        public CDataGridViewTSRain()
            : base()
        {
            m_proxyTSRain = new CDBSQLTSRain();
            this.Header   = new string[]
            {
                CS_StationID, CS_StationName, CS_TimeCollected, CS_TotalRain, CS_TimeReceived, CS_ChannelType, CS_MsgType
            };

            // 设置一页的数量
            this.PageRowCount = CDBParams.GetInstance().UIPageRowCount;
        }