/// <summary> /// Записывает измененный экземпляр Person в лист, файл и ListBox. /// </summary> private void WriteGhangedPersonFileListBox() { int indexList = lbxGeneratedPersons.SelectedIndex; if (indexList >= 0) { ListPerson[indexList].SetSurname(tBSurname.Text); ListPerson[indexList].SetName(tBName.Text); ListPerson[indexList].SetMiddlename(tBMiddlename.Text); ListPerson[indexList].SetAge(Convert.ToInt32(tBAge.Text)); ListPerson[indexList].SetFunction(tBFuntion.Text); ListPerson[indexList].SetSalary(Convert.ToInt32(tBSalary.Text)); DAO.WriteListInToFile(ListPerson, Constants.FILE_GENERATED_PERSONS); lbxGeneratedPersons.Items.Clear(); foreach (string person in DAO.SetListStringFromFile(Constants.FILE_GENERATED_PERSONS)) { lbxGeneratedPersons.Items.Add(Calculate.SetPersonStringForListBox(person)); } lbxGeneratedPersons.SelectedIndex = indexList; } }
private void btnGenerate_Click(object sender, EventArgs e) { Gender gender = Calculate.GenerateGender(); string surname = Calculate.SetRandomStringiInList(DAO.SetListStringFromFile(Calculate.SetFileSurName(gender))); string name = Calculate.SetRandomStringiInList(DAO.SetListStringFromFile(Calculate.SetFileName(gender))); string midllename = Calculate.SetRandomStringiInList(DAO.SetListStringFromFile(Calculate.SetFileMiddleName(gender))); string function = Calculate.SetRandomStringiInList(DAO.SetListStringFromFile(Constants.FILE_FUNCTION)); int age = Calculate.SetRandomAge(); int salary = Calculate.SetRandomSalary(); Person person = new Person(surname, name, midllename, age, function, salary, gender); AddListPerson(person); DAO.AddStringInToFile(Calculate.SetPersonStingForFile(person), Constants.FILE_GENERATED_PERSONS); lbxGeneratedPersons.Items.Add(Calculate.SetPersonStingForListBox(person)); lbxGeneratedPersons.SelectedIndex = lbxGeneratedPersons.Items.Count - 1; }