/////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// //add product to category public void addProduct(Product tempProduct) { categoryProducts.Add(tempProduct); }
private void frmLogin_Load(object sender, EventArgs e) { //READ FILE //local variables string[] productData; string[] branchData; string[] categoryData; //set up StreamReader StreamReader reader = new StreamReader("argus-BIG.txt"); //make reader start at beginning of file reader.DiscardBufferedData(); reader.BaseStream.Seek(0, SeekOrigin.Begin); reader.BaseStream.Position = 0; while (!reader.EndOfStream) { //create array to hold data values branchData = new string[11]; //get 11 lines of branch data file for (int i = 0; i < 11; i++) { branchData[i] = reader.ReadLine(); } //new instance of Branch Class Branch tempBranch = new Branch(branchData[0], branchData[1], branchData[2], branchData[3], branchData[4], branchData[5], branchData[6], branchData[7], branchData[8], branchData[9], Convert.ToInt32(branchData[10])); //add branch to main arrayList tempBranch.addBranchToMainArgus(tempBranch); for (int i = 0; i < Convert.ToInt32(tempBranch.getNoCategories()); i++) { //create array to hold data values categoryData = new string[3]; //get 3 lines of category data file for (int j = 0; j < 3; j++) { categoryData[j] = reader.ReadLine(); } //new instance of Category Class Category tempCategory = new Category(Convert.ToInt32(categoryData[0]), categoryData[1], Convert.ToInt32(categoryData[2])); //add category to Categories in branch arrayList tempBranch.addCategoryToBranch(tempCategory); for (int j = 0; j < Convert.ToInt32(tempCategory.getNoProduct()); j++) { //create array to hold data values productData = new string[6]; //get 6 lines of category data file for (int k = 0; k < 6; k++) { productData[k] = reader.ReadLine(); } //new instance of Product Class Product tempProduct = new Product(Convert.ToInt32(productData[0]), productData[1], productData[2], productData[3], Convert.ToSingle(productData[4]), Convert.ToInt32(productData[5])); //add product to productsincategory arraylist tempCategory.addProduct(tempProduct); } } } }
private void frmLogin_Load(object sender, EventArgs e) { //READ FILE //local variables int i; //set up StreamReader StreamReader reader = new StreamReader("argus-BIG.txt"); while (reader.ReadLine() != null) { //create array to hold data values string[] branchData = new string[11]; //get 11 lines of branch data file for (i = 0; i < 11; i++) { branchData[i] = reader.ReadLine(); } //new instance of Branch Class Branch tempBranch = new Branch(); //set branch values from branchData array tempBranch.setBranchID(branchData[0]); tempBranch.setBranchNickname(branchData[1]); tempBranch.setBranchAddressNo(branchData[2]); tempBranch.setBranchAddressStreet(branchData[3]); tempBranch.setBranchAddressCity(branchData[4]); tempBranch.setBranchAddressCounty(branchData[5]); tempBranch.setBranchAddressPostCode(branchData[6]); tempBranch.setNearestBranch1(branchData[7]); tempBranch.setNearestBranch2(branchData[8]); tempBranch.setNearestBranch3(branchData[9]); tempBranch.setNoCategories(Convert.ToInt32(branchData[10])); //add branch to main arrayList tempBranch.addBranchToMainArgus(tempBranch); for (i = 0; i < Convert.ToInt32(tempBranch.getNoCategories()); i++) { //create array to hold data values string[] categoryData = new string[3]; //get 3 lines of category data file for (i = 0; i < 3; i++) { categoryData[i] = reader.ReadLine(); } //new instance of Category Class Category tempCategory = new Category(); //set values tempCategory.setCategoryID(Convert.ToInt32(categoryData[0])); //ERROR! reading the line below it should be tempCategory.setCategoryName(categoryData[1]); tempCategory.setNoProducts(Convert.ToInt32(categoryData[2])); //add category to Categories in branch arrayList tempBranch.addCategoryToBranch(tempCategory); for (i = 0; i < Convert.ToInt32(tempCategory.getNoProduct()); i++) { //create array to hold data values string[] productData = new string[6]; //get 6 lines of category data file for (i = 0; i < 6; i++) { productData[i] = reader.ReadLine(); } //new instance of Product Class Product tempProduct = new Product(); //add values to temp product tempProduct.setProductID(Convert.ToInt32(productData[0])); tempProduct.setProductTitle(productData[1]); tempProduct.setProductDetails(productData[2]); tempProduct.setProductImageSource(productData[3]); tempProduct.setProductPrice(Convert.ToSingle(productData[4])); tempProduct.setProductStockLevel(Convert.ToInt32(productData[5])); //add product to productsincategory arraylist tempCategory.addProduct(tempProduct); } } } }