//read text files and copy the content to the employee list public void readFile(String file, String[] array, List <PlanStruct> list) { StreamReader fileIn; fileIn = File.OpenText(file); string lineIn; //holds each line from the Employees.txt if (File.Exists(file)) { //splitter array String[] splitter = new String[3]; while (!fileIn.EndOfStream) { PlanStruct plan = new PlanStruct(); // object of the struct lineIn = fileIn.ReadLine(); splitter = lineIn.Split(','); // split the line at the , character //pass each element to the list plan.code = splitter[0]; plan.description = splitter[1]; plan.cost = Convert.ToDecimal(splitter[2]); list.Add(plan); } } //if file doesnt exist, show an error message else { MessageBox.Show("Not able to open file!"); } fileIn.Close(); // close file }
//Shows the costs of two selected items from the ComboBox and total private void bCost_Click(object sender, EventArgs e) { //gets the of the selected item PlanStruct selectedMeal = (PlanStruct)cbMeal.SelectedItem; PlanStruct selectedDorm = (PlanStruct)cbDorm.SelectedItem; //construct strings to print on form2 String mealPrint = "Meal Plan: $" + selectedMeal.cost + " per semester!"; String DormPrint = "Dormitory: $" + selectedDorm.cost + " per semester!"; String totalPrint = "Total: $" + (selectedMeal.cost + selectedDorm.cost); //show the dialog PlanTotal form2 = new PlanTotal(mealPrint, DormPrint, totalPrint); form2.ShowDialog(); }