private void btnSellCar_Click(object sender, EventArgs e) { if (activeUser.username != "Guest") { using (var form = new addListing(activeUser.username)) { var result = form.ShowDialog(); if (result == DialogResult.OK) { DefaultListing(); } } } else { MessageBox.Show("You must create an account or login to list a car for sale."); Login(); } }
private void btnEditListing_Click(object sender, EventArgs e) { using (var form = new addListing(txtAccOwner.Text)) { form.txtMileage.Text = txtViewMileage.Text; form.txtModel.Text = txtViewModel.Text; form.txtPrice.Text = txtViewPrice.Text; form.cbMake.Text = txtViewMake.Text; form.cbTransmission.Text = txtViewTrans.Text; form.cbColour.Text = txtViewColour.Text; form.cbYear.Text = txtViewYear.Text; if (form.ShowDialog() == DialogResult.OK) { //Feeds the info back into the info form txtViewMileage.Text = form.txtMileage.Text; txtViewMake.Text = form.cbMake.Text; txtViewModel.Text = form.txtModel.Text; txtViewPrice.Text = form.txtPrice.Text; txtViewTrans.Text = form.cbTransmission.Text; txtViewColour.Text = form.cbColour.Text; txtViewYear.Text = form.cbYear.Text; //Parses the car list for the current listing and deletes it due to there being a new listing (info is different supposidly) List <string> carLines = File.ReadLines(listingsDatabase).ToList(); int toDelete = 0; int ctr = 0; foreach (string line in carLines) { string[] entries = line.Split('/'); if (entries[8] == listReference) { toDelete = ctr; } ctr++; } carLines.Remove(carLines[toDelete]); File.WriteAllLines(@"listings.txt", carLines); this.Close(); } } }