Exemplo n.º 1
0
        /// <summary>
        /// Save a geometry to the database given a list of coordinates and a name
        /// </summary>
        /// <param name="pointList"></param>
        /// <param name="name"></param>
        public static void SaveGeometry(List <Mapsui.Geometries.Point> pointList, string name)
        {
            var geom = new ReferenceGeometry();

            geom.geometryId   = Guid.NewGuid().ToString();
            geom.geometryName = name;
            geom.geometry     = DataDAO.CoordinatesToGeoJSON(pointList);
            geom.userName     = App.CurrentUser.userId;
            geom.fullUserName = App.CurrentUser.firstName + " " + App.CurrentUser.name;
            geom.timestamp    = DateTime.Now;
            geom.creationTime = DateTime.Now;
            geom.status       = -1;
            geom.readOnly     = false;
            var proj = Project.FetchCurrentProject();

            geom.project_fk = proj.Id;

            using (SQLiteConnection conn = new SQLiteConnection(Preferences.Get("databaseLocation", "")))
            {
                conn.Insert(geom);

                var project = conn.GetWithChildren <Project>(proj.Id);
                project.geometries = conn.Table <ReferenceGeometry>().Where(g => g.project_fk == proj.Id).ToList();
                conn.UpdateWithChildren(project);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Update the geometry with any changes made
 /// </summary>
 /// <param name="geom"></param>
 public static void SaveGeometry(ReferenceGeometry geom)
 {
     using (SQLiteConnection conn = new SQLiteConnection(Preferences.Get("databaseLocation", "")))
     {
         conn.Update(geom);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Create a new record given the form type and possible associated geometry
        /// </summary>
        /// <param name="formId"></param>
        /// <param name="geomId"></param>
        /// <returns>The created record</returns>
        public static Record CreateRecord(int formId, int?geomId)
        {
            Project proj = Project.FetchProjectWithChildren(App.CurrentProjectId);
            Record  rec  = new Record();

            rec.project_fk   = proj.Id;
            rec.geometry_fk  = geomId;
            rec.fullUserName = App.CurrentUser.firstName + " " + App.CurrentUser.name;
            rec.userName     = App.CurrentUser.userId;
            rec.creationTime = DateTime.Now;
            rec.timestamp    = DateTime.Now;
            rec.formId       = formId;
            rec.recordId     = Guid.NewGuid().ToString();
            rec.status       = -1;

            //Add record to db.
            using (SQLiteConnection conn = new SQLiteConnection(Preferences.Get("databaseLocation", "")))
            {
                var success = conn.Insert(rec);
                if (success == 1)
                {
                    if (rec.geometry_fk == null)
                    {
                        proj.records = conn.Table <Record>().Select(n => n).Where(Record => Record.project_fk == proj.Id).ToList();
                        conn.UpdateWithChildren(proj);
                    }
                    else
                    {
                        var recs = conn.Table <Record>().Select(n => n).Where(Record => Record.geometry_fk == geomId).ToList();
                        var geom = ReferenceGeometry.GetGeometry((int)geomId);
                        geom.records = recs;
                        conn.UpdateWithChildren(geom);
                    }
                    return(rec);
                }
            }
            return(null);
        }