Using the Collection Class
|
|
Once the collection class is ready, you can use it in
your application. Our application uses a class named StoreItems. Since it
implements the IList interface, the class is equipped to add and item
to the collection, to delete an item from the collection, to locate an item
inside the collection, to change the values (update) of a collection, to
count the number of items in the collection, etc.
Our application will use serialization to save the
collection of items.
Our application uses an entry form that presents the
items sold in the store. When the application starts, it checks if a store
inventory exists. The inventory is stored in a computer file. Therefore,
when the application starts, it checks whether that file exists. If it does,
the application opens it and stores is records in a variable declared from
our collection class.
To present some items, the user selects a category
followed by a sub-category, both from two list boxes. The items from the
sub-category display in the list view.
Practical
Learning: Setting the Read-Only Effect
|
|
- In the Solution Explorer, double-click SoloMusicStore and
double-click an unoccupied area of its body
- Implement the event as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace SoloMusicStore1
{
public partial class SoloMusicStore : Form
{
public SoloMusicStore()
{
InitializeComponent();
}
private void InitializeStoreItems()
{
StoreItems<StoreItem> items = new StoreItems<StoreItem>();
BinaryFormatter bfmStoreItem = new BinaryFormatter();
string strFileName = @"C:\Microsoft Visual C# Application Design\Solo Music Store\StoreItems.slm";
if (File.Exists(strFileName))
{
using (FileStream stmStoreItem = new FileStream(strFileName,
FileMode.Open,
FileAccess.Read,
FileShare.Read))
{
// Retrieve the list of items from file
items = (StoreItems<StoreItem>)bfmStoreItem.Deserialize(stmStoreItem);
// Display the categories in the combo box
foreach (StoreItem item in items)
{
if (!lbxCategories.Items.Contains(item.Category))
lbxCategories.Items.Add(item.Category);
}
pbxSelectedItem.Image = Image.FromFile(@"C:\Microsoft Visual C# Application Design\MusicItem.jpg");
}
}
}
private void SoloMusicStore_Load(object sender, EventArgs e)
{
// If this directory and the sub-directory don't exist, create them
Directory.CreateDirectory(@"C:\Microsoft Visual C# Application Design\Solo Music Store");
// If the default musical instrument picture is available, show it.
// If that picture is not found, the application is
if (File.Exists(@"C:\Microsoft Visual C# ApplicationDesign\default.jpg") )
pbxSelectedItem.Image = Image.FromFile(@"C:\Microsoft Visual C# ApplicationDesign\default.jpg");
// Initialize the Categories list box
InitializeStoreItems();
}
}
}
- Return to the Solo Music Store form and click the Categories list
box
- In the Properties window, click the Events button and double-click
SelectedIndexChanged
- Implement the event as follows:
private void lbxCategories_SelectedIndexChanged(object sender, EventArgs e)
{
lbxSubCategories.Items.Clear();
lvwAvailableItems.Items.Clear();
BinaryFormatter bfmStoreItem = new BinaryFormatter();
StoreItems<StoreItem> items = new StoreItems<StoreItem>();
// This is the file that holds the list of items
string strFileName = @"C:\Microsoft Visual C# Application Design\Solo Music Store\StoreItems.slm";
if (File.Exists(strFileName))
{
using (FileStream stmStoreItem = new FileStream(strFileName,
FileMode.Open,
FileAccess.Read,
FileShare.Read))
{
// Retrieve the list of items from file
items = (StoreItems<StoreItem>)bfmStoreItem.Deserialize(stmStoreItem);
// Display the sub-categories in the combo box
foreach (StoreItem item in items)
{
// Get only the sub-categories of the selected category
if (item.Category == lbxCategories.SelectedItem.ToString())
{
if (!lbxSubCategories.Items.Contains(item.SubCategory))
lbxSubCategories.Items.Add(item.SubCategory);
}
}
}
}
}
- Return to the Solo Music Store form and click the Sub-Categories
list box
- In the Events section of the Properties window, double-click
SelectedIndexChanged
- Implement the event as follows:
private void lbxSubCategories_SelectedIndexChanged(object sender, EventArgs e)
{
lvwAvailableItems.Items.Clear();
BinaryFormatter bfmStoreItem = new BinaryFormatter();
StoreItems<StoreItem> items = new StoreItems<StoreItem>();
// This is the file that holds the list of items
string strFileName = @"C:\Microsoft Visual C# Application Design\Solo Music Store\StoreItems.slm";
if (File.Exists(strFileName))
{
using (FileStream stmStoreItem = new FileStream(strFileName,
FileMode.Open,
FileAccess.Read,
FileShare.Read))
{
// Retrieve the list of items from file
items = (StoreItems<StoreItem>)bfmStoreItem.Deserialize(stmStoreItem);
// Display the sub-categories in the combo box
foreach (StoreItem item in items)
{
// Get only the sub-categories of the selected category
if (item.Category == lbxCategories.SelectedItem.ToString())
{
ListViewItem lviStoreItem = new ListViewItem(item.ItemNumber);
lviStoreItem.SubItems.Add(item.ItemName);
lviStoreItem.SubItems.Add(item.UnitPrice.ToString("F"));
lvwAvailableItems.Items.Add(lviStoreItem);
}
}
}
}
}
- Return to the Solo Music Store form and click the Available Items
list view
- In the Events section of the Properties window, double-click
ItemSelectionChanged
- Implement the event as follows:
private void lvwAvailableItems_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
string strFileName = @"C:\Microsoft Visual C# Application Design\" + e.Item.Text + ".jpg";
if( File.Exists(strFileName) )
pbxSelectedItem.Image = Image.FromFile(strFileName);
else
pbxSelectedItem.Image = Image.FromFile(@"C:\Microsoft Visual C# Application Design\MusicItem.jpg");
}
- Display the Store Item Maintenance form and double-click the button
on the left of Close
- Implement the event as follows:
private void btnMaintain_Click(object sender, EventArgs e)
{
bool itemFound = false;
BinaryFormatter bfmStoreItem = new BinaryFormatter();
StoreItems<StoreItem> items = new StoreItems<StoreItem>();
// This is the file that holds the list of items
string strFileName = @"C:\Microsoft Visual C# Application Design\Solo Music Store\StoreItems.slm";
// Make sure the user entered a valid item number. Otherwise, don't do nothing
if (string.IsNullOrEmpty(txtItemNumber.Text))
{
MessageBox.Show("You must enter an item number.",
"Solo Music Store",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
// Make sure the file that holds the store inventory was created already
if (File.Exists(strFileName))
{
// If the inventory file exists, open it
using (FileStream stmStoreItem = new FileStream(strFileName,
FileMode.Open,
FileAccess.Read,
FileShare.Read))
{
// Retrieve the list of items from file
items = (StoreItems<StoreItem>)bfmStoreItem.Deserialize(stmStoreItem);
// Because we are using one dialog box for update and delete operations,
// first find out what operation is being conducted.
// If the user is trying to update a store item...
if (btnMaintain.Text == "Update Store Item")
{
// ... as a courtesy (just in case), ask the user to confirm the operation
if (MessageBox.Show("Are you sure you want to update this item?",
"Solo Music Store",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
// Now that we know that the user wants to update the item, locate it
foreach (StoreItem item in items)
{
// If you find an item that has the number in the Item # text box, ...
if (item.ItemNumber == txtItemNumber.Text)
{
// ... change the values of that item based on those on the dialog box
item.Category = cbxCategories.Text;
item.SubCategory = cbxSubCategories.Text;
item.ItemName = txtItemName.Text;
item.UnitPrice = double.Parse(txtUnitPrice.Text);
// Since the item was found, make a note
itemFound = true;
// Now that the item has been found, stop looking for it
break;
}
}
// As a courtesy, let the user know that the item was updated
MessageBox.Show("The item has been updated in the inventory.",
"Solo Music Store",
MessageBoxButtons.OK, MessageBoxIcon.Question);
}
}
else // if (btnMaintain.Text == "Delete Store Item")
{
// Make sure the user really wants to delete the item
if (MessageBox.Show("Are you sure you want to delete this item?",
"Solo Music Store",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
// Since the user really wants to delete the item, look for it
foreach (StoreItem item in items)
{
// If you find the item, ...
if (item.ItemNumber == txtItemNumber.Text)
{
// ... remove it from the inventory
items.Remove(item);
// Let the user know that the item was deleted
MessageBox.Show("The item has been removed from the inventory.",
"Solo Music Store",
MessageBoxButtons.OK, MessageBoxIcon.Question);
// Since the item was found and deleted, make a note
itemFound = true;
// Stop looking for the item
break;
}
}
}
}
}
// Since there have been changes in the inventory (the StoreItems collection), update the file
using (FileStream stmStoreItem = new FileStream(strFileName,
FileMode.Create,
FileAccess.Write,
FileShare.Write))
{
bfmStoreItem.Serialize(stmStoreItem, items);
}
}
// If the item was updated or deleted, close the dialog box
if (itemFound == true)
Close();
}
- Return to the form and double-click the Close button
- Implement the event as follows:
private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
- Display the Solo Music Store form and double-click the Update Store
Item...
- Implement the event as follows:
private void btnUpdateStoreItem_Click(object sender, EventArgs e)
{
StoreItemMaintenance sim = new StoreItemMaintenance();
sim.btnMaintain.Text = "Update Store Item";
sim.ShowDialog();
InitializeStoreItems();
}
- Return to the Solo Music Store form and double-click Delete Store
Item
- Implement the event as follows:
private void btnDeleteStoreItem_Click(object sender, EventArgs e)
{
StoreItemMaintenance sim = new StoreItemMaintenance();
sim.cbxCategories.Enabled = false;
sim.cbxSubCategories.Enabled = false;
sim.txtItemName.Enabled = false;
sim.txtUnitPrice.Enabled = false;
sim.btnMaintain.Text = "Delete Store Item";
sim.ShowDialog();
InitializeStoreItems();
}
- Return to the Solo Music Store and double-click the Close button
- Implement the event as follows:
private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
- On the Standard toolbar, click the Save All button
We have a form, or rather a dialog box, that can be used
to add a new item to the inventory. That dialog box is called from the main
form where the user would click a button.
Practical
Learning: Adding an Item to the Collection
|
|
- In the Solution Explorer, double-click SoloMusicStore.cs
- On the form, double-click the New Store Item... button
- Implement the event as follows:
private void btnNewStoreItem_Click(object sender, EventArgs e)
{
lbxSubCategories.Items.Clear();
lvwAvailableItems.Items.Clear();
NewStoreItem nsi = new NewStoreItem();
StoreItem item = new StoreItem();
StoreItems<StoreItem> items = new StoreItems<StoreItem>();
BinaryFormatter bfmStoreItem = new BinaryFormatter();
// This is the file that holds the list of items
string strFileName = @"C:\Microsoft Visual C# Application Design\Solo Music Store\StoreItems.slm";
if (nsi.ShowDialog() == DialogResult.OK)
{
// Make sure the user had selected a category
if (string.IsNullOrEmpty(nsi.cbxCategories.Text))
{
MessageBox.Show("You must specify the item's category.",
"Solo Music Store",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
// Make sure the user had entered a name/description
if (string.IsNullOrEmpty(nsi.txtItemName.Text))
{
MessageBox.Show("You must enter the name (or a " +
"short description) for the item.",
"Solo Music Store",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
// Make sure the user had typed a price for the item
if (string.IsNullOrEmpty(nsi.txtUnitPrice.Text))
{
MessageBox.Show("You must enter the price of the item.",
"Solo Music Store",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
// Before saving the new item, find out if there was
// already a file that holds the list of items
// If that file exists, open it and store its items
// in our StoreItems list
if (File.Exists(strFileName))
{
using (FileStream stmStoreItem = new FileStream(strFileName,
FileMode.Open,
FileAccess.Read,
FileShare.Read))
{
// Retrieve the list of items from file
items = (StoreItems<StoreItem>)bfmStoreItem.Deserialize(stmStoreItem);
}
}
// Create the music item
item.ItemNumber = nsi.txtItemNumber.Text;
item.Category = nsi.cbxCategories.Text;
item.SubCategory = nsi.cbxSubCategories.Text;
item.ItemName = nsi.txtItemName.Text;
item.UnitPrice = double.Parse(nsi.txtUnitPrice.Text);
// Call the Add method of our collection class to add the item
items.Add(item);
// Save the StoreItems collection
using (FileStream stmStoreItem = new FileStream(strFileName,
FileMode.Create,
FileAccess.Write,
FileShare.Write))
{
bfmStoreItem.Serialize(stmStoreItem, items);
}
}
InitializeStoreItems();
}
Item maintenance will consist of updating an item (which
consists of changing one or more of its values), deleting it (which consists
of removing the item from the collection). Of course, when a maintenance
operation has been performed, the collection will have changed and must be
updated. It is not just the collection that is changed, the file that holds
the inventory must also be updated and changed.
Practical
Learning: Adding an Item to the Collection
|
|
- In the Solution Explorer, double-click StoreItemMaintenance and
double-click Find
- Implement the event as follows:
private void txtItemNumber_Leave(object sender, EventArgs e)
{
btnFind_Click(sender, e);
}
private void btnFind_Click(object sender, EventArgs e)
{
StoreItems<StoreItem> items = new StoreItems<StoreItem>();
BinaryFormatter bfmStoreItem = new BinaryFormatter();
// This is the file that holds the list of items
string strFileName = @"C:\Microsoft Visual C# Application Design\Solo Music Store\StoreItems.slm";
if (string.IsNullOrEmpty(txtItemNumber.Text))
{
MessageBox.Show("You must enter an item number.",
"Solo Music Store",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (File.Exists(strFileName))
{
using (FileStream stmStoreItem = new FileStream(strFileName,
FileMode.Open,
FileAccess.Read,
FileShare.Read))
{
// Retrieve the list of items from file
items = (StoreItems<StoreItem>)bfmStoreItem.Deserialize(stmStoreItem);
foreach (StoreItem item in items)
{
if(item.ItemNumber == txtItemNumber.Text)
{
cbxCategories.Text = item.Category;
cbxSubCategories.Text = item.SubCategory;
txtItemName.Text = item.ItemName;
txtUnitPrice.Text = item.UnitPrice.ToString("F");
}
}
}
}
strFileName = @"C:\Microsoft Visual C# Application Design\" + txtItemNumber.Text + ".jpg";
if (File.Exists(strFileName))
pbxSelectedItem.Image = Image.FromFile(strFileName);
else
pbxSelectedItem.Image = Image.FromFile(@"C:\Microsoft Visual C# Application Design\MusicItem.jpg");
}
- In the Solution Explorer, double-click NewStoreItem.cs
- Double-click an unoccupied area of the form to generate its Load
event
- Implement the event as follows:
private void NewStoreItem_Load(object sender, EventArgs e)
{
StoreItems<StoreItem> items = new StoreItems<StoreItem>();
BinaryFormatter bfmStoreItem = new BinaryFormatter();
// This is the file that holds the list of items
string strFileName = @"C:\Microsoft Visual C# Application Design\Solo Music Store\StoreItems.slm";
if (File.Exists(strFileName))
{
using (FileStream stmStoreItem = new FileStream(strFileName,
FileMode.Open,
FileAccess.Read,
FileShare.Read))
{
// Retrieve the list of items from file
items = (StoreItems<StoreItem>)bfmStoreItem.Deserialize(stmStoreItem);
// Display the categories in the combo box
for(int i = 0; i < items.Count; i++)
{
StoreItem item = (StoreItem)items[i];
if (!cbxCategories.Items.Contains(item.Category))
cbxCategories.Items.Add(item.Category);
}
}
}
strFileName = @"C:\Microsoft Visual C# Application Design\MusicItem.jpg";
if (File.Exists(strFileName))
pbxSelectedItem.Image = Image.FromFile(strFileName);
}
- Return to the New Store Item form and double-click the Category
combo box
- Implement the event as follows:
private void cbxCategories_SelectedIndexChanged(object sender, EventArgs e)
{
StoreItems<StoreItem> items = new StoreItems<StoreItem>();
BinaryFormatter bfmStoreItem = new BinaryFormatter();
// This is the file that holds the list of items
string strFileName = @"C:\Microsoft Visual C# Application Design\Solo Music Store\StoreItems.slm";
// If the file for the store inventory was created already, ...
if (File.Exists(strFileName))
{
// ... open it
using (FileStream stmStoreItem = new FileStream(strFileName,
FileMode.Open,
FileAccess.Read,
FileShare.Read))
{
// Retrieve the list of items from file
items = (StoreItems<StoreItem>)bfmStoreItem.Deserialize(stmStoreItem);
// Display the categories in the combo box
for (int i = 0; i < items.Count; i++)
{
// Get store item based on its index
StoreItem item = (StoreItem)items[i];
// Get the item category
if (item.Category == cbxCategories.Text)
{
// Make sure the category is not yet in the Categories combo box
if( !cbxSubCategories.Items.Contains(item.SubCategory) )
cbxSubCategories.Items.Add(item.SubCategory);
}
}
}
}
}
- Execute the application to test it
- Create some records with the following values:
Item # |
Category |
Sub-Category |
Item Name |
Unit Price |
930485 |
Keyboards |
Synthesizers |
Roland JUNO-Gi Synthesizer |
780.00 |
485948 |
Drums |
Acoustic Drum Sets |
Sound Percussion Complete 5-Piece Drum Set with Cymbals &
Hardware |
350.00 |
920820 |
Miscellaneous |
DJ Accessories |
Pioneer RMX-1000 Remix Station Black |
650.00 |
406033 |
Guitars |
Electric Guitars |
B.C. Rich Pro X Custom Special X3 Mockingbird Electric
Guitar Tobacco Burst |
395.95 |
358460 |
Bass |
Electric Basses |
Fender Deluxe P Bass Special 4-String Bass |
695.95 |
724799 |
Accessories |
Cables |
Monster Cable S-100 XLR Microphone Cable |
14.00 |
582693 |
Keyboards |
Organs |
Roland VK-88 Combo Organ |
5695.00 |
350250 |
Guitars |
Acoustic Guitars |
FA-100 Acoustic |
120.00 |
332085 |
Miscellaneous |
Multitrack Recorders |
Zoom R8 8-Track SD Recorder, Sampler & USB Interface |
295.75 |
836360 |
Brass Instruments |
Trumpets |
Brasswind Model II Student Bb Trumpet |
180.00 |
415158 |
Drums |
Electronic Drum Sets |
Simmons SD5X Electronic Drum Set |
425.75 |
886182 |
Keyboards |
Synthesizers |
Roland Jupiter-80 Synthesizer |
3525.00 |
516080 |
Guitars |
Acoustic-Electric Guitars |
Taylor 214ce Rosewood/Spruce Grand Auditorium
Acoustic-Electric Guitar |
1000.00 |
536949 |
Live Sound |
Packages |
Phonic Powerpod 620 Plus / S710 PA Package |
295.95 |
414913 |
Woodwinds |
Saxophones |
Allora Vienna Series Intermediate Alto Saxophone |
795.95 |
161553 |
Miscellaneous |
Multitrack Recorders |
TASCAM DP-32 Digital 32-Track Portastudio |
795.95 |
355862 |
Guitars |
Electric Guitars |
PRS SE Custom 24 Electric Guitar |
595.85 |
293488 |
Bass |
Electric Basses |
Ibanez SR1206E 6-String Electric Bass Vintage |
1250.00 |
330088 |
Keyboards |
Synthesizers |
Korg MicroKORG Synthesizer/Vocoder |
415.55 |
115599 |
Accessories |
Cables |
Right-On Cable |
98.95 |
402882 |
Accessories |
Cables |
Monster Cable Digilink 5 Pin MIDI Cable |
9.95 |
937528 |
Guitars |
Electric Guitars |
ESP LTD EC-256FM Electric Guitar |
395.95 |
355582 |
Miscellaneous |
Speakers |
Peavey PR 12 Speaker Pair |
360.00 |
140864 |
Brass Instruments |
Trombones |
Allora Student Series Bb Trombone Model AATB-102 |
215.50 |
173031 |
Drums |
Hi-Hat Cymbals |
Zildjian ZXT Solid Hi-Hat Cymbal (Pair) 14 Inches |
145.75 |
217790 |
Live Sound |
Microphones |
MXL 3000 Mic Bundle |
245.85 |
676184 |
Keyboards |
Pianos |
Williams Overture 88 Key Digital Piano |
595.95 |
406266 |
Live Sound |
Microphones |
MXL V63M Condenser Studio Microphone |
99.95 |
357020 |
Drums |
Acoustic Drum Sets |
Ludwig Breakbeats by Questlove 4-Piece Shell Pack Azure
Sparkle |
395.95 |
486021 |
Keyboards |
Synthesizers |
Roland BK-9 Backing Keyboard |
2495.85 |
686659 |
Bass |
Electric Basses |
Fender American Deluxe Jazz Bass V 5-String Electric Bass |
1795.95 |
583746 |
Guitars |
Acoustic Guitars |
Yamaha FG700S Folk Acoustic Guitar |
225.50 |
388835 |
Drums |
Acoustic Drum Sets |
Gretsch Drums Energy 5-Piece Drum Set with Hardware and
Sabian SBR Cymbals |
695.95 |
258395 |
Accessories |
Cables |
Monster Cable Performer 500 Speaker Cable |
21.50 |
769138 |
Live Sound |
Amplifiers |
Acoustic Lead Guitar Series G120 DSP 120W Guitar Combo Amp |
199.95 |
275157 |
Keyboards |
Synthesizers |
Yamaha S90XS 88-Key Balanced Weighted Hammer Action
Synthesizer |
2450.00 |
843814 |
Guitars |
Acoustic Guitars |
Fender CD100 12-String Acoustic Guitar Natural |
255.50 |
281141 |
Orchestra |
Violins |
Florea Recital II Violin Outfit |
150.00 |
966060 |
Drums |
Electronic Drum Sets |
Simmons SDXpress2 Compact 5-Piece Electronic Drum Kit |
225.50 |
559606 |
Live Sound |
Packages |
Gear One PA2400 / Kustom KPC15 Mains and Monitors Package |
696.95 |
725504 |
Miscellaneous |
Mixers |
Nady PMX-1600 16 Channel/4 Bus Powered Mixer w/DSP Effects |
649.95 |
972405 |
Guitars |
Electric Guitars |
ESP LTD EC-256FM Electric Guitar |
395.95 |
434426 |
Keyboards |
Pianos |
Suzuki S-350 Mini Grand Digital Piano |
2500.00 |
259592 |
Accessories |
Cables |
Mogami Gold Instrument Cable Angled - Straight Cable |
42.25 |
382730 |
Orchestra |
Violins |
Mendini 4/4 MV300 Solid Wood Violin in Satin Finish |
59.95 |
849926 |
Bass |
Electric Basses |
Squier by Fender Vintage Modified Jazz Bass ''77, Amber |
325.50 |
207925 |
Woodwinds |
Saxophones |
Yamaha YAS-62III Professional Alto Saxophone |
2950.00 |
- Close the forms and return to your programming environment
- Execute the application
- On the Solo Music Store form, click the Update Store Item button
- In the item # text box, type 350250 and press Tab
- Change its name to Fender FA-100 Acoustic Guitar
- Change its price to 125.75
- Click Update Store Item and click Yes
- On the Solo Music Store form, click the Update Store Item button
- In the item # text box, type 115599 and press Tab
- Click Delete Store Item and click Yes
- Close the forms and return to your programming environment
Practical
Learning: Clearing a Collection
|
|
- (You can skip this section)
- If necessary, Access the Solo Music Store
- Add a button and change its properties as follows:
(Name):
btnDeleteAllStoreItems Text: btnDelete all Store Items
- Double-click the button and implement its event as follows:
private void btnDeleteAllStoreItems_Click(object sender, EventArgs e)
{
BinaryFormatter bfmStoreItem = new BinaryFormatter();
StoreItems<StoreItem> items = new StoreItems<StoreItem>();
string strFileName = @"C:\Microsoft Visual C# Application Design\Solo Music Store\StoreItems.slm";
if (MessageBox.Show("Are you sure you want to delete all items?",
"Solo Music Store",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
items.Clear();
MessageBox.Show("All items have been deleted from the inventory.",
"Solo Music Store",
MessageBoxButtons.OK, MessageBoxIcon.Question);
lvwAvailableItems.Items.Clear();
lbxSubCategories.Items.Clear();
lbxCategories.Items.Clear();
if (File.Exists(strFileName))
{
File.Delete(strFileName);
}
}
}
Application
|
|