private void gprs_ModemInfoDataReceived(object sender, EventArgs e) { try { if (!this.IsHandleCreated) { return; } var gprs = sender as IGprs; if (gprs == null) { return; } if (!gprs.GetStarted()) { return; } if (gprs.DTUList == null) { return; } ushort portValue = gprs.GetListenPort(); //if (gprs.DTUList.Count() == 0) // return; if (isRefreshDgvWhenPageFirstLoad) { //MessageBox.Show("Update First : " + DateTime.Now + " " + dgvDTUList.IsHandleCreated); //dgvDTUList.ClearAllRows(); dgvDTUList.OnlineGprsCount = 0; dgvDTUList.TotalGprsCount = 0; //1025 //dgvDTUList.Hide(); // 添加数据库中所有已经配置的GPRS号码 // dgvDTUList.RefreshGPRSInfo(this.m_listStations); foreach (var station in m_listStations) { if (!string.IsNullOrEmpty(station.GPRS)) { dgvDTUList.m_totalGprsCount += 1; } } //foreach (var station in m_listSoilStations) //{ // if (!string.IsNullOrEmpty(station.GPRS)) // { // dgvDTUList.m_totalGprsCount += 1; // } //} // 更新已经上线的GPRS号码 foreach (var dtu in gprs.DTUList) { var stationName = QueryStationNameByUserID(dtu); var stationID = QueryStationIDByUserID(dtu); var port = QuerySubcenterNameByUserID(dtu); if (stationName != "---") { dgvDTUList.RefreshGPRSInfo(port, stationName, stationID, dtu); } } // dgvDTUList.Show(); dgvDTUList.UpdateDataToUI(); this.lblToolTip.Invoke((Action) delegate { this.lblToolTip.Text = string.Format("GPRS站点在线状态统计 在线:{0}个,离线:{1}个,共:{2}个,上次刷新时间{3}.", dgvDTUList.OnlineGprsCount, dgvDTUList.OfflineGprsCount, dgvDTUList.TotalGprsCount, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); }); isRefreshDgvWhenPageFirstLoad = false; // 更新时间 m_preRefreshTime = DateTime.Now; } else { TimeSpan span = DateTime.Now - m_preRefreshTime; //System.Diagnostics.Debug.WriteLine("Total Second : " + span.TotalSeconds); if (span.TotalSeconds >= m_timeSpanRefresh.TotalSeconds) { //MessageBox.Show("Update Second : " + DateTime.Now + " " + dgvDTUList.IsHandleCreated); //System.Diagnostics.Debug.WriteLine("Update Gprs !"); // dgvDTUList.ClearAllRows(); m_mutexDataTable_1.WaitOne(); if (SubcenterString == "全部") { dgvDTUList.OnlineGprsCount = 0; dgvDTUList.TotalGprsCount = 0; //1025 // dgvDTUList.Hide(); // 添加数据库中所有已经配置的GPRS号码 // dgvDTUList.RefreshGPRSInfo(this.m_listStations); foreach (var station in m_listStations) { if (!string.IsNullOrEmpty(station.GPRS)) { dgvDTUList.m_totalGprsCount += 1; } } //foreach (var station in m_listSoilStations) //{ // if (!string.IsNullOrEmpty(station.GPRS)) // { // dgvDTUList.m_totalGprsCount += 1; // } //} // 更新已经上线的GPRS号码 foreach (var dtu in gprs.DTUList) { var stationName = QueryStationNameByUserID(dtu); var stationID = QueryStationIDByUserID(dtu); var port = QuerySubcenterNameByUserID(dtu); if (stationName != "---") { dgvDTUList.RefreshGPRSInfo(port, stationName, stationID, dtu); } } // dgvDTUList.Show(); dgvDTUList.UpdateDataToUI(); this.lblToolTip.Invoke((Action) delegate { this.lblToolTip.Text = string.Format("GPRS站点在线状态统计 在线:{0}个,离线:{1}个,共:{2}个,上次刷新时间{3}.", dgvDTUList.OnlineGprsCount, dgvDTUList.OfflineGprsCount, dgvDTUList.TotalGprsCount, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); }); //this.lblToolTip.Show(); } else { dgvDTUList.OnlineGprsCount = 0; dgvDTUList.TotalGprsCount = 0; try { foreach (var station in m_listStations) { if (CDBDataMgr.Instance.GetSubCenterById(int.Parse(station.SubCenterID.ToString())).SubCenterName == SubcenterString) { if (!string.IsNullOrEmpty(station.GPRS)) { dgvDTUList.m_totalGprsCount += 1; } } } //foreach (var station in m_listSoilStations) //{ // if (CDBSoilDataMgr.Instance.GetSubCenterBySoilId(int.Parse(station.SubCenterID.ToString())).SubCenterName == SubcenterString) // { // if (!string.IsNullOrEmpty(station.GPRS)) // { // dgvDTUList.m_totalGprsCount += 1; // } // } //} } catch (Exception ex) { Console.WriteLine("获取所有分中心站点错误。。。"); } try { // 更新已经上线的GPRS号码 foreach (var dtu in gprs.DTUList) { var stationName = QueryStationNameByUserID(dtu); var stationID = QueryStationIDByUserID(dtu); var station = QueryStationEntityByUserID(dtu); var soil = QuerySoilStationEntityByUserID(dtu); var port = QuerySubcenterNameByUserID(dtu); if (station != null) { if (CDBDataMgr.Instance.GetSubCenterById(int.Parse(station.SubCenterID.ToString())).SubCenterName == SubcenterString) { dgvDTUList.RefreshGPRSInfo(port, stationName, stationID, dtu); } } //else if (soil != null) //{ // if (CDBSoilDataMgr.Instance.GetSubCenterBySoilId(int.Parse(soil.SubCenterID.ToString())).SubCenterName == SubcenterString) // { // dgvDTUList.RefreshGPRSInfo(port, stationName, stationID, dtu); // } //} } } catch (Exception ex) { Console.WriteLine("更新所有分中心站点错误。。。"); } // dgvDTUList.Show(); dgvDTUList.UpdateDataToUI(); this.lblToolTip.Invoke((Action) delegate { this.lblToolTip.Text = string.Format("GPRS站点在线状态统计 在线:{0}个,离线:{1}个,共:{2}个,上次刷新时间{3}.", dgvDTUList.OnlineGprsCount, dgvDTUList.OfflineGprsCount, dgvDTUList.TotalGprsCount, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); }); //this.lblToolTip.Show(); } m_mutexDataTable_1.ReleaseMutex(); // 更新时间 m_preRefreshTime = DateTime.Now; m_timeSpanRefresh = new TimeSpan(0, 0, 300); } } } catch (Exception exp) { Console.WriteLine("刷新错误。。。"); //MessageBox.Show("Update Third Exception : " + DateTime.Now + " " + dgvDTUList.IsHandleCreated); } }
private void gprs_ModemInfoDataReceived(object sender, EventArgs e) { try { if (!this.IsHandleCreated) { return; } var gprs = sender as IGprs; var hdgprs = sender as IHDGprs; #region gprs处理 if (gprs != null) { if (gprs == null) { return; } if (!gprs.GetStarted()) { return; } if (gprs.DTUList == null && hdgprs.DTUList == null) { return; } ushort portValue = gprs.GetListenPort(); if (isRefreshDgvWhenPageFirstLoad) { dgvDTUList.OnlineGprsCount = 0; dgvDTUList.TotalGprsCount = 0; foreach (var station in m_listStations) { if (!string.IsNullOrEmpty(station.GPRS)) { dgvDTUList.m_totalGprsCount += 1; } } //foreach (var station in m_listSoilStations) //{ // if (!string.IsNullOrEmpty(station.GPRS)) // { // dgvDTUList.m_totalGprsCount += 1; // } //} foreach (var dtu in gprs.DTUList) { var stationName = QueryStationNameByUserID(dtu); var stationID = QueryStationIDByUserID(dtu); if (stationName != "---") { dgvDTUList.RefreshGPRSInfo(portValue.ToString(), stationName, stationID, dtu); } } this.lblToolTip.Invoke((Action) delegate { this.lblToolTip.Text = string.Format("GPRS站点在线状态统计 在线:{0}个,离线:{1}个,共:{2}个,上次刷新时间{3}.", dgvDTUList.OnlineGprsCount + dgvDTUList.OnlineHDGprsCount, dgvDTUList.OfflineGprsCount, dgvDTUList.TotalGprsCount, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); }); isRefreshDgvWhenPageFirstLoad = false; // 更新时间 m_preRefreshTime = DateTime.Now; } else { TimeSpan span = DateTime.Now - m_preRefreshTime; if (span.TotalSeconds >= m_timeSpanRefresh.TotalSeconds) { m_mutexDataTable_1.WaitOne(); if (SubcenterString == "全部") { dgvDTUList.OnlineGprsCount = 0; dgvDTUList.TotalGprsCount = 0; foreach (var station in m_listStations) { if (!string.IsNullOrEmpty(station.GPRS)) { dgvDTUList.m_totalGprsCount += 1; } } List <string> gprsList = new List <string>(dgvDTUList.OnlineGprsList); foreach (var uid in gprsList) { var stationName = QueryStationNameByUserID(uid); var stationID = QueryStationIDByUserID(uid); dgvDTUList.ReleaseOnlineState(stationName, stationID, uid); } gprsList.Clear(); foreach (var dtu in gprs.DTUList) { var stationName = QueryStationNameByUserID(dtu); var stationID = QueryStationIDByUserID(dtu); if (stationName != "---") { dgvDTUList.RefreshGPRSInfo(portValue.ToString(), stationName, stationID, dtu); } } // dgvDTUList.Show(); dgvDTUList.UpdateDataToUI(); this.lblToolTip.Invoke((Action) delegate { this.lblToolTip.Text = string.Format("GPRS站点在线状态统计 在线:{0}个,离线:{1}个,共:{2}个,上次刷新时间{3}.", dgvDTUList.OnlineGprsCount + dgvDTUList.OnlineHDGprsCount, dgvDTUList.OfflineGprsCount, dgvDTUList.TotalGprsCount, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); }); //this.lblToolTip.Show(); } else { dgvDTUList.OnlineGprsCount = 0; dgvDTUList.TotalGprsCount = 0; try { foreach (var station in m_listStations) { if (CDBDataMgr.Instance.GetSubCenterById(int.Parse(station.SubCenterID.ToString())).SubCenterName == SubcenterString) { if (!string.IsNullOrEmpty(station.GPRS)) { dgvDTUList.m_totalGprsCount += 1; } } } List <string> gprsList = new List <string>(dgvDTUList.OnlineGprsList); foreach (var uid in gprsList) { var stationName = QueryStationNameByUserID(uid); var stationID = QueryStationIDByUserID(uid); dgvDTUList.ReleaseOnlineState(stationName, stationID, uid); } gprsList.Clear(); } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { Console.WriteLine("获取所有分中心站点错误。。。"); } try { // 更新已经上线的GPRS号码 foreach (var dtu in gprs.DTUList) { var stationName = QueryStationNameByUserID(dtu); var stationID = QueryStationIDByUserID(dtu); var station = QueryStationEntityByUserID(dtu); //var soil = QuerySoilStationEntityByUserID(dtu); if (station != null) { if (CDBDataMgr.Instance.GetSubCenterById(int.Parse(station.SubCenterID.ToString())).SubCenterName == SubcenterString) { dgvDTUList.RefreshGPRSInfo(portValue.ToString(), stationName, stationID, dtu); } } //else if (soil != null) //{ // if (CDBSoilDataMgr.Instance.GetSubCenterBySoilId(int.Parse(soil.SubCenterID.ToString())).SubCenterName == SubcenterString) // { // dgvDTUList.RefreshGPRSInfo(portValue, stationName, stationID, dtu); // } //} } } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { Console.WriteLine("更新所有分中心站点错误。。。"); } // dgvDTUList.Show(); dgvDTUList.UpdateDataToUI(); this.lblToolTip.Invoke((Action) delegate { this.lblToolTip.Text = string.Format("GPRS站点在线状态统计 在线:{0}个,离线:{1}个,共:{2}个,上次刷新时间{3}.", dgvDTUList.OnlineGprsCount + dgvDTUList.OnlineHDGprsCount, dgvDTUList.OfflineGprsCount, dgvDTUList.TotalGprsCount, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); }); //this.lblToolTip.Show(); } m_mutexDataTable_1.ReleaseMutex(); // 更新时间 m_preRefreshTime = DateTime.Now; m_timeSpanRefresh = new TimeSpan(0, 0, 300); } } } #endregion #region hggprs处理 if (hdgprs != null) { if (hdgprs == null) { return; } if (hdgprs.DTUList == null) { return; } ushort portValue = hdgprs.GetListenPort(); if (hdisRefreshDgvWhenPageFirstLoad) { dgvDTUList.OnlineHDGprsCount = 0; dgvDTUList.TotalGprsCount = 0; foreach (var station in m_listStations) { if (!string.IsNullOrEmpty(station.GPRS)) { dgvDTUList.m_totalGprsCount += 1; } } //foreach (var station in m_listSoilStations) //{ // if (!string.IsNullOrEmpty(station.GPRS)) // { // dgvDTUList.m_totalGprsCount += 1; // } //} foreach (var dtu in hdgprs.DTUList) { var stationName = QueryStationNameByUserID_new(dtu); var stationID = QueryStationIDByUserID_new(dtu); if (stationName != "---") { dgvDTUList.RefreshGPRSInfo_new(portValue, stationName, stationID, dtu); } } dgvDTUList.UpdateDataToUI(); this.lblToolTip.Invoke((Action) delegate { this.lblToolTip.Text = string.Format("GPRS站点在线状态统计 在线:{0}个,离线:{1}个,共:{2}个,上次刷新时间{3}.", dgvDTUList.OnlineGprsCount + dgvDTUList.OnlineHDGprsCount, dgvDTUList.OfflineGprsCount, dgvDTUList.TotalGprsCount, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); }); hdisRefreshDgvWhenPageFirstLoad = false; // 更新时间 m_preRefreshTime = DateTime.Now; } else { TimeSpan span = DateTime.Now - m_preRefreshTime; if (span.TotalSeconds >= m_timeSpanRefresh.TotalSeconds) { m_mutexDataTable_1.WaitOne(); if (SubcenterString == "全部") { dgvDTUList.OnlineHDGprsCount = 0; dgvDTUList.TotalGprsCount = 0; foreach (var station in m_listStations) { if (!string.IsNullOrEmpty(station.GPRS)) { dgvDTUList.m_totalGprsCount += 1; } } //foreach (var station in m_listSoilStations) //{ // if (!string.IsNullOrEmpty(station.GPRS)) // { // dgvDTUList.m_totalGprsCount += 1; // } //} // 更新已经上线的GPRS号码 foreach (var dtu in hdgprs.DTUList) { var stationName = QueryStationNameByUserID_new(dtu); var stationID = QueryStationIDByUserID_new(dtu); if (stationName != "---") { dgvDTUList.RefreshGPRSInfo_new(portValue, stationName, stationID, dtu); } } dgvDTUList.UpdateDataToUI(); this.lblToolTip.Invoke((Action) delegate { this.lblToolTip.Text = string.Format("GPRS站点在线状态统计 在线:{0}个,离线:{1}个,共:{2}个,上次刷新时间{3}.", dgvDTUList.OnlineGprsCount + dgvDTUList.OnlineHDGprsCount, dgvDTUList.OfflineGprsCount, dgvDTUList.TotalGprsCount, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); }); } else { dgvDTUList.OnlineHDGprsCount = 0; dgvDTUList.TotalGprsCount = 0; try { foreach (var station in m_listStations) { if (CDBDataMgr.Instance.GetSubCenterById(int.Parse(station.SubCenterID.ToString())).SubCenterName == SubcenterString) { if (!string.IsNullOrEmpty(station.GPRS)) { dgvDTUList.m_totalGprsCount += 1; } } } //foreach (var station in m_listSoilStations) //{ // if (CDBSoilDataMgr.Instance.GetSubCenterBySoilId(int.Parse(station.SubCenterID.ToString())).SubCenterName == SubcenterString) // { // if (!string.IsNullOrEmpty(station.GPRS)) // { // dgvDTUList.m_totalGprsCount += 1; // } // } //} } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { Console.WriteLine("获取所有分中心站点错误。。。"); } try { // 更新已经上线的GPRS号码 foreach (var dtu in hdgprs.DTUList) { var stationName = QueryStationNameByUserID_new(dtu); var stationID = QueryStationIDByUserID_new(dtu); var station = QueryStationEntityByUserID_new(dtu); //var soil = QuerySoilStationEntityByUserID_new(dtu); if (station != null) { if (CDBDataMgr.Instance.GetSubCenterById(int.Parse(station.SubCenterID.ToString())).SubCenterName == SubcenterString) { dgvDTUList.RefreshGPRSInfo_new(portValue, stationName, stationID, dtu); } } //else if (soil != null) //{ // if (CDBSoilDataMgr.Instance.GetSubCenterBySoilId(int.Parse(soil.SubCenterID.ToString())).SubCenterName == SubcenterString) // { // dgvDTUList.RefreshGPRSInfo_new(portValue, stationName, stationID, dtu); // } //} } } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { Console.WriteLine("更新所有分中心站点错误。。。"); } // dgvDTUList.Show(); dgvDTUList.UpdateDataToUI(); this.lblToolTip.Invoke((Action) delegate { this.lblToolTip.Text = string.Format("GPRS站点在线状态统计 在线:{0}个,离线:{1}个,共:{2}个,上次刷新时间{3}.", dgvDTUList.OnlineGprsCount + dgvDTUList.OnlineHDGprsCount, dgvDTUList.OfflineGprsCount, dgvDTUList.TotalGprsCount, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); }); //this.lblToolTip.Show(); } m_mutexDataTable_1.ReleaseMutex(); // 更新时间 m_preRefreshTime = DateTime.Now; m_timeSpanRefresh = new TimeSpan(0, 0, 300); } } } #endregion } #pragma warning disable CS0168 // 声明了变量“exp”,但从未使用过 catch (Exception exp) #pragma warning restore CS0168 // 声明了变量“exp”,但从未使用过 { Console.WriteLine("刷新错误。。。"); //MessageBox.Show("Update Third Exception : " + DateTime.Now + " " + dgvDTUList.IsHandleCreated); } }