private void LoadCarDatabase() { List <string> carLines = File.ReadAllLines(listingsDatabase).ToList(); foreach (string line in carLines) { string[] entries = line.Split('/'); carListing allocateCars = new carListing(); allocateCars.make = entries[0]; allocateCars.model = entries[1]; allocateCars.year = Int32.Parse(entries[2]); allocateCars.kilometers = Int32.Parse(entries[3]); allocateCars.colour = entries[4]; allocateCars.transmission = entries[5]; allocateCars.price = Int32.Parse(entries[6]); allocateCars.owner = entries[7]; allocateCars.listDate = entries[8]; carList.Add(allocateCars); } }
private bool CheckFavourites() { bool favourite = false; List <string> carLines = File.ReadAllLines(activeUser + ".txt").ToList(); carListing listedCar = new carListing(); foreach (string line in carLines) { string[] entries = line.Split('/'); if (entries[8] == listReference) { favourite = true; } else { favourite = false; } } return(favourite); }
private void SetUpGrid() { //Sets the grid up based on the user's accountname (only their cars in the list) gridCarList.Rows.Clear(); gridCarList.Refresh(); int row = 0; List <string> carLines = File.ReadAllLines(listingsDatabase).ToList(); foreach (string line in carLines) { string[] entries = line.Split('/'); if (entries[7] == currentUser) { gridCarList.Rows.Add(); DataGridViewRow rows = gridCarList.Rows[row]; string preview = entries[9]; Image listingImage = Image.FromFile(preview); listingImage = listingImage.GetThumbnailImage(200, 100, null, IntPtr.Zero); rows.Height = listingImage.Height; carListing allocateCars = new carListing(); rows.Cells[1].Value = row + 1; rows.Cells[2].Value = listingImage; rows.Cells[3].Value = entries[14]; rows.Cells[4].Value = entries[0]; rows.Cells[5].Value = entries[1]; rows.Cells[6].Value = Int32.Parse(entries[2]); rows.Cells[7].Value = Int32.Parse(entries[3]); rows.Cells[8].Value = entries[4]; rows.Cells[9].Value = entries[5]; rows.Cells[10].Value = Int32.Parse(entries[6]); rows.Cells[11].Value = entries[8]; row++; } } }
private void listInfo_FormClosing(object sender, FormClosingEventArgs e) { if (cbSold.Checked == true || cbDelete.Checked == true) { List <string> carLines = File.ReadAllLines(listingsDatabase).ToList(); List <string> updateList = new List <string>(); foreach (string line in carLines) { string[] entries = line.Split('/'); if (entries[8] != listReference) { carListing allocateCars = new carListing(); allocateCars.make = entries[0]; allocateCars.model = entries[1]; allocateCars.year = Int32.Parse(entries[2]); allocateCars.kilometers = Int32.Parse(entries[3]); allocateCars.colour = entries[4]; allocateCars.transmission = entries[5]; allocateCars.price = Int32.Parse(entries[6]); allocateCars.owner = entries[7]; allocateCars.listDate = entries[8]; allocateCars.img1 = entries[9]; allocateCars.img2 = entries[10]; allocateCars.img3 = entries[11]; allocateCars.img4 = entries[12]; allocateCars.img5 = entries[13]; allocateCars.visible = entries[14]; updateList.Add($"{ allocateCars.make }/{ allocateCars.model }/{ allocateCars.year }/{allocateCars.kilometers}/{allocateCars.colour}/" + $"{allocateCars.transmission}/{allocateCars.price}/{allocateCars.owner}/{allocateCars.listDate}/{allocateCars.img1}/{allocateCars.img2}/" + $"{allocateCars.img3}/{allocateCars.img4}/{allocateCars.img5}/{allocateCars.visible}"); } } File.WriteAllLines(listingsDatabase, updateList); } }
private void DefaultListing() { gridCarList.Rows.Clear(); gridCarList.Refresh(); int row = 0; List <string> carLines = File.ReadAllLines(listingsDatabase).ToList(); foreach (string line in carLines) { string[] entries = line.Split('/'); if (entries[14] == "Listed") { gridCarList.Rows.Add(); DataGridViewRow rows = gridCarList.Rows[row]; string preview = entries[9]; Image listingImage = Image.FromFile(preview); listingImage = listingImage.GetThumbnailImage(200, 100, null, IntPtr.Zero); rows.Height = listingImage.Height; carListing allocateCars = new carListing(); rows.Cells[1].Value = row + 1; rows.Cells[2].Value = listingImage; rows.Cells[3].Value = entries[0]; rows.Cells[4].Value = entries[1]; rows.Cells[5].Value = Int32.Parse(entries[2]); rows.Cells[6].Value = Int32.Parse(entries[3]); rows.Cells[7].Value = entries[4]; rows.Cells[8].Value = entries[5]; rows.Cells[9].Value = Int32.Parse(entries[6]); rows.Cells[10].Value = entries[8]; row++; } } }
public listInfo(string a, string b) // a gets car, b gets active user { InitializeComponent(); listReference = a; activeUser = b; List <string> carLines = File.ReadAllLines(listingsDatabase).ToList(); carListing listedCar = new carListing(); foreach (string line in carLines) { string[] entries = line.Split('/'); if (entries[8] == listReference) { listedCar.make = entries[0]; listedCar.model = entries[1]; listedCar.year = Int32.Parse(entries[2]); listedCar.kilometers = Int32.Parse(entries[3]); listedCar.colour = entries[4]; listedCar.transmission = entries[5]; listedCar.price = Int32.Parse(entries[6]); listedCar.owner = entries[7]; listedCar.listDate = entries[8]; img1 = entries[9]; img2 = entries[10]; img3 = entries[11]; img4 = entries[12]; img5 = entries[13]; break; } } txtAccOwner.Text = listedCar.owner; contactInfo = listedCar.owner; txtViewMake.Text = listedCar.make; txtViewModel.Text = listedCar.model; txtViewYear.Text = listedCar.year.ToString(); txtViewMileage.Text = listedCar.kilometers.ToString(); txtViewColour.Text = listedCar.colour; txtViewTrans.Text = listedCar.transmission; txtViewPrice.Text = listedCar.price.ToString(); placeImage(img1); txtImageCount.Text = "Image " + imageCount + "/5"; if (b == txtAccOwner.Text) { // show edit/modify buttons here btnEditListing.Visible = true; btnContact.Visible = false; cbFavourite.Visible = false; cbSold.Visible = true; cbDelete.Visible = true; } if (b == "Guest") { cbFavourite.Visible = false; } else { cbFavourite.Checked = CheckFavourites(); } }
private void btnSearchForCar_Click(object sender, EventArgs e) { //Determines how many search terms int ctr = 0; int ctr2 = 0; foreach (char c in txtSearch.Text) { if (c == ',') { ctr++; } } string[] parameters = txtSearch.Text.Split(','); if (txtSearch.Text != "") { //If they searched for anything other than space add it to their account if they are logged in if (activeUser.username != "Guest") { string g = ""; List <string> info = File.ReadAllLines(accountsDatabase).ToList(); List <string> users = new List <string>(); foreach (string s in info) { string[] account = s.Split('/'); if (account[0] == activeUser.username) //finds account { g = info[ctr2]; for (int i = 0; i < ctr + 1; i++) //adds search terms to info { g += '/' + parameters[i]; } users.Add(g); } else { users.Add(s); } ctr2++; } File.WriteAllLines(@"accounts.txt", users); } //Shows only related cars gridCarList.Rows.Clear(); gridCarList.Refresh(); int row = 0; List <string> carLines = File.ReadAllLines(listingsDatabase).ToList(); foreach (string line in carLines) { string[] entries = line.Split('/'); for (int i = 0; i < ctr + 1; i++) { if (entries[0].ToLower() == parameters[i].ToLower() || entries[1].ToLower() == parameters[i].ToLower() || entries[2].ToLower() == parameters[i].ToLower() || entries[3].ToLower() == parameters[i].ToLower() || entries[4].ToLower() == parameters[i].ToLower() || entries[5].ToLower() == parameters[i].ToLower() || entries[6].ToLower() == parameters[i].ToLower() || entries[7].ToLower() == parameters[i].ToLower()) { gridCarList.Rows.Add(); DataGridViewRow rows = gridCarList.Rows[row]; string preview = entries[9]; Image listingImage = Image.FromFile(preview); listingImage = listingImage.GetThumbnailImage(200, 100, null, IntPtr.Zero); rows.Height = listingImage.Height; carListing allocateCars = new carListing(); rows.Cells[1].Value = row + 1; rows.Cells[2].Value = listingImage; rows.Cells[3].Value = entries[0]; rows.Cells[4].Value = entries[1]; rows.Cells[5].Value = Int32.Parse(entries[2]); rows.Cells[6].Value = Int32.Parse(entries[3]); rows.Cells[7].Value = entries[4]; rows.Cells[8].Value = entries[5]; rows.Cells[9].Value = Int32.Parse(entries[6]); rows.Cells[10].Value = entries[8]; row++; } } } } else { DefaultListing(); } }