コード例 #1
0
    //****************************************************************************************************
    //
    //****************************************************************************************************

    private void UpdateMapObject()
    {
        if (DBObjects.instance == null)
        {
            return;
        }

        if (m_target == null)
        {
            return;
        }


        object session = DBObjects.instance.BeginEdit();

        if (session != null)
        {
            float LAT = 0.0f; float.TryParse(itemLat.TrimEnd('°'), out LAT);

            float LNG = 0.0f; float.TryParse(itemLng.TrimEnd('°'), out LNG);

            m_target.name = itemName;

            m_target.m_desc = itemDesc;

            m_target.m_pic = m_pictureName;

            m_target.m_coord.latitude.FromAngle(LAT, GPS.UNIT.DD);

            m_target.m_coord.longitude.FromAngle(LNG, GPS.UNIT.DD);


            if (m_sites != null)
            {
                Item item = (m_target is Item) ? m_target as Item : null;

                if (item != null)
                {
                    if ((m_sites.value > 0) && (m_sites.value < (DBObjects.instance.sites.Count + 1)))
                    {
                        long siteID = (DBObjects.instance.sites[m_sites.value - 1] as Site).id;

                        item.SetParent(siteID);
                    }
                    else
                    {
                        item.SetParent(DBObjects.instance.root);
                    }
                }
            }


            m_target.Async_DBPush(null);

            DBObjects.instance.EndEdit(session);
        }
    }
コード例 #2
0
        //************************************************************************************************
        //
        //************************************************************************************************

        private bool Import()
        {
            if ((m_header == null) || (m_header.Length < 2))
            {
                return(false);
            }

            if (DBObjects.instance == null)
            {
                return(false);
            }

            if (DBObjects.instance.busy)
            {
                return(false);
            }


            object session = DBObjects.instance.BeginEdit();

            if (session == null)
            {
                return(false);
            }


            List <KeyValuePair <Item, string> > parentNames = new List <KeyValuePair <Item, string> >();

            for (int entry = 1; entry < m_lines.Length; ++entry)
            {
                string[] values = m_lines[entry].Split(m_options.separator);

                Trim(values);


                if (values.Length != m_header.Length)
                {
                    Debug.Log(string.Format("CSV > IMPORT > entry {0} of {1} > Skipping", entry + 1, m_lines.Length));

                    continue;
                }
                else
                {
                    Debug.Log(string.Format("CSV > IMPORT > entry {0} of {1} > Adding", entry + 1, m_lines.Length));
                }


                Vector2 coords = Vector2.zero;

                float.TryParse(values[m_options.colX], out coords.x);

                float.TryParse(values[m_options.colY], out coords.y);

                string siteName = (m_options.colSiteName != -1) ? values[m_options.colSiteName] : string.Empty;

                string itemName = (m_options.colItemName != -1) ? values[m_options.colItemName] : string.Empty;

                string dateOpened = (m_options.colDateOpened != -1) ? values[m_options.colDateOpened] : string.Empty;

                string dateClosed = (m_options.colDateClosed != -1) ? values[m_options.colDateClosed] : string.Empty;

                string dateFound = (m_options.colDateFound != -1) ? values[m_options.colDateFound] : string.Empty;

                string desc = (m_options.colDesc != -1) ? values[m_options.colDesc] : string.Empty;



                Localizable localizable = null;

                if (string.IsNullOrEmpty(itemName) == false)
                {
                    localizable = DBObjects.instance.Create <Item>(null, null, session);
                }

                else
                {
                    localizable = DBObjects.instance.Create <Site>(null, null, session);
                }

                if (localizable == null)
                {
                    continue;
                }

                localizable.name = localizable is Site?MarkDuplicateNames <Site>(siteName) : MarkDuplicateNames <Item>(itemName);

                localizable.m_desc = desc;



                if (m_options.coords == COORDS.LAMBERT_93)
                {
                    coords = CORE.CONVERT.LambertToLngLat(coords);
                }

                coords.x = CORE.Angle.Normalize(coords.x, Angle.UNIT.DEG, Angle.NORM.NEG, GPS.TYPE.LONGITUDE);

                coords.y = CORE.Angle.Normalize(coords.y, Angle.UNIT.DEG, Angle.NORM.NEG, GPS.TYPE.LATITUDE);

                localizable.m_coord.longitude.FromAngle(coords.x, GPS.UNIT.DD);

                localizable.m_coord.latitude.FromAngle(coords.y, GPS.UNIT.DD);


                if (localizable is Site)
                {
                    Site site = localizable as Site;

                    System.DateTime date1 = System.DateTime.Now; System.DateTime.TryParse(dateOpened, out date1);

                    System.DateTime date2 = System.DateTime.Now; System.DateTime.TryParse(dateClosed, out date2);

                    site.m_dateOpened = date1;

                    site.m_dateClosed = date2;
                }
                else
                {
                    Item item = localizable as Item;

                    System.DateTime date1 = System.DateTime.Now; System.DateTime.TryParse(dateFound, out date1);

                    item.m_dateFound = date1;

                    parentNames.Add(new KeyValuePair <Item, string>(item, siteName));
                }

                localizable.Async_DBPush(null);
            }


            for (int pair = 0; pair < parentNames.Count; ++pair)
            {
                Localizable item = parentNames[pair].Key;

                Localizable parent = Localizable.Get(parentNames[pair].Value);

                if ((item != null) && (parent != null) && (parent is Site))
                {
                    item.SetParent(parent);
                }
            }


            DBObjects.instance.EndEdit(session);

            DiscardContent();

            return(true);
        }