コード例 #1
0
        /// <summary>
        /// When the user clicks the Add Electronic button, if the variable existingElec
        /// is null it means the electronic being added is a new one so it is added to the database.
        /// If it is not null, it already exists in the database and is being updated instead.
        /// </summary>
        private void addElectCmd_Click(object sender, EventArgs e)
        {
            if (existingElec == null)
            {
                Electronic electToAdd = new Electronic();
                electToAdd.Name         = nameTxt.Text;
                electToAdd.Manufacturer = manufactTxt.Text;
                electToAdd.Price        = Convert.ToDouble(priceTxt.Text);
                electToAdd.Category     = Validation.casingWords(categoryCbx.Text);

                ElectronicDb.Add(electToAdd);
            }
            else
            {
                existingElec.Name         = nameTxt.Text;
                existingElec.Manufacturer = manufactTxt.Text;
                existingElec.Price        = Convert.ToDouble(priceTxt.Text);
                existingElec.Category     = Validation.casingWords(categoryCbx.Text);

                ElectronicDb.Update(existingElec);
                MessageBox.Show("Successfully updated item " + existingElec.Name);
            }

            Close();
        }
コード例 #2
0
        /// <summary>
        /// When the Add Electronics button is clicked, open up a new form
        /// and then repopulate the list when it is closed.
        /// </summary>
        private void addElectCmd_Click(object sender, EventArgs e)
        {
            addElectFrm addForm = new addElectFrm();

            addForm.ShowDialog();

            List <Electronic> allElectronics = ElectronicDb.GetAllElectronics();

            populateList(allElectronics);
        }
コード例 #3
0
        /// <summary>
        /// When the Update Electronic button is pressed, open up a new form
        /// with the information of that electronic already populated. The user may
        /// then update any information regarding the electronic. After closing,
        /// the listbox is once again repopulated. Displays an error
        /// message if there is no electronic selected.
        /// </summary>
        private void updateElectCmd_Click(object sender, EventArgs e)
        {
            if (productLstBox.SelectedIndex < 0)
            {
                MessageBox.Show("You must choose a product to update.");
                return;
            }

            Electronic  electToUpdate = productLstBox.SelectedItem as Electronic;
            addElectFrm updateForm    = new addElectFrm(electToUpdate);

            updateForm.ShowDialog();

            populateList(ElectronicDb.GetAllElectronics());
        }
コード例 #4
0
        /// <summary>
        /// Populate the listbox with the list that is passed in.
        /// </summary>
        /// <param name="allElectronics">The list used to populate the listbox</param>
        private void populateList(List <Electronic> allElectronics)
        {
            productLstBox.Items.Clear();

            foreach (String cat in ElectronicDb.GetAllCategories())
            {
                productLstBox.Items.Add(Validation.casingWords(cat));

                foreach (Electronic elect in allElectronics)
                {
                    if (elect.Category == cat)
                    {
                        productLstBox.Items.Add(elect);
                    }
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// When the Delete Electronic button is pressed, a message box is
        /// presented that prompts the user whether to actually delete the electronic or not.
        /// If yes is clicked, then the electronic is deleted from the database. Once again,
        /// the listbox is repopulated if the user clicks yes. Displays an error message if
        /// there is no electronic selected.
        /// </summary>
        private void deleteElectCmd_Click(object sender, EventArgs e)
        {
            if (productLstBox.SelectedIndex < 0)
            {
                MessageBox.Show("You must select a product to delete.");
                return;
            }

            Electronic elecToDelete = productLstBox.SelectedItem as Electronic;

            DialogResult result = MessageBox.Show(
                text: $"Are you sure you want to delete {elecToDelete.ProductId}:{elecToDelete.Manufacturer}:{elecToDelete.Name}",
                caption: "Delete?",
                buttons: MessageBoxButtons.YesNo,
                icon: MessageBoxIcon.Warning);

            if (result == DialogResult.Yes)
            {
                ElectronicDb.Delete(elecToDelete.ProductId);
                populateList(ElectronicDb.GetAllElectronics());
            }
        }
コード例 #6
0
        private void addElectFrm_Load(object sender, EventArgs e)
        {
            List <String> allCategories = ElectronicDb.GetAllCategories();

            populateList(allCategories, categoryCbx);
        }
コード例 #7
0
        /// <summary>
        /// When the form loads, call a method to get all the electronics from the database
        /// and populate the listbox with them.
        /// </summary>
        private void MainForm_Load(object sender, EventArgs e)
        {
            List <Electronic> allElectronics = ElectronicDb.GetAllElectronics();

            populateList(allElectronics);
        }