public bool Setup()
        {
            _AllPolys = dal.GetPolygons();

            for (int i = 0; i < _AllPolys.Count; i++)
            {
                if (dal.GetNumberOfPointsinPolygon(_AllPolys[i].CN) > 2)
                {
                    _Polys.Add(_AllPolys[i]);
                }
            }

            try
            {
                _Meta = dal.GetMetaData()[0];
            }
            catch
            {
                return false;
            }

            if (_Polys.Count < 2)
                return false;

            return true;
        }
        public DataImport(DataAccessLayer d)
        {
            dal = d;

            //get default meta
            if(dal != null)
                _Meta = dal.GetMetaData()[0];
        }
        public Take5Form(TtPolygon poly, DataAccessLayer dal, TtMetaData meta, TtPoint currentPoint, int currIndex)
        {
            if (Engine.Values.WideScreen)
                InitializeComponentWide();
            else
                InitializeComponent();

            Init(poly, dal, meta, currentPoint, currIndex);
        }
        public TtMetaData(TtMetaData ttm)
        {
            CN = null;
            Name = null;
            Zone = ttm.Zone;
            datum = ttm.datum;
            uomDistance = ttm.uomDistance;
            uomElevation = ttm.uomElevation;
            uomSlope = ttm.uomSlope;
            decType = ttm.decType;
            magDec = 0;

            Receiver = null;
            Laser = null;
            Compass = null;
            Crew = null;
            Comment = null;
        }
        private QuondamPoint CreateQuondam(TtPoint parentpoint, TtPolygon poly, TtMetaData meta)
        {
            QuondamPoint tmpPoint = new QuondamPoint();
            tmpPoint.PolyCN = poly.CN;
            tmpPoint.PolyName = poly.Name;
            tmpPoint.MetaDefCN = meta.CN;
            tmpPoint.GroupCN = Values.MainGroup.CN;
            tmpPoint.GroupName = Values.MainGroup.Name;

            if (parentpoint.op == OpType.Quondam)
            {
                tmpPoint.ParentPoint = ((QuondamPoint)parentpoint).ParentPoint;
            }
            else
                tmpPoint.ParentPoint = parentpoint;

            tmpPoint.OnBnd = parentpoint.OnBnd;

            return tmpPoint;
        }
        public void Init(TtPolygon poly, DataAccessLayer dal, TtMetaData meta, int currIndex)
        {
            this.Icon = Properties.Resources.Map;
            TtUtils.ShowWaitCursor();
            Values.GPSA.BurstReceived += GPSA_BurstReceived;
            Values.GPSA.InvalidStringFound += GPSA_InvalidStringFound;
            Values.GPSA.ComTimeout += GPSA_ComTimeout;
            Values.GPSA.GpsStarted += GPSA_GpsStarted;
            Values.GPSA.GpsEnded += GPSA_GpsEnded;
            Values.GPSA.GpsError += GPSA_GpsError;

            Polygon = poly;
            DAL = dal;
            _currmeta = meta;

            logging = false;
            this.DialogResult = DialogResult.Cancel;
            OnBound = true;

            lblPoly.Text = "Poly: " + Polygon.Name;

            logged = 0;
            _locked = true;

            _sound = true;
            #if (PocketPC || WindowsCE || Mobile)
            player = new SoundPlayer(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ring.wav"));
            #else
            player = new SoundPlayer(Properties.Resources.Ring);
            #endif

            #if !(PocketPC || WindowsCE || Mobile)
            picBox.SizeMode = PictureBoxSizeMode.StretchImage;
            picBox.Image = Properties.Resources.Walking_Transparent;
            #else
            animation = new AnimationCtrl();
            animation.Location = new Point((this.Width - Properties.Resources.walking1.Width / 5) - 10, 0);
            this.Controls.Add(animation);
            animation.BringToFront();
            animation.LoadImage(new List<Bitmap>() { Properties.Resources.walking1, Properties.Resources.walking2,
            Properties.Resources.walking3 ,Properties.Resources.walking4, Properties.Resources.walking5,
            Properties.Resources.walking6, Properties.Resources.walking7,},
            Properties.Resources.walking1.Width / 5, Properties.Resources.walking1.Height / 5, 75, -1);
            #endif
            CurrentPoint = null;

            List<TtPoint> points = DAL.GetPointsInPolygon(Polygon);
            _index = currIndex;

            if (_index > 0)
            {
                TtPoint lPoint = (points[_index - 1]);
                LastPoint = new WalkPoint();
                LastPoint.PID = lPoint.PID;
                LastPoint.Index = lPoint.Index;
            }

            cboDOP.SelectedIndex = Values.Settings.DeviceOptions.Filter_WALK_DOP_TYPE;
            cboFixType.SelectedIndex = Values.Settings.DeviceOptions.Filter_WALK_FixType;

            #if (PocketPC || WindowsCE || Mobile)
            btnDOP.Text = cboDOP.Text;
            btnFixType.Text = cboFixType.Text;
            #endif

            txtDOP.Text = Values.Settings.DeviceOptions.Filter_WALK_DOP_VALUE.ToString();

            txtAcc.Text = Values.Settings.DeviceOptions.Filter_Accuracy.ToString();

            txtFreq.Text = Values.Settings.DeviceOptions.Filter_Frequency.ToString();

            txtIncrement.Text = Values.Settings.DeviceOptions.WalkIncrement.ToString();
            _increment = Values.Settings.DeviceOptions.WalkIncrement;

            gpsInfoAdvCtrl.SetZone(_currmeta.Zone);
            gpsInfoAdvCtrl.StartControl();

            TtUtils.HideWaitCursor();
        }
        public bool ImportTt(List<string> polys, bool useNmea)
        {
            if (!_MetaOpen)
                return false;

            _Points = new List<TtPoint>();
            _Polygons = new Dictionary<string, TtPolygon>();
            _IdToCN = new Dictionary<string, string>();
            pidToCN = new Dictionary<int, string>();
            _PolyIndexes = new Dictionary<string, int>();

            Dictionary<string, TtMetaData> metaData = new Dictionary<string, TtMetaData>();
            Dictionary<string, string> metaLinkToId = new Dictionary<string, string>();
            Dictionary<string, int> qndLinks = new Dictionary<string, int>();
            List<int> pointWNMEA = new List<int>();

            Dictionary<int, List<TwoTrails.GpsAccess.NmeaBurst>> nmeas = new Dictionary<int, List<TwoTrails.GpsAccess.NmeaBurst>>();

            int viewId = metaKitViews[polydata];
            int rowCount;
            int polyCount = (int)dal.GetPolyCount();
            polyCount++;

            string tmpStr, tmpStr2;
            int tmpInt;
            double tmpDouble;

            try
            {
                #region Polygons
                rowCount = metaKit.GetRowCount(viewId);
                for (int i = 0; i < rowCount; i++)
                {
                    _Poly = new TtPolygon();

                    tmpStr = metaKit.GetString(viewId, i, 0);

                    if (!tmpStr.IsEmpty())
                    {
                        tmpStr2 = null;
                        _Poly.Name = tmpStr;
                    }
                    else
                    {
                        tmpStr2 = tmpStr;
                        _Poly.Name = String.Format("Poly {0}", polyCount);
                    }

                    _Poly.PointStartIndex = 1000 * polyCount + 10;

                    if (!polys.Contains(tmpStr))
                        continue;
                    polyCount++;

                    tmpStr = metaKit.GetString(viewId, i, 1);
                    if (!tmpStr.IsEmpty())
                        _Poly.Description = tmpStr;

                    tmpStr = metaKit.GetString(viewId, i, 10);
                    if (!tmpStr.IsEmpty())
                    {
                        if(_Poly.Description.IsEmpty())
                            _Poly.Description = tmpStr;
                        else
                            String.Format("{0}, Comment: {1}", _Poly.Description, tmpStr);
                    }

                    tmpDouble = metaKit.GetDouble(viewId, i, 11);
                    if(tmpDouble > 0)
                        _Poly.PolyAccu = tmpDouble;

                    _Polygons.Add(_Poly.CN, _Poly);
                    _IdToCN.Add(_Poly.Name, _Poly.CN);
                    _PolyIndexes.Add(_Poly.CN, 0);

                    if (tmpStr2 != null)
                    {
                        _IdToCN.Add(tmpStr2, _Poly.CN);
                    }
                }
                #endregion

                #region Metadata
                viewId = metaKitViews[metadata];

                TtMetaData newMeta;

                for (int i = 0; i < metaKit.GetRowCount(viewId); i++)
                {
                    newMeta = new TtMetaData();
                    newMeta.CN = Guid.NewGuid().ToString();

                    tmpInt = metaKit.GetInt(viewId, i, 2);
                    if (tmpInt > -1)
                        newMeta.Zone = tmpInt;

                    newMeta.Receiver = metaKit.GetString(viewId, i, 3);
                    newMeta.Laser = metaKit.GetString(viewId, i, 4);
                    newMeta.Compass = metaKit.GetString(viewId, i, 5);
                    newMeta.Crew = metaKit.GetString(viewId, i, 9);
                    newMeta.Comment = metaKit.GetString(viewId, i, 17);

                    tmpStr = metaKit.GetString(viewId, i, 10);
                    if(tmpStr.IsEmpty())
                    {
                        newMeta.Name = String.Format("Metadata {0}", metaData.Count + 1);
                        metaLinkToId.Add(newMeta.Name, newMeta.CN);
                        if (!metaLinkToId.ContainsKey(tmpStr))
                            metaLinkToId.Add(tmpStr, newMeta.CN);
                    }
                    else
                    {
                        newMeta.Name = tmpStr;
                        metaLinkToId.Add(tmpStr, newMeta.CN);
                    }

                    tmpStr = metaKit.GetString(viewId, i, 11);
                    tmpStr = tmpStr.ToLower();
                    if (tmpStr.Contains("meter"))
                        newMeta.uomDistance = UomDistance.Meters;
                    else if (tmpStr.Contains("chain"))
                        newMeta.uomDistance = UomDistance.Chains;
                    else if (tmpStr.Contains("tenth"))
                        newMeta.uomDistance = UomDistance.FeetTenths;
                    else if (tmpStr.Contains("inch"))
                        newMeta.uomDistance = UomDistance.FeetInches;
                    else if (tmpStr.Contains("yard"))
                        newMeta.uomDistance = UomDistance.Yards;

                    tmpStr = metaKit.GetString(viewId, i, 15);
                    tmpStr = tmpStr.ToLower();
                    if (tmpStr.Contains("feet"))
                        newMeta.uomElevation = UomElevation.Feet;
                    else if (tmpStr.Contains("meter"))
                        newMeta.uomElevation = UomElevation.Meters;

                    tmpStr = metaKit.GetString(viewId, i, 16);
                    tmpStr = tmpStr.ToLower();
                    if (tmpStr.Contains("deg"))
                        newMeta.uomSlope = UomSlope.Degrees;
                    else if (tmpStr.Contains("per"))
                        newMeta.uomSlope = UomSlope.Percent;

                    metaData.Add(newMeta.CN, newMeta);
                }
                #endregion

                #region Points
                TtPoint point;

                GpsPoint gps;
                SideShotPoint ssp;

                viewId = metaKitViews[ptdata];
                rowCount = metaKit.GetRowCount(viewId);
                for (int i = 0; i < rowCount; i++)
                {
                    tmpStr = metaKit.GetString(viewId, i, 0);

                    if (tmpStr.IsEmpty() || !polys.Contains(tmpStr))
                        continue;

                    point = new TtPoint();

                    _Poly = _Polygons[_IdToCN[tmpStr]];
                    point.PolyCN = _Poly.CN;
                    point.PolyName = _Poly.Name;

                    point.GroupCN = Values.MainGroup.CN;
                    point.GroupName = Values.MainGroup.Name;

                    tmpInt = metaKit.GetInt(viewId, i, 1);
                    if (tmpInt > 0)
                        point.PID = tmpInt;
                    else
                    {
                        if (_Points.Count > 1)
                            PointNaming.NamePoint(_Points[_Points.Count - 1], _Poly);
                        else
                            PointNaming.NameFirstPoint(_Poly);
                    }

                    pidToCN.Add(point.PID, point.CN);

                    tmpStr = metaKit.GetString(viewId, i, 2);
                    if (tmpStr.IsEmpty() || !tmpStr.IsBool())
                        point.OnBnd = false;
                    else
                        point.OnBnd = tmpStr.ToBool();

                    OpType op;

                    tmpStr = metaKit.GetString(viewId, i, 3);
                    if (tmpStr.IsEmpty())
                        continue;
                    else
                    {
                        try
                        {
                            op = (OpType)Enum.Parse(typeof(OpType), tmpStr, true);
                        }
                        catch
                        {
                            continue;
                        }
                    }

                    switch (op)
                    {
                        case OpType.GPS:
                        case OpType.Walk:
                        case OpType.WayPoint:
                            {
                                gps = new GpsPoint(point);

                                gps.UnAdjX = metaKit.GetDouble(viewId, i, 4);
                                gps.UnAdjY = metaKit.GetDouble(viewId, i, 5);
                                gps.UnAdjZ = metaKit.GetDouble(viewId, i, 6);
                                //gps.UnAdjX = gps.X;
                                //gps.UnAdjY = gps.Y;
                                //gps.UnAdjZ = gps.Z;

                                tmpDouble = metaKit.GetDouble(viewId, i, 32);
                                if (tmpDouble != 0)
                                    gps.ManualAccuracy = tmpDouble;

                                tmpDouble = metaKit.GetDouble(viewId, i, 33);
                                if (tmpDouble != 0)
                                    gps.RMSEr = tmpDouble;

                                if(metaKit.GetInt(viewId, i, 55) > 0)
                                    pointWNMEA.Add(point.PID);

                                if (op == OpType.Walk)
                                    point = new WalkPoint(gps);
                                else if (op == OpType.WayPoint)
                                    point = new WayPoint(gps);
                                else
                                    point = gps;
                            }
                            break;
                        case OpType.SideShot:
                        case OpType.Traverse:
                            {
                                ssp = new SideShotPoint(point);

                                tmpDouble = metaKit.GetDouble(viewId, i, 22);
                                if (tmpDouble != -1)
                                    ssp.ForwardAz = tmpDouble;

                                tmpDouble = metaKit.GetDouble(viewId, i, 23);
                                if (tmpDouble != -1)
                                    ssp.BackwardAz = tmpDouble;

                                ssp.SlopeDistance = metaKit.GetDouble(viewId, i, 24);
                                ssp.SlopeAngle = metaKit.GetDouble(viewId, i, 25);

                                if (op == OpType.Traverse)
                                    point = new TravPoint(ssp);
                                else
                                    point = ssp;
                            }
                            break;
                        case OpType.Quondam:
                            {
                                point = new QuondamPoint(point);

                                tmpStr = metaKit.GetString(viewId, i, 29);
                                try
                                {
                                    if (!tmpStr.IsEmpty())
                                    {
                                        tmpStr2 = tmpStr.Split(',')[1].Trim();
                                        qndLinks.Add(point.CN, tmpStr2.ToInteger());
                                    }
                                }
                                catch
                                {
                                    //bad quondam
                                }
                            }
                            break;
                        default:
                            continue;
                    }

                    tmpStr = metaKit.GetString(viewId, i, 56);
                    if (tmpStr.IsEmpty() || !metadata.Contains(tmpStr))
                        point.MetaDefCN = _Meta.CN;
                    else
                    {
                        point.MetaDefCN = metaData[tmpStr].CN;
                    }

                    tmpStr = metaKit.GetString(viewId, i, 38);
                    if (!tmpStr.IsEmpty())
                        point.Comment = tmpStr;

                    point.Index = _PolyIndexes[point.PolyCN];
                    _PolyIndexes[point.PolyCN]++;

                    point.Time = DateTime.Now;

                    _Points.Add(point);
                }

                for (int i = 0; i < _Points.Count; i++)
                {
                    if (_Points[i].op == OpType.Quondam)
                    {
                        if(qndLinks.ContainsKey(_Points[i].CN))
                        {
                            QuondamPoint qp = ((QuondamPoint)_Points[i]);
                            qp.ParentPoint = _Points.Where(p => p.PID == qndLinks[qp.CN]).First();
                            _Points[i] = qp;
                        }
                    }
                }

                #endregion

                #region NMEA
                if (useNmea)
                {
                    TwoTrails.GpsAccess.NmeaBurst burst;

                    viewId = metaKitViews[nmeadata];
                    tmpInt = metaKit.GetRowCount(viewId);
                    for (int i = 0; i < tmpInt; i++)
                    {
                        tmpStr = metaKit.GetString(viewId, i, 1);
                        if (tmpStr.IsInteger())
                        {
                            int pid = tmpStr.ToInteger();
                            if (pointWNMEA.Contains(pid))
                            {
                                if (!nmeas.ContainsKey(pid))
                                    nmeas.Add(pid, new List<TwoTrails.GpsAccess.NmeaBurst>());

                                burst = new TwoTrails.GpsAccess.NmeaBurst();
                                burst._CN = Guid.NewGuid().ToString();

                                burst._Used = metaKit.GetInt(viewId, i, 2) > 0;

                                tmpStr = metaKit.GetString(viewId, i, 3);
                                if (!tmpStr.IsEmpty())
                                    burst._date = DateTime.ParseExact(tmpStr, "MMddyy", null);

                                tmpStr2 = metaKit.GetString(viewId, i, 4);
                                if (!tmpStr2.IsEmpty())
                                    burst._date = DateTime.ParseExact(tmpStr + tmpStr2, "MMddyyHHmmss", null);

                                burst._GGA_longitude = metaKit.GetDouble(viewId, i, 5);
                                burst._RMC_longitude = burst._GGA_longitude;

                                burst._GGA_latitude = metaKit.GetDouble(viewId, i, 6);
                                burst._RMC_latitude = burst._GGA_latitude;

                                burst._alt_unit = Unit.METERS;
                                burst._altitude = metaKit.GetFloat(viewId, i, 11);

                                burst._horiz_dilution_position = metaKit.GetDouble(viewId, i, 12);
                                burst._fix_quality = metaKit.GetInt(viewId, i, 13);

                                burst._fix = metaKit.GetInt(viewId, i, 15);

                                burst._PDOP = metaKit.GetFloat(viewId, i, 16);
                                burst._HDOP = metaKit.GetFloat(viewId, i, 17);
                                burst._VDOP = metaKit.GetFloat(viewId, i, 18);

                                burst._magVar = metaKit.GetFloat(viewId, i, 19);
                                burst._num_of_sat = metaKit.GetInt(viewId, i, 20);
                                burst._fixed_PRNs = metaKit.GetString(viewId, i, 21);

                                burst._GGA_latDir = TwoTrails.GpsAccess.NorthSouth.North;
                                burst._GGA_longDir = TwoTrails.GpsAccess.EastWest.West;
                                burst._magVarDir = TwoTrails.GpsAccess.EastWest.East;
                                burst._RMC_latDir = TwoTrails.GpsAccess.NorthSouth.North;
                                burst._RMC_longDir = TwoTrails.GpsAccess.EastWest.West;

                                for (int j = 22; j < 70; j += 4)
                                {
                                    GpsAccess.Satellite s = new TwoTrails.GpsAccess.Satellite();

                                    s.ID = metaKit.GetString(viewId, i, j);
                                    s.Elevation = metaKit.GetInt(viewId, i, j + 1);
                                    s.Azimuth = metaKit.GetInt(viewId, i, j + 2);
                                    s.SNR = metaKit.GetInt(viewId, i, j + 3);

                                    burst.AddSatalite(s);
                                }

                                burst.Complete();

                                nmeas[pid].Add(burst);
                            }
                        }
                    }
                }

                #endregion

                dal.InsertPoints(_Points);

                foreach (TtMetaData m in metaData.Values)
                    dal.InsertMetaData(m);
                foreach (TtPolygon poly in _Polygons.Values)
                    dal.InsertPolygon(poly);

                foreach (KeyValuePair<int, List<GpsAccess.NmeaBurst>> bl in nmeas)
                    dal.SaveNmeaBursts(bl.Value, pidToCN[bl.Key]);
            }
            catch (Exception ex)
            {
                TtUtils.WriteError(ex.Message, "DataImport:ImportTt", ex.StackTrace);
                return false;
            }

            return true;
        }
 private void ChangeMeta(int index)
 {
     if (_Meta.Count > 0 && index > -1 && index < _Meta.Count)
     {
         _CurrMeta = _Meta[index];
     #if (PocketPC || WindowsCE || Mobile)
         btnMeta.Text = _CurrMeta.Name;
     #endif
     }
 }
        private void ChangeMeta()
        {
            if (_UpdatedPoint != null)
            {
                _UpdatedPoint.MetaDefCN = pointInfoCtrl.MetaDefCN;

                CurrMeta = _Meta[_MetaCNs.IndexOf(_UpdatedPoint.MetaDefCN)];

                int pos = -1;
                TtMetaData metaFrom;
                pos = _MetaCNs.IndexOf(UpdatedPoint.MetaDefCN);

                if (pos > -1)
                    metaFrom = _Meta[pos];
                else
                    return;

                if (UpdatedPoint.IsTravType())
                {
                    ((SideShotPoint)_UpdatedPoint).SlopeDistance = TtUtils.ConvertDistance(((SideShotPoint)_UpdatedPoint).SlopeDistance, CurrMeta.uomDistance, metaFrom.uomDistance);
                    ((SideShotPoint)_UpdatedPoint).SlopeAngle = TtUtils.ConvertAngle(((SideShotPoint)_UpdatedPoint).SlopeAngle, CurrMeta.uomSlope, metaFrom.uomSlope);
                    travInfoControl1.CurrentPoint = (SideShotPoint)UpdatedPoint;
                }
                else if (UpdatedPoint.IsGpsType())
                {
                    _UpdatedPoint = TtUtils.RecalcPoint(UpdatedPoint, CurrMeta.Zone, metaFrom.Zone, DAL);
                    gpsInfoControl1.CurrentPoint = (GpsPoint)UpdatedPoint;
                }

                travInfoControl1.MetaData = CurrMeta;
                gpsInfoControl1.Meta = CurrMeta;
                _dirty = true;

                SavePoint();
            }
        }
        private List<TtMetaData> GetUpgradeMetaData()
        {
            StringBuilder query = new StringBuilder();
            StringBuilder fields = new StringBuilder();
            fields.AppendFormat("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13}",
                TwoTrailsSchema.MetaDataSchema.CN, //0
                TwoTrailsSchema.MetaDataSchema.Comment,//1
                TwoTrailsSchema.MetaDataSchema.Compass, //2
                TwoTrailsSchema.MetaDataSchema.Crew,    //3
                TwoTrailsSchema.MetaDataSchema.Datum,   //4
                TwoTrailsSchema.MetaDataSchema.DeclinationType, //5
                TwoTrailsSchema.MetaDataSchema.ID,      //6
                TwoTrailsSchema.MetaDataSchema.Laser,   //7
                TwoTrailsSchema.MetaDataSchema.MagDec,  //8
                TwoTrailsSchema.MetaDataSchema.Receiver,    //9
                (DalVersion < DbReleaseVersions.D1_1_0) ? "DistanceUOM" :
                TwoTrailsSchema.MetaDataSchema.UomDistance,     //10
                (DalVersion < DbReleaseVersions.D1_1_0) ? "ElevationUOM" :
                TwoTrailsSchema.MetaDataSchema.UomElevation,    //11
                (DalVersion < DbReleaseVersions.D1_1_0) ? "SlopeUOM" :
                TwoTrailsSchema.MetaDataSchema.UomSlope,        //12
                TwoTrailsSchema.MetaDataSchema.UtmZone);         //13

            query.AppendFormat("select {0} from {1}",
                fields.ToString(),
                TwoTrailsSchema.MetaDataSchema.TableName);

            SQLiteCommand cmd = _dbConnection.CreateCommand();
            List<TtMetaData> metas = new List<TtMetaData>();

            try
            {
                cmd.CommandText = query.ToString();
                TtMetaData md = new TtMetaData();
                SQLiteDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    md.CN = reader.GetString(0);
                    if (!reader.IsDBNull(1))
                        md.Comment = reader.GetString(1);
                    if (!reader.IsDBNull(2))
                        md.Compass = reader.GetString(2);
                    if (!reader.IsDBNull(3))
                        md.Crew = reader.GetString(3);
                    if (!reader.IsDBNull(4))
                        md.datum = (Datum)Enum.Parse(typeof(Datum), reader.GetString(4), true);
                    if (!reader.IsDBNull(5))
                        md.decType = (DeclinationType)Enum.Parse(typeof(DeclinationType), reader.GetString(5), true);
                    md.Name = reader.GetString(6);
                    if (!reader.IsDBNull(7))
                        md.Laser = reader.GetString(7);
                    if (!reader.IsDBNull(8))
                        md.magDec = reader.GetDouble(8);
                    if (!reader.IsDBNull(9))
                        md.Receiver = reader.GetString(9);
                    md.uomDistance = (UomDistance)Enum.Parse(typeof(UomDistance), reader.GetString(10), true);
                    md.uomElevation = (UomElevation)Enum.Parse(typeof(UomElevation), reader.GetString(11), true);
                    md.uomSlope = (UomSlope)Enum.Parse(typeof(UomSlope), reader.GetString(12), true);
                    md.Zone = reader.GetInt32(13);
                    metas.Add(md);
                    md = new TtMetaData();
                }
            }
            catch (Exception ex)
            {
                TtUtils.WriteError(ex.Message, "DataAccessUpgrader:GetMetaData", ex.StackTrace);
            }
            finally
            {
                cmd.Dispose();
            }

            return metas;
        }
示例#11
0
        public WalkForm(TtPolygon poly, DataAccessLayer dal, TtMetaData meta, int cIndex)
        {
            InitializeComponent();

            Init(poly, dal, meta, cIndex);
        }
        public void UpdateMetaData(TtMetaData md)
        {
            StringBuilder where = new StringBuilder();
            StringBuilder query = new StringBuilder();
            query.AppendFormat("Update {0} set ", TwoTrailsSchema.MetaDataSchema.TableName);
            query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.MetaDataSchema.Comment, md.Comment);
            query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.MetaDataSchema.Compass, md.Compass);
            query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.MetaDataSchema.Crew, md.Crew);
            query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.MetaDataSchema.Datum, md.datum.ToString());
            query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.MetaDataSchema.DeclinationType, md.decType.ToString());
            query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.MetaDataSchema.ID, md.Name);
            query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.MetaDataSchema.Laser, md.Laser);
            query.AppendFormat("{0} = {1}, ", TwoTrailsSchema.MetaDataSchema.MagDec, md.magDec);
            query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.MetaDataSchema.Receiver, md.Receiver);
            query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.MetaDataSchema.UomDistance, md.uomDistance.ToString());
            query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.MetaDataSchema.UomElevation, md.uomElevation.ToString());
            query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.MetaDataSchema.UomSlope, md.uomSlope.ToString());
            query.AppendFormat("{0} = {1} ", TwoTrailsSchema.MetaDataSchema.UtmZone, md.Zone);

            query.AppendFormat("where {0} = '{1}'", TwoTrailsSchema.MetaDataSchema.CN, md.CN);

            if (!IsOpen)
                OpenDB();

            SQLiteCommand update = _dbConnection.CreateCommand();

            try
            {
                update.CommandText = query.ToString();
                update.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                TtUtils.WriteError(ex.Message, "DataAccessLayer:UpdateMetaData");
            }
            finally
            {
                update.Dispose();
            }
        }
        public void InsertMetaData(TtMetaData md)
        {
            StringBuilder queryBeginning = new StringBuilder();
            StringBuilder queryEnd = new StringBuilder();
            queryBeginning.AppendFormat("INSERT INTO {0} (", TwoTrailsSchema.MetaDataSchema.TableName);
            queryEnd.Append("(");

            //CN
            queryBeginning.AppendFormat("{0},", TwoTrailsSchema.MetaDataSchema.CN);
            queryEnd.AppendFormat("'{0}',", md.CN);

            //Name
            queryBeginning.AppendFormat("{0},", TwoTrailsSchema.MetaDataSchema.ID);
            queryEnd.AppendFormat("'{0}',", md.Name);

            //Zone
            queryBeginning.AppendFormat("{0},", TwoTrailsSchema.MetaDataSchema.UtmZone);
            queryEnd.AppendFormat("'{0}',", md.Zone);

            //Datum
            queryBeginning.AppendFormat("{0},", TwoTrailsSchema.MetaDataSchema.Datum);
            queryEnd.AppendFormat("'{0}',", md.datum.ToString());

            //Distance UoM
            queryBeginning.AppendFormat("{0},", TwoTrailsSchema.MetaDataSchema.UomDistance);
            queryEnd.AppendFormat("'{0}',", md.uomDistance.ToString());

            //Elev UoM
            queryBeginning.AppendFormat("{0},", TwoTrailsSchema.MetaDataSchema.UomElevation);
            queryEnd.AppendFormat("'{0}',", md.uomElevation);

            //Slope UoM
            queryBeginning.AppendFormat("{0},", TwoTrailsSchema.MetaDataSchema.UomSlope);
            queryEnd.AppendFormat("'{0}',", md.uomSlope);

            //Comment
            queryBeginning.AppendFormat("{0},", TwoTrailsSchema.MetaDataSchema.Comment);
            queryEnd.AppendFormat("'{0}',", md.Comment);

            //Compass
            queryBeginning.AppendFormat("{0},", TwoTrailsSchema.MetaDataSchema.Compass);
            queryEnd.AppendFormat("'{0}',", md.Compass);

            //Crew
            queryBeginning.AppendFormat("{0},", TwoTrailsSchema.MetaDataSchema.Crew);
            queryEnd.AppendFormat("'{0}',", md.Crew);

            //Declination Type
            queryBeginning.AppendFormat("{0},", TwoTrailsSchema.MetaDataSchema.DeclinationType);
            queryEnd.AppendFormat("'{0}',", md.decType.ToString());

            //Declination
            queryBeginning.AppendFormat("{0},", TwoTrailsSchema.MetaDataSchema.MagDec);
            queryEnd.AppendFormat("{0},", md.magDec);

            //Laser
            queryBeginning.AppendFormat("{0},", TwoTrailsSchema.MetaDataSchema.Laser);
            queryEnd.AppendFormat("'{0}',", md.Laser);

            //Receiver
            queryBeginning.AppendFormat("{0}", TwoTrailsSchema.MetaDataSchema.Receiver);
            queryEnd.AppendFormat("'{0}'", md.Receiver);

            queryBeginning.Append(") values ");
            queryEnd.Append(");");
            queryBeginning.AppendFormat(" {0}", queryEnd.ToString());

            if (!IsOpen)
                OpenDB();

            SQLiteCommand update = _dbConnection.CreateCommand();

            try
            {
                update.CommandText = queryBeginning.ToString();
                update.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                TtUtils.WriteError(ex.Message, "DataAccessLayer:InsertMetaData");
            }
            finally
            {
                update.Dispose();
            }
        }
        public TtMetaData CreateDefaultMetaData()
        {
            TtMetaData md = Engine.Values.Settings.ReadMetaSettings();

            if (md == null)
            {
                md = new TtMetaData();
                md.Name = "Meta1";
                md.magDec = 0;
                md.decType = DeclinationType.MagDec;
                md.Zone = 13;
                md.uomSlope = UomSlope.Percent;
                md.uomElevation = UomElevation.Feet;
                md.uomDistance = UomDistance.FeetTenths;
                md.datum = Datum.NAD83;
            }

            md.CN = Values.EmptyGuid;

            return md;
        }
        public void Init()
        {
            TtUtils.ShowWaitCursor();

            loaded =  _saving = _closing = false;
            _adjust = dirty = reloadQuondamList = false;

            _init = false;

            _Groups = DAL.GetGroups().ToDictionary(g => g.CN, g => g);
            _Polygons = DAL.GetPolygons();
            _NumOfPoly = _Polygons.Count;

            _Points = new List<TtPoint>();
            _PointCNs = new List<string>();
            _Meta = new List<TtMetaData>();
            _MetaCNs = new List<string>();

            pointInfoCtrl.ReadOnly = true;

            if (_NumOfPoly > 0)
            {
                //Setup Point Info Control with the Polygon List
                pointInfoCtrl.SetPolygons(_Polygons);

                //Set Current Polygon
                CurrPoly = _Polygons[0];
                CurrPolyCN = CurrPoly.CN;

                _Meta = DAL.GetMetaData();
                foreach (TtMetaData m in _Meta)
                {
                    _MetaCNs.Add(m.CN);
                }
                pointInfoCtrl.SetMetaDefs(_Meta);
                CurrMeta = _Meta[0];

                CurrPointIndex = -1;
                CurrPoint = null;
                UpdatedPoint = null;
                CurrPointIndex = -1;

                //Load Points, move to last one then update the navigation control with that info
                _init = true;
                ChangePolygon();
                LoadPoints();
                MoveToLastPoint();
                pointNavigationCtrl.UpdatePointList(_PointCNs, CurrPointIndex);

                //setup Quondam Control
                quondamInfoControl1.DAL = DAL;
                quondamInfoControl1.Polygons = _Polygons;

                //Show correct Point Control
                DisplayPointCtrl();
                actionsControl.NewEnabled = true;
            }
            else
            {
                CurrPointIndex = -1;
                pointInfoCtrl.CheckLockEnabled = false;

                //dont create new points if no polygons
                actionsControl.MiscButtonEnabled = false;
                actionsControl.DeleteEnabled = false;
                actionsControl.NewEnabled = false;
            }

            _dirty = false;
            _adjust = false;
            reloadQuondamList = false;

            gpsInfoControl1.Visible = false;
            quondamInfoControl1.Visible = false;
            travInfoControl1.Visible = false;
            walkInfoCtrl1.Visible = false;
            take5InfoCtrl1.Visible = false;

            TtUtils.HideWaitCursor();
        }
示例#16
0
        public Take5Form(TtPolygon poly, DataAccessLayer dal, TtMetaData meta, TtPoint lastPoint, int cIndex)
        {
            InitializeComponent();

            Init(poly, dal, meta, lastPoint, cIndex);
        }
示例#17
0
        private void WriteWayPoints(string file, List<WayPoint> points, TtMetaData md)
        {
            #if !(PocketPC || WindowsCE || Mobile)
            string FileName = file + "_WayPoints";
            GeometryFactory geoFac = new GeometryFactory();
            ShapefileDataWriter sdw = new ShapefileDataWriter(FileName, geoFac);

            ArrayList features = new ArrayList();
            AttributesTable attTable;

            Feature feat = new Feature();
            DbaseFileHeader dbh;

            foreach (WayPoint point in points)
            {
                feat = new Feature();
                attTable = new AttributesTable();

                attTable.AddAttribute("PID", point.PID);
                attTable.AddAttribute("Comment", point.Comment ?? String.Empty);
                attTable.AddAttribute("CN", point.CN);
                attTable.AddAttribute("Group", point.GroupName ?? String.Empty);
                attTable.AddAttribute("RMSEr", point.RMSEr ?? -1);
                attTable.AddAttribute("UnAdjX", point.UnAdjX);
                attTable.AddAttribute("UnAdjY", point.UnAdjY);
                attTable.AddAttribute("UnAdjZ", point.UnAdjZ);

                feat.Geometry = new NetTopologySuite.Geometries.Point(point.UnAdjX, point.UnAdjY, point.UnAdjZ);
                feat.Attributes = attTable;

                features.Add(feat);
            }

            dbh = ShapefileDataWriter.GetHeader((Feature)features[0], features.Count);

            sdw.Header = dbh;
            sdw.Write(features);
            WriteProjection(FileName, md.Zone);
            #endif
        }
        public void Init(TtPolygon poly, DataAccessLayer dal, TtMetaData meta, TtPoint currentPoint, int currIndex)
        {
            this.Icon = Properties.Resources.Map;
            TtUtils.ShowWaitCursor();
            #if (PocketPC || WindowsCE || Mobile)
            lblLabel.Text = "Take " + Values.Settings.DeviceOptions.Take5NmeaAmount.ToString();
            #endif
            btnCapture.Text = "Take " + Values.Settings.DeviceOptions.Take5NmeaAmount.ToString();
            this.Text = "Take " + Values.Settings.DeviceOptions.Take5NmeaAmount.ToString() + " Point Capture";

            Values.GPSA.BurstReceived += GPSA_BurstReceived;
            Values.GPSA.InvalidStringFound += GPSA_InvalidStringFound;
            Values.GPSA.ComTimeout += GPSA_ComTimeout;
            Values.GPSA.GpsStarted += GPSA_GpsStarted;
            Values.GPSA.GpsEnded += GPSA_GpsEnded;
            Values.GPSA.GpsError += GPSA_GpsError;

            travInfoControl1.UseLaser = false;

            Polygon = poly;
            DAL = dal;
            CurrMeta = meta;

            logging = false;
            this.DialogResult = DialogResult.Cancel;
            OnBound = true;
            _index = 0;
            ignore = 0;

            progCapture.Value = 0;
            progCapture.Minimum = 0;
            progCapture.Maximum = Values.Settings.DeviceOptions.Take5NmeaAmount;

            logged = 0;
            _locked = true;

            CurrentNmea = new List<NmeaBurst>();
            LastNmea = new List<NmeaBurst>();
            CurrentPoint = null;

            _index = currIndex;
            LastPoint = currentPoint;

            gpsInfoAdvCtrl.SetZone(CurrMeta.Zone);
            gpsInfoAdvCtrl.StartControl();

            if (Values.GPSA.UsesFile && Values.Settings.DeviceOptions.GetGpsOnStart)
            {
                using (DeviceSetupForm dsf = new DeviceSetupForm())
                {
                    dsf.ShowDialog();
                }
            }

            T5Group = new TtGroup();
            T5Group.Name = String.Format("Take5_{0}", T5Group.CN.Truncate(8));
            T5Group.GroupType = GroupType.Take5;

            if(!Values.GPSA.IsBusy)
                Values.GPSA.OpenGps(Values.Settings.DeviceOptions.GpsComPort, Values.Settings.DeviceOptions.GpsBaud);
            TtUtils.HideWaitCursor();

            if (dal.GetPointCount(poly.CN) < 1)
            {
                checkMeta = true;
            }
        }
        public void Init()
        {
            this.Icon = Properties.Resources.Map;
            _init = false;

            _Polygons = new List<TtPolygon>();
            _FromPoints = new List<TtPoint>();
            _ToPoints = new List<TtPoint>();
            _PolyNames = new List<string>();
            _FromPointNames = new List<string>();
            _ToPointNames = new List<string>();
            _Meta = new List<TtMetaData>();

            pointsAvail = false;

            _FromPoint = null;
            _ToPoint = null;
            _FromPolygon = null;
            _ToPolygon = null;
            _CurrMeta = null;

            _navigating = false;

            if (DAL != null)
            {
                _Polygons = DAL.GetPolygons();

                _Meta = DAL.GetMetaData();

                if (_Meta.Count > 0)
                {
                    foreach (TtMetaData m in _Meta)
                    {
                        cboMeta.Items.Add(m.Name);
                    }

                    _CurrMeta = _Meta[0];
            #if (PocketPC || WindowsCE || Mobile)
                    btnMeta.Text = _CurrMeta.Name;
            #endif
                    cboMeta.SelectedIndex = 0;
                }

                if (_Polygons.Count > 0)
                {
                    foreach (TtPolygon poly in _Polygons)
                    {
                        if (DAL.GetPointCount(poly.CN) > 0)
                            pointsAvail = true;
                    }
                }
            }
            else
            {
            #if (PocketPC || WindowsCE || Mobile)
                btnMeta.Enabled = false;
            #endif
                cboMeta.Enabled = false;
                _CurrMeta = Values.Settings.ReadMetaSettings();

                if (_CurrMeta == null)
                {
                    _CurrMeta = new TtMetaData()
                    {
                        CN = Guid.Empty.ToString(),
                        Name = "DefaultMeta",
                        magDec = 0,
                        decType = DeclinationType.MagDec,
                        Zone = 13,
                        uomSlope = UomSlope.Percent,
                        uomElevation = UomElevation.Feet,
                        uomDistance = UomDistance.FeetTenths,
                        datum = Datum.NAD83
                    };
                }
            }

            UseMyPos = false;

            #region Setup Controls
            if (Values.Settings.DeviceOptions.UseSelection)
            {
                cboFromPoint.Visible = false;
                cboFromPoly.Visible = false;
                cboToPoint.Visible = false;
                cboToPoly.Visible = false;
                cboMeta.Visible = false;

            #if (PocketPC || WindowsCE || Mobile)
                btnToPoint.Visible = true;
                btnToPoly.Visible = true;
                btnFromPoint.Visible = true;
                btnFromPoly.Visible = true;
                btnMeta.Visible = true;

                btnToPoint.Enabled = true;
                btnToPoly.Enabled = true;
                btnFromPoint.Enabled = true;
                btnFromPoly.Enabled = true;
            #endif
                cboFromPoint.Enabled = false;
                cboFromPoly.Enabled = false;
                cboToPoint.Enabled = false;
                cboToPoly.Enabled = false;
            }
            else
            {
                cboFromPoint.Visible = true;
                cboFromPoly.Visible = true;
                cboToPoint.Visible = true;
                cboToPoly.Visible = true;
                cboMeta.Visible = true;

            #if (PocketPC || WindowsCE || Mobile)
                btnToPoint.Visible = false;
                btnToPoly.Visible = false;
                btnFromPoint.Visible = false;
                btnFromPoly.Visible = false;
                btnMeta.Visible = false;

                btnToPoint.Enabled = false;
                btnToPoly.Enabled = false;
                btnFromPoint.Enabled = false;
                btnFromPoly.Enabled = false;
            #endif
                cboFromPoint.Enabled = true;
                cboFromPoly.Enabled = true;
                cboToPoint.Enabled = true;
                cboToPoly.Enabled = true;
            }

            txtFromX.Enabled = false;
            txtFromY.Enabled = false;
            txtToX.Enabled = false;
            txtToY.Enabled = false;

            if (pointsAvail == true)
            {
                foreach (TtPolygon poly in _Polygons)
                {
                    cboFromPoly.Items.Add(poly.Name);
                    cboToPoly.Items.Add(poly.Name);
                    _PolyNames.Add(poly.Name);
                }

                cboFromPoly.SelectedIndex = 0;
                cboToPoly.SelectedIndex = 0;
                //ChangeFromPoly(0);
                //ChangeToPoly(0);
            }
            else
            {
                radToPoint.Enabled = false;
                radFromPoint.Enabled = false;

                txtFromX.Enabled = true;
                txtFromY.Enabled = true;
                txtToX.Enabled = true;
                txtToY.Enabled = true;

                radFromUTM.Checked = true;
                radToUTM.Checked = true;
            }
            #endregion
        }
        private void actionsControl_Misc_OnClick2(object sender, EventArgs e)
        {
            TtMetaData newmeta = new TtMetaData();

            newmeta.CN = Guid.NewGuid().ToString();
            newmeta.Comment = Current.Comment;
            newmeta.Compass = Current.Compass;
            newmeta.Crew = Current.Crew;
            newmeta.datum = Current.datum;
            newmeta.decType = Current.decType;
            newmeta.Laser = Current.Laser;
            newmeta.magDec = Current.magDec;
            newmeta.Receiver = Current.Receiver;
            newmeta.uomDistance = Current.uomDistance;
            newmeta.uomElevation = Current.uomElevation;
            newmeta.uomSlope = Current.uomSlope;
            newmeta.Zone = Current.Zone;

            int i = 1;
            string name = string.Empty;

            while (true)
            {
                name = String.Format("m_{0}", i);

                if (MetaData.Where(m => m.Name == name).Any())
                {
                    i++;
                }
                else
                {
                    newmeta.Name = name;
                    break;
                }
            }

            SaveMeta();

            _CNs.Add(newmeta.CN);
            MetaData.Add(newmeta);

            Current = newmeta;

            pointNavigationCtrl.UpdatePointList(_CNs, CurrIndex);

            AdjustNavControls();

            DAL.InsertMetaData(Current);
        }