public HowAmIDoingOptions(DataAccessLayer dal)
 {
     _data = dal;
     SaveReport = false;
     ReportPath = String.Empty;
     ReportText = new StringBuilder();
 }
        public bool DeleteGroup(string cn, DataAccessLayer dal, bool deletePoints)
        {
            if (Groups.ContainsKey(cn))
            {
                List<TtPoint> points = dal.GetPointsInGroup(cn);

                if (deletePoints)
                {
                    dal.DeletePointsInGroup(cn);
                }
                else
                {
                    for (int i = 0; i < points.Count; i++)
                    {
                        points[i].GroupCN = MainGroup.CN;
                        points[i].GroupName = MainGroup.Name;
                    }

                    dal.SavePoints(points, points);
                }

                _Groups.Remove(cn);

                return dal.DeleteGroup(cn);
            }

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

            //get default meta
            if(dal != null)
                _Meta = dal.GetMetaData()[0];
        }
        public CalcGpsPointForm(List<NmeaBurst> nb, int pn, string cn, DataAccessLayer dal, int currentZone, bool recalc)
        {
            if(Engine.Values.WideScreen)
                InitializeComponentWide();
            else
                InitializeComponent();

            Init(nb, pn, cn, dal, currentZone, recalc);
        }
        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 ImportForm(DataAccessLayer dal, bool isOpen)
        {
            InitializeComponent();

            this.DialogResult = DialogResult.Abort;

            DAL = dal;
            Init();
        }
        public DrawGMap(DataAccessLayer dal)
        {
            InitializeComponent();

            if (dal == null)
                throw new NullReferenceException();

            DAL = dal;
        }
        public AcquireGpsForm(TtPoint p, int currentZone, DataAccessLayer dal)
        {
            if(Engine.Values.WideScreen)
                InitializeComponentWide();
            else
                InitializeComponent();

            Init(p, currentZone, dal);
        }
        public RenamePointForm(DataAccessLayer dal)
        {
            if (Values.WideScreen)
                InitializeComponentWide();
            else
                InitializeComponent();

            DAL = dal;
            Init();
        }
        public PointEditForm(DataAccessLayer d)
        {
            InitializeComponent();

            DAL = d;

            Init();

            TtUtils.HideWaitCursor();
        }
        public ImportForm(DataAccessLayer dal, bool isOpen)
        {
            this.DialogResult = DialogResult.Abort;

            if(Engine.Values.WideScreen)
                InitializeComponentWide();
            else
                InitializeComponent();

            DAL = dal;
            Init();
        }
        public MetadataForm(DataAccessLayer d)
        {
            _init = false;
            DAL = d;

            if(Engine.Values.WideScreen)
                InitializeComponentWide();
            else
                InitializeComponent();

            Init();
        }
        public bool AddGroup(TtGroup group, DataAccessLayer dal)
        {
            if (!Groups.ContainsKey(group.CN))
            {
                Groups.Add(group.CN, group);
                if (dal.InsertGroup(group) > 0)
                    return true;

                Groups.Remove(group.CN);
            }

            return false;
        }
        public MassEditForm(DataAccessLayer dal)
        {
            if (Engine.Values.WideScreen)
            {
                InitializeComponentWide();
                btnConvert.MakeMultiline();
                btnSwitchPoly.MakeMultiline();
            }
            else
                InitializeComponent();

            Init(dal);
        }
        public MassEditPointLocManip(List<TtPolygon> polys, List<TtPoint> points, List<TtPoint> movePoints,
            bool move, DataAccessLayer d)
        {
            InitializeComponent();
            _Polys = polys;
            _Points = points;
            _MovePoints = movePoints;
            _MovePoints.Sort();

            radMove.Checked = move;
            radQuondam.Checked = !move;

            dal = d;
        }
        //private List<TtPoint> origPoints;
        //private DataAccessLayer _db;
        //Dictionary<string, TtMetaData> metas;
        public SegmentFactory(DataAccessLayer dal)
        {
            Dictionary<string, TtMetaData> meta = dal.GetMetaData().ToDictionary(m => m.CN, m => m);
            polys = dal.GetPolygons().ToDictionary(p => p.CN, p => p);

            List<TtPoint> tmpWayPoints = new List<TtPoint>();
            Dictionary<string, TtPoint> tmpPoints = new Dictionary<string, TtPoint>();

            foreach (TtPoint p in dal.GetPoints())
            {
                if (p.op == OpType.WayPoint)
                {
                    p.CalculatePoint();
                    p.AdjustPoint();
                    tmpWayPoints.Add(p);
                }
                else
                {
                    tmpPoints.Add(p.CN, p);

                    if (p.IsTravType())
                    {
                        ((SideShotPoint)p).Declination = meta[p.MetaDefCN].magDec;
                    }
                }
            }

            if (tmpWayPoints.Count > 0)
            {
                dal.SavePoints(tmpWayPoints, tmpWayPoints);
            }

            QuondamPoint qp;
            foreach (TtPoint p in tmpPoints.Values)
            {
                if (p.op == OpType.Quondam)
                {
                    qp = p as QuondamPoint;
                    qp.ParentPoint = tmpPoints[qp.ParentCN];
                }
            }

            points = tmpPoints.Values.ToList();
        }
        public PolyEditForm(DataAccessLayer data)
        {
            DAL = data;

            #if (PocketPC || WindowsCE || Mobile)
            if(Values.WideScreen)
                InitializeComponentWide();
            else
                InitializeComponent();
            #else
            InitializeComponent();
            #endif

            actionsControlPolygons.MiscButtonEnabled = false;
            actionsControlPolygons.MiscButtonText = "Dup";

            _dirty = false;
            _recalc = false;
        }
        public MapOptionsForm(DataAccessLayer d)
        {
            if(Values.WideScreen)
                InitializeComponentWide();
            else
                InitializeComponent();

            dal = d;

            MapOptionsForm_Load();

            if (MapValues.mapMyPos)
            {
                chkFollowPos.Enabled = true;
            }
            else
            {
                chkFollowPos.Enabled = false;
            }
        }
        public bool Upgrade(DataAccessLayer oldData)
        {
            _upgradeData = oldData;
            bool success = false;

            try
            {
                if (_upgradeData != null)
                {
                    if (!_upgradeData.IsOpen)
                        _upgradeData.OpenDAL();

            #if !(PocketPC || WindowsCE || Mobile)
                    Values.UpdateStatusProgress();
            #endif

                    if (_upgradeData.IsOpen)
                    {
                        success = UpgradeProject() &&
                            UpgradeMeta() &&
                            UpgradePolys() &&
                            UpgradeGroups() &&
                            UpgradePoints() &&
                            UpgradeNmea();
                    }
                }
            }
            catch (Exception ex)
            {
                TtUtils.WriteError(ex.Message, "DataAccessUpgrader:Upgrade", ex.StackTrace);
                return false;
            }
            finally
            {
                if (_upgradeData != null && _upgradeData.IsOpen)
                    _upgradeData.CloseDB();
                _upgradeData = null;
            }

            return success;
        }
        public WhereIsForm(DataAccessLayer dal)
        {
            #if (PocketPC || WindowsCE || Mobile)
            if (Values.WideScreen)
                InitializeComponentWide();
            else
                InitializeComponent();
            #else
            InitializeComponent();
            #endif

            if (navCtrl == null)
            {
                navCtrl = new NavCtrl();
                navCtrl.Location = new Point(0, 0);

                navCtrl.Size = new Size(panel1.Width, panel2.Height + panel2.Location.Y);
            }

            //#if (PocketPC || WindowsCE || Mobile)
            //            if (Values.WideScreen)
            //                navCtrl.Size = new Size(240, 183);
            //            else
            //                navCtrl.Size = new Size(240, 205);
            //#else
            //            navCtrl.Size = new Size(277, 252);
            //#endif

            navCtrl.BringToFront();
            navCtrl.Visible = false;
            navCtrl.TabStop = false;

            Controls.Add(navCtrl);

            DAL = dal;
            Init();
        }
 public PlotGridForm(DataAccessLayer d)
 {
     DAL = d;
     InitializeComponent();
     Init();
 }
 public bool MergeGroups(string cn1, string cn2, DataAccessLayer dal)
 {
     if (Groups.ContainsKey(cn1) && Groups.ContainsKey(cn2))
         return MergeGroups(Groups[cn1], Groups[cn2], dal);
     return false;
 }
 public void InitGroups(DataAccessLayer dal)
 {
     Groups = dal.GetGroups().ToDictionary(k => k.CN, g => g);
 }
 public bool DeleteGroup(string cn, DataAccessLayer dal)
 {
     return DeleteGroup(cn, dal, false);
 }
 public void SaveGroups(DataAccessLayer dal)
 {
     dal.UpdateGroups(Groups.Values.ToList());
 }
 public void SaveGroup(string cn, DataAccessLayer dal)
 {
     dal.UpdateGroup(Groups[cn], Groups[cn]);
 }
        public bool MergeGroups(TtGroup group1, TtGroup group2, DataAccessLayer dal)
        {
            List<TtPoint> points = dal.GetPointsInGroup(group2.CN);  //group2.Points.Values.ToList();

            for (int i = 0; i < points.Count; i++)
            {
                points[i].GroupCN = group1.CN;
                points[i].GroupName = group1.Name;
            }

            //group1.AddPointsToGroup(points);

            dal.SavePoints(points, points);
            return dal.DeleteGroup(group2.CN);
        }
        private void loadListbox(DataAccessLayer d)
        {
            dal = d;

            int w = lstPolygons.Width;

            lstPolygons.Columns.Add("Polygons", w / 4, HorizontalAlignment.Left);
            lstPolygons.Columns.Add("Points", w / 5,HorizontalAlignment.Left);
            lstPolygons.Columns.Add("Area (Ac)", -1, HorizontalAlignment.Left);

            /*
            lstPolygons.Columns.Add("Polygons", 100, HorizontalAlignment.Left);
            lstPolygons.Columns.Add("Points",50,HorizontalAlignment.Left);
            lstPolygons.Columns.Add("Area (Ac)", 70, HorizontalAlignment.Left);
            */

            cboLabels.Items.Add("None");
            cboLabels.Items.Add("All");

            if(dal != null)
            {
                List<TtPolygon> polys = dal.GetPolygons();
                allPolyCNs = new List<string>();

                TtPolygon poly;

                for (int i = 0; i < polys.Count; i++)
                {
                    poly = polys[i];

                    ListViewItem l = new ListViewItem(poly.Name);
                    l.SubItems.Add(dal.GetPointCount(poly.CN).ToString());
                    //l.SubItems.Add((polys[i].Area / 1000).ToString());
                    l.SubItems.Add(TtUtils.ConvertMeters2ToAcres(poly.Area).ToString());
                    allPolyCNs.Add(poly.CN);

                    if (i % 2 == 1)
                        l.BackColor = Color.LightGray;

                    lstPolygons.Items.Add(l);
                    cboLabels.Items.Add(poly.Name);

                    if (MapValues.mapPolyLabels == poly.CN)
                        cboLabels.SelectedIndex = i + 2;
                }

                if (MapValues.mapPolyLabels == Values.EmptyGuid)
                    cboLabels.SelectedIndex = 0;

                if (MapValues.mapPolyLabels == Values.FullGuid)
                    cboLabels.SelectedIndex = 1;

                lstPolygons.CheckBoxes = true;
            }

            #if !(PocketPC || WindowsCE || Mobile)
            lstPolygons.Columns[0].Width = -2;
            lstPolygons.Columns[1].Width = -2;
            lstPolygons.Columns[2].Width = -2;
            #endif
        }
        public void Init(TtPoint p, int currentZone, DataAccessLayer dal)
        {
            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;
            _init = true;

            this.currentZone = currentZone;

            pointName = p.PID;
            this.Text = "Point: " + pointName;
            pointCN = p.CN;

            DAL = dal;

            logged = 0;
            recieved = 0;
            logging = bLogBtn = _data = calculated = false;

            NmeaData = new List<NmeaBurst>();

            if (dal.GetPointCount(p.PolyCN) < 1)
            {
                checkMeta = true;
            }
        }
 public EditPointTableForm(DataAccessLayer d)
 {
     InitializeComponent();
     DAL = d;
 }