/// <summary>
 /// 更新站点状态
 /// </summary>
 /// <returns></returns>
 public bool UpdateStationStatus(string stationId, EStationClockState state)
 {
     base.m_mutexDataTable.WaitOne();
     for (int i = 0; i < m_dataTable.Rows.Count; ++i)
     {
         if (stationId == m_dataTable.Rows[i][CS_StationID].ToString())
         {
             // 如果找到匹配
             EDataState showstate = CExDataGridView.EDataState.ENormal;
             if (state == EStationClockState.EAdjustFailed)
             {
                 // 对时失败,显示成红色
                 showstate = CExDataGridView.EDataState.EError;
             }
             else if (state == EStationClockState.EAjustSuccess)
             {
                 showstate = CExDataGridView.EDataState.EPink;
             }
             string[] newRow = new string[]
             {
                 m_dataTable.Rows[i][CS_Select].ToString(),
                 m_dataTable.Rows[i][CS_StationID].ToString(),
                 m_dataTable.Rows[i][CS_StationName].ToString(),
                 m_dataTable.Rows[i][CS_StationGprs].ToString(),
                 m_dataTable.Rows[i][CS_SubCenterName].ToString(),
                 //  m_dataTable.Rows[i][CS_OnlineOrOffline].ToString(),
                 GetStatusUIStr(state)
             };
             base.m_mutexDataTable.ReleaseMutex();
             base.UpdateRowData(i, newRow, showstate);
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 2
0
 /// 更新站点状态
 /// </summary>
 /// <returns></returns>
 public bool UpdateStorage(string stationId, string data)
 {
     base.m_mutexDataTable.WaitOne();
     for (int i = 0; i < m_dataTable.Rows.Count; ++i)
     {
         if (stationId == m_dataTable.Rows[i][CS_StationID].ToString())
         {
             // 如果找到匹配
             EDataState showstate = CExDataGridView.EDataState.ENormal;
             //if (state == Hydrology.CControls.CDataGridViewSystemClock.EStationClockState.EAdjustFailed)
             //{
             //    // 对时失败,显示成红色
             //    showstate = CExDataGridView.EDataState.EError;
             //}
             //else if (state == Hydrology.CControls.CDataGridViewSystemClock.EStationClockState.EAjustSuccess)
             //{
             //    showstate = CExDataGridView.EDataState.EPink;
             //}
             string[] newRow = new string[]
             {
                 m_dataTable.Rows[i][CS_Select].ToString(),
                 m_dataTable.Rows[i][CS_StationID].ToString(),
                 m_dataTable.Rows[i][CS_StationName].ToString(),
                 m_dataTable.Rows[i][CS_StationGprs].ToString(),
                 m_dataTable.Rows[i][CS_SubCenterName].ToString(),
                 //    m_dataTable.Rows[i][CS_OnlineOrOffline].ToString(),
                 float.Parse(data.Substring(0, 4)).ToString() + "." + data.Substring(4, 2).ToString()
             };
             base.m_mutexDataTable.ReleaseMutex();
             base.UpdateRowData(i, newRow, showstate);
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 3
0
        // 设置显示的雨量记录
        public void SetRain(List <FSFXData> listFsfx)
        {
            // 清空所有数据,是否一定要这样?好像可以考虑其它方式
            base.m_dataTable.Rows.Clear();
            // 判断状态值
            List <string[]>   newRows = new List <string[]>();
            List <EDataState> states  = new List <EDataState>();

            if (!m_bIsEditable)
            {
                // 只读模式
                for (int i = 0; i < listFsfx.Count; ++i)
                {
                    EDataState     state          = EDataState.ENormal; //默认所有数据都是正常的
                    string         strStationName = "";
                    string         strStationId   = "";
                    string         state_1        = CS_DataState_Normal;
                    CEntityStation station        = CDBDataMgr.Instance.GetStationById(listFsfx[i].StationID);
                    if (null != station)
                    {
                        strStationName = station.StationName;
                        strStationId   = station.StationID;
                    }

                    if (listFsfx[i].BState == 0)
                    {
                        // 不正常
                        state   = CExDataGridView.EDataState.EError;//红色显示
                        state_1 = CS_DataState_AbNormal;
                    }
                    else if (listFsfx[i].BState == 2)
                    {
                        // 不正常
                        state   = CExDataGridView.EDataState.EWarning;//黄色显示
                        state_1 = CS_DataState_Warning;
                    }
                    string[] newRow = new string[]
                    {
                        strStationId,
                        strStationName,
                        listFsfx[i].TimeCollect.ToString(CS_TimeFormat), /*采集时间*/
                        listFsfx[i].shfx.ToString(),                     /*瞬时风向*/
                        listFsfx[i].shfs.ToString(),                     /*瞬时风向*/
                        listFsfx[i].yxszdshfx.ToString(),                /*瞬时风向*/
                        listFsfx[i].yxszdshfs.ToString(),                /*瞬时风向*/
                        state_1,
                        listFsfx[i].avg10fx.ToString(),                  /*瞬时风向*/
                        listFsfx[i].avg10fs.ToString()                   /*瞬时风向*/
                        //CEnumHelper.ChannelTypeToUIStr(listFsfx[i].ChannelType), /*通讯方式*/
                        //CEnumHelper.MessageTypeToUIStr(listFsfx[i].MessageType) /*报文类型*/
                    };
                    newRows.Add(newRow);
                    states.Add(state);
                }
            }
            // 添加到集合的数据表中
            base.AddRowRange(newRows, states);
        }
Ejemplo n.º 4
0
        // 设置显示的雨量记录
        public void SetWaters(List <CEntityWaterSpeed> listWaterSpeed)
        {
            // 清空所有数据,是否一定要这样?好像可以考虑其它方式
            base.m_dataTable.Rows.Clear();
            // 判断状态值
            List <string[]>   newRows = new List <string[]>();
            List <EDataState> states  = new List <EDataState>();

            if (!m_bIsEditable)
            {
                string[] newRow;
                // 只读模式
                for (int i = 0; i < listWaterSpeed.Count; ++i)
                {
                    EDataState     state          = EDataState.ENormal; //默认所有数据都是正常的
                    string         strStationName = "";
                    string         strStationId   = "";
                    string         state_1        = CS_DataState_Normal;
                    CEntityStation station        = CDBDataMgr.Instance.GetStationById(listWaterSpeed[i].STCD);
                    if (null != station)
                    {
                        strStationName = station.StationName;
                        strStationId   = station.StationID;
                    }
                    newRow = new string[]
                    {
                        strStationId,
                        strStationName,                                                /*站名*/
                        listWaterSpeed[i].DT.ToString(CS_TimeFormat),                  /*采集时间*/
                        listWaterSpeed[i].W1.ToString(),                               /*水位*/
                        listWaterSpeed[i].AvgV1.ToString(),                            /*水位*/
                        listWaterSpeed[i].AvgV2.ToString(),                            /*水位*/
                        listWaterSpeed[i].AvgV3.ToString(),                            /*水位*/
                        listWaterSpeed[i].AvgV4.ToString(),                            /*水位*/
                        listWaterSpeed[i].Q.ToString(),                                /*流量*/
                        listWaterSpeed[i].rawQ.ToString(),                             /*流量*/
                        state_1,
                        listWaterSpeed[i].RevtDT.ToString(CS_TimeFormat),              /*接收时间*/
                        CEnumHelper.ChannelTypeToUIStr(listWaterSpeed[i].ChannelType), /*通讯方式*/
                        CEnumHelper.MessageTypeToUIStr(listWaterSpeed[i].MessageType), /*报文类型*/
                    };



                    newRows.Add(newRow);
                    states.Add(state);
                }
                // 添加到集合的数据表中
                base.AddRowRange(newRows, states);
            }
            else
            {
                // 添加到集合的数据表中
                base.AddRowRange(newRows, states);
            }
        }
Ejemplo n.º 5
0
 // 更新某一行数据
 public bool UpdateRowData(int rowIndex, string[] newRow, EDataState state)
 {
     try
     {
         m_mutexDataTable.WaitOne();
         if (rowIndex < 0 || rowIndex >= m_dataTable.Rows.Count /*|| !this.IsHandleCreated*/)
         {
             m_mutexDataTable.ReleaseMutex();
             return(false);
         }
         if (this.IsHandleCreated)
         {
             // 窗体已经创建,考虑多线程
             this.Invoke(new Action(() =>
             {
                 Enabled         = false;
                 string[] tmpRow = new string[newRow.Length + 1];
                 newRow.CopyTo(tmpRow, 0);
                 tmpRow[newRow.Length] = ((Int32)state).ToString(); //保存状态位
                 m_bindingSource.SuspendBinding();
                 m_bindingSource.RaiseListChangedEvents = false;
                 for (int i = 0; i < tmpRow.Length; ++i)
                 {
                     m_dataTable.Rows[rowIndex][i] = tmpRow[i];
                 }
                 m_bindingSource.RaiseListChangedEvents = true;
                 m_bindingSource.ResumeBinding();
                 Enabled = true;
             }));
         }
         else
         {
             // 窗体还没有创建
             string[] tmpRow = new string[newRow.Length + 1];
             newRow.CopyTo(tmpRow, 0);
             tmpRow[newRow.Length] = ((Int32)state).ToString(); //保存状态位
             for (int i = 0; i < tmpRow.Length; ++i)
             {
                 m_dataTable.Rows[rowIndex][i] = tmpRow[i];
             }
         }
         //m_bindingSource.ResumeBinding();
         m_mutexDataTable.ReleaseMutex();
         TryToUpdateData();
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.ToString());
     }
     finally
     {
         //this.Invoke((Action)delegate { Enabled = true; });
     }
     return(true);
 }
        /// 更新站点状态
        /// </summary>
        /// <returns></returns>
        public bool UpdateRainStorage(string stationId, string data)
        {
            base.m_mutexDataTable.WaitOne();
            for (int i = 0; i < m_dataTable.Rows.Count; ++i)
            {
                if (stationId == m_dataTable.Rows[i][CS_StationID].ToString())
                {
                    // 如果找到匹配
                    EDataState showstate = CExDataGridView.EDataState.ENormal;
                    //if (state == Hydrology.CControls.CDataGridViewSystemClock.EStationClockState.EAdjustFailed)
                    //{
                    //    // 对时失败,显示成红色
                    //    showstate = CExDataGridView.EDataState.EError;
                    //}
                    //else if (state == Hydrology.CControls.CDataGridViewSystemClock.EStationClockState.EAjustSuccess)
                    //{
                    //    showstate = CExDataGridView.EDataState.EPink;
                    //}
                    // $60191G021584
                    string raindata_1 = "";
                    try{
                        float raindata = float.Parse(data);
                        float a        = CDBDataMgr.Instance.GetStationById(stationId).DRainAccuracy;
                        if (a.ToString() == "0.1" || a.ToString() == "0.2" || a.ToString() == "0.5" || a.ToString() == "1")
                        {
                            raindata_1 = (a * raindata).ToString();
                        }

#pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过
                    }catch (Exception ex) {
#pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过
                        raindata_1 = "--";
                    }
                    string[] newRow = new string[]
                    {
                        m_dataTable.Rows[i][CS_Select].ToString(),
                        m_dataTable.Rows[i][CS_StationID].ToString(),
                        m_dataTable.Rows[i][CS_StationName].ToString(),
                        m_dataTable.Rows[i][CS_StationGprs].ToString(),
                        m_dataTable.Rows[i][CS_SubCenterName].ToString(),
                        raindata_1
                        //float.Parse(
                        //     m_dataTable.Rows[i][CS_OnlineOrOffline].ToString(),
                        //    float.Parse(data.Substring(0,3)).ToString()+"."+data.Substring(3,1).ToString()
                    };
                    base.m_mutexDataTable.ReleaseMutex();
                    base.UpdateRowData(i, newRow, showstate);
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 7
0
        private List <string> GetShowStringList(string stationID, DateTime time, out EDataState state)
        {
            List <CEntityRain> tmpResults = new List <CEntityRain>();
            List <string>      results    = new List <string>();

            results.Add(flag + "月");
            tmpResults = CDBDataMgr.Instance.GetRainsForYearTable(stationID, time);
            for (int i = 1; i <= 31; i++)
            {
                DateTime time1 = time.AddHours(23);
                double   sum   = 0;
                int      count = 0;
                //for (int k = 110; k < tmpResults.Count; k++)
                for (int k = 0; k < tmpResults.Count; k++)
                {
                    if (tmpResults[k].TimeCollect >= time && tmpResults[k].TimeCollect <= time1 && tmpResults[k].TimeCollect.Minute == 0)
                    {
                        if (tmpResults[k].PeriodRain != -9999)
                        {
                            count = count + 1;
                            //sum = double.Parse(sum + (tmpResults[k].PeriodRain.ToString()));
                            sum = sum + double.Parse(tmpResults[k].PeriodRain.ToString());
                        }
                    }
                }
                if (count == 0)
                {
                    results.Add("--");
                }
                else
                {
                    if (sum != 0)
                    {
                        results.Add((sum).ToString("0.0"));
                    }
                    else
                    {
                        results.Add((sum).ToString(" "));
                    }

                    MonthSum = MonthSum + sum;
                }
                time = time.AddDays(1);
            }
            results.Add(MonthSum.ToString());
            double rate = 0.5;

            state = GetState(rate);
            return(results);
        }
Ejemplo n.º 8
0
 private static EntityState GetEntityState(EDataState state)
 {
     switch (state)
     {
         case EDataState.Added:
             return EntityState.Added;
         case EDataState.Modified:
             return EntityState.Modified;
         case EDataState.Deleted:
             return EntityState.Deleted;
         default:
             return EntityState.Unchanged;
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// 导出到Excel表格中
        /// </summary>


        #region 帮助方法
        private List <string> AddAllSum(double allSum, out EDataState state)
        {
            List <string> result = new List <string>();

            result.Add("月雨量");
            for (int i = 0; i < 24; i++)
            {
                result.Add(" ");
            }
            result.Add(allSum.ToString());
            double rate = 0.5;

            state = GetState(rate);
            return(result);
        }
Ejemplo n.º 10
0
 public void ReleaseOnlineState(string stationName, string stationID, string uid)
 {
     try
     {
         for (int j = 0; j < m_onlineGprsList.Count; ++j)
         {
             if (m_onlineGprsList[j] == uid)
             {
                 m_onlineGprsList.RemoveAt(j);
                 break;
             }
         }
         EDataState state = EDataState.ENormal;
         this.BeginInvoke(new System.Action(() =>
         {
             for (int i = 0; i < m_dataTable_1.Rows.Count; ++i)
             {
                 if (m_dataTable_1.Rows[i][CS_UserId].ToString() == uid)
                 {
                     DataRow newRow            = m_dataTable_1.NewRow();
                     newRow[CS_Port]           = "---";
                     newRow[CS_StationName]    = stationName;
                     newRow[CS_StationID]      = stationID;
                     newRow[CS_UserId]         = uid;
                     newRow[CS_Telephone]      = "---";
                     newRow[CS_DynamicIP]      = "---";
                     newRow[CS_ConnectionTime] = "---";
                     newRow[CS_RecvTime]       = "---";
                     newRow["在线状态"]            = "---";
                     newRow["在线状态记录"]          = "0";
                     newRow["state"]           = Convert.ToString((int)state);
                     m_dataTable_1.Rows.InsertAt(newRow, i);
                     m_dataTable_1.Rows.RemoveAt(i + 1);
                     break;
                 }
             }
             base.DataSource = m_dataTable_1.DefaultView;
             return;
         }));
         return;
     }
     catch (Exception ex)
     {
         this.Hide();
         MessageBox.Show("Refresh Error!" + ex.ToString());
         this.Show();
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Calls and execute plugin in write operation.
        /// </summary>
        /// <param name="execContext">Data loader context.</param>
        /// <returns>Called plugin result.</returns>
        protected override object Write(IDataLoaderWriteContext execContext)
        {
            EDataState state = EDataState.Unchanged;

            if (execContext.Row.ContainsKey(STATENAME))
            {
                if (int.TryParse(execContext.Row[STATENAME].ToString(), out int stateAsInt))
                {
                    state = (EDataState)stateAsInt;
                }
            }

            Dictionary <string, object> parameters = ParseAdditionalParameters(execContext.CurrentNode.Write, state);

            return(ExecuteOperation(execContext, parameters, true));
        }
Ejemplo n.º 12
0
        private static EntityState GetEntityState(EDataState state)
        {
            switch (state)
            {
            case EDataState.Added:
                return(EntityState.Added);

            case EDataState.Modified:
                return(EntityState.Modified);

            case EDataState.Deleted:
                return(EntityState.Deleted);

            default:
                return(EntityState.Unchanged);
            }
        }
Ejemplo n.º 13
0
        private List <string> GetShowStringList(string station, DateTime time, out EDataState state)
        {
            int           year    = time.Year;
            int           month   = time.Month;
            int           days    = DateTime.DaysInMonth(year, month);
            List <string> results = new List <string>();

            results.Add(flag + "月");
            //List<string> tmpResults = new List<string>();
            List <CEntityWater> temResults = new List <CEntityWater>();

            temResults = CDBDataMgr.Instance.getWaterForYearTable(station, time);
            for (int j = 1; j <= days; j++)
            {
                decimal tmpSum = 0;
                int     count  = 0;

                for (int k = 0; k < temResults.Count; k++)
                {
                    if (temResults[k].TimeCollect.Day == j)
                    {
                        if (temResults[k].WaterStage != -9999)
                        {
                            tmpSum = tmpSum + temResults[k].WaterStage;
                            count  = count + 1;
                        }
                    }
                }
                if (count != 0)
                {
                    results.Add((tmpSum / count).ToString("0.00"));
                }
                else
                {
                    results.Add("--");
                }
            }
            for (int l = results.Count; l < 32; l++)
            {
                results.Add("--");
            }
            double rate = 0.5;

            state = GetState(rate);
            return(results);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 刷新实时数据超时的状态值,超过1个半小时,为黄色,超过2个半小时为红色
        /// </summary>
        /// <returns></returns>
        public bool RefreshRTDTimeOutStatus()
        {
            base.m_mutexDataTable.WaitOne();
            List <int>        updateRowIndex = new List <int>();
            List <EDataState> updateStatus   = new List <EDataState>();

            for (int i = 0; i < m_dataTable.Rows.Count; ++i)
            {
                DateTime   time  = DateTime.Parse(m_dataTable.Rows[i][CS_TimeCollected].ToString());
                EDataState state = GetDataStatus(time);
                if (state == EDataState.EError || state == EDataState.EWarning)
                {
                    // 只有显示红色或者黄色才更新,否则不变
                    updateRowIndex.Add(i);
                    updateStatus.Add(state);
                }
            }
            base.m_mutexDataTable.ReleaseMutex();
            return(base.UpdateRowRangeStatus(updateRowIndex, updateStatus));
        }
Ejemplo n.º 15
0
        private List <string> GetShowStringList(string station, string name, DateTime time, out EDataState state)
        {
            List <string> results = new List <string>();
            double        sum     = 0;

            results.Add("|");
            results.Add(station);
            results.Add(name);
            List <CEntityRain> temResults = new List <CEntityRain>();
            int      year  = time.Year;
            int      month = time.Month;
            int      day   = time.Day;
            DateTime tmp   = new DateTime(year, month, day, 9, 0, 0);

            temResults = CDBDataMgr.Instance.GetMRaainsForTable(station, tmp);
            int length = temResults.Count;

            for (int i = 0; i < length; i++)
            {
                double rain = double.Parse(temResults[i].PeriodRain.ToString());
                sum = sum + rain;
            }
            if (length == 24)
            {
                for (int i = 0; i < 24; i++)
                {
                    if (temResults[i].PeriodRain.ToString() == "0.0")
                    {
                        results.Add(" ");
                    }
                    else
                    {
                        results.Add(temResults[i].PeriodRain.ToString());
                    }
                }
            }
            else
            {
                List <int> hours = new List <int>();
                int        array = 0;
                for (int j = 0; j < length; j++)
                {
                    DateTime dt = temResults[j].TimeCollect;
                    int      d  = dt.Hour;
                    hours.Add(d);
                }
                for (int k = 9; k < 24; k++)
                {
                    if (hours.Contains(k))
                    {
                        if (temResults[array].PeriodRain.ToString() == "0.0")
                        {
                            results.Add(" ");
                        }
                        else
                        {
                            results.Add(temResults[array].PeriodRain.ToString());
                        }

                        array = array + 1;
                    }
                    else
                    {
                        results.Add("--");
                    }
                }
                for (int k = 0; k < 9; k++)
                {
                    if (hours.Contains(k))
                    {
                        if (temResults[array].PeriodRain.ToString() == "0.0")
                        {
                            results.Add(" ");
                        }
                        else
                        {
                            results.Add(temResults[array].PeriodRain.ToString());
                        }

                        array = array + 1;
                    }
                    else
                    {
                        results.Add("--");
                    }
                }
            }
            results.Add(sum.ToString());
            double rate = 0.5;

            state = GetState(rate);
            return(results);
        }
Ejemplo n.º 16
0
 /// <summary>
 /// 更新系列数据的状态值
 /// </summary>
 /// <returns></returns>
 public bool UpdateRowRangeStatus(List <int> listRowIndex, List <EDataState> listState)
 {
     try
     {
         // 判断参数个数是否匹配
         if (listRowIndex.Count != listState.Count)
         {
             // 参数不匹配
             return(false);
         }
         int        rowIndex = 0;
         EDataState state    = EDataState.ENormal;
         m_mutexDataTable.WaitOne();
         // 判断索引是否合法
         for (int i = 0; i < listRowIndex.Count; ++i)
         {
             rowIndex = listRowIndex[i];
             if (rowIndex < 0 || rowIndex >= m_dataTable.Rows.Count /*|| !this.IsHandleCreated*/)
             {
                 Debug.WriteLine("UpdateRowStatus 索引越界,退出更新");
                 m_mutexDataTable.ReleaseMutex();
                 return(false);
             }
         }
         if (this.IsHandleCreated)
         {
             // 窗体已经创建,考虑多线程
             this.Invoke(new Action(() =>
             {
                 Enabled = false;
                 m_bindingSource.SuspendBinding();
                 for (int i = 0; i < listRowIndex.Count; ++i)
                 {
                     rowIndex = listRowIndex[i];
                     state    = listState[i];
                     m_dataTable.Rows[rowIndex][S_C_State] = ((Int32)state).ToString(); //保存状态位
                 }
                 m_bindingSource.RaiseListChangedEvents = true;
                 m_bindingSource.ResumeBinding();
                 Enabled = true;
             }));
         }
         else
         {
             // 窗体还没有创建
             for (int i = 0; i < listRowIndex.Count; ++i)
             {
                 rowIndex = listRowIndex[i];
                 state    = listState[i];
                 m_dataTable.Rows[rowIndex][S_C_State] = ((Int32)state).ToString(); //保存状态位
             }
         }
         //m_bindingSource.ResumeBinding();
         m_mutexDataTable.ReleaseMutex();
         TryToUpdateData();
     }
     catch (Exception ex)
     {
         m_mutexDataTable.ReleaseMutex();
         Debug.WriteLine(ex.ToString());
         return(false);
     }
     return(true);
 }
        // 设置显示的电压记录
        public void SetVoltage(List <CEntityVoltage> listVoltage)
        {
            // 清空所有数据,是否一定要这样?好像可以考虑其它方式
            base.m_dataTable.Rows.Clear();
            // 判断状态值
            List <string[]>   newRows = new List <string[]>();
            List <EDataState> states  = new List <EDataState>();

            if (!m_bIsEditable)
            {
                // 只读模式
                for (int i = 0; i < listVoltage.Count; ++i)
                {
                    CEntityStation station        = CDBDataMgr.Instance.GetStationById(listVoltage[i].StationID);
                    string         strStationName = "";
                    string         strStationId   = "";
                    string         state_1        = CS_DataState_Normal;
                    if (station != null)
                    {
                        strStationName = station.StationName;
                        strStationId   = station.StationID;
                    }
                    EDataState state = EDataState.ENormal; //默认所有数据都是正常的
                    string[]   newRow;
                    if (listVoltage[i].state == 0)
                    {
                        // 不正常
                        state   = CExDataGridView.EDataState.EError;//红色显示
                        state_1 = CS_DataState_AbNormal;
                    }
                    if (listVoltage[i].Voltage < 0)
                    {
                        newRow = new string[]
                        {
                            strStationId,
                            strStationName,                                             /*站名*/
                            listVoltage[i].TimeCollect.ToString(CS_TimeFormat),         /*采集时间*/
                            "--",                                                       /*电压值*/
                            state_1,
                            listVoltage[i].TimeRecieved.ToString(CS_TimeFormat),        /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listVoltage[i].ChannelType), /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listVoltage[i].MessageType)  /*报文类型*/
                        };
                    }
                    else
                    {
                        newRow = new string[]
                        {
                            strStationId,
                            strStationName,                                             /*站名*/
                            listVoltage[i].TimeCollect.ToString(CS_TimeFormat),         /*采集时间*/
                            listVoltage[i].Voltage.ToString(),                          /*电压值*/
                            state_1,
                            listVoltage[i].TimeRecieved.ToString(CS_TimeFormat),        /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listVoltage[i].ChannelType), /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listVoltage[i].MessageType)  /*报文类型*/
                        };
                    }
                    newRows.Add(newRow);
                    states.Add(state);
                }
            }
            else
            {
                // 编辑模式,需要将更新的数据和删除的数据,与当前数据进行合并
                for (int i = 0; i < listVoltage.Count; ++i)
                {
                    CEntityStation station        = CDBDataMgr.Instance.GetStationById(listVoltage[i].StationID);
                    string         strStationName = "";
                    string         strStationId   = "";
                    string         state_1        = CS_DataState_Normal;
                    if (station != null)
                    {
                        strStationName = station.StationName;
                        strStationId   = station.StationID;
                    }
                    EDataState state = EDataState.ENormal; //默认所有数据都是正常的
                    if (listVoltage[i].state == 0)
                    {
                        // 不正常
                        state   = CExDataGridView.EDataState.EError;//红色显示
                        state_1 = CS_DataState_AbNormal;
                    }
                    string[] newRow = new string[]
                    {
                        "False",                                                    /*未选中*/
                        strStationId,
                        strStationName,                                             /*站名*/
                        listVoltage[i].TimeCollect.ToString(CS_TimeFormat),         /*采集时间*/
                        listVoltage[i].Voltage.ToString(),                          /*电压值*/
                        state_1,
                        listVoltage[i].TimeRecieved.ToString(CS_TimeFormat),        /*接收时间*/
                        CEnumHelper.ChannelTypeToUIStr(listVoltage[i].ChannelType), /*通讯方式*/
                        CEnumHelper.MessageTypeToUIStr(listVoltage[i].MessageType), /*报文类型*/
                        //     listVoltage[i].VoltageID.ToString() /*电压ID,不可见,隐藏列*/
                    };
                    newRows.Add(newRow);
                    states.Add(state);
                }
            }
            // 添加到集合的数据表中
            base.AddRowRange(newRows, states);
        }
Ejemplo n.º 18
0
        private List <string> GetShowStringList(string stationId, string name, DateTime time, out EDataState state)
        {
            int           year    = time.Year;
            int           month   = time.Month;
            int           day     = time.Day;
            List <string> results = new List <string>();

            results.Add(" ");
            results.Add(stationId);
            results.Add(name);
            string minTime = "";
            string maxTime = "";

            double              max        = 0;
            double              min        = 100000;
            double              sum        = 0;
            double              aver       = 0;
            DateTime            tmp        = new DateTime(year, month, day, 0, 0, 0);
            List <CEntityWater> temResults = new List <CEntityWater>();

            temResults = CDBDataMgr.Instance.GetWaterForTable(stationId, tmp);
            int length = temResults.Count;

            for (int i = 0; i < length; i++)
            {
                if (double.Parse(temResults[i].WaterStage.ToString()) > max)
                {
                    max     = double.Parse(temResults[i].WaterStage.ToString());
                    maxTime = temResults[i].TimeCollect.Hour + "时" + temResults[i].TimeCollect.Minute + "分";
                }
                if (double.Parse(temResults[i].WaterStage.ToString()) < min)
                {
                    min     = double.Parse(temResults[i].WaterStage.ToString());
                    minTime = temResults[i].TimeCollect.Hour + "时" + temResults[i].TimeCollect.Minute + "分";
                }
                sum = sum + double.Parse(temResults[i].WaterStage.ToString());
            }
            if (length != 0)
            {
                aver = sum / length;
            }
            else
            {
                aver = 9999.9999;
            }

            for (int i = 1; i < 25; i++)
            {
                double        tmpSum       = 0;
                List <string> smallResults = new List <string>();
                for (int j = 0; j < temResults.Count; j++)
                {
                    DateTime temp = temResults[j].TimeCollect;
                    if (temp.Hour == i)
                    {
                        smallResults.Add(temResults[j].WaterStage.ToString());
                    }
                    if (i == 24)
                    {
                        if (temp.Hour == 0)
                        {
                            smallResults.Add(temResults[j].WaterStage.ToString());
                        }
                    }
                }
                if (smallResults.Count == 0)
                {
                    results.Add("--");
                }
                if (smallResults.Count != 0)
                {
                    for (int j = 0; j < smallResults.Count; j++)
                    {
                        tmpSum = tmpSum + double.Parse(smallResults[j]);
                    }
                    double tmpAver = tmpSum / smallResults.Count;
                    results.Add(tmpAver.ToString("0.00"));
                }
            }
            if (aver != 9999.9999)
            {
                results.Add(aver.ToString("0.00"));
            }
            else
            {
                results.Add("--");
            }

            if (max - 0 < 0.001)
            {
                results.Add("\\");
            }
            else
            {
                results.Add(max.ToString());
            }
            results.Add(maxTime);
            if (min - 9999 > 0.1)
            {
                results.Add("\\");
            }
            else
            {
                results.Add(min.ToString());
            }

            results.Add(minTime);

            double rate = 0.5;

            state = GetState(rate);
            return(results);
        }
Ejemplo n.º 19
0
        private List <string> GetShowStringList(CEntityStation station, DateTime time, out EDataState state)
        {
            // 统计某个月的畅通率
            int      year      = time.Year;
            int      month     = time.Month;
            int      days      = DateTime.DaysInMonth(year, month);
            DateTime startTime = new DateTime(year, month, 1, 0, 0, 0);
            DateTime endTime   = new DateTime(year, month, days, 0, 0, 0);
            List <CEntityVoltage> tmpResults  = new List <CEntityVoltage>();
            List <CEntityVoltage> GSMResults  = new List <CEntityVoltage>();
            List <CEntityVoltage> GPRSResults = new List <CEntityVoltage>();

            tmpResults = CDBDataMgr.Instance.GetVoltageForRateMonthTable(station, startTime, endTime);
            for (int i = 0; i < tmpResults.Count; i++)
            {
                int n = int.Parse(tmpResults[i].type);
                if (n == 3)
                {
                    GPRSResults.Add(tmpResults[i]);
                }
                if (n == 6)
                {
                    GSMResults.Add(tmpResults[i]);
                }
            }
            int        GPRSNum = GPRSResults.Count;
            int        GSMNum  = GSMResults.Count;
            List <int> daylist = new List <int>();

            for (int i = 0; i < tmpResults.Count; ++i)
            {
                daylist.Add(tmpResults[i].TimeCollect.Day);
            }
            List <string> resultUI = new List <string>();

            resultUI.Add(station.StationID);
            //resultUI.Add(station.StationName);
            for (int i = 1; i <= days; i++)
            {
                double        tmpCount     = 0;
                List <string> smallResults = new List <string>();
                for (int k = 0; k < tmpResults.Count; k++)
                {
                    if (tmpResults[k].TimeCollect.Day == i)
                    {
                        tmpCount++;
                    }
                }
                resultUI.Add(tmpCount.ToString());
                //if (daylist.Contains(i))
                //{
                //    resultUI.Add(CS_RecordRight);
                //}
                //else
                //{
                //    resultUI.Add(CS_RecordError);
                //}
            }
            for (int k = 0; k < 31 - days; k++)
            {
                resultUI.Add("//");
            }

            //DateTime timeStart = new DateTime(time.Year, time.Month, 1, 8, 0, 0);
            //DateTime timeEnd = timeStart.AddMonths(1);
            //int count = m_proxyCommnunicationRate.GetCountOfRecordByStationIdAndPeriod(station.StationID,timeStart,timeEnd);
            //TimeSpan span = timeEnd - timeStart;
            //int theorialCount = (int)span.TotalHours /*+ 1*/;

            //resultUI.Add(station.StationID);
            //resultUI.Add(station.StationName);

            //月报表的计算肯定有问题,问题在于实收记录数是直接取的数据库中电压的总数,而其中存在多条同一个时段的数据。
            int reportInterval = Int16.Parse(CDBDataMgr.Instance.GetIntervalForRateTable(station));

            resultUI.Add((reportInterval * days).ToString()); //应收条数
            resultUI.Add(tmpResults.Count.ToString());        //实收的记录数
            double all      = reportInterval * days;
            double rate     = tmpResults.Count / all;
            double GSMRate  = GSMNum / all;
            double GPRSRate = GPRSNum / all;

            state = GetState(rate);
            CalcState(rate);
            rate     = rate * 100; //百分比
            GSMRate  = GSMRate * 100;
            GPRSRate = GPRSRate * 100;
            resultUI.Add(rate.ToString("0.00") + "%"); //保留两位小数
            resultUI.Add(GSMRate.ToString("0.00") + "%");
            resultUI.Add(GPRSRate.ToString("0.00") + "%");
            return(resultUI);
        }
Ejemplo n.º 20
0
        private List <string> GetShowStringList(string station, string name, DateTime date, out EDataState state)
        {
            int           year        = date.Year;
            int           month       = date.Month;
            int           days        = DateTime.DaysInMonth(year, month);
            List <string> averResults = new List <string>();
            List <string> results     = new List <string>();

            for (int i = 1; i <= days; i++)
            {
                DateTime           tmp        = new DateTime(year, month, i, 9, 0, 0);
                List <CEntityRain> temResults = new List <CEntityRain>();
                temResults = CDBDataMgr.Instance.GetMRaainsForTable(station, tmp);
                int    length = temResults.Count;
                double sum    = 0;
                for (int j = 0; j < length; j++)
                {
                    if (temResults[j].PeriodRain >= 0)
                    {
                        double temp = double.Parse(temResults[j].PeriodRain.ToString());
                        sum = sum + temp;
                    }
                }
                if (length == 0)
                {
                    averResults.Add("--");
                }
                else
                {
                    averResults.Add(sum.ToString());
                }
            }
            results.Add("|");
            results.Add(station);
            results.Add(name);
            int    cha = 31 - averResults.Count;
            double all = 0;

            for (int i = 0; i < averResults.Count; i++)
            {
                if (averResults[i] == "0")
                {
                    results.Add(" ");
                }
                else
                {
                    results.Add(averResults[i]);
                    if (averResults[i] != "--")
                    {
                        all = all + double.Parse(averResults[i]);
                    }
                }
            }
            for (int i = 0; i < cha; i++)
            {
                results.Add("\\");
            }
            results.Add(all.ToString());
            double rate = 0.5;

            state = GetState(rate);
            return(results);
        }
Ejemplo n.º 21
0
        private List <string> GetShowStringList(string stationID, DateTime time, int day, out EDataState state)
        {
            try
            {
                List <CEntityRain> tmpResults = new List <CEntityRain>();
                List <string>      results    = new List <string>();
                results.Add(day + "日");
                if (day == 30)
                {
                    int abc = 123;
                }
                //j=-double aver = 0;
                double sum = 0;
                tmpResults = CDBDataMgr.Instance.GetRainsForTable(stationID, time);
                int len = tmpResults.Count;
                for (int i = 0; i < len; i++)
                {
                    if (tmpResults[i].PeriodRain.ToString() != "" && tmpResults[i].PeriodRain != -9999)
                    {
                        double rain = double.Parse(tmpResults[i].PeriodRain.ToString());
                        sum = sum + rain;
                    }
                }
                allSum = allSum + sum;
                if (len == 24)
                {
                    for (int i = 0; i < 24; i++)
                    {
                        if (tmpResults[i].PeriodRain.ToString() != "" && tmpResults[i].PeriodRain != -9999)
                        {
                            double flag = double.Parse(tmpResults[i].PeriodRain.ToString());
                            if (flag - 0 > 0.01)
                            {
                                results.Add(tmpResults[i].PeriodRain.ToString());
                            }
                            else
                            {
                                results.Add(" ");
                            }
                        }
                        else
                        {
                            results.Add("-- ");
                        }
                    }
                }
                else
                {
                    List <int> hours = new List <int>();
                    int        array = 0;
                    for (int j = 0; j < len; j++)
                    {
                        DateTime dt = tmpResults[j].TimeCollect;
                        int      d  = dt.Hour;
                        hours.Add(d);
                    }
                    for (int k = 9; k < 24; k++)
                    {
                        if (hours.Contains(k))
                        {
                            foreach (var t in tmpResults)
                            {
                                if (t.TimeCollect.Hour == k)
                                {
                                    if (t.PeriodRain.ToString() != "" && t.PeriodRain != -9999)
                                    {
                                        double flag = double.Parse(tmpResults[array].PeriodRain.ToString());
                                        if (flag - 0 > 0.01)
                                        {
                                            results.Add(tmpResults[array].PeriodRain.ToString());
                                        }
                                        else
                                        {
                                            results.Add(" ");
                                        }
                                    }
                                    else
                                    {
                                        results.Add("--");
                                    }
                                    array = array + 1;
                                }
                            }
                        }
                        else
                        {
                            results.Add("--");
                        }
                    }
                    for (int k = 0; k < 9; k++)
                    {
                        if (hours.Contains(k))
                        {
                            foreach (var t in tmpResults)
                            {
                                if (t.TimeCollect.Hour == k)
                                {
                                    if (t.PeriodRain.ToString() != "" && t.PeriodRain != -9999)
                                    {
                                        double flag = double.Parse(tmpResults[array].PeriodRain.ToString());
                                        if (flag - 0 > 0.01)
                                        {
                                            results.Add(tmpResults[array].PeriodRain.ToString());
                                        }
                                        else
                                        {
                                            results.Add(" ");
                                        }
                                    }
                                    else
                                    {
                                        results.Add("--");
                                    }
                                    array = array + 1;
                                }
                            }
                        }
                        else
                        {
                            results.Add("--");
                        }
                    }
                }
                double rate = 0.5;
                state = GetState(rate);

                results.Add(sum.ToString());
                return(results);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.Write(e.ToString());
                state = EDataState.EWarning;
                return(null);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Parses custom parameters passed in different operation (for example {"read" : { "query": "key1=value1&key2=>value2" } }).
        /// </summary>
        /// <param name="operation">Operation base - read, write.</param>
        /// <param name="state">Unchange, Insert, Update or Delete.</param>
        /// <returns>Returns dictionary of parsed values.</returns>
        private Dictionary <string, object> ParseAdditionalParameters(OperationBase operation, EDataState state = EDataState.Unchanged)
        {
            Dictionary <string, object> resultDictionary = new Dictionary <string, object>();
            string parseText = null;

            if (operation is Read read)
            {
                parseText = read?.Select?.Query ?? null;
            }

            if (operation is Write write)
            {
                if (state == EDataState.Deleted && (write?.Delete?.Query ?? null) != null)
                {
                    parseText = write.Delete.Query;
                }

                if (state == EDataState.Insert && (write?.Insert?.Query ?? null) != null)
                {
                    parseText = write.Insert.Query;
                }

                if (state == EDataState.Deleted && (write?.Update?.Query ?? null) != null)
                {
                    parseText = write.Update.Query;
                }
            }

            if (string.IsNullOrWhiteSpace(parseText))
            {
                return(resultDictionary);
            }

            string[] keyValues = parseText.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string keyValue in keyValues)
            {
                string[] values = keyValue.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);

                if (values.Length == 2)
                {
                    if (resultDictionary.ContainsKey(values[0]))
                    {
                        resultDictionary[values[0]] = values[1];
                    }
                    else
                    {
                        resultDictionary.Add(values[0], values[1]);
                    }
                }
            }

            return(resultDictionary);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 添加新的一行数据,保证和头部一致,否则失败 ,bWriteToBak是否需要写入备份表,默认是需要写入的
        /// </summary>
        /// <param name="newRow"></param>
        /// <param name="state"></param>
        /// <param name="bWriteToBak"></param>
        /// <returns></returns>
        public bool AddRow(string[] newRow, EDataState state = EDataState.ENormal, bool bWriteToBak = true)
        {
            try
            {
                if (newRow.Length != Header.Length)
                {
                    return(false);
                }
                m_mutexDataTable.WaitOne();
                if (this.IsHandleCreated)
                {
                    // 跨线程调用
                    this.Invoke(new Action(() =>
                    {
                        this.Enabled    = false; //防止在更新的时候点击界面崩溃
                        string[] tmpRow = new string[newRow.Length + 1];
                        newRow.CopyTo(tmpRow, 0);
                        tmpRow[newRow.Length] = ((Int32)state).ToString(); //保存状态位
                        m_bindingSource.SuspendBinding();
                        m_bindingSource.RaiseListChangedEvents = false;
                        //m_dataTable.EndLoadData();
                        m_dataTable.Rows.Add(tmpRow);
                        if (bWriteToBak)
                        {
                            m_dataTableBak.Rows.Add(tmpRow);
                        }
                        //m_dataTable.BeginLoadData();
                        m_bindingSource.RaiseListChangedEvents = true;
                        m_bindingSource.ResumeBinding();

                        //this.Rows[m_dataTable.Rows.Count - 1].Selected = true;
                        //this.FirstDisplayedScrollingRowIndex = m_dataTable.Rows.Count - 1;

                        this.Enabled = true;
                    }));
                }
                else
                {
                    // 窗体还没有创建,直接更新
                    string[] tmpRow = new string[newRow.Length + 1];
                    newRow.CopyTo(tmpRow, 0);
                    tmpRow[newRow.Length] = ((Int32)state).ToString(); //保存状态位
                    m_dataTable.Rows.Add(tmpRow);

                    //this.Rows[m_dataTable.Rows.Count - 1].Selected = true;
                    //this.FirstDisplayedScrollingRowIndex = m_dataTable.Rows.Count - 1;
                }
                m_mutexDataTable.ReleaseMutex();
                TryToUpdateData();
            }
            catch (System.InvalidOperationException e)
            {
                Debug.WriteLine("###Catch Exception:{0}", e.ToString());
            }
            catch (System.ArgumentException e)
            {
                Debug.WriteLine("###Catch Exception:{0}", e.ToString());
            }
            catch (System.InvalidCastException e)
            {
                Debug.WriteLine("###Catch Exception:{0}", e.ToString());
            }
            catch (System.Data.ConstraintException e)
            {
                Debug.WriteLine("###Catch Exception:{0}", e.ToString());
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine("###Catch Exception:{0}", ex.ToString());
            }
            finally
            {
            }
            return(true);
        }
Ejemplo n.º 24
0
        private List <string> GetShowStringList(string stationID, DateTime time, out EDataState state)
        {
            List <string> results = new List <string>();

            results.Add(time.Day + "日");
            int      year    = time.Year;
            int      month   = time.Month;
            int      days    = time.Day;
            DateTime temp    = new DateTime(year, month, days, 0, 0, 0);
            float    moi10   = 0;
            float    moi20   = 0;
            float    moi30   = 0;
            float    sum10   = 0;
            float    sum20   = 0;
            float    sum30   = 0;
            int      count10 = 0;
            int      count20 = 0;
            int      count30 = 0;
            List <CEntitySoilData> tmpResults = new List <CEntitySoilData>();

            tmpResults = CDBDataMgr.Instance.GetMSoilsForTable(stationID, temp);
            if (tmpResults.Count == 0)
            {
                results.Add("-");
                results.Add("-");
                results.Add("-");
                results.Add(" ");
            }
            else
            {
                int length = tmpResults.Count;
                for (int i = 0; i < length; i++)
                {
                    if (tmpResults[i].Moisture10 != -1)
                    {
                        sum10   = sum10 + float.Parse(tmpResults[i].Moisture10.ToString());
                        count10 = count10 + 1;
                    }
                    if (tmpResults[i].Moisture20 != -1)
                    {
                        sum20   = sum20 + float.Parse(tmpResults[i].Moisture20.ToString());
                        count20 = count20 + 1;
                    }
                    if (tmpResults[i].Moisture30 != -1)
                    {
                        sum30   = sum30 + float.Parse(tmpResults[i].Moisture30.ToString());
                        count30 = count30 + 1;
                    }
                }
                if (count10 != 0)
                {
                    moi10 = sum10 / count10;
                    results.Add(moi10.ToString("0.00"));
                }
                else
                {
                    results.Add("--");
                }

                if (count20 != 0)
                {
                    moi20 = sum20 / count20;
                    results.Add(moi20.ToString("0.00"));
                }
                else
                {
                    results.Add("--");
                }

                if (count30 != 0)
                {
                    moi30 = sum30 / count30;
                    results.Add(moi30.ToString("0.00"));
                }
                else
                {
                    results.Add("--");
                }
                results.Add(" ");
            }

            double rate = 0.5;

            state = GetState(rate);
            return(results);
        }
        // 设置显示的雨量记录
        public void SetWaters(List <CEntityWater> listWater)
        {
            // 清空所有数据,是否一定要这样?好像可以考虑其它方式
            base.m_dataTable.Rows.Clear();
            // 判断状态值
            List <string[]>   newRows = new List <string[]>();
            List <EDataState> states  = new List <EDataState>();

            if (!m_bIsEditable)
            {
                string[] newRow;
                // 只读模式
                for (int i = 0; i < listWater.Count; ++i)
                {
                    EDataState     state          = EDataState.ENormal; //默认所有数据都是正常的
                    string         strStationName = "";
                    string         strStationId   = "";
                    string         state_1        = CS_DataState_Normal;
                    CEntityStation station        = CDBDataMgr.Instance.GetStationById(listWater[i].StationID);
                    if (null != station)
                    {
                        strStationName = station.StationName;
                        strStationId   = station.StationID;
                    }
                    if (listWater[i].state == 0)
                    {
                        // 不正常
                        state   = CExDataGridView.EDataState.EError;//红色显示
                        state_1 = CS_DataState_AbNormal;
                    }
                    //水位可以小于0,流量不行
                    //if (listWater[i].WaterFlow < 0 && listWater[i].WaterStage !=-9999)
                    //{
                    //    newRow = new string[]
                    //        {
                    //            strStationId,
                    //            strStationName,/*站名*/
                    //            listWater[i].TimeCollect.ToString(CS_TimeFormat), /*采集时间*/
                    //            listWater[i].WaterStage.ToString(), /*水位*/
                    //             "--",
                    //            listWater[i].TimeRecieved.ToString(CS_TimeFormat), /*接收时间*/
                    //            CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType), /*通讯方式*/
                    //            CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType) /*报文类型*/
                    //        };
                    //}
                    if (listWater[i].WaterStage == -9999 && listWater[i].WaterFlow > 0)
                    {
                        newRow = new string[]
                        {
                            strStationId,
                            strStationName,                                                             /*站名*/
                            listWater[i].TimeCollect.ToString(CS_TimeFormat),                           /*采集时间*/
                            "--",                                                                       /*水位*/
                            listWater[i].WaterFlow.HasValue?listWater[i].WaterFlow.Value.ToString():"", /*流量*/
                            state_1,
                            listWater[i].TimeRecieved.ToString(CS_TimeFormat),                          /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType),                   /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType)                    /*报文类型*/
                        };
                    }
                    else if (listWater[i].WaterStage != -9999 && listWater[i].WaterFlow < 0)
                    {
                        newRow = new string[]
                        {
                            strStationId,
                            strStationName,                                   /*站名*/
                            listWater[i].TimeCollect.ToString(CS_TimeFormat), /*采集时间*/
                            listWater[i].WaterStage.ToString(),               /*水位*/
                            "--",
                            state_1,
                            listWater[i].TimeRecieved.ToString(CS_TimeFormat),        /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType), /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType)  /*报文类型*/
                        };
                    }
                    else if (listWater[i].WaterStage == -9999 && listWater[i].WaterFlow < 0)
                    {
                        newRow = new string[]
                        {
                            strStationId,
                            strStationName,                                   /*站名*/
                            listWater[i].TimeCollect.ToString(CS_TimeFormat), /*采集时间*/
                            "--",
                            "--",
                            state_1,
                            listWater[i].TimeRecieved.ToString(CS_TimeFormat),        /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType), /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType)  /*报文类型*/
                        };
                    }
                    else
                    {
                        newRow = new string[]
                        {
                            m_strStaionId,
                            strStationName,                                           /*站名*/
                            listWater[i].TimeCollect.ToString(CS_TimeFormat),         /*采集时间*/
                            listWater[i].WaterStage.ToString(),                       /*水位*/
                            listWater[i].WaterFlow.ToString(),                        /*流量*/
                            state_1,
                            listWater[i].TimeRecieved.ToString(CS_TimeFormat),        /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType), /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType), /*报文类型*/
                            //        listWater[i].WaterID.ToString() /*水量ID*/
                        };
                    }
                    newRows.Add(newRow);
                    states.Add(state);
                }
                // 添加到集合的数据表中
                base.AddRowRange(newRows, states);
            }
            else
            {
                string[] newRow;
                // 编辑模式,需要将更新的数据和删除的数据,与当前数据进行合并
                for (int i = 0; i < listWater.Count; ++i)
                {
                    EDataState     state          = EDataState.ENormal; //默认所有数据都是正常的
                    string         strStationName = "";
                    string         state_1        = CS_DataState_Normal;
                    CEntityStation station        = CDBDataMgr.Instance.GetStationById(listWater[i].StationID);
                    if (null != station)
                    {
                        strStationName = station.StationName;
                    }
                    if (listWater[i].state == 0)
                    {
                        // 不正常
                        state   = CExDataGridView.EDataState.EError;//红色显示
                        state_1 = CS_DataState_AbNormal;
                    }
                    //    string[] newRow = new string[]
                    //    {
                    //        "False", /*未选中*/
                    //        m_strStaionId,
                    //        strStationName,/*站名*/
                    //        listWater[i].TimeCollect.ToString(CS_TimeFormat), /*采集时间*/
                    //        listWater[i].WaterStage.ToString(), /*水位*/
                    //        listWater[i].WaterFlow.ToString(), /*流量*/
                    //        listWater[i].TimeRecieved.ToString(CS_TimeFormat), /*接收时间*/
                    //        CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType), /*通讯方式*/
                    //        CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType), /*报文类型*/
                    ////        listWater[i].WaterID.ToString() /*水量ID*/
                    //    };

                    if (listWater[i].WaterStage == -9999 && listWater[i].WaterFlow > 0)
                    {
                        newRow = new string[]
                        {
                            "False",                                                                    /*未选中*/
                            m_strStaionId,
                            strStationName,                                                             /*站名*/
                            listWater[i].TimeCollect.ToString(CS_TimeFormat),                           /*采集时间*/
                            "",                                                                         /*水位*/
                            listWater[i].WaterFlow.HasValue?listWater[i].WaterFlow.Value.ToString():"", /*流量*/
                            state_1,
                            listWater[i].TimeRecieved.ToString(CS_TimeFormat),                          /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType),                   /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType)                    /*报文类型*/
                        };
                    }
                    else if (listWater[i].WaterStage != -9999 && listWater[i].WaterFlow < 0)
                    {
                        newRow = new string[]
                        {
                            "False",                                          /*未选中*/
                            m_strStaionId,
                            strStationName,                                   /*站名*/
                            listWater[i].TimeCollect.ToString(CS_TimeFormat), /*采集时间*/
                            listWater[i].WaterStage.ToString(),               /*水位*/
                            "",
                            state_1,
                            listWater[i].TimeRecieved.ToString(CS_TimeFormat),        /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType), /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType)  /*报文类型*/
                        };
                    }
                    else if (listWater[i].WaterStage == -9999 && listWater[i].WaterFlow < 0)
                    {
                        newRow = new string[]
                        {
                            "False",                                          /*未选中*/
                            m_strStaionId,
                            strStationName,                                   /*站名*/
                            listWater[i].TimeCollect.ToString(CS_TimeFormat), /*采集时间*/
                            "",
                            "",
                            state_1,
                            listWater[i].TimeRecieved.ToString(CS_TimeFormat),        /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType), /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType)  /*报文类型*/
                        };
                    }
                    else
                    {
                        newRow = new string[]
                        {
                            "False",                                                  /*未选中*/
                            m_strStaionId,
                            strStationName,                                           /*站名*/
                            listWater[i].TimeCollect.ToString(CS_TimeFormat),         /*采集时间*/
                            listWater[i].WaterStage.ToString(),                       /*水位*/
                            listWater[i].WaterFlow.ToString(),                        /*流量*/
                            state_1,
                            listWater[i].TimeRecieved.ToString(CS_TimeFormat),        /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType), /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType), /*报文类型*/
                            //        listWater[i].WaterID.ToString() /*水量ID*/
                        };
                    }
                    newRows.Add(newRow);
                    states.Add(state);
                }
                // 添加到集合的数据表中
                base.AddRowRange(newRows, states);
            }
        }
        private List <string> GetShowStringList(CEntityStation station, DateTime time, out EDataState state)
        {
            // 一天从9点钟开始,到第二天8点结束
            int                   year        = time.Year;
            int                   month       = time.Month;
            int                   day         = time.Day;
            DateTime              dt          = new DateTime(year, month, day, 9, 0, 0);
            List <DateTime>       results     = new List <DateTime>();
            List <CEntityVoltage> tmpResults  = new List <CEntityVoltage>();
            List <CEntityVoltage> GSMResults  = new List <CEntityVoltage>();
            List <CEntityVoltage> GPRSResults = new List <CEntityVoltage>();

            //DateTime timeStart = new DateTime(time.Year, time.Month, time.Day, 9, 0, 0);
            //DateTime timeEnd = new DateTime(time.Year, time.Month, time.Day, 8, 0, 0);
            //timeEnd = timeEnd.AddDays(1);
            //results = m_proxyCommnunicationRate.QueryRecordByStationIdAndPeriod(station.StationID,
            //    timeStart, timeEnd);
            tmpResults = CDBDataMgr.Instance.GetVoltageForRateTable(station, dt);
            //for (int k = 0; k < tmpResults.Count; k++)
            //{
            //    int n = int.Parse(tmpResults[k].type);
            //    if (n == 3)
            //    {
            //        GPRSResults.Add(tmpResults[k]);
            //    }
            //    if (n == 6)
            //    {
            //        GSMResults.Add(tmpResults[k]);
            //    }
            //}
            //int GPRSNum = GPRSResults.Count;
            //int GSMNum = GSMResults.Count;
            List <int> hourlist = new List <int>();

            for (int i = 0; i < tmpResults.Count; ++i)
            {
                if (!hourlist.Contains(tmpResults[i].TimeCollect.Hour))
                {
                    int n = int.Parse(tmpResults[i].type);
                    if (n == 3)
                    {
                        GPRSResults.Add(tmpResults[i]);
                    }
                    if (n == 6)
                    {
                        GSMResults.Add(tmpResults[i]);
                    }
                    hourlist.Add(tmpResults[i].TimeCollect.Hour);
                }
            }
            List <string> resultUI = new List <string>();

            resultUI.Add(station.StationID);
            resultUI.Add(station.StationName);
            // 24小时是00点
            for (int i = 9; i < 24; ++i)
            {
                if (hourlist.Contains(i))
                {
                    resultUI.Add(CS_RecordRight);
                }
                else
                {
                    resultUI.Add(CS_RecordError);
                }
            }
            for (int i = 0; i < 9; ++i)
            {
                if (hourlist.Contains(i))
                {
                    resultUI.Add(CS_RecordRight);
                }
                else
                {
                    resultUI.Add(CS_RecordError);
                }
            }
            int GPRSNum        = GPRSResults.Count;
            int GSMNum         = GSMResults.Count;
            int reportInterval = Int16.Parse(CDBDataMgr.Instance.GetIntervalForRateTable(station));

            resultUI.Add(reportInterval.ToString()); //应收24条 需要从表中获取
            resultUI.Add(hourlist.Count.ToString()); //实收的条数
            double GSMRate  = GSMNum / (double)reportInterval * 100;
            double GPRSRate = GPRSNum / (double)reportInterval * 100;
            double rate     = hourlist.Count / (double)reportInterval;

            state = GetState(rate);                    //计算颜色
            CalcState(rate);
            rate = rate * 100;                         //百分比
            resultUI.Add(rate.ToString("0.00") + "%"); //保留两位小数
            resultUI.Add(GSMRate.ToString("0.00") + "%");
            resultUI.Add(GPRSRate.ToString("0.00") + "%");
            return(resultUI);
        }
        // 设置显示的雨量记录
        public void SetRain(List <CEntityRain> listRain)
        {
            // 清空所有数据,是否一定要这样?好像可以考虑其它方式
            base.m_dataTable.Rows.Clear();
            // 判断状态值
            List <string[]>   newRows = new List <string[]>();
            List <EDataState> states  = new List <EDataState>();

            if (!m_bIsEditable)
            {
                // 只读模式
                for (int i = 0; i < listRain.Count; ++i)
                {
                    EDataState     state          = EDataState.ENormal; //默认所有数据都是正常的
                    string         strStationName = "";
                    string         strStationId   = "";
                    string         state_1        = CS_DataState_Normal;
                    CEntityStation station        = CDBDataMgr.Instance.GetStationById(listRain[i].StationID);
                    if (null != station)
                    {
                        strStationName = station.StationName;
                        strStationId   = station.StationID;
                    }

                    if (listRain[i].BState == 0)
                    {
                        // 不正常
                        state   = CExDataGridView.EDataState.EError;//红色显示
                        state_1 = CS_DataState_AbNormal;
                    }
                    else if (listRain[i].BState == 2)
                    {
                        // 不正常
                        state   = CExDataGridView.EDataState.EWarning;//黄色显示
                        state_1 = CS_DataState_Warning;
                    }
                    string[] newRow = new string[]
                    {
                        strStationId,
                        strStationName,
                        listRain[i].TimeCollect.ToString(CS_TimeFormat),                          /*采集时间*/
                        listRain[i].TotalRain.ToString(),                                         /*累计雨量*/
                        (listRain[i].DifferneceRain < 0?0:listRain[i].DifferneceRain).ToString(), /*差值雨量*/
                        (listRain[i].PeriodRain < 0?0:listRain[i].PeriodRain).ToString(),         /*时段雨量*/
                        (listRain[i].DayRain < 0?0:listRain[i].DayRain).ToString(),               /*日雨量,貌似只有8点钟才有,注意*/
                        state_1,
                        listRain[i].TimeRecieved.ToString(CS_TimeFormat),                         /*接收时间*/
                        CEnumHelper.ChannelTypeToUIStr(listRain[i].ChannelType),                  /*通讯方式*/
                        CEnumHelper.MessageTypeToUIStr(listRain[i].MessageType)                   /*报文类型*/
                    };

                    newRows.Add(newRow);
                    states.Add(state);
                }
            }
            else
            {
                // 编辑模式,需要将更新的数据和删除的数据,与当前数据进行合并,不弄这个
                for (int i = 0; i < listRain.Count; ++i)
                {
                    EDataState     state          = EDataState.ENormal; //默认所有数据都是正常的
                    string         strStationName = "";
                    string         strStationId   = "";
                    string         state_1        = CS_DataState_Normal;
                    CEntityStation station        = CDBDataMgr.Instance.GetStationById(listRain[i].StationID);
                    if (null != station)
                    {
                        strStationName = station.StationName;
                        strStationId   = station.StationID;
                    }
                    if (listRain[i].BState == 0)
                    {
                        // 不正常
                        state   = CExDataGridView.EDataState.EError;//红色显示
                        state_1 = CS_DataState_AbNormal;
                    }
                    else if (listRain[i].BState == 2)
                    {
                        // 不正常
                        state   = CExDataGridView.EDataState.EWarning;//黄色显示
                        state_1 = CS_DataState_Warning;
                    }
                    string[] newRow = new string[]
                    {
                        "False",                                                                  /*未选中*/
                        strStationId,
                        strStationName,                                                           /*站名*/
                        listRain[i].TimeCollect.ToString(CS_TimeFormat),                          /*采集时间*/
                        listRain[i].TotalRain.ToString(),                                         /*累计雨量*/
                        (listRain[i].DifferneceRain < 0?0:listRain[i].DifferneceRain).ToString(), /*差值雨量*/
                        (listRain[i].PeriodRain < 0?0:listRain[i].PeriodRain).ToString(),         /*时段雨量*/
                        (listRain[i].DayRain < 0?0:listRain[i].DayRain).ToString(),               /*日雨量,貌似只有8点钟才有,注意*/
                        state_1,
                        listRain[i].TimeRecieved.ToString(CS_TimeFormat),                         /*接收时间*/
                        CEnumHelper.ChannelTypeToUIStr(listRain[i].ChannelType),                  /*通讯方式*/
                        CEnumHelper.MessageTypeToUIStr(listRain[i].MessageType),                  /*报文类型*/
                        //    listRain[i].RainID.ToString() /*雨量ID*/
                    };

                    newRows.Add(newRow);
                    states.Add(state);
                }
            }
            // 添加到集合的数据表中
            base.AddRowRange(newRows, states);
        }
        private List <string> GetShowStringList(string station, string name, DateTime date, out EDataState state)
        {
            int           year          = date.Year;
            int           month         = date.Month;
            int           days          = DateTime.DaysInMonth(year, month);
            string        averResults10 = "";
            string        averResults20 = "";
            string        averResults30 = "";
            List <string> results       = new List <string>();
            float         moi10         = 0;
            float         moi20         = 0;
            float         moi30         = 0;
            float         sum10         = 0;
            float         sum20         = 0;
            float         sum30         = 0;
            int           count10       = 0;
            int           count20       = 0;
            int           count30       = 0;

            for (int i = 1; i <= days; i++)
            {
                DateTime tmp = new DateTime(year, month, i, 0, 0, 0);
                List <CEntitySoilData> temResults = new List <CEntitySoilData>();
                temResults = CDBDataMgr.Instance.GetMSoilsForTable(station, tmp);
                int length = temResults.Count;
                for (int j = 0; j < length; j++)
                {
                    if (temResults[j].Moisture10 != -1)
                    {
                        sum10   = sum10 + float.Parse(temResults[j].Moisture10.ToString());
                        count10 = count10 + 1;
                    }
                    if (temResults[j].Moisture20 != -1)
                    {
                        sum20   = sum20 + float.Parse(temResults[j].Moisture20.ToString());
                        count20 = count20 + 1;
                    }
                    if (temResults[j].Moisture30 != -1)
                    {
                        sum30   = sum30 + float.Parse(temResults[j].Moisture30.ToString());
                        count30 = count30 + 1;
                    }
                }
            }
            moi10 = sum10 / count10;
            moi20 = sum20 / count20;
            moi30 = sum30 / count30;
            if (count10 == 0)
            {
                averResults10 = "--";
            }
            else
            {
                averResults10 = moi10.ToString();
            }
            if (count20 == 0)
            {
                averResults20 = "--";
            }
            else
            {
                averResults20 = moi20.ToString();
            }
            if (count30 == 0)
            {
                averResults30 = "--";
            }
            else
            {
                averResults30 = moi30.ToString();
            }
            results.Add("。。。");
            results.Add(station);
            results.Add(name);
            results.Add(averResults10);
            results.Add(averResults20);
            results.Add(averResults30);
            results.Add("....");
            double rate = 0.5;

            state = GetState(rate);
            return(results);
        }
Ejemplo n.º 29
0
        public void RefreshGPRSInfo(ushort port, string stationName, string stationID, ModemInfoStruct dtu)
        {
            try
            {
                string uid = ((uint)dtu.m_modemId).ToString("X").PadLeft(8, '0');
                //int cutPort = dtu.
                string phoneno = CGprsUtil.Byte11ToPhoneNO(dtu.m_phoneno, 0);

                string   dynIP       = CGprsUtil.Byte4ToIP(dtu.m_dynip, 0);
                DateTime connetime   = CGprsUtil.ULongToDatetime(dtu.m_conn_time);
                DateTime refreshTime = CGprsUtil.ULongToDatetime(dtu.m_refresh_time);
                //如果计算机当前时间与刷新时间间隔超过一小时,标记为红色
                //现在改为10分钟,不在线,红色标记
                EDataState state = EDataState.ENormal;

                //  if ((DateTime.Now - refreshTime).TotalMinutes > 60)
                //超过10分钟,表示不在线
                if ((DateTime.Now - refreshTime).TotalMinutes > 10)
                {
                    this.cS_OnlineOrOffline     = "离线";
                    this.CS_OnlineOrOfflineFlag = "0";
                    state = EDataState.EError;
                }
                else
                {
                    this.cS_OnlineOrOffline     = "在线";
                    this.CS_OnlineOrOfflineFlag = "2";
                    this.m_onlineGprsCount     += 1;
                    if (!m_onlineGprsList.Contains(uid))
                    {
                        m_onlineGprsList.Add(uid);
                    }
                }

                // 判断是否在列中存在,如果不存在,则新建列
                // 先找到ID所在的行
                // this.Hide();
                // m_dataTable_1 = base.m_dataTable;

                this.BeginInvoke(new System.Action(() =>
                {
                    for (int i = 0; i < m_dataTable_1.Rows.Count; ++i)
                    {
                        if (m_dataTable_1.Rows[i][CS_UserId].ToString() == uid)
                        {
                            //m_dataTable_1.Rows.Add(new string[] { port.ToString(), stationName, uid, phoneno, dynIP, connetime.ToString(), refreshTime.ToString(), CS_OnlineOrOffline.ToString(), CS_OnlineOrOfflineFlag, Convert.ToString((int)state) });
                            DataRow newRow            = m_dataTable_1.NewRow();
                            newRow[CS_Port]           = port.ToString();
                            newRow[CS_StationName]    = stationName;
                            newRow[CS_StationID]      = stationID;
                            newRow[CS_UserId]         = uid;
                            newRow[CS_Telephone]      = phoneno;
                            newRow[CS_DynamicIP]      = dynIP;
                            newRow[CS_ConnectionTime] = connetime.ToString();
                            newRow[CS_RecvTime]       = refreshTime.ToString();
                            newRow["在线状态"]            = this.cS_OnlineOrOffline.ToString();
                            newRow["在线状态记录"]          = CS_OnlineOrOfflineFlag;
                            newRow["state"]           = Convert.ToString((int)state);
                            m_dataTable_1.Rows.InsertAt(newRow, i);
                            m_dataTable_1.Rows.RemoveAt(i + 1);
                            // 找到匹配,更新行的内容
                            //Gprs_Copy.UpdateRowData(i, new string[] { port.ToString(), stationName, uid, phoneno, dynIP, connetime.ToString(), refreshTime.ToString(), CS_OnlineOrOffline.ToString(), CS_OnlineOrOfflineFlag }, state);
                            //m_mutexDataTable.ReleaseMutex();
                            //return;
                        }
                    }
                    //DataView dataView = m_dataTable_1.DefaultView;
                    //dataView.Sort = "用户ID asc";
                    //m_dataTable_1 = dataView.ToTable();
                    //for (int i = 0; i < base.m_dataTable.Columns.Count; ++i)
                    //{
                    //    Console.WriteLine(base.m_dataTable.Columns[i].ColumnName + "...");
                    //}
                    //for (int i = 0; i < 1; ++i)
                    //{
                    //    for (int j = 0; j < base.m_dataTable.Columns.Count; ++j)
                    //    {
                    //        Console.WriteLine(base.m_dataTable.Rows[i][j] + "...");
                    //    }
                    //}
                    // m_dataTable_1.DefaultView.Sort="用户ID asc";
                    base.DataSource = m_dataTable_1.DefaultView;
                    return;
                }));
                //  this.Show();
                // 没有找到匹配,添加新的行记录
                //  m_mutexDataTable.ReleaseMutex();
                return;
                //base.AddRow(new string[] { port.ToString(), stationName, uid, phoneno, dynIP, connetime.ToString(), refreshTime.ToString(), CS_OnlineOrOffline.ToString(), CS_OnlineOrOfflineFlag }, state);
                //this.m_totalGprsCount += 1;
            }
            catch (Exception ex)
            {
                this.Hide();
                MessageBox.Show("刷新出错!" + ex.ToString());
                this.Show();
            }
        }
Ejemplo n.º 30
0
        private List <string> GetShowStringList(string station, DateTime time, int day, out EDataState state)
        {
            //List<string> tmpResults = new List<string>();
            string minTime    = "";
            string maxTime    = "";
            double max        = 0;
            double min        = 100000;
            double aver       = 0;
            double sumForAver = 0;
            List <CEntityWater> temResults = new List <CEntityWater>();

            temResults = CDBDataMgr.Instance.GetWaterForTable(station, time);
            //if(temResults.Count == 0)
            //{
            //    min = 0;
            //    max = 0;
            //}
            for (int k = 0; k < temResults.Count; k++)
            {
                double temp = double.Parse(temResults[k].WaterStage.ToString());
                if (temp < min)
                {
                    min     = temp;
                    minTime = temResults[k].TimeCollect.Hour + "时" + temResults[k].TimeCollect.Minute + "分";
                }
                if (temp > max)
                {
                    max     = temp;
                    maxTime = temResults[k].TimeCollect.Hour + "时" + temResults[k].TimeCollect.Minute + "分";
                }
                sumForAver = sumForAver + temp;
            }
            if (temResults.Count != 0)
            {
                aver = sumForAver / temResults.Count;
            }
            else
            {
                aver = 9999.9999;
            }


            List <string> results = new List <string>();

            results.Add(day + "日");
            for (int i = 1; i < 25; i++)
            {
                double        tmpSum       = 0;
                List <string> smallResults = new List <string>();

                for (int j = 0; j < temResults.Count; j++)
                {
                    DateTime temp = temResults[j].TimeCollect;
                    if (temp.Hour == i)
                    {
                        smallResults.Add(temResults[j].WaterStage.ToString());
                    }
                    if (i == 24)
                    {
                        if (temp.Hour == 0)
                        {
                            smallResults.Add(temResults[j].WaterStage.ToString());
                        }
                    }
                }
                if (smallResults.Count == 0)
                {
                    results.Add("--");
                }
                if (smallResults.Count != 0)
                {
                    for (int j = 0; j < smallResults.Count; j++)
                    {
                        tmpSum = tmpSum + double.Parse(smallResults[j]);
                    }
                    double tmpAver = tmpSum / smallResults.Count;
                    results.Add(tmpAver.ToString("0.00"));
                }
            }
            if (aver == 9999.9999)
            {
                results.Add("--");
            }
            else
            {
                results.Add(aver.ToString("0.00"));
            }

            if (max - 0 < 0.001)
            {
                results.Add("-");
            }
            else
            {
                results.Add(max.ToString("0.00"));
            }
            results.Add(maxTime);
            if (min - 9999 > 0.1)
            {
                results.Add("-");
            }
            else
            {
                results.Add(min.ToString("0.00"));
            }

            results.Add(minTime);
            double rate = 0.5;

            state = GetState(rate);
            return(results);
        }
Ejemplo n.º 31
0
        public void RefreshGPRSInfo_new(ushort port, string stationName, string stationID, HDModemInfoStruct dtu)
        {
            try
            {
                string uid     = System.Text.Encoding.Default.GetString(dtu.m_modemId).Substring(0, 11);
                string phoneno = "------";
                string dynIP   = this.IntToIp((int)dtu.m_sin_addr);

                string   cutport1       = this.IntToIp((int)dtu.m_sin_port);
                string   cutport2       = this.IntToIp((int)dtu.m_local_port);
                string   conntimeStr    = System.Text.Encoding.Default.GetString(dtu.m_logon_date);
                string   refreshtimeStr = System.Text.Encoding.Default.GetString(dtu.m_update_time);
                DateTime connetime      = DateTime.Parse(conntimeStr.Substring(0, conntimeStr.Length - 1));
                DateTime refreshTime    = DateTime.Now;
                try
                {
                    refreshTime = DateTime.Parse(refreshtimeStr.Substring(0, 17));;
#pragma warning disable CS0168 // 声明了变量“eee”,但从未使用过
                }catch (Exception eee)
#pragma warning restore CS0168 // 声明了变量“eee”,但从未使用过
                {
                    //refreshTime = connetime;
                }
                EDataState state = EDataState.ENormal;
                if ((DateTime.Now - refreshTime).TotalMinutes > 60)
                {
                    this.cS_OnlineOrOffline     = "离线";
                    this.CS_OnlineOrOfflineFlag = "0";
                    state = EDataState.EError;
                }
                else
                {
                    this.cS_OnlineOrOffline     = "在线";
                    this.CS_OnlineOrOfflineFlag = "2";
                    this.m_onlineGprsCount     += 1;
                    if (!m_onlineGprsList.Contains(uid))
                    {
                        m_onlineGprsList.Add(uid);
                    }
                }
                this.BeginInvoke(new System.Action(() =>
                {
                    for (int i = 0; i < m_dataTable_1.Rows.Count; ++i)
                    {
                        if (m_dataTable_1.Rows[i][CS_UserId].ToString() == uid)
                        {
                            //m_dataTable_1.Rows.Add(new string[] { port.ToString(), stationName, uid, phoneno, dynIP, connetime.ToString(), refreshTime.ToString(), CS_OnlineOrOffline.ToString(), CS_OnlineOrOfflineFlag, Convert.ToString((int)state) });
                            DataRow newRow            = m_dataTable_1.NewRow();
                            newRow[CS_Port]           = port.ToString();
                            newRow[CS_StationName]    = stationName;
                            newRow[CS_StationID]      = stationID;
                            newRow[CS_UserId]         = uid;
                            newRow[CS_Telephone]      = phoneno;
                            newRow[CS_DynamicIP]      = dynIP;
                            newRow[CS_ConnectionTime] = connetime.ToString();
                            newRow[CS_RecvTime]       = refreshTime.ToString();
                            newRow["在线状态"]            = this.cS_OnlineOrOffline.ToString();
                            newRow["在线状态记录"]          = CS_OnlineOrOfflineFlag;
                            newRow["state"]           = Convert.ToString((int)state);
                            m_dataTable_1.Rows.InsertAt(newRow, i);
                            m_dataTable_1.Rows.RemoveAt(i + 1);
                            // 找到匹配,更新行的内容
                            //Gprs_Copy.UpdateRowData(i, new string[] { port.ToString(), stationName, uid, phoneno, dynIP, connetime.ToString(), refreshTime.ToString(), CS_OnlineOrOffline.ToString(), CS_OnlineOrOfflineFlag }, state);
                            //m_mutexDataTable.ReleaseMutex();
                            //return;
                        }
                    }
                    //DataView dataView = m_dataTable_1.DefaultView;
                    //dataView.Sort = "用户ID asc";
                    //m_dataTable_1 = dataView.ToTable();
                    //for (int i = 0; i < base.m_dataTable.Columns.Count; ++i)
                    //{
                    //    Console.WriteLine(base.m_dataTable.Columns[i].ColumnName + "...");
                    //}
                    //for (int i = 0; i < 1; ++i)
                    //{
                    //    for (int j = 0; j < base.m_dataTable.Columns.Count; ++j)
                    //    {
                    //        Console.WriteLine(base.m_dataTable.Rows[i][j] + "...");
                    //    }
                    //}
                    // m_dataTable_1.DefaultView.Sort="用户ID asc";
                    base.DataSource = m_dataTable_1.DefaultView;
                    return;
                }));
                //  this.Show();
                // 没有找到匹配,添加新的行记录
                //  m_mutexDataTable.ReleaseMutex();
                return;
                //base.AddRow(new string[] { port.ToString(), stationName, uid, phoneno, dynIP, connetime.ToString(), refreshTime.ToString(), CS_OnlineOrOffline.ToString(), CS_OnlineOrOfflineFlag }, state);
                //this.m_totalGprsCount += 1;
            }
            catch (Exception ex)
            {
                this.Hide();
                MessageBox.Show("刷新出错!" + ex.ToString());
                this.Show();
            }
        }