//============================================================================* // cFirearmDetailForm() - Constructor //============================================================================* public cFirearmDetailForm(ref cFirearm Firearm, cDataFiles DataFiles, bool fViewOnly = false) { InitializeComponent(); m_Firearm = new cFirearm(Firearm); m_DataFiles = DataFiles; m_fViewOnly = fViewOnly; //----------------------------------------------------------------------------* // Size the dialog //----------------------------------------------------------------------------* SetClientSizeCore(AcquisitionDetailsGroupBox.Location.X + AcquisitionDetailsGroupBox.Width + 10, DetailCancelButton.Location.Y + DetailCancelButton.Height + 20); //----------------------------------------------------------------------------* // Set Control Event Handlers //----------------------------------------------------------------------------* if (!m_fViewOnly) { AddImageButton.Click += OnAddImageClicked; RemoveImageButton.Click += OnRemoveImageClicked; MakePrimaryButton.Click += OnMakePrimaryClicked; SourceComboBox.TextChanged += OnSourceChanged; PurchaseDatePicker.TextChanged += OnPurchaseDateChanged; PriceTextBox.TextChanged += OnPriceChanged; TaxTextBox.TextChanged += OnTaxChanged; ShippingTextBox.TextChanged += OnShippingChanged; TransferFeesTextBox.TextChanged += OnTransferFeesChanged; OtherFeesTextBox.TextChanged += OnOtherFeesChanged; ReceiverFinishComboBox.TextChanged += OnReceiverFinishChanged; ReceiverFinishComboBox.GotFocus += OnFinishComboGotFocus; BarrelFinishComboBox.TextChanged += OnBarrelFinishChanged; BarrelFinishComboBox.GotFocus += OnFinishComboGotFocus; TypeComboBox.SelectedIndexChanged += OnTypeChanged; ActionComboBox.SelectedIndexChanged += OnActionChanged; HammerComboBox.SelectedIndexChanged += OnHammerChanged; MagazineComboBox.SelectedIndexChanged += OnMagazineChanged; CapacityTextBox.TextChanged += OnMagazineCapacityChanged; NotesTextBox.TextChanged += OnNotesChanged; } else { AddImageButton.Enabled = false; RemoveImageButton.Enabled = false; MakePrimaryButton.Enabled = false; } PreviousImageButton.Click += OnPreviousImageClicked; NextImageButton.Click += OnNextImageClicked; //----------------------------------------------------------------------------* // Set Measurement Labels //----------------------------------------------------------------------------* PriceLabel.Text = String.Format("Price ({0}):", m_DataFiles.Preferences.Currency); TaxLabel.Text = String.Format("Tax ({0}):", m_DataFiles.Preferences.Currency); ShippingLabel.Text = String.Format("Shipping ({0}):", m_DataFiles.Preferences.Currency); //----------------------------------------------------------------------------* // Verify Firearm Image Info //----------------------------------------------------------------------------* m_strImagePath = Path.Combine(m_DataFiles.GetDataPath(), "Firearm Images"); if (!Directory.Exists(m_strImagePath)) { Directory.CreateDirectory(m_strImagePath); } string strFileName = m_Firearm.ImageFileName; string[] astrImageFiles = Directory.GetFiles(m_strImagePath, strFileName + "*.*"); foreach (string strImage in astrImageFiles) { m_ImageList.Add(strImage); } if (m_ImageList.Count == 0) { if (!String.IsNullOrEmpty(m_Firearm.ImageFile)) { try { string strNewFileName = Path.Combine(m_strImagePath, strFileName); strNewFileName = Path.ChangeExtension(strNewFileName, Path.GetExtension(m_Firearm.ImageFile)); File.Copy(m_Firearm.ImageFile, Path.Combine(m_strImagePath, strNewFileName)); m_ImageList.Add(strNewFileName); m_Firearm.ImageFile = strNewFileName; } catch { m_Firearm.ImageFile = ""; } } } //----------------------------------------------------------------------------* // Fill in the firearm data //----------------------------------------------------------------------------* cDataFiles.SetInputParameters(PriceTextBox, cDataFiles.eDataType.Cost); cDataFiles.SetInputParameters(TaxTextBox, cDataFiles.eDataType.Cost); cDataFiles.SetInputParameters(ShippingTextBox, cDataFiles.eDataType.Cost); PopulateFirearmData(); SetFinishLabels(); SetStaticToolTips(); //----------------------------------------------------------------------------* // Set title //----------------------------------------------------------------------------* string strTitle; if (!m_fViewOnly) { strTitle = "Edit Firearm Details"; } else { strTitle = "View Firearm Details"; } Text = strTitle; //----------------------------------------------------------------------------* // Finish up and exit //----------------------------------------------------------------------------* UpdateButtons(); m_fInitialized = true; }
//============================================================================* // OnAddImageClicked() //============================================================================* private void OnAddImageClicked(object sender, EventArgs e) { //----------------------------------------------------------------------------* // Show the file dialog //----------------------------------------------------------------------------* OpenFileDialog FileDlg = new OpenFileDialog(); FileDlg.Title = "Select Firearm Image File"; FileDlg.AddExtension = true; FileDlg.CheckFileExists = true; if (!String.IsNullOrEmpty(m_DataFiles.Preferences.FirearmImagePath)) { FileDlg.InitialDirectory = m_DataFiles.Preferences.FirearmImagePath; } else { FileDlg.InitialDirectory = Environment.SpecialFolder.MyPictures.ToString(); } FileDlg.Filter = "Image Files (*.jpg, *.jpeg, *.bmp, *.gif, *.png, *.tiff)|*.jpg;*.jpeg;*.bmp;*.gif;*.png;*.tiff"; FileDlg.FileName = ""; DialogResult rc = FileDlg.ShowDialog(); if (rc == DialogResult.Cancel) { return; } m_DataFiles.Preferences.FirearmImagePath = Path.GetDirectoryName(FileDlg.FileName); try { string strImagePath = Path.Combine(m_DataFiles.GetDataPath(), "Firearm Images"); string strImageFilePath = Path.Combine(strImagePath, m_Firearm.ImageFileName); string strCheckFile = strImageFilePath; int nImageNum = 1; while (File.Exists(Path.ChangeExtension(strCheckFile, Path.GetExtension(FileDlg.FileName)))) { strCheckFile = strImageFilePath + String.Format(" ({0:D0})", nImageNum); nImageNum++; } strImageFilePath = strCheckFile; strImageFilePath = Path.ChangeExtension(strImageFilePath, Path.GetExtension(FileDlg.FileName)); m_ImageList.Add(strImageFilePath); m_strCurrentImagePath = strImageFilePath; File.Copy(FileDlg.FileName, strImageFilePath); Bitmap FirearmImage = new Bitmap(strImageFilePath); FirearmPictureBox.Image = FirearmImage; if (String.IsNullOrEmpty(m_Firearm.ImageFile) || Path.GetDirectoryName(strImageFilePath) != Path.GetDirectoryName(m_Firearm.ImageFile)) { m_Firearm.ImageFile = strImageFilePath; } SetImageDimensions(); m_fChanged = true; } catch { MessageBox.Show("Unable to add the selected image file to this firearm. Try another", "Image File Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } UpdateButtons(); }