private void btnSearch_Click(object sender, EventArgs e) { using (var db = new LandxEntities()) { if (txtSearch.Text.Trim().ToLower().StartsWith("land")) { int id; try { id = Convert.ToInt32(txtSearch.Text.Replace("land", "").Trim()); } catch (Exception) { MessageBox.Show("The Input text is not a valid ID."); return; } Models.Land land = db.Lands.Find(id); if (land == null) { MessageBox.Show("No land was found with this ID."); return; } else { lstFound.Items.Add(string.Format("land{0} ({1})", land.Id.ToString("d4"), land.Person.ApplicantsFullname)); } } else if (txtSearch.Text.Trim().ToLower().StartsWith("psn")) { int id; try { id = Convert.ToInt32(txtSearch.Text.Replace("psn", "").Trim()); } catch (Exception) { MessageBox.Show("The Input text is not a valid ID."); return; } Models.Person psn = db.People.Find(id); if (psn == null) { MessageBox.Show("No Person was found with this ID."); return; } else { lstFound.Items.Add(string.Format("psn{0} ({1})", psn.Id.ToString("d4"), psn.ApplicantsFullname)); } } else { List <Person> ppl = db.People.Where(x => x.ApplicantsFullname.Contains(txtSearch.Text.Trim().ToLower())).ToList(); if (ppl.Count < 1) { MessageBox.Show("No Person was found with this Name."); return; } else { foreach (var psn in ppl) { lstFound.Items.Add(string.Format("psn{0} ({1})", psn.Id.ToString("d4"), psn.ApplicantsFullname)); } } } } }
private void lstFound_SelectedIndexChanged(object sender, EventArgs e) { try { string selectedString = lstFound.SelectedItem.ToString(); string selectedId = selectedString.Replace(selectedString.Substring(selectedString.IndexOf(' ')), ""); using (var db = new LandxEntities()) { if (selectedId.Trim().StartsWith("land")) { int id = Convert.ToInt32(selectedId.Replace("land", "").Trim()); Models.Land land = db.Lands.Find(id); if (land == null) { MessageBox.Show("No land was found with this ID."); return; } else { lblLandDescription.Text = land.LandDescription; lblLandLocation.Text = land.Town; lblLandOwnerName.Text = land.Person.ApplicantsFullname; lblLandOwnerNumber.Text = land.Person.PhoneNumber; //08157026571 btnLandDetails.Tag = land; var ms = new MemoryStream(land.Person.Pic); picProfile.Image = Image.FromStream(ms); animPan.HideSync(panSearch); animPan.ShowSync(panLand); } } else if (selectedId.Trim().StartsWith("psn")) { int id = Convert.ToInt32(selectedId.Replace("psn", "").Trim()); Models.Person psn = db.People.Find(id); if (psn == null) { MessageBox.Show("No Person was found with this ID."); return; } else { lblOwnerName.Text = psn.ApplicantsFullname; lblOwnerNumber.Text = psn.PhoneNumber; btnOwnerDetail.Tag = psn; var ms = new MemoryStream(psn.Pic); picOwner.Image = Image.FromStream(ms); panLands4Owner.Controls.Clear(); Models.Land[] land = psn.Lands.ToArray(); for (int i = 0; i < land.Count(); i++) { UClands pLand = new UClands(); pLand.Tag = land[i]; pLand.Top = (i * pLand.Height) + ((i + 1) * 10); panLands4Owner.Controls.Add(pLand); } animPan.HideSync(panSearch); animPan.ShowSync(panOwner); } } } } catch (Exception) { } }
private void UClands_Load(object sender, EventArgs e) { Models.Land land = (Models.Land) this.Tag; lblLandDescription.Text = land.LandDescription; lblLandLocation.Text = land.Town; }