//============================================================================* // AddLoad() //============================================================================* public ListViewItem AddLoad(cLoad Load, cFirearm.eFireArmType eFirearmType, cCaliber Caliber, cBullet Bullet, cPowder Powder) { //----------------------------------------------------------------------------* // Verify that the load should be added //----------------------------------------------------------------------------* if (!VerifyLoad(Load, eFirearmType, Caliber, Bullet, Powder)) { return(null); } //----------------------------------------------------------------------------* // Create the Item //----------------------------------------------------------------------------* ListViewItem Item = new ListViewItem(); SetLoadData(Item, Load); //----------------------------------------------------------------------------* // Add the item and exit //----------------------------------------------------------------------------* AddItem(Item); return(Item); }
//============================================================================* // Populate() //============================================================================* private void Populate() { m_fPopulating = true; Items.Clear(); if (m_fIncludeAny) { Items.Add("Any Firearm Type"); } Items.Add("Handgun"); Items.Add("Rifle"); if (m_fIncludeShotgun) { Items.Add("Shotgun"); } m_eValue = (cFirearm.eFireArmType) 0; SelectedIndex = 0; m_fPopulating = false; }
//============================================================================* // VerifyLoad() //============================================================================* public bool VerifyLoad(cLoad Load, cFirearm.eFireArmType eFirearmType, cCaliber Caliber, cBullet Bullet, cPowder Powder) { //----------------------------------------------------------------------------* // Check the filters //----------------------------------------------------------------------------* if (Load.FirearmType != eFirearmType || (Caliber != null && Load.Caliber.CompareTo(Caliber) != 0) || (Bullet != null && Load.Bullet.CompareTo(Bullet) != 0) || (Powder != null && Load.Powder.CompareTo(Powder) != 0)) { return(false); } //----------------------------------------------------------------------------* // Make sure the components aren't hidden //----------------------------------------------------------------------------* if ((m_DataFiles.Preferences.HideUncheckedCalibers && !Load.Caliber.Checked)) { return(false); } if (m_DataFiles.Preferences.HideUncheckedSupplies && (!Load.Bullet.Checked || !Load.Powder.Checked || !Load.Primer.Checked || !Load.Case.Checked)) { return(false); } //----------------------------------------------------------------------------* // Good to go! //----------------------------------------------------------------------------* return(true); }
//============================================================================* // Populate() //============================================================================* public void Populate(cFirearm.eFireArmType eFireArmType, cCaliber Caliber, cBullet Bullet, cPowder Powder) { if (Populating) { return; } Populating = true; Items.Clear(); ListViewItem SelectItem = null; foreach (cBatch Batch in m_DataFiles.BatchList) { if (Batch.Archived && !m_DataFiles.Preferences.ShowArchivedBatches) { continue; } if (m_DataFiles.Preferences.HideUncheckedCalibers && !Batch.Load.Caliber.Checked) { continue; } if (m_DataFiles.Preferences.HideUncheckedSupplies && (!Batch.Load.Bullet.Checked || !Batch.Load.Case.Checked || !Batch.Load.Powder.Checked || !Batch.Load.Primer.Checked)) { continue; } ListViewItem Item = AddBatch(Batch, eFireArmType, Caliber, Bullet, Powder); if (Item != null && m_DataFiles.Preferences.LastBatchSelected != null && m_DataFiles.Preferences.LastBatchSelected.CompareTo(Batch) == 0) { SelectItem = Item; } } Focus(); if (SelectItem != null && SelectItem.Index >= 0) { SelectItem.Selected = true; EnsureVisible(SelectItem.Index); } else { if (Items.Count > 0) { Items[0].Selected = true; m_DataFiles.Preferences.LastBatchSelected = (cBatch)Items[0].Tag; EnsureVisible(Items[0].Index); } } Populating = false; }
//============================================================================* // VerifyLoad() //============================================================================* public bool VerifyLoad(cLoad Load, cFirearm.eFireArmType eFirearmType, cCaliber Caliber, cBullet Bullet, cPowder Powder) { if (Load == null) { return(false); } //----------------------------------------------------------------------------* // See if we need to show this load regardless of other considerations //----------------------------------------------------------------------------* if (m_fShowBatchLoad && m_Batch.Load.CompareTo(Load) == 0) { return(true); } //----------------------------------------------------------------------------* // Check Filters //----------------------------------------------------------------------------* if ((eFirearmType != cFirearm.eFireArmType.None && Load.FirearmType != eFirearmType) || (Caliber != null && Load.Caliber.CompareTo(Caliber) != 0) || (Bullet != null && Load.Bullet.CompareTo(Bullet) != 0) || (Powder != null && Load.Powder.CompareTo(Powder) != 0)) { return(false); } //----------------------------------------------------------------------------* // Check Inventory //----------------------------------------------------------------------------* if (!m_DataFiles.VerifyLoadQuantities(m_Batch, Load)) { return(false); } //----------------------------------------------------------------------------* // Make sure the caliber is not hidden //----------------------------------------------------------------------------* if (m_DataFiles.Preferences.HideUncheckedCalibers && !Load.Caliber.Checked) { return(false); } //----------------------------------------------------------------------------* // Make sure the supplies are not hidden //----------------------------------------------------------------------------* if (m_DataFiles.Preferences.HideUncheckedSupplies) { if (!Load.Bullet.Checked || !Load.Powder.Checked || !Load.Primer.Checked || !Load.Case.Checked) { return(false); } } return(true); }
//============================================================================* // Copy() //============================================================================* public void Copy(cCaliber Caliber) { m_eFirearmType = Caliber.m_eFirearmType; m_strName = Caliber.m_strName; m_fCrossUse = Caliber.m_fCrossUse; m_strHeadStamp = Caliber.m_strHeadStamp; m_fPistol = Caliber.m_fPistol; m_fSmallPrimer = Caliber.m_fSmallPrimer; m_fLargePrimer = Caliber.m_fLargePrimer; m_fMagnumPrimer = Caliber.m_fMagnumPrimer; m_fRimfire = Caliber.m_fRimfire; m_dMinBulletDiameter = Caliber.m_dMinBulletDiameter; m_dMaxBulletDiameter = Caliber.m_dMaxBulletDiameter; m_dMinBulletWeight = Caliber.m_dMinBulletWeight; m_dMaxBulletWeight = Caliber.m_dMaxBulletWeight; m_dCaseTrimLength = Caliber.m_dCaseTrimLength; m_dMaxCaseLength = Caliber.m_dMaxCaseLength; m_dMaxCOL = Caliber.m_dMaxCOL; m_dMaxNeckDiameter = Caliber.m_dMaxNeckDiameter; m_strSAAMIPDF = Caliber.m_strSAAMIPDF; m_fChecked = Caliber.m_fChecked; m_fIdentity = Caliber.m_fIdentity; }
//============================================================================* // Populate() //============================================================================* public void Populate(cFirearm.eFireArmType eFirearmType, cCaliber Caliber, cBullet Bullet, double dBulletWeight, cPowder Powder, cPrimer Primer, cCase Case) { Populating = true; //----------------------------------------------------------------------------* // LoadsListView Items //----------------------------------------------------------------------------* Items.Clear(); while (Columns.Count > 3) { Columns.RemoveAt(3); } ListViewItem SelectItem = null; foreach (cLoad Load in m_DataFiles.LoadList) { if (Load.FirearmType == eFirearmType && (Caliber == null || Load.Caliber.CompareTo(Caliber) == 0) && (Bullet == null || Load.Bullet.CompareTo(Bullet) == 0) && (Load.Bullet.Weight == dBulletWeight) && (Powder == null || Load.Powder.CompareTo(Powder) == 0) && (Case == null || Load.Case.CompareTo(Case) == 0) && (Primer == null || Load.Primer.CompareTo(Primer) == 0)) { ListViewItem Item = AddLoad(Load); if (Item != null && Load.CompareTo(m_DataFiles.Preferences.LastCopyLoadSelected) == 0) { SelectItem = Item; } } } if (SelectItem != null) { SelectItem.Selected = true; } else { if (Items.Count > 0) { Items[0].Selected = true; m_DataFiles.Preferences.LastCopyLoadSelected = (cLoad)Items[0].Tag; Items[0].EnsureVisible(); } } Populating = false; }
//============================================================================* // OnSelectedIndexChanged() //============================================================================* protected override void OnSelectedIndexChanged(EventArgs e) { if (m_fPopulating) { return; } m_eValue = (cFirearm.eFireArmType)SelectedIndex; base.OnSelectedIndexChanged(e); }
//============================================================================* // cLoad() - Copy Constructor //============================================================================* public cLoad(cLoad Load) { m_eFirearmType = Load.m_eFirearmType; m_Caliber = Load.m_Caliber; m_Bullet = Load.m_Bullet; m_Powder = Load.m_Powder; m_Case = Load.m_Case; m_Primer = Load.m_Primer; m_fChecked = Load.m_fChecked; m_fIdentity = Load.m_fIdentity; m_ChargeList = new cChargeList(Load.m_ChargeList); }
//============================================================================* // Populate() //============================================================================* public void Populate(cFirearm.eFireArmType eFirearmType, cCaliber Caliber, cBullet Bullet, cPowder Powder) { Populating = true; //----------------------------------------------------------------------------* // LoadsListView Items //----------------------------------------------------------------------------* Items.Clear(); while (Columns.Count > 5) { Columns.RemoveAt(5); } ListViewItem SelectItem = null; foreach (cLoad Load in m_DataFiles.LoadList) { ListViewItem Item = AddLoad(Load, eFirearmType, Caliber, Bullet, Powder); if (Item != null && Load.CompareTo(m_DataFiles.Preferences.LastLoadSelected) == 0) { SelectItem = Item; } } if (SelectItem != null) { SelectItem.Selected = true; } else { if (Items.Count > 0) { Items[0].Selected = true; m_DataFiles.Preferences.LastLoadSelected = (cLoad)Items[0].Tag; } } if (SelectedItems.Count > 0) { SelectedItems[0].EnsureVisible(); } Populating = false; }
//============================================================================* // FirearmTypeString() //============================================================================* public static string FirearmTypeString(cFirearm.eFireArmType eFirearmType) { switch (eFirearmType) { case cFirearm.eFireArmType.Handgun: return(cm_strHandgun); case cFirearm.eFireArmType.Rifle: return(cm_strRifle); case cFirearm.eFireArmType.Shotgun: return(cm_strShotgun); } return("Unknown"); }
//============================================================================* // PopulateChargeListView() //============================================================================* private void PopulateChargeListView() { //----------------------------------------------------------------------------* // ChargeListView Data //----------------------------------------------------------------------------* cFirearm.eFireArmType FirearmType = m_Load.FirearmType; cCaliber Caliber = m_Load.Caliber; cPowder Powder = m_Load.Powder; cBullet Bullet = MatchBulletRadioButton.Checked ? m_Load.Bullet : null; cPrimer Primer = MatchPrimerRadioButton.Checked ? m_Load.Primer : null; cCase Case = MatchCaseRadioButton.Checked ? m_Load.Case : null; m_ChargeListView.Populate(FirearmType, Caliber, Bullet, m_Load.Bullet.Weight, Powder, Primer, Case); UpdateButtons(); }
//============================================================================* // UpdateLoad() //============================================================================* public ListViewItem UpdateLoad(cLoad Load, cFirearm.eFireArmType eFirearmType, cCaliber Caliber, cBullet Bullet, cPowder Powder, bool fSelect = false) { //----------------------------------------------------------------------------* // Find the Item //----------------------------------------------------------------------------* ListViewItem Item = null; foreach (ListViewItem CheckItem in Items) { if ((CheckItem.Tag as cLoad).Equals(Load)) { Item = CheckItem; break; } } //----------------------------------------------------------------------------* // If the item was not found, add it //----------------------------------------------------------------------------* if (Item == null) { return(AddLoad(Load, eFirearmType, Caliber, Bullet, Powder, fSelect)); } //----------------------------------------------------------------------------* // Otherwise, update the Item Data //----------------------------------------------------------------------------* SetLoadData(Item, Load); Item.Selected = fSelect; if (SelectedItems.Count > 0) { SelectedItems[0].EnsureVisible(); } Focus(); return(Item); }
//============================================================================* // UpdateBatch() //============================================================================* public ListViewItem UpdateBatch(cBatch Batch, cFirearm.eFireArmType eFirearmType, cCaliber Caliber, cBullet Bullet, cPowder Powder, bool fSelect = false) { //----------------------------------------------------------------------------* // Find the Item //----------------------------------------------------------------------------* ListViewItem Item = null; foreach (ListViewItem CheckItem in Items) { if ((CheckItem.Tag as cBatch).CompareTo(Batch) == 0) { Item = CheckItem; break; } } //----------------------------------------------------------------------------* // If the item was not found, add it //----------------------------------------------------------------------------* if (Item == null) { return(null); } //----------------------------------------------------------------------------* // Otherwise, update the Item Data //----------------------------------------------------------------------------* SetBatchData(Item, Batch); Item.Selected = fSelect; if (SelectedItems.Count > 0) { SelectedItems[0].EnsureVisible(); } Focus(); return(Item); }
//============================================================================* // VerifyBatch() //============================================================================* public bool VerifyBatch(cBatch Batch, cFirearm.eFireArmType eFirearmType, cCaliber Caliber, cBullet Bullet, cPowder Powder) { //----------------------------------------------------------------------------* // Make sure the batch shouldn't be hidden //----------------------------------------------------------------------------* /* * if ((m_DataFiles.Preferences.HideUncheckedCalibers && !Batch.Load.Caliber.Checked) || * (m_DataFiles.Preferences.HideUncheckedSupplies && !Batch.Load.Bullet.Checked) || * (m_DataFiles.Preferences.HideUncheckedSupplies && !Batch.Load.Powder.Checked) || * (m_DataFiles.Preferences.HideUncheckedSupplies && !Batch.Load.Primer.Checked) || * (m_DataFiles.Preferences.HideUncheckedSupplies && !Batch.Load.Case.Checked) || * Batch.Archived) * return (false); */ //----------------------------------------------------------------------------* // Check the filters //----------------------------------------------------------------------------* if (Batch.Load.FirearmType != eFirearmType) { return(false); } if (Caliber != null && Batch.Load.Caliber != Caliber) { return(false); } if (Bullet != null && Batch.Load.Bullet != Bullet) { return(false); } if (Powder != null && Batch.Load.Powder != Powder) { return(false); } return(true); }
//============================================================================* // Populate() //============================================================================* public void Populate(cFirearm.eFireArmType eFirearmType, cCaliber Caliber, cBullet Bullet, cPowder Powder) { Populating = true; Items.Clear(); ListViewItem SelectItem = null; foreach (cLoad CheckLoad in m_DataFiles.LoadList) { ListViewItem Item = AddLoad(CheckLoad, eFirearmType, Caliber, Bullet, Powder); if (Item != null && m_Batch.Load != null && m_Batch.Load.CompareTo(CheckLoad) == 0) { SelectItem = Item; } } Focus(); if (SelectItem != null) { SelectItem.Selected = true; EnsureVisible(SelectItem.Index); } else { if (Items.Count > 0) { Items[0].Selected = true; m_DataFiles.Preferences.LastBatchLoadSelected = (cLoad)Items[0].Tag; EnsureVisible(Items[0].Index); } } Populating = false; }
//============================================================================* // AddBatch() //============================================================================* public ListViewItem AddBatch(cBatch Batch, cFirearm.eFireArmType eFireArmType, cCaliber Caliber, cBullet Bullet, cPowder Powder, bool fSelect = false) { if (!VerifyBatch(Batch, eFireArmType, Caliber, Bullet, Powder)) { return(null); } //----------------------------------------------------------------------------* // Create the ListViewItem //----------------------------------------------------------------------------* ListViewItem Item = new ListViewItem(); SetBatchData(Item, Batch); //----------------------------------------------------------------------------* // Add the item and exit //----------------------------------------------------------------------------* AddItem(Item, fSelect); return(Item); }
//============================================================================* // AddLoad() //============================================================================* public ListViewItem AddLoad(cLoad Load, cFirearm.eFireArmType eFirearmType, cCaliber Caliber, cBullet Bullet, cPowder Powder, bool fSelect = false) { if (!VerifyLoad(Load, eFirearmType, Caliber, Bullet, Powder)) { return(null); } //----------------------------------------------------------------------------* // Create the ListViewItem //----------------------------------------------------------------------------* ListViewItem Item = new ListViewItem(); SetLoadData(Item, Load); //----------------------------------------------------------------------------* // Add the item to the list and exit //----------------------------------------------------------------------------* AddItem(Item, fSelect); return(Item); }
//============================================================================* // PopulateLoadDataPowderCombo() //============================================================================* private void PopulateLoadDataPowderCombo() { cCaliber.CurrentFirearmType = LoadDataFirearmTypeCombo.Value; m_fPopulating = true; LoadDataPowderCombo.Items.Clear(); cFirearm.eFireArmType eFirearmType = LoadDataFirearmTypeCombo.Value; cCaliber Caliber = null; if (LoadDataCaliberCombo.SelectedIndex > 0) { Caliber = (cCaliber)LoadDataCaliberCombo.SelectedItem; } cBullet Bullet = null; if (LoadDataBulletCombo.SelectedIndex > 0) { Bullet = (cBullet)LoadDataBulletCombo.SelectedItem; } LoadDataPowderCombo.Items.Add("Any Powder"); cPowder SelectPowder = null; foreach (cLoad Load in m_DataFiles.LoadList) { if ((Caliber == null || Load.Caliber.CompareTo(Caliber) == 0) && (eFirearmType == cFirearm.eFireArmType.None || Load.FirearmType == eFirearmType) && (Bullet == null || Load.Bullet.CompareTo(Bullet) == 0)) { if (Load.Powder.CrossUse || Load.Powder.FirearmType == eFirearmType) { if (LoadDataPowderCombo.Items.IndexOf(Load.Powder) < 0) { LoadDataPowderCombo.Items.Add(Load.Powder); if (Load.Powder.CompareTo(m_DataFiles.Preferences.LastLoadDataPowderSelected) == 0) { SelectPowder = Load.Powder; } } } } } if (SelectPowder != null) { LoadDataPowderCombo.SelectedItem = SelectPowder; } else { if (LoadDataPowderCombo.Items.Count > 0) { LoadDataPowderCombo.SelectedIndex = 0; } } if (LoadDataPowderCombo.SelectedIndex < 0) { LoadDataPowderCombo.SelectedIndex = 0; } m_fPopulating = false; PopulateLoadDataListView(); }
//============================================================================* // PopulateCaliberCombo() - Case //============================================================================* public static void PopulateCaliberCombo(ComboBox CaliberCombo, cDataFiles DataFiles, cCase Case, cFirearm.eFireArmType eFirearmType = cFirearm.eFireArmType.None) { CaliberCombo.Items.Clear(); cCaliber.CurrentFirearmType = eFirearmType; cCaliber SelectCaliber = null; foreach (cCaliber CheckCaliber in DataFiles.CaliberList) { if ((!DataFiles.Preferences.HideUncheckedCalibers || CheckCaliber.Checked) && !CheckCaliber.Rimfire) { if (eFirearmType == cFirearm.eFireArmType.None || CheckCaliber.FirearmType == eFirearmType) { CaliberCombo.Items.Add(CheckCaliber); if (Case != null && SelectCaliber == null && Case.Caliber != null && Case.Caliber.CompareTo(CheckCaliber) == 0) { SelectCaliber = CheckCaliber; } } } } if (SelectCaliber != null) { CaliberCombo.SelectedItem = SelectCaliber; if (CaliberCombo.SelectedIndex < 0 && CaliberCombo.Items.Count > 0) { CaliberCombo.SelectedIndex = 0; } } else { if (Case != null && Case.Caliber != null) { if (!CaliberCombo.Items.Contains(Case.Caliber)) { CaliberCombo.Items.Add(Case.Caliber); } CaliberCombo.SelectedItem = Case.Caliber; } if (CaliberCombo.SelectedIndex == -1 && CaliberCombo.Items.Count > 0) { CaliberCombo.SelectedIndex = 0; } } }
//============================================================================* // PopulateFirearmCombo() //============================================================================* public static void PopulateFirearmCombo(ComboBox FirearmCombo, cDataFiles DataFiles, cFirearm Firearm = null, cCaliber Caliber = null, cFirearm.eFireArmType eFirearmType = cFirearm.eFireArmType.None, bool fAddFactory = false) { //----------------------------------------------------------------------------* // Validate Input //----------------------------------------------------------------------------* if (DataFiles == null || FirearmCombo == null) { return; } //----------------------------------------------------------------------------* // Populate Combo //----------------------------------------------------------------------------* FirearmCombo.Items.Clear(); if (fAddFactory) { FirearmCombo.Items.Add("Factory"); } cCaliber.CurrentFirearmType = eFirearmType; cFirearm SelectedFirearm = null; foreach (cFirearm CheckFirearm in DataFiles.FirearmList) { if (Caliber == null || CheckFirearm.HasCaliber(Caliber)) { if ((eFirearmType == cFirearm.eFireArmType.None || CheckFirearm.FirearmType == eFirearmType)) { FirearmCombo.Items.Add(CheckFirearm); if (Firearm != null && CheckFirearm.CompareTo(Firearm) == 0) { SelectedFirearm = CheckFirearm; } } } } //----------------------------------------------------------------------------* // Select a firearm in the combo //----------------------------------------------------------------------------* if (SelectedFirearm != null) { FirearmCombo.SelectedItem = SelectedFirearm; } else { if (FirearmCombo.Items.Count > 0) { FirearmCombo.SelectedIndex = 0; } else { FirearmCombo.SelectedIndex = -1; } } }
//============================================================================* // PopulateManufacturerCombo() //============================================================================* public static void PopulateManufacturerCombo(ComboBox ManufacturerCombo, cDataFiles DataFiles, cManufacturer Manufacturer = null, cFirearm.eFireArmType eFirearmType = cFirearm.eFireArmType.None, int nSupplyType = -1) { ManufacturerCombo.Items.Clear(); //----------------------------------------------------------------------------* // Loop through the manufacturers //----------------------------------------------------------------------------* cManufacturer SelectManufacturer = null; foreach (cManufacturer CheckManufacturer in DataFiles.ManufacturerList) { //----------------------------------------------------------------------------* // Check that this manufacturer provides the specfied firearm type, if any //----------------------------------------------------------------------------* switch (eFirearmType) { case cFirearm.eFireArmType.None: break; case cFirearm.eFireArmType.Handgun: if (!CheckManufacturer.Handguns) { continue; } break; case cFirearm.eFireArmType.Rifle: if (!CheckManufacturer.Rifles) { continue; } break; case cFirearm.eFireArmType.Shotgun: if (!CheckManufacturer.Shotguns) { continue; } break; } //----------------------------------------------------------------------------* // Check that this manufacturer provides the specfied supply type, if any //----------------------------------------------------------------------------* switch (nSupplyType) { case -1: break; case (int)cSupply.eSupplyTypes.Bullets: if (!CheckManufacturer.Bullets && !CheckManufacturer.BulletMolds) { continue; } break; case (int)cSupply.eSupplyTypes.Cases: if (!CheckManufacturer.Cases) { continue; } break; case (int)cSupply.eSupplyTypes.Powder: if (!CheckManufacturer.Powder) { continue; } break; case (int)cSupply.eSupplyTypes.Primers: if (!CheckManufacturer.Primers) { continue; } break; } //----------------------------------------------------------------------------* // If we get to here, the manufacturer is ok to be added to the combo //----------------------------------------------------------------------------* if (Manufacturer != null && CheckManufacturer.CompareTo(Manufacturer) == 0) { SelectManufacturer = CheckManufacturer; } ManufacturerCombo.Items.Add(CheckManufacturer); } if (SelectManufacturer != null) { ManufacturerCombo.SelectedIndex = ManufacturerCombo.Items.IndexOf(SelectManufacturer); if (ManufacturerCombo.SelectedIndex < 0 && ManufacturerCombo.Items.Count > 0) { ManufacturerCombo.SelectedIndex = 0; } } else { if (ManufacturerCombo.Items.Count > 0) { ManufacturerCombo.SelectedIndex = 0; } } }