コード例 #1
0
ファイル: DBObjects.cs プロジェクト: lickey10/u_CrimeMapper
    //****************************************************************************************************
    //
    //****************************************************************************************************

    private void OnLocalizableDBDeleted(HTTPReq req, params object[] paramsList)
    {
        Localizable localizable = CORE.Params.Get <Localizable>(0, paramsList);

        if (localizable != null)
        {
            if ((req == null) || (req.result == QUERY_RESULT.SUCCESS))
            {
                if (localizable is Site)
                {
                    sites.Remove(localizable);
                }

                else if (localizable is Item)
                {
                    items.Remove(localizable);
                }

                localizable.id = -1L;

                localizable.SetParent(null);

                m_listeners.Notify(EVT.EVT_OBJECT_DELETED, localizable);
            }
        }
    }
コード例 #2
0
ファイル: DBObjects.cs プロジェクト: lickey10/u_CrimeMapper
    //****************************************************************************************************
    //
    //****************************************************************************************************

    public Localizable Create <LocalizableT>(Localizable parent, HTTPReqDelegate.Delegate onCompletion, object session) where LocalizableT : Localizable, new()
    {
        Localizable localizable = (disabled == false) && (IsSessionActive(session)) ? new LocalizableT() : null;

        if (localizable != null)
        {
            localizable.SetParent((parent != null) ? parent : root);

            localizable.Async_DBInsert(new HTTPReqDelegate(OnLocalizableDBInserted + onCompletion, localizable));
        }

        return(localizable);
    }
コード例 #3
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);
        }