Exemplo n.º 1
0
 public bool GetLastData(ref Nullable <Decimal> lastVoltage, ref Nullable <DateTime> lastDayTime, ref Nullable <EChannelType> lastChannelType, ref Nullable <EMessageType> lastMessageType, string stationId)
 {
     // 获取计算雨量值所需的数据
     try
     {
         // 获取最近一条的雨量值
         string sql = string.Format("select top 1 * from {0} where {1} = '{2}' order by {3} desc;",
                                    CT_TableName,
                                    CN_StationId, stationId,
                                    CN_DataTime);
         SqlDataAdapter adapter      = new SqlDataAdapter(sql, CDBManager.GetInstacne().GetConnection());
         DataTable      dataTableTmp = new DataTable();
         adapter.Fill(dataTableTmp);
         if (dataTableTmp.Rows.Count > 0)
         {
             lastVoltage     = Decimal.Parse(dataTableTmp.Rows[0][CN_Voltage].ToString());
             lastDayTime     = DateTime.Parse(dataTableTmp.Rows[0][CN_DataTime].ToString());
             lastChannelType = CEnumHelper.DBStrToChannelType(dataTableTmp.Rows[0][CN_TransType].ToString());
             lastMessageType = CEnumHelper.DBStrToMessageType(dataTableTmp.Rows[0][CN_MsgType].ToString());
         }
         else
         {
             //      Debug.WriteLine(string.Format("查询电压表为空,站点{0}", stationId));
         }
         return(true);
     }
     catch (System.Exception ex)
     {
         Debug.WriteLine(ex.ToString());
         return(false);
     }
     finally
     {
     }
 }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        private List <CEntityOBS> CopyDataToList(int key, int startRow)
        {
            List <CEntityOBS> result = new List <CEntityOBS>();

            try
            {
                // 取最小值 ,保证不越界
                int       endRow = Math.Min(m_mapDataTable[key].Rows.Count, startRow + CDBParams.GetInstance().UIPageRowCount);
                DataTable table  = m_mapDataTable[key];
                for (; startRow < endRow; ++startRow)
                {
                    CEntityOBS obs = new CEntityOBS();
                    //  rain.RainID = long.Parse(table.Rows[startRow][CN_RainID].ToString());
                    obs.StationID   = table.Rows[startRow][CN_StationId].ToString();
                    obs.TimeCollect = DateTime.Parse(table.Rows[startRow][CN_DataTime].ToString());
                    if (!table.Rows[startRow][CN_Depth].ToString().Equals(""))
                    {
                        obs.Depth = Decimal.Parse(table.Rows[startRow][CN_Depth].ToString());
                    }
                    if (!table.Rows[startRow][CN_NTU].ToString().Equals(""))
                    {
                        obs.NTU = Decimal.Parse(table.Rows[startRow][CN_NTU].ToString());
                    }
                    if (!table.Rows[startRow][CN_ppm].ToString().Equals(""))
                    {
                        obs.ppm = Decimal.Parse(table.Rows[startRow][CN_ppm].ToString());
                    }
                    if (!table.Rows[startRow][CN_Temperature].ToString().Equals(""))
                    {
                        obs.Temperature = Decimal.Parse(table.Rows[startRow][CN_Temperature].ToString());
                    }
                    //obs.maxTime = DateTime.Parse(table.Rows[startRow][CN_maxTime].ToString());
                    if (!table.Rows[startRow][CN_Conductivity].ToString().Equals(""))
                    {
                        obs.Conductivity = Decimal.Parse(table.Rows[startRow][CN_Conductivity].ToString());
                    }
                    if (!table.Rows[startRow][CN_Salinity].ToString().Equals(""))
                    {
                        obs.Salinity = Decimal.Parse(table.Rows[startRow][CN_Salinity].ToString());
                    }
                    if (!table.Rows[startRow][CN_Batt].ToString().Equals(""))
                    {
                        obs.Batt = Decimal.Parse(table.Rows[startRow][CN_Batt].ToString());
                    }
                    obs.BState       = 1;
                    obs.ChannelType  = CEnumHelper.DBStrToChannelType(table.Rows[startRow][CN_transtype].ToString());
                    obs.MessageType  = CEnumHelper.DBStrToMessageType(table.Rows[startRow][CN_messagetype].ToString());
                    obs.TimeRecieved = DateTime.Parse(table.Rows[startRow][CN_recvdatatime].ToString());
                    result.Add(obs);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("" + e.ToString());
            }
            return(result);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        // 将Map中由key指定的DataTable,从startRow开始返回界面最大行数的集合
        private List <CEntityVoltage> CopyDataToList(int key, int startRow)
        {
            List <CEntityVoltage> result = new List <CEntityVoltage>();
            // 取最小值 ,保证不越界
            int       endRow = Math.Min(m_mapDataTable[key].Rows.Count, startRow + CDBParams.GetInstance().UIPageRowCount);
            DataTable table  = m_mapDataTable[key];

            for (; startRow < endRow; ++startRow)
            {
                CEntityVoltage voltage = new CEntityVoltage();
                //   voltage.VoltageID = long.Parse(table.Rows[startRow][CN_VoltageID].ToString());
                voltage.StationID   = table.Rows[startRow][CN_StationId].ToString();
                voltage.TimeCollect = DateTime.Parse(table.Rows[startRow][CN_DataTime].ToString());
                if (!table.Rows[startRow][CN_Voltage].ToString().Equals(""))
                {
                    voltage.Voltage = Decimal.Parse(table.Rows[startRow][CN_Voltage].ToString());
                }
                else
                {
                    voltage.Voltage = -9999;
                }
                if (table.Rows[startRow][CN_State].ToString() != "")
                {
                    try
                    {
                        voltage.state = int.Parse(table.Rows[startRow][CN_State].ToString());
                    }
                    catch (Exception ex) { }
                }
                else
                {
                    voltage.state = 1;
                }
                voltage.TimeRecieved = DateTime.Parse(table.Rows[startRow][CN_RecvDataTime].ToString());
                voltage.ChannelType  = CEnumHelper.DBStrToChannelType(table.Rows[startRow][CN_TransType].ToString());
                voltage.MessageType  = CEnumHelper.DBStrToMessageType(table.Rows[startRow][CN_MsgType].ToString());
                result.Add(voltage);
            }
            return(result);
        }
Exemplo n.º 6
0
        private List <PWDData> CopyDataToList(int key, int startRow)
        {
            List <PWDData> result = new List <PWDData>();

            try
            {
                // 取最小值 ,保证不越界
                int       endRow = Math.Min(m_mapDataTable[key].Rows.Count, startRow + CDBParams.GetInstance().UIPageRowCount);
                DataTable table  = m_mapDataTable[key];
                for (; startRow < endRow; ++startRow)
                {
                    PWDData pwd = new PWDData();
                    //  rain.RainID = long.Parse(table.Rows[startRow][CN_RainID].ToString());
                    pwd.StationID   = table.Rows[startRow][CN_StationId].ToString();
                    pwd.TimeCollect = DateTime.Parse(table.Rows[startRow][CN_DataTime].ToString());
                    if (!table.Rows[startRow][CN_Visi1min].ToString().Equals(""))
                    {
                        pwd.Visi1min = Decimal.Parse(table.Rows[startRow][CN_Visi1min].ToString());
                    }
                    if (!table.Rows[startRow][CN_Visi10min].ToString().Equals(""))
                    {
                        pwd.Visi10min = Decimal.Parse(table.Rows[startRow][CN_Visi10min].ToString());
                    }

                    pwd.BState       = 1;
                    pwd.ChannelType  = CEnumHelper.DBStrToChannelType(table.Rows[startRow][CN_transtype].ToString());
                    pwd.MessageType  = CEnumHelper.DBStrToMessageType(table.Rows[startRow][CN_messagetype].ToString());
                    pwd.TimeRecieved = DateTime.Parse(table.Rows[startRow][CN_recvdatatime].ToString());

                    result.Add(pwd);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("" + e.ToString());
            }
            return(result);
        }
Exemplo n.º 7
0
        private List <CEntityTSRain> CopyDataToList(int key, int startRow)
        {
            List <CEntityTSRain> result = new List <CEntityTSRain>();
            // 取最小值 ,保证不越界
            int       endRow = Math.Min(m_mapDataTable[key].Rows.Count, startRow + CDBParams.GetInstance().UIPageRowCount);
            DataTable table  = m_mapDataTable[key];

            for (; startRow < endRow; ++startRow)
            {
                CEntityTSRain rain = new CEntityTSRain();
                //  rain.RainID = long.Parse(table.Rows[startRow][CN_RainID].ToString());
                rain.StationID   = table.Rows[startRow][CN_StationId].ToString();
                rain.TimeCollect = DateTime.Parse(table.Rows[startRow][CN_DataTime].ToString());
                if (!table.Rows[startRow][CN_TotalRain].ToString().Equals(""))
                {
                    rain.TotalRain = Decimal.Parse(table.Rows[startRow][CN_TotalRain].ToString());
                }
                rain.TimeRecieved = DateTime.Parse(table.Rows[startRow][CN_RecvDataTime].ToString());
                rain.ChannelType  = CEnumHelper.DBStrToChannelType(table.Rows[startRow][CN_TransType].ToString());
                rain.MessageType  = CEnumHelper.DBStrToMessageType(table.Rows[startRow][CN_MsgType].ToString());
                result.Add(rain);
            }
            return(result);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 获取某个站点最新的数据,如果没有,lastData = null
        /// </summary>
        /// <param name="lastData"></param>
        /// <returns></returns>
        public bool GetLastStationData(string stationId, out CEntitySoilData lastData)
        {
            lastData = null;
            string sql = string.Format("select top 1 * from {0} where {1} = {2} order by {3} desc",
                                       CT_TableName,
                                       CN_StationId, stationId,
                                       CN_DataTime);
            SqlDataAdapter adapter      = new SqlDataAdapter(sql, CDBManager.GetInstacne().GetConnection());
            DataTable      dataTableTmp = new DataTable();

            adapter.Fill(dataTableTmp);
            // 只有一行噻?不然怎么玩??
            if (dataTableTmp.Rows.Count == 1)
            {
                int             rowid = 0;
                CEntitySoilData data  = new CEntitySoilData();
                data.StationID   = dataTableTmp.Rows[rowid][CN_StationId].ToString();
                data.DataTime    = DateTime.Parse(dataTableTmp.Rows[rowid][CN_DataTime].ToString());
                data.DVoltage    = decimal.Parse(dataTableTmp.Rows[rowid][CN_Voltage].ToString());
                data.MessageType = CEnumHelper.DBStrToMessageType(dataTableTmp.Rows[rowid][CN_MessageType].ToString());
                data.ChannelType = CEnumHelper.DBStrToChannelType(dataTableTmp.Rows[rowid][CN_ChannelType].ToString());

                data.Voltage10  = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Voltage10]);
                data.Moisture10 = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Moisture10]);

                data.Voltage20  = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Voltage20]);
                data.Moisture20 = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Moisture20]);

                data.Voltage30  = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Voltage30]);
                data.Moisture30 = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Moisture30]);

                data.Voltage40  = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Voltage40]);
                data.Moisture40 = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Moisture40]);

                data.Voltage60  = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Voltage60]);
                data.Moisture60 = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Moisture60]);
                try
                {
                    if (dataTableTmp.Rows[rowid][CN_RecvTime].ToString() != "")
                    {
                        data.reciveTime = DateTime.Parse(dataTableTmp.Rows[rowid][CN_RecvTime].ToString());
                    }
                }
                catch (Exception e)
                {
                    data.reciveTime = DateTime.Now;
                }
                try
                {
                    if (dataTableTmp.Rows[rowid][CN_State].ToString() != "")
                    {
                        data.state = int.Parse(dataTableTmp.Rows[rowid][CN_State].ToString());
                    }
                }
                catch (Exception e)
                {
                    data.state = 1;
                }
                lastData = data;
            }
            //  Debug.WriteLine(string.Format("查询站点{0}最新墒情数据完成", stationId));
            return(true);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 根据起始时间以及结束时间还有站点ID,查询墒情数据
        /// </summary>
        /// <param name="stationId"></param>
        /// <param name="timeStart"></param>
        /// <param name="timeEnd"></param>
        /// <returns></returns>
        public List <CEntitySoilData> QueryByStationAndTime(string stationId, DateTime timeStart, DateTime timeEnd)
        {
            ////传递得参数
            //Dictionary<string, object> param = new Dictionary<string, object>();
            ////TODO添加datatime转string timeStart timeEnd

            ////查询条件
            //Dictionary<string, string> paramInner = new Dictionary<string, string>();
            //paramInner["stationid"] = stationId;
            ////paramInner["strttime"] = timeStart.ToString("yyyy-MM-dd HH:mm:ss");
            //paramInner["strttime"] = timeStart.ToString();
            ////paramInner["endtime"] = timeEnd.ToString("yyyy-MM-dd HH:mm:ss");
            //paramInner["endtime"] = timeEnd.ToString();
            ////返回结果
            //List<CEntitySoilData> soildataList = new List<CEntitySoilData>();
            ////string suffix = "/subcenter/getSubcenter";
            //string url = "http://127.0.0.1:8088/soildata/getSoildata";
            //string jsonStr = HttpHelper.SerializeDictionaryToJsonString(paramInner);
            //param["soildata"] = jsonStr;
            //try
            //{
            //    string resultJson = HttpHelper.Post(url, param);
            //    soildataList = (List<CEntitySoilData>)HttpHelper.JsonToObject(resultJson, new List<CEntitySoilData>());
            //}
            //catch (Exception e)
            //{
            //    Debug.WriteLine("查询墒情信息失败");
            //    throw e;
            //}
            //return soildataList;
            List <CEntitySoilData> results = new List <CEntitySoilData>();

            try
            {
                string sql = string.Format("select * from {0} where {1} = {2} and {3} between {4} and {5} order by {6} desc",
                                           CT_TableName,
                                           CN_StationId, stationId,
                                           CN_DataTime, DateTimeToDBStr(timeStart), DateTimeToDBStr(timeEnd),
                                           CN_DataTime);
                SqlDataAdapter adapter      = new SqlDataAdapter(sql, CDBManager.GetInstacne().GetConnection());
                DataTable      dataTableTmp = new DataTable();
                adapter.Fill(dataTableTmp);
                for (int rowid = 0; rowid < dataTableTmp.Rows.Count; ++rowid)
                {
                    CEntitySoilData data = new CEntitySoilData();
                    data.StationID   = dataTableTmp.Rows[rowid][CN_StationId].ToString();
                    data.DataTime    = DateTime.Parse(dataTableTmp.Rows[rowid][CN_DataTime].ToString());
                    data.DVoltage    = decimal.Parse(dataTableTmp.Rows[rowid][CN_Voltage].ToString());
                    data.MessageType = CEnumHelper.DBStrToMessageType(dataTableTmp.Rows[rowid][CN_MessageType].ToString());
                    data.ChannelType = CEnumHelper.DBStrToChannelType(dataTableTmp.Rows[rowid][CN_ChannelType].ToString());

                    data.Voltage10  = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Voltage10]);
                    data.Moisture10 = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Moisture10]);

                    data.Voltage20  = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Voltage20]);
                    data.Moisture20 = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Moisture20]);

                    data.Voltage30  = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Voltage30]);
                    data.Moisture30 = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Moisture30]);

                    data.Voltage40  = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Voltage40]);
                    data.Moisture40 = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Moisture40]);

                    data.Voltage60  = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Voltage60]);
                    data.Moisture60 = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Moisture60]);

                    data.reciveTime = DateTime.Parse(dataTableTmp.Rows[rowid][CN_DataTime].ToString());

                    try
                    {
                        if (dataTableTmp.Rows[rowid][CN_RecvTime].ToString() != "")
                        {
                            data.reciveTime = DateTime.Parse(dataTableTmp.Rows[rowid][CN_RecvTime].ToString());
                        }
                    }
                    catch (Exception e)
                    {
                        data.reciveTime = DateTime.Now;
                    }
                    try
                    {
                        if (dataTableTmp.Rows[rowid][CN_State].ToString() != "")
                        {
                            data.state = int.Parse(dataTableTmp.Rows[rowid][CN_State].ToString());
                        }
                    }
                    catch (Exception e)
                    {
                        data.state = 1;
                    }
                    results.Add(data);
                }
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
            return(results);
        }
Exemplo n.º 10
0
        public List <CEntityWaterSpeed> QueryByTime(string station, DateTime start, DateTime end)
        {
            List <CEntityWaterSpeed> results = new List <CEntityWaterSpeed>();
            String         sql           = "select * from " + CT_TableName + " where STCD=" + station + " and DT between '" + start + "'and '" + end + "'" + "order by DT desc;";
            SqlDataAdapter adapter       = new SqlDataAdapter(sql, CDBManager.GetInstacne().GetConnection());
            DataTable      dataTableTemp = new DataTable();

            adapter.Fill(dataTableTemp);
            int flag = dataTableTemp.Rows.Count;

            if (flag == 0)
            {
            }
            else
            {
                for (int rowid = 0; rowid < dataTableTemp.Rows.Count; ++rowid)
                {
                    CEntityWaterSpeed waterSpeed = new CEntityWaterSpeed();
                    waterSpeed.STCD = dataTableTemp.Rows[rowid][CN_StationId].ToString();
                    waterSpeed.DT   = DateTime.Parse(dataTableTemp.Rows[rowid][CN_DataTime].ToString());
                    if (dataTableTemp.Rows[rowid][CN_WaterStage].ToString() != null && dataTableTemp.Rows[rowid][CN_WaterStage].ToString() != "")
                    {
                        waterSpeed.W1 = decimal.Parse(dataTableTemp.Rows[rowid][CN_WaterStage].ToString());
                    }
                    else
                    {
                        waterSpeed.W1 = null;
                    }

                    if (dataTableTemp.Rows[rowid][CN_V1].ToString() != null && dataTableTemp.Rows[rowid][CN_V1].ToString() != "")
                    {
                        waterSpeed.AvgV1 = decimal.Parse(dataTableTemp.Rows[rowid][CN_V1].ToString());
                    }
                    else
                    {
                        waterSpeed.AvgV1 = null;
                    }

                    if (dataTableTemp.Rows[rowid][CN_V2].ToString() != null && dataTableTemp.Rows[rowid][CN_V2].ToString() != "")
                    {
                        waterSpeed.AvgV2 = decimal.Parse(dataTableTemp.Rows[rowid][CN_V2].ToString());
                    }
                    else
                    {
                        waterSpeed.AvgV2 = null;
                    }

                    if (dataTableTemp.Rows[rowid][CN_V3].ToString() != null && dataTableTemp.Rows[rowid][CN_V3].ToString() != "")
                    {
                        waterSpeed.AvgV3 = decimal.Parse(dataTableTemp.Rows[rowid][CN_V3].ToString());
                    }
                    else
                    {
                        waterSpeed.AvgV3 = null;
                    }

                    if (dataTableTemp.Rows[rowid][CN_V4].ToString() != null && dataTableTemp.Rows[rowid][CN_V4].ToString() != "")
                    {
                        waterSpeed.AvgV4 = decimal.Parse(dataTableTemp.Rows[rowid][CN_V4].ToString());
                    }
                    else
                    {
                        waterSpeed.AvgV4 = null;
                    }

                    if (dataTableTemp.Rows[rowid][CN_WaterFlowMc].ToString() != null && dataTableTemp.Rows[rowid][CN_WaterFlowMc].ToString() != "")
                    {
                        waterSpeed.rawQ = decimal.Parse(dataTableTemp.Rows[rowid][CN_WaterFlowMc].ToString());
                    }
                    else
                    {
                        waterSpeed.rawQ = null;
                    }

                    if (dataTableTemp.Rows[rowid][CN_WaterFlow].ToString() != null && dataTableTemp.Rows[rowid][CN_WaterFlow].ToString() != "")
                    {
                        waterSpeed.Q = decimal.Parse(dataTableTemp.Rows[rowid][CN_WaterFlow].ToString());
                    }
                    else
                    {
                        waterSpeed.Q = null;
                    }



                    //waterSpeed.AvgV1 = decimal.Parse(dataTableTemp.Rows[rowid][CN_V1].ToString());
                    //waterSpeed.AvgV2 = decimal.Parse(dataTableTemp.Rows[rowid][CN_V2].ToString());
                    //waterSpeed.AvgV3 = decimal.Parse(dataTableTemp.Rows[rowid][CN_V3].ToString());
                    //waterSpeed.AvgV4 = decimal.Parse(dataTableTemp.Rows[rowid][CN_V4].ToString());
                    //waterSpeed.rawQ = decimal.Parse(dataTableTemp.Rows[rowid][CN_WaterFlowMc].ToString());
                    //waterSpeed.Q = decimal.Parse(dataTableTemp.Rows[rowid][CN_WaterFlow].ToString());
                    waterSpeed.RevtDT      = DateTime.Parse(dataTableTemp.Rows[rowid][CN_RecvDataTime].ToString());
                    waterSpeed.ChannelType = CEnumHelper.DBStrToChannelType(dataTableTemp.Rows[rowid][CN_TransType].ToString());
                    waterSpeed.MessageType = CEnumHelper.DBStrToMessageType(dataTableTemp.Rows[rowid][CN_MsgType].ToString());
                    results.Add(waterSpeed);
                }
            }
            return(results);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 根据起始时间以及结束时间还有站点ID,查询墒情数据
        /// </summary>
        /// <param name="stationId"></param>
        /// <param name="timeStart"></param>
        /// <param name="timeEnd"></param>
        /// <returns></returns>
        public List <CEntitySoilData> QueryByStationAndTime(string stationId, DateTime timeStart, DateTime timeEnd)
        {
            List <CEntitySoilData> results = new List <CEntitySoilData>();

            try
            {
                string sql = string.Format("select * from {0} where {1} = {2} and {3} between {4} and {5} order by {6}",
                                           CT_TableName,
                                           CN_StationId, stationId,
                                           CN_DataTime, DateTimeToDBStr(timeStart), DateTimeToDBStr(timeEnd),
                                           CN_DataTime);
                SqlDataAdapter adapter      = new SqlDataAdapter(sql, CDBManager.GetInstacne().GetConnection());
                DataTable      dataTableTmp = new DataTable();
                adapter.Fill(dataTableTmp);
                for (int rowid = 0; rowid < dataTableTmp.Rows.Count; ++rowid)
                {
                    CEntitySoilData data = new CEntitySoilData();
                    data.StationID   = dataTableTmp.Rows[rowid][CN_StationId].ToString();
                    data.DataTime    = DateTime.Parse(dataTableTmp.Rows[rowid][CN_DataTime].ToString());
                    data.DVoltage    = decimal.Parse(dataTableTmp.Rows[rowid][CN_Voltage].ToString());
                    data.MessageType = CEnumHelper.DBStrToMessageType(dataTableTmp.Rows[rowid][CN_MessageType].ToString());
                    data.ChannelType = CEnumHelper.DBStrToChannelType(dataTableTmp.Rows[rowid][CN_ChannelType].ToString());

                    data.Voltage10  = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Voltage10]);
                    data.Moisture10 = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Moisture10]);

                    data.Voltage20  = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Voltage20]);
                    data.Moisture20 = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Moisture20]);

                    data.Voltage30  = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Voltage30]);
                    data.Moisture30 = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Moisture30]);

                    data.Voltage40  = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Voltage40]);
                    data.Moisture40 = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Moisture40]);

                    data.Voltage60  = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Voltage60]);
                    data.Moisture60 = GetCellFloatValue(dataTableTmp.Rows[rowid][CN_Moisture60]);

                    data.reciveTime = DateTime.Parse(dataTableTmp.Rows[rowid][CN_DataTime].ToString());

                    try
                    {
                        if (dataTableTmp.Rows[rowid][CN_RecvTime].ToString() != "")
                        {
                            data.reciveTime = DateTime.Parse(dataTableTmp.Rows[rowid][CN_RecvTime].ToString());
                        }
                    }
#pragma warning disable CS0168 // 声明了变量“e”,但从未使用过
                    catch (Exception e)
#pragma warning restore CS0168 // 声明了变量“e”,但从未使用过
                    {
                        data.reciveTime = DateTime.Now;
                    }
                    try
                    {
                        if (dataTableTmp.Rows[rowid][CN_State].ToString() != "")
                        {
                            data.state = int.Parse(dataTableTmp.Rows[rowid][CN_State].ToString());
                        }
                    }
#pragma warning disable CS0168 // 声明了变量“e”,但从未使用过
                    catch (Exception e)
#pragma warning restore CS0168 // 声明了变量“e”,但从未使用过
                    {
                        data.state = 1;
                    }
                    results.Add(data);
                }
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
            return(results);
        }