예제 #1
0
        //通过用户ID查询站名
        private string QueryStationNameByUserID(ModemInfoStruct dtu)
        {
            string uid = ((uint)dtu.m_modemId).ToString("X").PadLeft(8, '0');

            if (this.m_listStations != null)
            {
                foreach (var station in this.m_listStations)
                {
                    if (station.GPRS.Trim() == uid.Trim())
                    {
                        return(station.StationName);
                    }
                }
            }
            //if (this.m_listSoilStations != null)
            //{
            //    foreach (var station in this.m_listSoilStations)
            //    {
            //        if (station.GPRS.Trim() == uid.Trim())
            //        {
            //            return station.StationName;
            //        }
            //    }
            //}
            return("---");
        }
        //201704gm
        private string QueryStationIDByUserID(ModemInfoStruct dtu)
        {
            //string uid = ((uint)dtu.m_modemId).ToString("X").PadLeft(8, '0');
            string uid = dtu.m_modemId.ToString();

            if (this.m_listStations != null)
            {
                foreach (var station in this.m_listStations)
                {
                    if (station.GPRS.Trim() == uid.Trim())
                    {
                        return(station.StationID);
                    }
                }
            }
            if (this.m_listSoilStations != null)
            {
                foreach (var station in this.m_listSoilStations)
                {
                    if (station.GPRS.Trim() == uid.Trim())
                    {
                        return(station.StationID);
                    }
                }
            }
            return("---");
        }
        private CEntitySoilStation QuerySoilStationEntityByUserID(ModemInfoStruct dtu)
        {
            string uid = ((uint)dtu.m_modemId).ToString("X").PadLeft(8, '0');

            if (this.m_listSoilStations != null)
            {
                foreach (var station in this.m_listSoilStations)
                {
                    if (station.GPRS.Trim() == uid.Trim())
                    {
                        return(station);
                    }
                }
            }
            return(null);
        }
예제 #4
0
        public bool FindByID(string userID, out uint dtuID)
        {
            dtuID = 0;
            List <ModemInfoStruct> DTUList_1 = DTUList;

            //foreach (var item in DTUList_1)
            for (int i = 0; i < DTUList_1.Count; i++)
            {
                ModemInfoStruct item = DTUList_1[i];
                if (item.m_modemId.ToString("X").PadLeft(8, '0') == userID)
                {
                    dtuID = item.m_modemId;
                    return(true);
                }
            }
            return(false);
        }
        //20181010 gm 通过ID查询分中心名称
        private string QuerySubcenterNameByUserID(ModemInfoStruct dtu)
        {
            String subcenterid = null;
            string uid         = ((uint)dtu.m_modemId).ToString("X").PadLeft(8, '0');

            if (this.m_listStations != null)
            {
                foreach (var station in this.m_listStations)
                {
                    if (station.GPRS.Trim() == uid.Trim())
                    {
                        subcenterid = station.SubCenterID.ToString();
                        break;
                    }
                }
            }
            if (this.m_listSoilStations != null)
            {
                foreach (var station in this.m_listSoilStations)
                {
                    if (station.GPRS.Trim() == uid.Trim())
                    {
                        subcenterid = station.SubCenterID.ToString();
                        break;
                    }
                }
            }
            if (subcenterid != null && subcenterid.Length > 0)
            {
                if (m_listSubcenters != null)
                {
                    foreach (var subcenter in this.m_listSubcenters)
                    {
                        if (subcenter.SubCenterID.ToString().Trim() == subcenterid.Trim())
                        {
                            return(subcenter.SubCenterName.ToString());
                        }
                    }
                }
            }
            return("---");
        }
예제 #6
0
 public bool GetDTUList(out Dictionary <uint, ModemInfoStruct> dtuList)
 {
     try
     {
         int cnt = DSGetModemCount();
         //System.Diagnostics.Debug.WriteLine("0414Count=" + cnt.ToString() + "      ");
         dtuList = new Dictionary <uint, ModemInfoStruct>();
         for (uint ii = 0; ii < cnt; ii++)
         {
             ModemInfoStruct dtu  = new ModemInfoStruct();
             bool            flag = DSGetModemByPosition(ii, ref dtu);
             //System.Diagnostics.Debug.WriteLine("0414id=" + dtu.m_modemId + " 0414idTIME  " + dtu.m_refresh_time);
             if (!flag)
             {
                 this.GetLastError();
                 return(false);
             }
             else
             {
                 if (!dtuList.ContainsKey(dtu.m_modemId))
                 {
                     dtuList.Add(dtu.m_modemId, dtu);
                     //System.Diagnostics.Debug.WriteLine("0414Count=" + dtuList.Count);
                 }
             }
         }
         LastError = null;
         return(true);
     }
     catch (Exception ee)
     {
         LastError = ee.Message;
         dtuList   = new Dictionary <uint, ModemInfoStruct>();
         return(false);
     }
 }
예제 #7
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();
            }
        }
예제 #8
0
 private static extern bool DSGetModemByPosition(uint pos, ref ModemInfoStruct pModemInfo);
예제 #9
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);
        }