private void btnUppdateraInfo_Click(object sender, EventArgs e) { if (lstbResultat.SelectedItem == null) { MessageBox.Show("Välj vilken person du vill uppdatera."); } else { uppdaterainfoForm uppdateraform = new uppdaterainfoForm(); nysokning.uppdaterainfo(this); } }
private void btnInfo_Click(object sender, EventArgs e) { uppdaterainfoForm uppdateraform = new uppdaterainfoForm(); if (lstbResultat.Items.Count == 0) { MessageBox.Show("Finns ingen information du kan visa."); } else { nysokning.visainfo(this); } }
public string visainfo(sokning form) { var lines = File.ReadAllLines(@"C:\Users\Mario\Desktop\adressbok.txt").Where(arg => !string.IsNullOrWhiteSpace(arg)); File.WriteAllLines(@"C:\Users\Mario\Desktop\adressbok.txt", lines); string[] värdenEfterSplit = allavärden.Split(Environment.NewLine.ToCharArray()); string information; string namn; string adress; string postnummer; string postort; string telefon; string mail; uppdaterainfoForm formuppdaterainfo = new uppdaterainfoForm(); for (int i = 0; i < värdenEfterSplit.Length; i++) { if (form.lstbResultat.SelectedItem.ToString().Contains("\r\n")) { string värdeNamnSökning = form.lstbResultat.SelectedItem.ToString().Replace("\r\n", ""); if (värdenEfterSplit[i].Contains(värdeNamnSökning)) { information = värdenEfterSplit[i]; string[] info = information.Split(':'); namn = info[0]; adress = info[1]; postnummer = info[2]; postort = info[3]; telefon = info[4]; mail = info[5]; formuppdaterainfo.txtNamn.Text = namn.ToString(); formuppdaterainfo.txtNamn.ReadOnly = true; formuppdaterainfo.txtAdress.Text = adress.ToString(); formuppdaterainfo.txtAdress.ReadOnly = true; formuppdaterainfo.txtPostnummer.Text = postnummer.ToString(); formuppdaterainfo.txtPostnummer.ReadOnly = true; formuppdaterainfo.txtPostort.Text = postort.ToString(); formuppdaterainfo.txtPostort.ReadOnly = true; formuppdaterainfo.txtTelefon.Text = telefon.ToString(); formuppdaterainfo.txtTelefon.ReadOnly = true; formuppdaterainfo.txtMail.Text = mail.ToString(); formuppdaterainfo.txtMail.ReadOnly = true; formuppdaterainfo.btnUppdatera.Enabled = false; formuppdaterainfo.Show(); return(information); } } else if (värdenEfterSplit[i].Contains(form.lstbResultat.SelectedItem.ToString())) { information = värdenEfterSplit[i]; string[] info = information.Split(':'); namn = info[0]; adress = info[1]; postnummer = info[2]; postort = info[3]; telefon = info[4]; mail = info[5]; formuppdaterainfo.txtNamn.Text = namn.ToString(); formuppdaterainfo.txtNamn.ReadOnly = true; formuppdaterainfo.txtAdress.Text = adress.ToString(); formuppdaterainfo.txtAdress.ReadOnly = true; formuppdaterainfo.txtPostnummer.Text = postnummer.ToString(); formuppdaterainfo.txtPostnummer.ReadOnly = true; formuppdaterainfo.txtPostort.Text = postort.ToString(); formuppdaterainfo.txtPostort.ReadOnly = true; formuppdaterainfo.txtTelefon.Text = telefon.ToString(); formuppdaterainfo.txtTelefon.ReadOnly = true; formuppdaterainfo.txtMail.Text = mail.ToString(); formuppdaterainfo.txtMail.ReadOnly = true; formuppdaterainfo.btnUppdatera.Enabled = false; formuppdaterainfo.Show(); return(information); } } information = ""; return(information); }