//============================================================================* // cTargetDetailsForm() - Constructor //============================================================================* public cTargetDetailsForm(cDataFiles DataFiles, cTarget Target) { InitializeComponent(); m_DataFiles = DataFiles; m_Target = new cTarget(Target); if (m_Target.BatchID != 0) { m_Batch = m_DataFiles.GetBatchByID(m_Target.BatchID); } //----------------------------------------------------------------------------* // Event Handlers //----------------------------------------------------------------------------* DatePicker.ValueChanged += OnDateChanged; ShooterTextBox.TextChanged += OnShooterChanged; LocationTextBox.TextChanged += OnLocationChanged; EventTextBox.TextChanged += OnEventChanged; NotesTextBox.TextChanged += OnNotesChanged; FirearmCombo.SelectedIndexChanged += OnFirearmChanged; //----------------------------------------------------------------------------* // Size Dialog and create Sho tList View //----------------------------------------------------------------------------* SetClientSizeCore(GeneralGroupBox.Location.X + GeneralGroupBox.Width + 10, OKButton.Location.Y + OKButton.Height + 20); m_ShotListView = new cTargetShotListView(m_DataFiles, m_Target); m_ShotListView.Location = new Point(6, 25); m_ShotListView.Size = new Size(ShotDataGroupBox.Width - 12, ShotDataGroupBox.Height - 31); m_ShotListView.TabIndex = 0; ShotDataGroupBox.Controls.Add(m_ShotListView); //----------------------------------------------------------------------------* // Populate Data //----------------------------------------------------------------------------* PopulateFirearmCombo(); PopulateDetailData(); //----------------------------------------------------------------------------* // Finish up and exit //----------------------------------------------------------------------------* m_fInitialized = true; UpdateButtons(); }
//============================================================================* // OnMouseClick() //============================================================================* protected override void OnMouseClick(MouseEventArgs args) { int nX = args.X; int nY = args.Y; ListViewItem Item = GetItemAt(nX, nY); //----------------------------------------------------------------------------* // Find the Column that was clicked //----------------------------------------------------------------------------* int nColumn = 0; int nColumnX = 0; bool fColumnFound = false; if (Item != null) { foreach (ColumnHeader Column in Columns) { if (nX >= nColumnX && nX <= nColumnX + Column.Width) { fColumnFound = true; break; } nColumnX += Column.Width; nColumn++; } } if (fColumnFound) { ColumnHeader Header = Columns[nColumn]; Graphics g = Graphics.FromHwnd(this.Handle); SizeF TextSize = g.MeasureString(Item.SubItems[nColumn].Text, this.Font); //----------------------------------------------------------------------------* // Website Column //----------------------------------------------------------------------------* if (Header.Text == "Website") { if (Item.SubItems[nColumn].Text.Length > 0) { if (nX - nColumnX < (int)TextSize.Width) { try { System.Diagnostics.Process.Start(Item.SubItems[nColumn].Text); WebsiteVisited(Item); } catch { MessageBox.Show("Invalid Website URL. Correct the URL and try again.", "Invalid URL", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } } //----------------------------------------------------------------------------* // Part Number Column //----------------------------------------------------------------------------* if (Header.Text == "Part Number" && Item.Text == "Batch Editor") { Size BoxSize = CheckBoxRenderer.GetGlyphSize(g, (Item.Checked ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal)); if ((nColumn == 0 && CheckBoxes && nX > 4 + BoxSize.Width && nX - 4 - BoxSize.Width - nColumnX < (int)TextSize.Width) || (nColumn == 0 && !CheckBoxes && nX > 4 && nX - nColumnX < (int)TextSize.Width) || (nColumn != 0 && nX > 4 && nX - nColumnX < (int)TextSize.Width)) { string strBatchNumber = Item.SubItems[1].Text; if (strBatchNumber.Length >= 7 && strBatchNumber.Substring(0, 6) == "Batch ") { strBatchNumber = strBatchNumber.Substring(6); } else { strBatchNumber = ""; } int nBatchID = 0; Int32.TryParse(strBatchNumber, out nBatchID); if (nBatchID > 0) { cBatch Batch = m_DataFiles.GetBatchByID(nBatchID); if (Batch != null) { cBatchForm BatchForm = new cBatchForm(Batch, m_DataFiles, null, cFirearm.eFireArmType.None, true); BatchForm.ShowDialog(); } } } } //----------------------------------------------------------------------------* // Caliber Column //----------------------------------------------------------------------------* if (Header.Text == "Caliber" || Header.Text == "Primary Caliber") { cCaliber Caliber = GetCaliberFromTag(Item); if (Caliber != null && !String.IsNullOrEmpty(Caliber.SAAMIPDF)) { Size BoxSize = CheckBoxRenderer.GetGlyphSize(g, (Item.Checked ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal)); if ((nColumn == 0 && CheckBoxes && nX > 4 + BoxSize.Width && nX - 4 - BoxSize.Width - nColumnX < (int)TextSize.Width) || (nColumn == 0 && !CheckBoxes && nX > 4 && nX - nColumnX < (int)TextSize.Width) || (nColumn != 0 && nX > 4 && nX - nColumnX < (int)TextSize.Width)) { cCaliber.ShowSAAMIPDF(m_DataFiles, Caliber); } } } } base.OnMouseClick(args); }
//============================================================================* // Compare() //============================================================================* public override int Compare(Object Object1, Object Object2) { if (Object1 == null) { if (Object2 == null) { return(0); } else { return(-1); } } else { if (Object2 == null) { return(1); } } cEvaluationItem Item1 = (cEvaluationItem)(Object1 as ListViewItem).Tag; cEvaluationItem Item2 = (cEvaluationItem)(Object2 as ListViewItem).Tag; if (Item1 == null) { if (Item2 == null) { return(0); } else { return(0); } } else { if (Item2 == null) { return(1); } } //----------------------------------------------------------------------------* // Do Special Compares //----------------------------------------------------------------------------* bool fSpecial = false; int rc = 0; string strPart1 = ""; string strPart2 = ""; cBatch Batch1 = null; cBatch Batch2 = null; switch (SortColumn) { //----------------------------------------------------------------------------* // Batch ID //----------------------------------------------------------------------------* case 0: rc = Item1.ChargeTest.BatchID.CompareTo(Item2.ChargeTest.BatchID); fSpecial = true; break; //----------------------------------------------------------------------------* // Caliber //----------------------------------------------------------------------------* case 1: rc = Item1.Load.Caliber.CompareTo(Item2.Load.Caliber); fSpecial = true; break; //----------------------------------------------------------------------------* // Bullet //----------------------------------------------------------------------------* case 2: rc = Item1.Load.Bullet.Manufacturer.CompareTo(Item2.Load.Bullet.Manufacturer); if (rc == 0) { strPart1 = Item1.Load.Bullet.PartNumber; strPart2 = Item2.Load.Bullet.PartNumber; if (strPart1.Length != strPart2.Length) { if (strPart1.Length > strPart2.Length) { string strPad = ""; while (strPart1.Length > strPart2.Length + strPad.Length) { strPad += " "; } strPart2 = strPad + strPart2; } else { string strPad = ""; while (strPart2.Length > strPart1.Length + strPad.Length) { strPad += " "; } strPart1 = strPad + strPart1; } } rc = strPart1.CompareTo(strPart2); if (rc == 0) { rc = Item1.Load.Powder.CompareTo(Item2.Load.Powder); } } fSpecial = true; break; //----------------------------------------------------------------------------* // Powder //----------------------------------------------------------------------------* case 3: rc = Item1.Load.Powder.Manufacturer.CompareTo(Item2.Load.Powder.Manufacturer); if (rc == 0) { strPart1 = Item1.Load.Powder.Type; strPart2 = Item2.Load.Powder.Type; if (strPart1.Length != strPart2.Length) { string strPad = ""; if (strPart1.Length < strPart2.Length) { while (strPart1.Length + strPad.Length < strPart2.Length) { strPad += " "; } strPart1 = strPad + strPart1; } else { while (strPart2.Length + strPad.Length < strPart1.Length) { strPad += " "; } strPart2 = strPad + strPart2; } } rc = strPart1.CompareTo(strPart2); if (rc == 0) { rc = Item1.Charge.PowderWeight.CompareTo(Item2.Charge.PowderWeight); } } fSpecial = true; break; //----------------------------------------------------------------------------* // Charge //----------------------------------------------------------------------------* case 4: rc = Item1.Charge.PowderWeight.CompareTo(Item2.Charge.PowderWeight); fSpecial = true; break; //----------------------------------------------------------------------------* // Primer //----------------------------------------------------------------------------* case 5: rc = Item1.Load.Primer.Manufacturer.CompareTo(Item2.Load.Primer.Manufacturer); if (rc == 0) { strPart1 = Item1.Load.Primer.Model; strPart2 = Item2.Load.Primer.Model; if (strPart1.Length != strPart2.Length) { string strPad = ""; if (strPart1.Length < strPart2.Length) { while (strPart1.Length + strPad.Length < strPart2.Length) { strPad += " "; } strPart1 = strPad + strPart1; } else { while (strPart2.Length + strPad.Length < strPart1.Length) { strPad += " "; } strPart2 = strPad + strPart2; } } rc = strPart1.CompareTo(strPart2); } fSpecial = true; break; //----------------------------------------------------------------------------* // Case //----------------------------------------------------------------------------* case 6: rc = Item1.Load.Case.Manufacturer.CompareTo(Item2.Load.Case.Manufacturer); if (rc == 0) { rc = Item1.Load.Case.Caliber.CompareTo(Item2.Load.Case.Caliber); } if (rc == 0) { strPart1 = Item1.Load.Case.PartNumber; strPart2 = Item2.Load.Case.PartNumber; if (strPart1.Length != strPart2.Length) { string strPad = ""; if (strPart1.Length < strPart2.Length) { while (strPart1.Length + strPad.Length < strPart2.Length) { strPad += " "; } strPart1 = strPad + strPart1; } else { while (strPart2.Length + strPad.Length < strPart1.Length) { strPad += " "; } strPart2 = strPad + strPart2; } } rc = strPart1.CompareTo(strPart2); } fSpecial = true; break; //----------------------------------------------------------------------------* // Num Rounds //----------------------------------------------------------------------------* case 7: int nItem1 = 0; int nItem2 = 0; Int32.TryParse((Object1 as ListViewItem).Text, out nItem1); Int32.TryParse((Object2 as ListViewItem).Text, out nItem2); rc = nItem1.CompareTo(nItem2); fSpecial = true; break; //----------------------------------------------------------------------------* // Best Group //----------------------------------------------------------------------------* case 8: rc = Item1.ChargeTest.BestGroup.CompareTo(Item2.ChargeTest.BestGroup); fSpecial = true; break; //----------------------------------------------------------------------------* // MOA //----------------------------------------------------------------------------* case 9: double Group1 = Item1.ChargeTest.BestGroup; double Group2 = Item2.ChargeTest.BestGroup; Group1 = cDataFiles.MetricToStandard(Group1, cDataFiles.eDataType.GroupSize); Group2 = cDataFiles.MetricToStandard(Group2, cDataFiles.eDataType.GroupSize); double dRange1 = Item1.ChargeTest.BestGroupRange; double dRange2 = Item2.ChargeTest.BestGroupRange; if (cPreferences.StaticPreferences.MetricRanges) { dRange1 = cConversions.MetersToYards(dRange1); dRange2 = cConversions.MetersToYards(dRange2); } double dMOA1 = (dRange1 > 0) ? Group1 / ((dRange1 / 100.0) * 1.047) : 0; double dMOA2 = (dRange2 > 0) ? Group2 / ((dRange2 / 100.0) * 1.047) : 0; rc = dMOA1.CompareTo(dMOA2); fSpecial = true; break; //----------------------------------------------------------------------------* // Best Group Range //----------------------------------------------------------------------------* case 10: rc = Item1.ChargeTest.BestGroupRange.CompareTo(Item2.ChargeTest.BestGroupRange); fSpecial = true; break; //----------------------------------------------------------------------------* // Muzzle Velocity //----------------------------------------------------------------------------* case 11: rc = Item1.ChargeTest.MuzzleVelocity.CompareTo(Item2.ChargeTest.MuzzleVelocity); fSpecial = true; break; //----------------------------------------------------------------------------* // Max Deviation //----------------------------------------------------------------------------* case 12: Batch1 = m_DataFiles.GetBatchByID(Item1.ChargeTest.BatchID); Batch2 = m_DataFiles.GetBatchByID(Item2.ChargeTest.BatchID); if (Batch1 == null || Batch1.BatchTest == null || Batch1.BatchTest.TestShotList == null || Batch2 == null || Batch2.BatchTest == null || Batch2.BatchTest.TestShotList == null) { rc = 0; } else { rc = Batch1.BatchTest.TestShotList.Statistics.MaxDeviation.CompareTo(Batch2.BatchTest.TestShotList.Statistics.MaxDeviation); } fSpecial = true; break; //----------------------------------------------------------------------------* // Std Deviation //----------------------------------------------------------------------------* case 13: Batch1 = m_DataFiles.GetBatchByID(Item1.ChargeTest.BatchID); Batch2 = m_DataFiles.GetBatchByID(Item2.ChargeTest.BatchID); if (Batch1 == null || Batch1.BatchTest == null || Batch1.BatchTest.TestShotList == null || Batch2 == null || Batch2.BatchTest == null || Batch2.BatchTest.TestShotList == null) { rc = 0; } else { rc = Batch1.BatchTest.TestShotList.Statistics.StdDev.CompareTo(Batch2.BatchTest.TestShotList.Statistics.StdDev); } fSpecial = true; break; } if (fSpecial) { if (SortingOrder == SortOrder.Descending) { return(0 - rc); } return(rc); } return(base.Compare(Object1, Object2)); }
//============================================================================* // SetLoadData() //============================================================================* public void SetLoadData(cLoad Load) { //----------------------------------------------------------------------------* // Create the format strings //----------------------------------------------------------------------------* string strChargeFormat = m_DataFiles.Preferences.FormatString(cDataFiles.eDataType.PowderWeight); string strGroupFormat = m_DataFiles.Preferences.FormatString(cDataFiles.eDataType.GroupSize); //----------------------------------------------------------------------------* // Loop through the charges //----------------------------------------------------------------------------* foreach (cCharge Charge in Load.ChargeList) { //----------------------------------------------------------------------------* // Loop through the charge tests //----------------------------------------------------------------------------* foreach (cChargeTest ChargeTest in Charge.TestList) { if (ChargeTest.BatchID == 0 && !m_fFactoryTest) { continue; } //----------------------------------------------------------------------------* // Create the ListViewItem //----------------------------------------------------------------------------* ListViewItem Item = new ListViewItem(); //----------------------------------------------------------------------------* // Set the ListViewItem Data //----------------------------------------------------------------------------* Item.Text = (ChargeTest.BatchID != 0) ? String.Format("Batch #{0:G0}", ChargeTest.BatchID) : ChargeTest.Source; Item.Tag = new cEvaluationItem(Load, Charge, ChargeTest); Item.SubItems.Add(Load.Caliber.ToString()); Item.SubItems.Add(Load.Bullet.ToString()); Item.SubItems.Add(Load.Powder.ToString()); Item.SubItems.Add(String.Format(strChargeFormat, cDataFiles.StandardToMetric(Charge.PowderWeight, cDataFiles.eDataType.PowderWeight))); Item.SubItems.Add(Load.Primer.ToShortString()); Item.SubItems.Add(Load.Case.ToShortString()); cBatch Batch = null; if (ChargeTest.BatchID != 0) { Batch = m_DataFiles.GetBatchByID(ChargeTest.BatchID); } if (Batch == null || Batch.BatchTest == null) { Item.SubItems.Add("-"); } else { Item.SubItems.Add(String.Format("{0:G0}", Batch.BatchTest.NumRounds)); } if (ChargeTest.BestGroup == 0.0) { Item.SubItems.Add("-"); } else { Item.SubItems.Add(String.Format(strGroupFormat, cDataFiles.StandardToMetric(ChargeTest.BestGroup, cDataFiles.eDataType.GroupSize))); } if (ChargeTest.BestGroupRange == 0.0) { Item.SubItems.Add("-"); Item.SubItems.Add("-"); } else { Item.SubItems.Add(String.Format("{0:F3}", ChargeTest.BestGroup / ((double)((double)ChargeTest.BestGroupRange / 100.0) * 1.047))); Item.SubItems.Add(String.Format("{0:N0}", cDataFiles.StandardToMetric(ChargeTest.BestGroupRange, cDataFiles.eDataType.Range))); } if (ChargeTest.MuzzleVelocity == 0) { Item.SubItems.Add("-"); } else { Item.SubItems.Add(String.Format("{0:N0}", cDataFiles.StandardToMetric(ChargeTest.MuzzleVelocity, cDataFiles.eDataType.Velocity))); } if (Batch == null || Batch.BatchTest == null || Batch.BatchTest.TestShotList == null) { Item.SubItems.Add("-"); Item.SubItems.Add("-"); } else { cTestStatistics Statistics = new cTestStatistics(Batch.BatchTest.TestShotList); if (Statistics.MaxDeviation == 0) { Item.SubItems.Add("-"); } else { Item.SubItems.Add(String.Format("{0:N0}", cDataFiles.StandardToMetric(Statistics.MaxDeviation, cDataFiles.eDataType.Velocity))); } if (Statistics.StdDev == 0.0) { Item.SubItems.Add("-"); } else { Item.SubItems.Add(String.Format("{0:F2}", cDataFiles.StandardToMetric(Statistics.StdDev, cDataFiles.eDataType.Velocity))); } } //----------------------------------------------------------------------------* // Add the item to the list //----------------------------------------------------------------------------* AddItem(Item); } } }
//============================================================================* // Import() //============================================================================* public bool Import(cRWXMLDocument XMLDocument, XmlNode XMLThisNode, cDataFiles DataFiles) { int nInt = 0; XmlNode XMLNode = XMLThisNode.FirstChild; while (XMLNode != null) { switch (XMLNode.Name) { case "BatchID": Int32.TryParse(XMLNode.FirstChild.Value, out nInt); m_Batch = DataFiles.GetBatchByID(nInt); break; case "TestDate": DateTime.TryParse(XMLNode.FirstChild.Value, out m_TestDate); break; case "FirearmIdentity": m_Firearm = cRWXMLDocument.GetFirearmByIdentity(XMLDocument, XMLThisNode, DataFiles); break; case "Suppressed": m_fSuppressed = XMLNode.FirstChild.Value == "Yes"; break; case "Location": m_strLocation = XMLNode.FirstChild.Value; break; case "Altitude": Int32.TryParse(XMLNode.FirstChild.Value, out m_nAltitude); break; case "Pressure": Double.TryParse(XMLNode.FirstChild.Value, out m_dPressure); break; case "Temperature": Int32.TryParse(XMLNode.FirstChild.Value, out m_nTemperature); break; case "Humidity": Double.TryParse(XMLNode.FirstChild.Value, out m_dHumidity); break; case "WindSpeed": Int32.TryParse(XMLNode.FirstChild.Value, out m_nWindSpeed); break; case "WindDirection": Int32.TryParse(XMLNode.FirstChild.Value, out m_nWindDirection); break; case "NumRounds": Int32.TryParse(XMLNode.FirstChild.Value, out m_nNumRounds); break; case "BestGroup": Double.TryParse(XMLNode.FirstChild.Value, out m_dBestGroup); break; case "BestGroupRange": Double.TryParse(XMLNode.FirstChild.Value, out m_dBestGroupRange); break; case "Notes": m_strNotes = XMLNode.FirstChild.Value; break; case "TestShots": case "TestShotList": m_TestShotList.Import(XMLDocument, XMLNode, DataFiles); break; default: break; } XMLNode = XMLNode.NextSibling; } m_nNumRounds = m_TestShotList.Count; return(true); }