I have a project that deals with barcodes. It is basically an inventory tracking program that tells us what we have in stock at any given time. Each barcode has a text file containing relevant information. Each file contains the following lines of information:
- “Office Printer” <- this is the item description
- “1” <- 0 equals out of stock, 1 equals in stock
- “irrelevant information” <- any additional information not used in sorting
There are approximately 200+ different text files That I need to search first through the item description and then search again through those to see if they are in stock. Ideally it would then display an integer listing the number in stock, but it could also just display the names of the text files if that would be easiest. Here is my code so far. comboBox1 has a drop down list of possible items to search by. richTextbox1 is what I have setup to display the search results. Right now it only shows one “1”.
EDIT
Thanks to VBRonPaulFan for the breakthrough. This shows how many items are in stock based on the selection of the comboBox. The only other thing I am going to research is have it display the number of items in stock rather than listing them all. Thanks!
private void searchButton_Click(object sender, EventArgs e)
{
richTextBox1.Text = "";
foreach (string fileName in Directory.GetFiles("C:\\ITRS_equipment_log\\", "*.txt"))
{
using (StreamReader sw = new StreamReader(fileName))
{
string Description = sw.ReadLine();
bool InStock = sw.ReadLine().Trim() == "1";
if (Description.Contains(comboBox1.Text) && InStock == true)
{
richTextBox1.AppendText("Item '" + Description + "' is " + (InStock ? "in" : "not in") + " stock.\r\n");
}
}
}
}
everytime you find a ‘match’, you’re overwriting the value in richTextBox1 with the updated value. it doesn’t just ‘stop’ after the first file, it just displays the last value it’s set to when it’s done running through all of the files…
it’s not real clear on how you want to display this to the user… but a rich text box probably isn’t the best way. a combobox would probably be better. this looks like basically what you want to do though?