/// <summary> /// Give the updated details to the UIController to pass to the master. /// This will not cause the information to be saved to the database, but /// most be done before doing so. /// </summary> private void CommitData() { Datatype.ImageData updatedData = new Datatype.ImageData( null, null, DateFired, ShooterLastName, ShooterFirstName, Place, DistanceUnits, Distance, Temperature, Nomenclature, SerialNumber, WeaponNotes, CaliberUnit, Caliber, LotNumber, Mass, AmmoNotes, Scaling, ShotsFired, null); if (_uic.Active.Length == 1) { updatedData.origFilename = _uic.CurrentData.origFilename; updatedData.reportFilename = _uic.CurrentData.reportFilename; updatedData.points = _uic.CurrentData.points; updatedData.regionOfInterest = measureBox.RegionOfInterest; updatedData.scale = measureBox.Scaling; updatedData.scale.horizontalLength = (float)Convert.ToDouble(text_Width.Text); updatedData.scale.verticalLength = (float)Convert.ToDouble(text_Height.Text); updatedData.points = selectBox.BulletHoles; updatedData.bitmap = _uic.CurrentData.bitmap; } _uic.SetData(updatedData, _modifiedAttributes); }
/// <summary> /// Sets the filenames to the array of input filenames. /// </summary> /// <param name="fileNames">The filenames of the target images.</param> public void SetFileNames(String[] fileNames) { if (fileNames.Length <= 0) { throw new ArgumentException("fileNames must have Length > 0"); } List<String> newFileNames = new List<String>(); List<Datatype.ImageData> imageData = new List<Datatype.ImageData>(); for (int i = 0; i < fileNames.Length; i++ ) { if (!File.Exists(fileNames[i])) { Log.LogError("Invalid filename input from user.", "filename", fileNames[i]); } try { Bitmap bmp = IO.LoadBitmap(fileNames[i]); newFileNames.Add(fileNames[i]); Datatype.ImageData imageDatum = new Datatype.ImageData(); imageDatum.origFilename = fileNames[i]; imageDatum.bitmap = bmp; imageDatum.dateTimeFired = DateTime.Today; imageData.Add(imageDatum); } catch (ArgumentException) { Log.LogInfo("Invalid filename (not an image) input from user.", "filename", fileNames[i]); } } _fileNames = newFileNames.ToArray(); _imageData = imageData.ToArray(); _stats = new Datatype.Stats[imageData.Count]; }
/// <summary> /// Loads an <c>ImageData</c> from the database. /// </summary> /// <param name="targetID">The <paramref name="targetID"/> of the target to load.</param> /// <param name="configReader">The <c>ConfigReader</c> with the path to the database.</param> /// <returns>The <c>ImageData</c> corresponding to the <paramref name="targetID"/>.</returns> /// <exception cref="OleDbException">A connection-level error occurred while opening the connection.</exception> public static Datatype.ImageData LoadData(int targetID, ConfigReader configReader) { Datatype.ImageData imageData = new Datatype.ImageData(); using (OleDbConnection conn = new OleDbConnection(configReader.getValue("Database Location"))) { openConnection(conn); using (OleDbCommand command = new OleDbCommand()) { command.Connection = conn; command.CommandText = "SELECT * FROM Target WHERE TargetID = ?"; command.Prepare(); command.Parameters.Add("TargetID", OleDbType.Integer).Value = targetID; using (OleDbDataReader reader = command.ExecuteReader()) { if (reader.Read()) { imageData.targetID = reader.GetInt32(reader.GetOrdinal("TargetID")); if (imageData.targetID != targetID) { throw new Exception("Error in LoadData()"); } imageData.origFilename = reader.GetString(reader.GetOrdinal("OrigFilename")); imageData.reportFilename = reader.GetString(reader.GetOrdinal("ReportFilename")); imageData.dateTimeFired = reader.GetDateTime(reader.GetOrdinal("DateTimeFired")); imageData.dateTimeProcessed = reader.GetDateTime(reader.GetOrdinal("DateTimeProcessed")); imageData.shooterLName = reader.GetString(reader.GetOrdinal("ShooterLName")); imageData.shooterFName = reader.GetString(reader.GetOrdinal("ShooterFName")); imageData.rangeLocation = reader.GetString(reader.GetOrdinal("RangeLocation")); imageData.distanceUnits = (Datatype.UnitsOfMeasure)reader.GetByte(reader.GetOrdinal("DistanceUnits")); imageData.distance = reader.GetInt32(reader.GetOrdinal("Distance")); imageData.temperature = (Datatype.ImageData.Temperature)reader.GetByte(reader.GetOrdinal("Temperature")); imageData.weaponName = reader.GetString(reader.GetOrdinal("WeaponName")); imageData.serialNumber = reader.GetString(reader.GetOrdinal("SerialNumber")); imageData.weaponNotes = reader.GetString(reader.GetOrdinal("WeaponNotes")); imageData.caliber = GetCaliberUnit(reader.GetInt32(reader.GetOrdinal("CaliberID")), configReader); imageData.caliberValue = reader.GetDouble(reader.GetOrdinal("CaliberValue")); imageData.lotNumber = reader.GetString(reader.GetOrdinal("LotNumber")); imageData.projectileMassGrains = reader.GetInt32(reader.GetOrdinal("ProjectileMassGrains")); imageData.ammunitionNotes = reader.GetString(reader.GetOrdinal("AmmunitionNotes")); imageData.shotsFired = reader.GetInt32(reader.GetOrdinal("ShotsFired")); String points = reader.GetString(reader.GetOrdinal("ShotLocations")); String[] pointElements = points.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (pointElements.Length % 2 != 0) { Log.LogWarning("A Points field has invalid values.", "targetID", targetID.ToString(), "SQL", command.CommandText); } else { for (int i = 0; i < pointElements.Length; i += 2) { imageData.points.Add(new Point(Int32.Parse(pointElements[i]), Int32.Parse(pointElements[i + 1]))); } } String scale = reader.GetString(reader.GetOrdinal("Scale")); String[] scaleElements = scale.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (scaleElements.Length != 8) { Log.LogWarning("A Scale field has invalid values.", "targetID", targetID.ToString(), "SQL", command.CommandText); } else { imageData.scale.horizontal = new Point(Int32.Parse(scaleElements[0]), Int32.Parse(scaleElements[1])); imageData.scale.middle = new Point(Int32.Parse(scaleElements[2]), Int32.Parse(scaleElements[3])); imageData.scale.vertical = new Point(Int32.Parse(scaleElements[4]), Int32.Parse(scaleElements[5])); imageData.scale.horizontalLength = float.Parse(scaleElements[6]); imageData.scale.verticalLength = float.Parse(scaleElements[7]); } String ROI = reader.GetString(reader.GetOrdinal("ROI")); String[] ROIElements = ROI.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (ROIElements.Length != 4) { Log.LogWarning("An ROI field has invalid values.", "targetID", targetID.ToString(), "SQL", command.CommandText); } else { imageData.regionOfInterest.topLeft = new Point(Int32.Parse(ROIElements[0]), Int32.Parse(ROIElements[1])); imageData.regionOfInterest.bottomRight = new Point(Int32.Parse(ROIElements[2]), Int32.Parse(ROIElements[3])); } } else { Log.LogInfo("Target ID not found.", "targetID", targetID.ToString(), "SQL", command.CommandText); return null; } } } } return imageData; }
/// <summary> /// Gets the <code>ImageData</code> for the current selection of images. /// If the selection contains multiple images and they have differing /// values, the common values are set and the rest of null (or otherwise /// equivalent) value. /// </summary> /// <param name="images">A list of image indices (typically the current selection).</param> /// <returns>The associated <code>ImageData</code> for the set of images.</returns> public Datatype.ImageData GetImageData(int[] images) { _active = images; // If there is only one image selected if (images.Length == 1) { CurrentData = _master.GetImageData(images[0]); return CurrentData; } else { // commonAttributes describes the common attributes of all images selected Attributes commonAttributes = Attributes.DateTimeFired | Attributes.ShooterFirstName | Attributes.ShooterLastName | Attributes.TotalShotsFired | Attributes.RangeLocation | Attributes.RangeDistance | Attributes.RangeDistanceUnits | Attributes.RangeTemperature | Attributes.WeaponName | Attributes.WeaponSerial | Attributes.WeaponNotes | Attributes.AmmoCaliber | Attributes.AmmoCaliberUnits | Attributes.AmmoLotNumber | Attributes.AmmoMass | Attributes.AmmoNotes; Datatype.ImageData first = null; foreach (int image in images) { Datatype.ImageData current = _master.GetImageData(image); if (first == null) { first = current; continue; } // Compare each attribute to the first element. If that does // not match the first element, remove that from commonAttributes // because we don't want that to be part of the return value. if (DateTime.Compare(first.dateTimeFired, current.dateTimeFired) != 0) commonAttributes &= ~Attributes.DateTimeFired; if (first.shooterFName != current.shooterFName) commonAttributes &= ~Attributes.ShooterFirstName; if (first.shooterLName != current.shooterLName) commonAttributes &= ~Attributes.ShooterLastName; if (first.shotsFired != current.shotsFired) commonAttributes &= ~Attributes.TotalShotsFired; if (first.weaponName != current.weaponName) commonAttributes &= ~Attributes.WeaponName; if (first.serialNumber != current.serialNumber) commonAttributes &= ~Attributes.WeaponSerial; if (first.weaponNotes != current.weaponNotes) commonAttributes &= ~Attributes.WeaponNotes; if (first.rangeLocation != current.rangeLocation) commonAttributes &= ~Attributes.RangeLocation; if (first.distance != current.distance) commonAttributes &= ~Attributes.RangeDistance; if (first.distanceUnits != current.distanceUnits) commonAttributes &= ~Attributes.RangeDistanceUnits; if (first.temperature != current.temperature) commonAttributes &= ~Attributes.RangeTemperature; if (first.caliberValue != current.caliberValue) commonAttributes &= ~Attributes.AmmoCaliber; if (first.caliber != current.caliber) commonAttributes &= ~Attributes.AmmoCaliberUnits; if (first.lotNumber != current.lotNumber) commonAttributes &= ~Attributes.AmmoLotNumber; if (first.projectileMassGrains != current.projectileMassGrains) commonAttributes &= ~Attributes.AmmoMass; if (first.ammunitionNotes != current.ammunitionNotes) commonAttributes &= ~Attributes.AmmoNotes; } // Create and return an ImageData instance with the only common values set. Datatype.ImageData common = new Datatype.ImageData(); if ((commonAttributes & Attributes.DateTimeFired) != 0) common.dateTimeFired = first.dateTimeFired; else common.dateTimeFired = DummyDate; if ((commonAttributes & Attributes.ShooterFirstName) != 0) common.shooterFName = first.shooterFName; if ((commonAttributes & Attributes.ShooterLastName) != 0) common.shooterLName = first.shooterLName; if ((commonAttributes & Attributes.WeaponName) != 0) common.weaponName = first.weaponName; if ((commonAttributes & Attributes.TotalShotsFired) != 0) common.shotsFired = first.shotsFired; if ((commonAttributes & Attributes.WeaponSerial) != 0) common.serialNumber = first.serialNumber; if ((commonAttributes & Attributes.WeaponNotes) != 0) common.weaponNotes = first.weaponNotes; if ((commonAttributes & Attributes.RangeLocation) != 0) common.rangeLocation = first.rangeLocation; if ((commonAttributes & Attributes.RangeDistance) != 0) common.distance = first.distance; if ((commonAttributes & Attributes.RangeDistanceUnits) != 0) common.distanceUnits = first.distanceUnits; if ((commonAttributes & Attributes.RangeTemperature) != 0) common.temperature = first.temperature; if ((commonAttributes & Attributes.AmmoCaliber) != 0) common.caliberValue = first.caliberValue; if ((commonAttributes & Attributes.AmmoCaliberUnits) != 0) common.caliber = first.caliber; if ((commonAttributes & Attributes.AmmoLotNumber) != 0) common.lotNumber = first.lotNumber; if ((commonAttributes & Attributes.AmmoMass) != 0) common.projectileMassGrains = first.projectileMassGrains; if ((commonAttributes & Attributes.AmmoNotes) != 0) common.ammunitionNotes = first.ammunitionNotes; CurrentData = common; return common; } }