private void justLinkFileToLesson(string sourcePathAndFileName) { DbClasses.Image currentImage = db.FindImageWithGivenFile(sourcePathAndFileName); // if the image that reference to the file isn't anymore in the database // create a new image that references to this file // (eg. if the lesson has been deleted from the database together with its images, but // the file is (somehow) still there) if (currentImage == null) { currentImage = new DbClasses.Image(); currentImage.IdImage = 0; currentImage.RelativePathAndFilename = sourcePathAndFileName.Remove(0, Commons.PathImages.Length + 1); currentImage.Caption = txtCaption.Text; } else { LoadImage(); } db.LinkOneImage(currentImage, currentLesson); // refresh images in grid DgwLessonsImages.DataSource = db.GetLessonsImagesList(currentLesson); }