private void rbnBtnDone_Click(object sender, EventArgs e) { try { #region Insert Series if (opr.ToUpper() == "INSERT") { //Check if the series information are filled well . . . if ((rbnCboPatiant.SelectedItem != "Select Patiant") && (picLstSerImage.Items.Count > 0) && (rbnCboPatiant.SelectedItem != null)) { //Preparing the progress bar . . . int xx = picLstSerImage.Items.Count; xx = 100 / xx; proBarOpr.Visible = true; proBarOpr.BringToFront(); proBarOpr.Value = 0; //Create the physical path where the image and the series is contained int sid = int.Parse(rbnTxtSeriesID.Text); string serFolder = SC.SettingsList[0].TrimEnd('\\') + "\\" + sid.ToString(); Directory.CreateDirectory(serFolder); sid = sid * 100; int imgID = 0; //Extract image features for each image in the series : foreach (PictureListItem P in picLstSerImage.Items) { Application.DoEvents(); fe = new featureExtractor(P.Tag.ToString()); fv = fe.AllFeatures(); //Get all image information : string[] info = fe.GetImageInfo().Split('\n'); for (int i = 0; i < info.Length; i++) { info[i] = info[i].Trim(); } //Get image size and Dimensions string size = "", h = "", w = ""; for (int i = 0; i < info.Length; i++) { if (info[i].StartsWith("FileSize")) { size = info[i]; } else if (info[i].StartsWith("Width")) { w = info[i]; } else if (info[i].StartsWith("Height")) { h = info[i]; } } info = new string[2]; info[0] = size.Split(':')[1].Trim(); //Image size . . . info[1] = h.Split(':')[1].Trim() + "X" + w.Split(':')[1].Trim(); //Image Dimensions . . . imgID++; //Image ID in the series . . . int ID = sid + imgID; //Image ID in the database . . . //Create image record . . . ImageRecord = new imageRecord(ID.ToString(), info, P.Text, fv); // . . . and insert that record in the opened database if (!ImageRecord.InsertImage(DBC)) //If insertion is not done { throw new Exception("Failed to insert the image record with ID: " + ID.ToString() + "!"); //Throw an exception } //Copy image file from its location to where each image in the database is stored File.Copy(P.Tag.ToString(), serFolder + "\\" + P.Text, true); Application.DoEvents(); proBarOpr.Value += xx; } sid = sid / 100; //Determine series categories . . . List <category> catList = new List <category>(); for (int i = 0; i < mListCats.Items.Count; i++) { if (mListCats.Items[i].CheckState == CheckState.Checked) { catList.Add(new category(mListCats.Items[i].Description, null, null)); } } //Create series record . . . SeriesRecord = new Series(sid.ToString() , rbnCboPatiant.SelectedItem.Split('\t')[0] , sid.ToString() , this.rbnTxtNotes.Text, catList); //Try to insert the series . . . if (!SeriesRecord.InsertSeries(DBC)) //In insertion is not done { throw new Exception("Failed to insert this series !"); //Throw an exception } proBarOpr.Value = 100; proBarOpr.SendToBack(); proBarOpr.Visible = false; this.DialogResult = DialogResult.OK; this.Close();//Close when done } else { throw new Exception("Please fill all the fields !"); } } #endregion #region Modify Series else if (opr.ToUpper() == "MODIFY") { //Check if the fields are filled well . . . if ((rbnCboPatiant.SelectedItem != "Select Patiant") && (rbnCboSeriesID.SelectedItem != "Select Series")) { if (!(pat_changed || cats_changed || images_changed || notes_changed)) { this.DialogResult = DialogResult.None; MessageBox.Show("No change done to this series !", "Closing", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } //Preparing the progress bar . . . int xx = picLstSerImage.Items.Count; xx = 100 / xx; proBarOpr.Visible = true; proBarOpr.BringToFront(); proBarOpr.Value = 0; //Get the physical path where the image and the series is contained int sid = int.Parse(rbnCboSeriesID.SelectedItem); string serFolder = SC.SettingsList[0].TrimEnd('\\') + "\\" + sid.ToString(); sid = sid * 100; int imgID = 0; //Extract image features for each changed or new image in the series : foreach (PictureListItem P in picLstSerImage.Items) { Application.DoEvents(); string txt = P.Text.ToLower(); #region If image is removed if (txt.Contains("removed")) { if (txt.Contains("new")) { picLstSerImage.Items.Remove(P); } else { ImageRecord = (imageRecord)P.Value; if (ImageRecord.DeleteImage(DBC)) { P.Text = P.Text.ToLower(); P.Text = P.Text.Replace(" removed", ""); //File.Delete(serFolder + "\\" + P.Text); } else { throw new Exception("The image with ImageID : " + ImageRecord.ID + "\nCannot be deleted"); } } } #endregion #region If image is new and not removed else { if (!txt.Contains("removed") && (txt.Contains("new"))) { fe = new featureExtractor(P.Tag.ToString()); fv = fe.AllFeatures(); //Get all image information : string[] info = fe.GetImageInfo().Split('\n'); for (int i = 0; i < info.Length; i++) { info[i] = info[i].Trim(); } //Get image size and Dimensions string size = "", h = "", w = ""; for (int i = 0; i < info.Length; i++) { if (info[i].StartsWith("FileSize")) { size = info[i]; } else if (info[i].StartsWith("Width")) { w = info[i]; } else if (info[i].StartsWith("Height")) { h = info[i]; } } info = new string[2]; info[0] = size.Split(':')[1].Trim(); //Image size . . . info[1] = h.Split(':')[1].Trim() + "X" + w.Split(':')[1].Trim(); //Image Dimensions . . . imgID = getUnusedImageID(sid / 100); //Image ID in the series . . . int ID = imgID + 1; //Image ID in the database . . . //Create image record . . . P.Text = P.Text.ToLower(); P.Text = P.Text.Replace(" new", ""); ImageRecord = new imageRecord(ID.ToString(), info, P.Text, fv); // . . . and insert that record in the opened database if (!ImageRecord.InsertImage(DBC)) //If insertion is not done { throw new Exception("Failed to insert the new image record with ID: " + ID.ToString() + "!"); //Throw an exception } //Copy image file from its location to where each image in the database is stored File.Copy(P.Tag.ToString(), serFolder + "\\" + P.Text, true); } } #endregion #region If image is not new nor removed but changed if (txt.Contains("changed")) //Manipulated (Edited) image { //Do not do any thing to this image why?!!! . . . //simply because it was added by the manipulation process } #endregion Application.DoEvents(); proBarOpr.Value += xx; } sid = sid / 100; //Determine series categories . . . List <category> catList = new List <category>(); for (int i = 0; i < mListCats.Items.Count; i++) { if (mListCats.Items[i].CheckState == CheckState.Checked) { catList.Add(new category(mListCats.Items[i].Description, null, null)); } } //Create series record . . . SeriesRecord = new Series(sid.ToString() , rbnCboPatiant.SelectedItem.Split('\t')[0] , sid.ToString() , this.rbnTxtNotes.Text, catList); //Try to update the series . . . if (!SeriesRecord.UpdateSeries(DBC)) //If modification not done . . . { throw new Exception("Failed to update this series !"); //Throw an exception } proBarOpr.Value = 100; proBarOpr.SendToBack(); proBarOpr.Visible = false; this.DialogResult = DialogResult.OK; this.Close();//Close when done } else { throw new Exception("Please fill all the fields !"); } } #endregion #region Delete Series else if (opr.ToUpper() == "DELETE") { DialogResult dr = MessageBox.Show("Are you sure you want to delete this series and all its images ?", "Deletion", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { //Check if the fields are filled well . . . if ((rbnCboPatiant.SelectedItem != "Select Patiant") && (rbnCboSeriesID.SelectedItem != "Select Series")) { //Preparing the progress bar . . . int xx = picLstSerImage.Items.Count; xx = 100 / xx; proBarOpr.Visible = true; proBarOpr.BringToFront(); proBarOpr.Value = 0; //Get the physical path where the image and the series is contained int sid = int.Parse(rbnCboSeriesID.SelectedItem); string serFolder = SC.SettingsList[0].TrimEnd('\\') + "\\" + sid.ToString(); sid = sid * 100; int imgID = 0; //Delete each image in the series : foreach (PictureListItem P in picLstSerImage.Items) { Application.DoEvents(); string txt = P.Text.ToLower(); ImageRecord = (imageRecord)P.Value; if (!P.Text.ToLower().Contains("new")) { if (!ImageRecord.DeleteImage(DBC)) { throw new Exception("The image with ImageID : " + ImageRecord.ID + "\nCannot be deleted"); } } Application.DoEvents(); proBarOpr.Value += xx; } sid = sid / 100; //Determine series categories . . . List <category> catList = new List <category>(); for (int i = 0; i < mListCats.Items.Count; i++) { catList.Add(new category(mListCats.Items[i].Description, null, null)); } //Create series record . . . SeriesRecord = new Series(sid.ToString() , rbnCboPatiant.SelectedItem.Split('\t')[0] , sid.ToString() , this.rbnTxtNotes.Text, catList); //Try to delete the series . . . if (!SeriesRecord.DeleteSeries(DBC)) //If deletion not done . . . { throw new Exception("Failed to delete this series !"); //Throw an exception } proBarOpr.Value = 100; proBarOpr.SendToBack(); proBarOpr.Visible = false; this.DialogResult = DialogResult.OK; this.Close();//Close when done } } } #endregion } catch (Exception ex) { MessageBox.Show( ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); if (proBarOpr.Visible) { proBarOpr.Visible = false; } } }
private void tlStrpSave_Click(object sender, EventArgs e) { try { if (opr.ToLower() == "insert") { //picViewImage.Image.Save(ImgPro.OriginalImagePath); System.IO.File.Copy(ImgPro.NewImagePath, ImgPro.OriginalImagePath, true); DialogResult = DialogResult.OK; this.Close(); } else //If operation is modify image . . . { featureExtractor fe = new featureExtractor(ImgPro.NewImagePath); List <Feature> fv = new List <Feature>(); fv = fe.AllFeatures(); //Get all image information : string[] info = fe.GetImageInfo().Split('\n'); for (int i = 0; i < info.Length; i++) { info[i] = info[i].Trim(); } //Get image size and Dimensions string size = "", h = "", w = ""; for (int i = 0; i < info.Length; i++) { if (info[i].StartsWith("FileSize")) { size = info[i]; } else if (info[i].StartsWith("Width")) { w = info[i]; } else if (info[i].StartsWith("Height")) { h = info[i]; } } info = new string[2]; info[0] = size.Split(':')[1].Trim(); //Image size . . . info[1] = h.Split(':')[1].Trim() + "X" + w.Split(':')[1].Trim(); //Image Dimensions . . . ImageRecord.ImageInfo = info; ImageRecord.FeatureVector = fv; // . . . and modify that record in the opened database if (!ImageRecord.ModifyImage(DBC)) //If insertion is not done { throw new Exception("Failed to save changes to image record with ID: " + ImageRecord.ID + "!"); //Throw an exception } //picViewImage.Image.Save(ImgPro.OriginalImagePath); System.IO.File.Copy(ImgPro.NewImagePath, ImgPro.OriginalImagePath, true); DialogResult = DialogResult.OK; this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Saving Changes", MessageBoxButtons.OK, MessageBoxIcon.Error); } }