Ejemplo n.º 1
0
    //****************************************************************************************************
    //
    //****************************************************************************************************

    private void RestoreUIContext()
    {
        if (m_items == null)
        {
            return;
        }

        if ((m_initDefaultSelection) && (m_context.selection == -1L))
        {
            if ((DBObjects.instance != null) && (DBObjects.instance.sites.Count > 0))
            {
                m_items.SelectItemUserDatas(DBObjects.instance.sites[0]);

                m_initDefaultSelection = false;
            }
        }
        else
        {
            object selection = Localizable.Get(m_context.selection);

            if (selection != null)
            {
                m_items.SelectItemUserDatas(selection);
            }
        }

        for (int expanded = 0; expanded < m_context.expandeds.Count; ++expanded)
        {
            Localizable localizable = Localizable.Get(m_context.expandeds[expanded]);

            if ((localizable != null) && (localizable.m_ListItemDatas != null))
            {
                localizable.m_ListItemDatas.Expand(true, UIListItemData.RECURSE.NO);
            }
        }

        m_context.Clear();
    }
Ejemplo n.º 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);
        }