Example #1
0
        /// <summary>
        /// 添加船舶
        /// </summary>
        /// <param name="strCurShipInfos">船舶信息字符串,格式为:shipid,mmsi,name,geoX,geoY,course,speed,state,time_....</param>
        /// <returns>返回值:true=添加成功,false=添加失败</returns>
        public static bool AddShipsByStringInfos(string strCurShipInfos)
        {
            bool bResult = false;

            if (!strCurShipInfos.Equals(""))
            {
                string[] arrShipInfoValue = strCurShipInfos.Split(new char[1] {
                    '_'
                });;
                int iCurAddShipCount = arrShipInfoValue.Length;

                for (int i = 0; i < iCurAddShipCount; i++)
                {
                    string[] arrCurShipAtrr = arrShipInfoValue[i].Split(new char[1] {
                        ','
                    });
                    int      iCurShipAtrrCount = arrCurShipAtrr.Length;
                    ShipInfo curShipInfo       = new ShipInfo();

                    if (iCurShipAtrrCount > 8)
                    {
                        curShipInfo.iShipId     = Convert.ToInt32(arrCurShipAtrr[0]);    //shipid
                        curShipInfo.iShipMmsi   = Convert.ToInt32(arrCurShipAtrr[1]);    //mmsi;
                        curShipInfo.strShipName = arrCurShipAtrr[2].ToString();          //name
                        curShipInfo.iShipGeoX   = Convert.ToInt32(arrCurShipAtrr[3]);    //geoX
                        curShipInfo.iShipGeoY   = Convert.ToInt32(arrCurShipAtrr[4]);    //geoY
                        curShipInfo.dShipCourse = Convert.ToDouble(arrCurShipAtrr[5]);   //course
                        curShipInfo.dShipSpeed  = Convert.ToDouble(arrCurShipAtrr[6]);   //speed
                        curShipInfo.iShipState  = Convert.ToInt32(arrCurShipAtrr[7]);    //state
                        curShipInfo.dtInfoTime  = Convert.ToDateTime(arrCurShipAtrr[8]); //time

                        SHIP_MAN.AddOneShip(curShipInfo);
                        bResult = true;
                    }
                }
            }

            return(bResult);
        }
Example #2
0
        /// <summary>
        /// 添加一艘船舶,假如该船舶存在,那么就更新
        /// </summary>
        /// <param name="curShipInfo">当前船舶的结构体</param>
        /// <returns>返回船舶在数组中的posid</returns>
        public static int AddOneShip(ShipInfo curShipInfo)
        {
            if (m_iCurShipCount > m_iMaxShipCount)
            {
                m_iMaxShipCount--;
            }

            int  iShipPos   = 0;
            bool bShipInArr = GetCurShipPosInArr(curShipInfo.iShipMmsi, ref iShipPos);

            if (bShipInArr)
            {
                m_arrShipInfo[iShipPos].UpdateShipInfo(curShipInfo.iShipGeoX, curShipInfo.iShipGeoY, curShipInfo.dShipSpeed, curShipInfo.dShipCourse, curShipInfo.iShipState, curShipInfo.dtInfoTime);
            }
            else
            {
                m_arrShipInfo[iShipPos] = curShipInfo;
                m_iCurShipCount++;
            }

            return(iShipPos);
        }