//============================================================================* // SetFirearmBulletData() //============================================================================* public void SetFirearmBulletData(ListViewItem Item, cFirearmBullet FirearmBullet) { Item.SubItems.Clear(); Item.Text = FirearmBullet.ToString(); Item.Tag = FirearmBullet; Item.SubItems.Add(String.Format(m_strDimensionFormat, cDataFiles.StandardToMetric(FirearmBullet.COL, cDataFiles.eDataType.Dimension))); if (FirearmBullet.Bullet.FirearmType != cFirearm.eFireArmType.Rifle) { Item.SubItems.Add("N/A"); } else { Item.SubItems.Add(String.Format(m_strDimensionFormat, cDataFiles.StandardToMetric(FirearmBullet.CBTO, cDataFiles.eDataType.Dimension))); } if (FirearmBullet.Bullet.FirearmType != cFirearm.eFireArmType.Rifle) { Item.SubItems.Add("N/A"); } else { Item.SubItems.Add(String.Format(m_strDimensionFormat, cDataFiles.StandardToMetric(FirearmBullet.Jump, cDataFiles.eDataType.Dimension))); } }
//============================================================================* // Copy() //============================================================================* public void Copy(cFirearmBullet FirearmBullet) { m_Caliber = FirearmBullet.m_Caliber; m_Bullet = FirearmBullet.m_Bullet; m_dCOL = FirearmBullet.m_dCOL; m_dCBTO = FirearmBullet.m_dCBTO; m_dJump = FirearmBullet.m_dJump; }
//============================================================================* // AddFirearmBullet() //============================================================================* public ListViewItem AddFirearmBullet(cFirearmBullet FirearmBullet, bool fSelect = false) { //----------------------------------------------------------------------------* // Create the ListViewItem //----------------------------------------------------------------------------* ListViewItem Item = new ListViewItem(String.Format("{0:N0}", FirearmBullet.Bullet.ToString())); SetFirearmBulletData(Item, FirearmBullet); base.AddItem(Item, fSelect); return(Item); }
//============================================================================* // Comparer() //============================================================================* public static int Comparer(cFirearmBullet FirearmBullet1, cFirearmBullet FirearmBullet2) { if (FirearmBullet1 == null) { if (FirearmBullet2 != null) { return(-1); } else { return(0); } } return(FirearmBullet1.CompareTo(FirearmBullet2)); }
//============================================================================* // UpdateFirearmBullet() //============================================================================* public ListViewItem UpdateFirearmBullet(cFirearmBullet FirearmBullet, bool fSelect = false) { //----------------------------------------------------------------------------* // Find the Item //----------------------------------------------------------------------------* ListViewItem Item = null; foreach (ListViewItem CheckItem in Items) { if ((CheckItem.Tag as cFirearmBullet).CompareTo(FirearmBullet) == 0) { Item = CheckItem; break; } } //----------------------------------------------------------------------------* // If the item was not found, add it //----------------------------------------------------------------------------* if (Item == null) { return(AddFirearmBullet(FirearmBullet, fSelect)); } //----------------------------------------------------------------------------* // Otherwise, update the Item Data //----------------------------------------------------------------------------* SetFirearmBulletData(Item, FirearmBullet); if (fSelect) { Item.Selected = fSelect; Item.EnsureVisible(); } Focus(); return(Item); }
//============================================================================* // Append() //============================================================================* public int Append(cFirearmBullet FirearmBullet, bool fCountOnly = false) { int nUpdateCount = 0; if (m_dCOL == 0.0 && FirearmBullet.m_dCOL != 0.0) { if (!fCountOnly) { m_dCOL = FirearmBullet.m_dCOL; } nUpdateCount++; } if (m_dCBTO == 0.0 && FirearmBullet.m_dCBTO != 0.0) { if (!fCountOnly) { m_dCBTO = FirearmBullet.m_dCBTO; } nUpdateCount++; } if (m_dJump == 0.0 && FirearmBullet.m_dJump != 0.0) { if (!fCountOnly) { m_dJump = FirearmBullet.m_dJump; } nUpdateCount++; } return(nUpdateCount); }
//============================================================================* // CompareTo() //============================================================================* public int CompareTo(cFirearmBullet FirearmBullet) { if (FirearmBullet == null) { return(1); } //----------------------------------------------------------------------------* // Compare Caliber //----------------------------------------------------------------------------* int rc = m_Caliber.CompareTo(FirearmBullet.m_Caliber); //----------------------------------------------------------------------------* // Compare Bullet //----------------------------------------------------------------------------* if (rc == 0) { rc = m_Bullet.CompareTo(FirearmBullet.m_Bullet); } return(rc); }
//============================================================================* // cFirearmBullet() - Copy Constructor //============================================================================* public cFirearmBullet(cFirearmBullet FirearmBullet) { Copy(FirearmBullet); }
//============================================================================* // cFirearmCOLForm() - Constructor //============================================================================* public cFirearmBulletForm(cFirearmBullet FirearmBullet, cFirearm Firearm, cCaliber Caliber, cDataFiles DataFiles) { InitializeComponent(); m_Firearm = Firearm; m_Caliber = Caliber; m_DataFiles = DataFiles; string strTitle = ""; if (FirearmBullet == null) { FirearmBulletOKButton.Text = "Add"; strTitle = "Add"; m_FirearmBullet = new cFirearmBullet(); m_FirearmBullet.Caliber = m_Caliber; } else { m_FirearmBullet = new cFirearmBullet(FirearmBullet); FirearmBulletOKButton.Text = "Update"; strTitle = "Update"; m_fAdd = false; } SetClientSizeCore(BulletDataGroupBox.Location.X + BulletDataGroupBox.Width + 10, FirearmBulletCancelButton.Location.Y + FirearmBulletCancelButton.Height + 20); //----------------------------------------------------------------------------* // Set Title //----------------------------------------------------------------------------* strTitle += " Firearm Specific Bullet Data"; Text = strTitle; //----------------------------------------------------------------------------* // Set Control Event Handlers //----------------------------------------------------------------------------* BulletCombo.SelectedIndexChanged += OnBulletSelected; COALTextBox.TextChanged += OnCOLChanged; CBTOTextBox.TextChanged += OnCBTOChanged; JumpTextBox.TextChanged += OnJumpChanged; FirearmBulletOKButton.Click += OnOKClicked; //----------------------------------------------------------------------------* // Set Min/Max Values //----------------------------------------------------------------------------* COALTextBox.MinValue = cDataFiles.StandardToMetric(m_Caliber.CaseTrimLength, cDataFiles.eDataType.Dimension); COALTextBox.MaxValue = cDataFiles.StandardToMetric(m_Caliber.MaxCOL, cDataFiles.eDataType.Dimension); COALTextBox.NumDecimals = m_DataFiles.Preferences.DimensionDecimals; COALTextBox.ToolTip = cm_strCOLToolTip; CBTOTextBox.MinValue = 0.0; CBTOTextBox.MaxValue = cDataFiles.StandardToMetric(m_Caliber.MaxCOL, cDataFiles.eDataType.Dimension); CBTOTextBox.NumDecimals = m_DataFiles.Preferences.DimensionDecimals; CBTOTextBox.ToolTip = cm_strCBTOToolTip; JumpTextBox.MinValue = 0.0; JumpTextBox.MaxValue = cDataFiles.StandardToMetric(0.5, cDataFiles.eDataType.Dimension); JumpTextBox.NumDecimals = m_DataFiles.Preferences.DimensionDecimals; JumpTextBox.ToolTip = cm_strJumpToolTip; //----------------------------------------------------------------------------* // Populate Bullet Combo //----------------------------------------------------------------------------* BulletCombo.Items.Clear(); if (m_fAdd) { foreach (cBullet CheckBullet in DataFiles.BulletList) { if ((!m_DataFiles.Preferences.HideUncheckedSupplies || CheckBullet.Checked) && CheckBullet.HasCaliber(m_Caliber) && m_Firearm.FirearmType == CheckBullet.FirearmType && !m_Firearm.HasBullet(CheckBullet, m_Caliber)) { BulletCombo.Items.Add(CheckBullet); } } } else { BulletCombo.Items.Add(m_FirearmBullet.Bullet); } if (BulletCombo.Items.Count > 0) { BulletCombo.SelectedIndex = 0; } //----------------------------------------------------------------------------* // Set measurement labels //----------------------------------------------------------------------------* cDataFiles.SetMetricLabel(COLMeasurementLabel, cDataFiles.eDataType.Dimension); cDataFiles.SetMetricLabel(CBTOMeasurementLabel, cDataFiles.eDataType.Dimension); cDataFiles.SetMetricLabel(JumpMeasurementLabel, cDataFiles.eDataType.Dimension); //----------------------------------------------------------------------------* // Populate FirearmCOL Data //----------------------------------------------------------------------------* FirearmLabel.Text = m_Firearm.ToString() + " - " + m_Caliber.ToString(); string strFormat = COALTextBox.FormatString + "{1}"; MaxCOALLabel.Text = String.Format(strFormat, cDataFiles.StandardToMetric(m_Caliber.MaxCOL, cDataFiles.eDataType.Dimension), cDataFiles.MetricString(cDataFiles.eDataType.Dimension)); COALTextBox.Value = cDataFiles.StandardToMetric(m_FirearmBullet.COL, cDataFiles.eDataType.Dimension); CBTOTextBox.Value = m_Firearm.FirearmType == cFirearm.eFireArmType.Rifle ? cDataFiles.StandardToMetric(m_FirearmBullet.CBTO, cDataFiles.eDataType.Dimension) : 0.0; CBTOTextBox.Enabled = m_Firearm.FirearmType == cFirearm.eFireArmType.Rifle; JumpTextBox.Value = m_Firearm.FirearmType == cFirearm.eFireArmType.Rifle ? cDataFiles.StandardToMetric(m_FirearmBullet.Jump, cDataFiles.eDataType.Dimension) : 0.0; JumpTextBox.Enabled = m_Firearm.FirearmType == cFirearm.eFireArmType.Rifle; m_fInitialized = true; UpdateButtons(); }
//============================================================================* // 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); } } cFirearmBullet Bullet1 = (cFirearmBullet)(Object1 as ListViewItem).Tag; cFirearmBullet Bullet2 = (cFirearmBullet)(Object2 as ListViewItem).Tag; if (Bullet1 == null) { if (Bullet2 == null) { return(0); } else { return(-1); } } else { if (Bullet2 == null) { return(1); } } bool fSpecial = false; int rc = 0; switch (SortColumn) { //----------------------------------------------------------------------------* // Manufacturer //----------------------------------------------------------------------------* case 0: rc = Bullet1.Bullet.Manufacturer.CompareTo(Bullet2.Bullet.Manufacturer); if (rc == 0) { string strPart1 = Bullet1.Bullet.PartNumber; string strPart2 = Bullet2.Bullet.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; //----------------------------------------------------------------------------* // COL //----------------------------------------------------------------------------* case 1: rc = Bullet1.COL.CompareTo(Bullet2.COL); fSpecial = true; break; //----------------------------------------------------------------------------* // CBTO //----------------------------------------------------------------------------* case 2: rc = Bullet1.CBTO.CompareTo(Bullet2.CBTO); fSpecial = true; break; } if (fSpecial) { if (SortingOrder == SortOrder.Descending) { return(0 - rc); } return(rc); } return(base.Compare(Object1, Object2)); }