Example #1
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();
            }
        }
Example #2
0
        private DtuList FindDtuList(Subcenter subcenter)
        {
            DtuList dtuList = new DtuList();

            List <ModemInfoStruct>               stateList    = new List <ModemInfoStruct>();
            List <CEntityStation>                stations     = new List <CEntityStation>();
            List <CEntitySoilStation>            soilStations = new List <CEntitySoilStation>();
            List <CEntitySubCenter>              subCenters   = new List <CEntitySubCenter>();
            Dictionary <string, ModemInfoStruct> gprsDic      = new Dictionary <string, ModemInfoStruct>();

            stateList    = Clone <ModemInfoStruct>(CProtocolEventManager.Instance.GetOnlineStatusList());
            stations     = CDBDataMgr.Instance.GetAllStation();
            soilStations = CDBSoilDataMgr.Instance.GetAllSoilStation();
            subCenters   = CDBDataMgr.Instance.GetAllSubCenter();

            if (stateList.Count() != 0)
            {
                for (int i = 0; i < stateList.Count(); i++)
                {
                    string uid = ((uint)stateList[i].m_modemId).ToString("X").PadLeft(8, '0');
                    gprsDic.Add(uid, stateList[i]);
                }
            }

            foreach (var s in stations)
            {
                if (subcenter.SubcenterdId == s.SubCenterID.ToString() || subcenter.SubcenterdId == "0")
                {
                    if (gprsDic.Count() != 0)
                    {
                        if (gprsDic.ContainsKey(s.GPRS))
                        {
                            Dtu dtu = new Dtu();

                            ModemInfoStruct state       = gprsDic[s.GPRS];
                            string          phoneno     = CGprsUtil.Byte11ToPhoneNO(state.m_phoneno, 0);
                            string          dynIP       = CGprsUtil.Byte4ToIP(state.m_dynip, 0);
                            string          connectTime = CGprsUtil.ULongToDatetime(state.m_conn_time).ToString();
                            string          refreshTime = CGprsUtil.ULongToDatetime(state.m_refresh_time).ToString();

                            dtu.SubcenterId = s.SubCenterID.ToString();
                            string subName = CDBDataMgr.Instance.GetSubCenterName(s.SubCenterID.ToString());
                            dtu.SubcenterName = subName;
                            dtu.StationId     = s.StationID;
                            dtu.StationName   = s.StationName;
                            dtu.GprsId        = s.GPRS;
                            dtu.GsmNum        = phoneno;
                            dtu.IpAddr        = dynIP;
                            dtu.ConnTime      = connectTime;
                            dtu.RefreshTime   = refreshTime;
                            dtu.State         = "1";
                            dtu.StationType   = CEnumHelper.StationTypeToDBStr(s.StationType);
                            dtuList.Dtu.Add(dtu);
                        }
                    }
                    else
                    {
                        Dtu dtu = new Dtu();
                        dtu.SubcenterId = s.SubCenterID.ToString();
                        string subName = CDBDataMgr.Instance.GetSubCenterName(s.SubCenterID.ToString());
                        dtu.SubcenterName = subName;
                        dtu.StationId     = s.StationID;
                        dtu.StationName   = s.StationName;
                        dtu.GprsId        = s.GPRS;
                        dtu.State         = "2";
                        dtu.StationType   = CEnumHelper.StationTypeToDBStr(s.StationType);
                        dtuList.Dtu.Add(dtu);
                    }
                }
            }

            foreach (var s in stations)
            {
                if (subcenter.SubcenterdId == s.SubCenterID.ToString() || subcenter.SubcenterdId == "0")
                {
                    if (gprsDic.Count() != 0)
                    {
                        if (!gprsDic.ContainsKey(s.GPRS))
                        {
                            Dtu dtu = new Dtu();
                            dtu.SubcenterId = s.SubCenterID.ToString();
                            string subName = CDBDataMgr.Instance.GetSubCenterName(s.SubCenterID.ToString());
                            dtu.SubcenterName = subName;
                            dtu.StationId     = s.StationID;
                            dtu.StationName   = s.StationName;
                            dtu.GprsId        = s.GPRS;
                            dtu.State         = "2";
                            dtu.StationType   = CEnumHelper.StationTypeToDBStr(s.StationType);
                            dtuList.Dtu.Add(dtu);
                        }
                    }
                }
            }

            foreach (var s in soilStations)
            {
                if (subcenter.SubcenterdId == s.SubCenterID.ToString() || subcenter.SubcenterdId == "0")
                {
                    if (gprsDic.Count() != 0)
                    {
                        if (gprsDic.ContainsKey(s.GPRS))
                        {
                            Dtu dtu = new Dtu();

                            ModemInfoStruct state       = gprsDic[s.GPRS];
                            string          phoneno     = CGprsUtil.Byte11ToPhoneNO(state.m_phoneno, 0);
                            string          dynIP       = CGprsUtil.Byte4ToIP(state.m_dynip, 0);
                            string          connectTime = CGprsUtil.ULongToDatetime(state.m_conn_time).ToString();
                            string          refreshTime = CGprsUtil.ULongToDatetime(state.m_refresh_time).ToString();

                            if (subcenter.SubcenterdId == s.SubCenterID.ToString() || subcenter.SubcenterdId == "0")
                            {
                                dtu.SubcenterId = s.SubCenterID.ToString();
                                string subName = CDBDataMgr.Instance.GetSubCenterName(s.SubCenterID.ToString());
                                dtu.SubcenterName = subName;
                                dtu.StationId     = s.StationID;
                                dtu.StationName   = s.StationName;
                                dtu.GprsId        = s.GPRS;
                                dtu.GsmNum        = phoneno;
                                dtu.IpAddr        = dynIP;
                                dtu.ConnTime      = connectTime;
                                dtu.RefreshTime   = refreshTime;
                                dtu.State         = "1";
                                dtu.StationType   = CEnumHelper.StationTypeToDBStr(s.StationType);
                                dtuList.Dtu.Add(dtu);
                            }
                        }
                    }
                    else
                    {
                        Dtu dtu = new Dtu();
                        dtu.SubcenterId = s.SubCenterID.ToString();
                        string subName = CDBDataMgr.Instance.GetSubCenterName(s.SubCenterID.ToString());
                        dtu.SubcenterName = subName;
                        dtu.StationId     = s.StationID;
                        dtu.StationName   = s.StationName;
                        dtu.GprsId        = s.GPRS;
                        dtu.State         = "2";
                        dtu.StationType   = CEnumHelper.StationTypeToDBStr(s.StationType);
                        dtuList.Dtu.Add(dtu);
                    }
                }
            }

            foreach (var s in soilStations)
            {
                if (subcenter.SubcenterdId == s.SubCenterID.ToString() || subcenter.SubcenterdId == "0")
                {
                    if (gprsDic.Count() != 0)
                    {
                        if (!gprsDic.ContainsKey(s.GPRS))
                        {
                            Dtu dtu = new Dtu();
                            dtu.SubcenterId = s.SubCenterID.ToString();
                            string subName = CDBDataMgr.Instance.GetSubCenterName(s.SubCenterID.ToString());
                            dtu.SubcenterName = subName;
                            dtu.StationId     = s.StationID;
                            dtu.StationName   = s.StationName;
                            dtu.GprsId        = s.GPRS;
                            dtu.State         = "2";
                            dtu.StationType   = CEnumHelper.StationTypeToDBStr(s.StationType);
                            dtuList.Dtu.Add(dtu);
                        }
                    }
                }
            }

            return(dtuList);
        }