コード例 #1
0
        private void ImageCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            EditSuccess = false;
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                int          newIndex = e.NewStartingIndex;
                LogbookImage newImage = ImageCollection[newIndex];

                if (LogBookImages.Add(newImage))
                {
                    CurrentEntity = newImage;
                    EditSuccess   = true;
                }
            }
            break;

            case NotifyCollectionChangedAction.Remove:
            {
                List <LogbookImage> tempListOfRemovedItems = e.OldItems.OfType <LogbookImage>().ToList();
                EditSuccess = LogBookImages.Delete(tempListOfRemovedItems[0].Comment);
            }
            break;

            case NotifyCollectionChangedAction.Replace:
            {
                List <LogbookImage> tempList = e.NewItems.OfType <LogbookImage>().ToList();
                EditSuccess = LogBookImages.Update(tempList[0]);              // As the IDs are unique, only one row will be effected hence first index only
            }
            break;
            }
        }
コード例 #2
0
        public EntityValidationResult EntityValidated(LogbookImage image, bool isNew)
        {
            var result = new EntityValidationResult();


            return(result);
        }
コード例 #3
0
        public List <LogbookImage> getLogbookImages()
        {
            var thisList = new List <LogbookImage>();
            var dt       = new DataTable();

            using (var conection = new OleDbConnection(Global.ConnectionString))
            {
                try
                {
                    conection.Open();
                    string query = $"Select * from logbook_image";


                    var adapter = new OleDbDataAdapter(query, conection);
                    adapter.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        thisList.Clear();
                        foreach (DataRow dr in dt.Rows)
                        {
                            LogbookImage item = new LogbookImage();
                            item.FileName            = dr["FileName"].ToString();
                            item.GPS                 = Entities.GPSViewModel.GetGPS(dr["GPSID"].ToString());
                            item.Start               = (DateTime)dr["DateStart"];
                            item.End                 = (DateTime)dr["DateEnd"];
                            item.FisherID            = int.Parse(dr["FisherID"].ToString());
                            item.Boat                = dr["Boat"].ToString();
                            item.Gear                = Entities.GearViewModel.GetGear(dr["GearID"].ToString());
                            item.DateAddedToDatabase = (DateTime)dr["DateAdded"];
                            item.Ignore              = false;
                            item.Trip                = Entities.TripViewModel.GetTrip(int.Parse(dr["TripID"].ToString()));
                            item.Comment             = dr["ID"].ToString();
                            thisList.Add(item);
                        }
                    }
                }
                catch (OleDbException dbex)
                {
                    if (dbex.ErrorCode == -2147217865)
                    {
                        //table not found so we create one
                        CreateTable();
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                }
            }
            thisList.AddRange(GetIgnoredImages());
            return(thisList);
        }
コード例 #4
0
        public bool Add(LogbookImage image)
        {
            bool success = false;

            using (OleDbConnection conn = new OleDbConnection(Global.ConnectionString))
            {
                conn.Open();
                var sql = "";
                if (image.Ignore)
                {
                    sql = $@"Insert into logbook_image_ignore(ID, FileName,DateAdded ) Values
                             ('{image.Comment}', '{image.FileName}', '{DateTime.Now}')";
                }
                else
                {
                    sql = $@"Insert into logbook_image (
                            ID,    
                            FileName, 
                            GPSID,
                            DateStart,
                            DateEnd,        
                            GearID,
                            DateAdded,
                            FisherID,
                            Boat,
                            TripID )
                           Values (
                            '{image.Comment}',
                            '{image.FileName}',
                            '{image.GPS.DeviceID}',
                            '{image.Start}', 
                            '{image.End}',
                            '{image.Gear.Code}',
                            '{DateTime.Now.ToString("dd-MMMM-yyyyy HH:mm:ss")}',
                             {image.FisherID},
                            '{image.Boat}',
                             {image.Trip.TripID}   
                           )";
                }

                using (OleDbCommand update = new OleDbCommand(sql, conn))
                {
                    success = update.ExecuteNonQuery() > 0;
                }
            }
            return(success);
        }
コード例 #5
0
        public bool AddRecordToRepo(LogbookImage image)
        {
            if (image == null)
            {
                throw new ArgumentNullException("Error: The argument is Null");
            }

            image.Comment = GetImageCommentMetadata(image.FileName);

            if (image.Comment.Contains("GPXManager"))
            {
                ImageCollection.Add(image);
            }


            return(EditSuccess);
        }
コード例 #6
0
        public List <LogbookImage> GetIgnoredImages()
        {
            var thisList = new List <LogbookImage>();
            var dt       = new DataTable();

            using (var conection = new OleDbConnection(Global.ConnectionString))
            {
                try
                {
                    conection.Open();
                    string query = $"Select * from logbook_image_ignore";


                    var adapter = new OleDbDataAdapter(query, conection);
                    adapter.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        thisList.Clear();
                        foreach (DataRow dr in dt.Rows)
                        {
                            LogbookImage item = new LogbookImage();
                            item.FileName            = dr["FileName"].ToString();
                            item.DateAddedToDatabase = (DateTime)dr["DateAdded"];
                            item.Ignore = true;
                            thisList.Add(item);
                        }
                    }
                }
                catch (OleDbException dbex)
                {
                    if (dbex.ErrorCode == -2147217865)
                    {
                        //table not found so we create one
                        CreateTable();
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                }
            }

            return(thisList);
        }
コード例 #7
0
        public bool UpdateRecordInRepo(LogbookImage image)
        {
            if (image.FileName == null)
            {
                throw new Exception("Error: Filename cannot be null");
            }


            image.Comment = GetImageCommentMetadata(image.FileName);

            int index = 0;

            while (index < ImageCollection.Count)
            {
                if (ImageCollection[index].Comment == image.Comment)
                {
                    ImageCollection[index] = image;
                    break;
                }
                index++;
            }
            return(EditSuccess);
        }
コード例 #8
0
        public bool Update(LogbookImage image)
        {
            bool success = false;

            using (OleDbConnection conn = new OleDbConnection(Global.ConnectionString))
            {
                conn.Open();
                var sql = $@"Update logbook_image set
                                GPSID= '{image.GPS.DeviceID}',
                                DateStart = '{image.Start}',
                                DateEnd = '{image.End}',
                                GearID = '{image.Gear.Code}',
                                FisherID = {image.FisherID},
                                Boat = '{image.Boat}',
                                TripID = {image.Trip.TripID}
                            WHERE ID = '{image.Comment}'";
                using (OleDbCommand update = new OleDbCommand(sql, conn))
                {
                    success = update.ExecuteNonQuery() > 0;
                }
            }
            return(success);
        }
コード例 #9
0
 public bool IgnoreImage(LogbookImage image)
 {
     return(AddRecordToRepo(image));
 }