private void btnAdd_Click(object sender, EventArgs e) { // // Creating a new class for the new character // LocationClass NewLoc = new LocationClass(); NewLoc.Name = txtName.Text; NewLoc.Description = txtDescription.Text; NewLoc.Population = txtPopulation.Text; NewLoc.Type = txtType.Text; NewLoc.Address = txtAddress.Text; // // Add character to main form's list // MainForm.AddNewLocation(NewLoc, pbImage.Image); // // Show main form // Enable main form // Close this form // MainForm.Show(); MainForm.Enabled = true; this.Close(); }
private void btnUpdate_Click(object sender, EventArgs e) { LocationClass EditLoc = new LocationClass(); EditLoc.Address = txtAddress.Text; EditLoc.Description = txtDescription.Text; EditLoc.Name = txtName.Text; EditLoc.Population = txtPopulation.Text; EditLoc.Type = txtType.Text; MainForm.EditLocation(GetLocationByName(lbLocations.SelectedItem.ToString()), EditLoc, pbImage.Image, this); }
public void EditLocation(LocationClass chrOld, LocationClass chrUpdate, Image Picture, frmListLocations FLL) { bool Found = false; if (chrOld != null) { foreach (LocationClass CC in CBC[0].Locations) { if (!Found) { if (CC.Name == chrOld.Name) { CC.Name = chrUpdate.Name; CC.Type = chrUpdate.Type; CC.Address = chrUpdate.Address; CC.Population = chrUpdate.Population; CC.Description = chrUpdate.Description; CC.SavePicture = ImageToString(Picture); Found = true; blDataSaved = false; } } } } if (Found) MessageBox.Show("Location edit successful!", "Editing..."); else MessageBox.Show("Failed to edit location!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
public void AddNewLocation(LocationClass locNew, Image Picture) { locNew.SavePicture = ImageToString(Picture); CBC[0].Locations.Add(locNew); blDataSaved = false; CheckStatus(); }
public void DeleteLocation(LocationClass locDel, frmListLocations FLL) { bool Found = false; if (locDel != null) { foreach (LocationClass CC in CBC[0].Locations) { if (!Found) { if (CC == locDel) Found = true; } } } if (Found) { CBC[0].Locations.Remove(locDel); MessageBox.Show("Location has been deleted.", "Success"); } else MessageBox.Show("Couldn't delete location.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FLL.PopulateLocations(CBC[0].Locations); blDataSaved = false; CheckStatus(); }