Ejemplo n.º 1
0
        public static void SaveImage(int fileNumber, string filePath, int vehicleid)
        {
            Image image = new Image();

            image.VehicleID  = vehicleid;
            image.FileNumber = fileNumber;
            image.FileName   = filePath;

            using (Connection sqlConn = new Connection(SQLiteBoostDB.GetDBPath())) {
                VehicleImagesDB vidb = new VehicleImagesDB(sqlConn);
                vidb.RemoveImage(vehicleid, fileNumber);
                vidb.AddImage(image);
            }
        }
Ejemplo n.º 2
0
        private void swapimage(int oldFileNumber, int newFileNumber)
        {
            using (Connection sqlConn = new Connection(SQLiteBoostDB.GetDBPath())) {
                VehicleImagesDB vidb     = new VehicleImagesDB(sqlConn);
                Image           oldImage = vidb.GetImage(vehicleid, oldFileNumber);
                Image           newImage = vidb.GetImage(vehicleid, newFileNumber);
                vidb.RemoveImage(vehicleid, oldFileNumber);
                vidb.RemoveImage(vehicleid, newFileNumber);

                oldImage.FileNumber = newFileNumber;
                vidb.AddImage(oldImage);

                if (newImage != null)
                {
                    newImage.FileNumber = oldFileNumber;
                    vidb.AddImage(newImage);
                }
            }

            string filePathMoving   = Path.Combine(imagePath, "image_" + oldFileNumber + ".jpg");
            string thumbPathMoving  = Path.Combine(imagePath, "thumb_" + oldFileNumber + ".jpg");
            string filePathMovedTo  = Path.Combine(imagePath, "image_" + newFileNumber + ".jpg");
            string thumbPathMovedTo = Path.Combine(imagePath, "thumb_" + newFileNumber + ".jpg");

            try
            {
                if (File.Exists(filePathMoving))
                {
                    File.Move(filePathMoving, filePathMovedTo.Replace("image_", "movedimage_"));
                    if (File.Exists(thumbPathMoving))
                    {
                        File.Move(thumbPathMoving, thumbPathMovedTo.Replace("thumb_", "movedthumb_"));
                    }
                }

                if (File.Exists(filePathMovedTo))
                {
                    File.Move(filePathMovedTo, filePathMoving.Replace("image_", "movedimage_"));
                    if (File.Exists(thumbPathMovedTo))
                    {
                        File.Move(thumbPathMovedTo, thumbPathMoving.Replace("thumb_", "movedthumb_"));
                    }
                }

                if (File.Exists(filePathMoving.Replace("image_", "movedimage_")))
                {
                    File.Move(filePathMoving.Replace("image_", "movedimage_"), filePathMoving.Replace("moveimage_", "image_"));
                    if (File.Exists(thumbPathMoving.Replace("thumb_", "movedthumb_")))
                    {
                        File.Move(thumbPathMoving.Replace("thumb_", "movedthumb_"), thumbPathMoving.Replace("movedthumb_", "thumb_"));
                    }
                }

                if (File.Exists(filePathMovedTo.Replace("image_", "movedimage_")))
                {
                    File.Move(filePathMovedTo.Replace("image_", "movedimage_"), filePathMovedTo.Replace("moveimage_", "image_"));
                    if (File.Exists(thumbPathMovedTo.Replace("thumb_", "movedthumb_")))
                    {
                        File.Move(thumbPathMovedTo.Replace("thumb_", "movedthumb_"), thumbPathMovedTo.Replace("movedthumb_", "thumb_"));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("error moving images: " + ex.ToString());
            }

            LoadImagesFromDatabase();
            DisplayThumbnail(oldFileNumber);
            DisplayThumbnail(newFileNumber);
        }