private void FindStud_btn_Click(object sender, EventArgs e) { RemoveList.Items.Clear(); var snfield = FindStudField.Text; using (StudentsServiceAppClient client = new StudentsServiceAppClient()) { foreach (var item in client.StudetsInfoList()) { if (item.LastName == snfield) { string[] row = { item.Id.ToString(), item.FirstName, item.Surname, item.LastName, item.Sex, item.Age.ToString(), item.Birthdate.ToString(), string.Join(", ", item.StudentPhones?.Select(x => x.PhoneNumber.ToString())) }; var listView = new ListViewItem(row); RemoveList.Items.Add(listView); } } } }
private void SaveChanges_btn_Click(object sender, EventArgs e) { int id = Convert.ToInt32(ShowIdField.Text); string lname = LastNameStudField.Text; string name = NameStudField.Text; string surname = SurnameStudField.Text; int age = Convert.ToInt32(AgeStudField.Text); DateTime birthOfDate = Convert.ToDateTime(BirthDateStudField.Text); string address = AddressStudField.Text; float progress = float.Parse(ProgressStudField.Text); string group = GroupStudField.Text; int numbRecBook = Convert.ToInt32(NumbStudCertificateField.Text); string changedNumbersSt = StPhoneGridView.SelectedCells[0].Value.ToString(); Phone newPhone = new Phone(); newPhone.PhoneNumber = changedNumbersSt; string motherLastName = EditRelInfoGridView.Rows[0].Cells[0].Value.ToString(); string motherName = EditRelInfoGridView.Rows[0].Cells[1].Value.ToString(); string motherWorkPlace = EditRelInfoGridView.Rows[0].Cells[2].Value.ToString(); string fatherLastName = EditRelInfoGridView.Rows[1].Cells[0].Value.ToString(); string fatherName = EditRelInfoGridView.Rows[1].Cells[1].Value.ToString(); string fatherWorkPlace = EditRelInfoGridView.Rows[1].Cells[2].Value.ToString(); string additionalRelInfo = EditAdditionalRelGridView.Rows[0].Cells[0].Value.ToString(); int motherId = Convert.ToInt32(EditRelInfoGridView.Rows[0].Cells[3].Value.ToString()); int fatherId = Convert.ToInt32(EditRelInfoGridView.Rows[1].Cells[3].Value.ToString()); int additionalRelId = Convert.ToInt32(EditAdditionalRelGridView.Rows[0].Cells[1].Value.ToString()); StudentsServiceAppClient ChagedStud = new StudentsServiceAppClient(); StudentsServiceAppClient ChagedParents = new StudentsServiceAppClient(); StudentsServiceAppClient ChagedAdditionalRel = new StudentsServiceAppClient(); List <Phone> phoneS = new List <Phone>(); phoneS.Clear(); phoneS.Add(newPhone); ChagedStud.UpdateStudent(id, name, lname, surname, age, address, group, numbRecBook, birthOfDate, progress, phoneS.ToArray()); ChagedParents.UpdateParents(motherName, motherLastName, motherWorkPlace, fatherName, fatherLastName, fatherWorkPlace, motherId, fatherId); ChagedAdditionalRel.UpdateAdditionalRelations(additionalRelInfo, additionalRelId); }
private void RemoveStud_btn_Click(object sender, EventArgs e) { try { int idStud = Convert.ToInt32(RemoveStudByIdField.Text); using (StudentsServiceAppClient client = new StudentsServiceAppClient()) { foreach (var item in client.StudetsInfoList()) { if (item.Id == idStud) { client.DeleteStudentById(idStud); } } } } catch (Exception ex) { MessageBox.Show(ex.InnerException.ToString()); } }
public void LoadValueFromService() { listViewAllStud.Items.Clear(); using (var client = new StudentsServiceAppClient()) { foreach (var item in client.StudetsInfoList()) { string phones = string.Join(", ", item.StudentPhones?.Select(x => x.PhoneNumber).ToList()); string[] row = { item.Id.ToString(), item.FirstName, item.Surname, item.LastName, item.Sex,item.Age.ToString(), item.Birthdate.ToString(), phones }; var listViewItem = new ListViewItem(row); listViewAllStud.Items.Add(listViewItem); } } }
private void findStudentById_btn_Click(object sender, EventArgs e) { LastNameStudField.Text = ""; NameStudField.Text = ""; SurnameStudField.Text = ""; AgeStudField.Text = ""; BirthDateStudField.Text = ""; AddressStudField.Text = ""; ProgressStudField.Text = ""; GroupStudField.Text = ""; NumbStudCertificateField.Text = ""; StPhoneGridView.Rows.Clear(); EditAdditionalRelGridView.Rows.Clear(); EditRelInfoGridView.Rows.Clear(); RelPhonesTable.Items.Clear(); var id = Convert.ToInt32(InputIDTextBox.Text); using (StudentsServiceAppClient client = new StudentsServiceAppClient()) { foreach (var item in client.StudetsInfoList()) { if (item.Id == id) { ShowIdField.Text = item.Id.ToString(); LastNameStudField.Text = item.LastName; NameStudField.Text = item.FirstName; SurnameStudField.Text = item.Surname; AgeStudField.Text = item.Age.ToString(); BirthDateStudField.Text = item.Birthdate.ToString(); AddressStudField.Text = item.Adress.Address; ProgressStudField.Text = item.StudentProgress.Progress.ToString(); GroupStudField.Text = item.Group.Speciality; NumbStudCertificateField.Text = item.NumberRecordBook.ToString(); string phonesStud = string.Join(", ", item.StudentPhones?.Select(x => x.PhoneNumber.ToString())); StPhoneGridView.Rows.Add(phonesStud); string name = string.Join(",", item.ParentsInfo?.Select(x => x.FirstName)); string lName = string.Join(",", item.ParentsInfo?.Select(x => x.LastName)); string lid = string.Join(",", item.ParentsInfo?.Select(x => x.Id)); string spec = string.Join(",", item.ParentsInfo?.Select(x => x.WorkPlace)); string additionalRelId = string.Join(",", item.ParentsInfo?.Select(x => x.Relation.Id.ToString())); string additionalRelation = string.Join(",", item.ParentsInfo?.Select(x => x.Relation.Name).ToList()); string[] splitString1 = lName.Split(','); string motherLName = splitString1[0].Trim(); string fatherLName = splitString1[1].Trim(); string[] splitStringId = lid.Split(','); string motherId = splitStringId[0].Trim(); string fatherId = splitStringId[1].Trim(); string[] splitString = name.Split(','); string motherFName = splitString[0].Trim(); string fatherFName = splitString[1].Trim(); string[] splitString3 = spec.Split(','); string motherSpec = splitString3[0].Trim(); string fatherSpec = splitString3[1].Trim(); string[] splitString4 = additionalRelId.Split(','); string[] relString = additionalRelation.Split(','); string additionalRels = relString[0].Trim(); string additionalRelsId = splitString4[1].Trim(); string[] motherInforow = { motherLName, motherFName, motherSpec, motherId }; string[] fatherInforow = { fatherLName, fatherFName, fatherSpec, fatherId }; string[] additionalRelations = { additionalRels, additionalRelsId }; EditRelInfoGridView.Rows.Add(motherInforow); EditRelInfoGridView.Rows.Add(fatherInforow); EditAdditionalRelGridView.Rows.Add(additionalRelations); var RelClient = new StudentsServiceAppClient(); foreach (var item2 in RelClient.ParentsInfosInfoList()) { string phonesRelations = string.Join(",", item2.Phones.Select(x => x.PhoneNumber.ToString())); string[] phoneRow = phonesRelations.Split(','); string phoneRel = phoneRow[0].Trim(); var Row = new ListViewItem(phoneRel); RelPhonesTable.Items.Add(Row); } } } } }
private void AddMainInfo_btn_Click(object sender, EventArgs e) // Add main info student { try { using (StudentsServiceAppClient client = new StudentsServiceAppClient()) { Phone newPhone = new Phone(); newPhone.PhoneNumber = MobTelField.Text; List <Phone> phone = new List <Phone>(); phone.Add(newPhone); StudentProgress newProgress = new StudentProgress(); newProgress.Progress = float.Parse(ProgressAddField.Text); Adress newAdress = new Adress(); newAdress.Address = AddressAddField.Text; Group newGroup = new Group(); newGroup.Speciality = GroupAddField.Text; Phone newParentsPhone = new Phone(); newParentsPhone.PhoneNumber = PhonesRelatonsAddFielad.Text; List <Phone> relationsPhones = new List <Phone>(); relationsPhones.Add(newParentsPhone); ParentsInfo newMotheInfo = new ParentsInfo(); ParentsInfo newFatherInfo = new ParentsInfo(); Relation newRelationInfo = new Relation(); newRelationInfo.Name = RelationField.Text; newMotheInfo.FirstName = MotherNameField.Text; newMotheInfo.LastName = MotherLastNameField.Text; newMotheInfo.WorkPlace = MotherWorkPlace.Text; newMotheInfo.Relation = newRelationInfo; newMotheInfo.Phones = relationsPhones; newFatherInfo.FirstName = FatherNameField.Text; newFatherInfo.LastName = FatherLastNameField.Text; newFatherInfo.WorkPlace = FatherWorkPlaseField.Text; newFatherInfo.Relation = newRelationInfo; List <ParentsInfo> parents = new List <ParentsInfo>(); parents.Add(newMotheInfo); parents.Add(newFatherInfo); //parents.Add(newRelationInfo); StudentInfo newStudentInfo = new StudentInfo { FirstName = NameField.Text, LastName = LastNameField.Text, Surname = surnameAddField.Text, NumberRecordBook = Convert.ToInt32(NumbRecBookAddField.Text), Sex = SexField.Text, Age = Convert.ToInt32(AgeField.Text), Birthdate = DateTime.Parse(DateOfBirthField.Text), StudentPhones = phone, StudentProgress = newProgress, Adress = newAdress, Group = newGroup, ParentsInfo = parents, }; client.AddNewStudent(newStudentInfo); client.Close(); } string message = "Студент був доданий"; string caption = "Додання студента до БД"; MessageBoxButtons button = MessageBoxButtons.OK; MessageBox.Show(message, caption, button); } catch (Exception ex) { string message = ex.Message; string caption = "Помилка!"; MessageBoxButtons button = MessageBoxButtons.OK; MessageBox.Show(message, caption, button); } }
private void FindStudentByLastName_Click(object sender, EventArgs e) { listViewStud.Items.Clear(); secondRow.Items.Clear(); motherInfoList.Items.Clear(); fatherInfo.Items.Clear(); additionalRel.Items.Clear(); relationsPhones.Items.Clear(); var id = Convert.ToInt32(IDStudTextBox.Text); using (StudentsServiceAppClient client = new StudentsServiceAppClient()) { foreach (var item in client.StudetsInfoList()) { if (item.Id == id) { string[] row = { item.Id.ToString(), item.FirstName, item.Surname, item.LastName, item.Sex, item.Age.ToString(), item.Birthdate.ToString(), string.Join(", ", item.StudentPhones?.Select(x => x.PhoneNumber.ToString())) }; string[] row2 = { item.NumberRecordBook.ToString(), item.Adress.Address, item.StudentProgress.Progress.ToString(), item.Group.Speciality }; string name = string.Join(",", item.ParentsInfo?.Select(x => x.FirstName)); string lName = string.Join(",", item.ParentsInfo?.Select(x => x.LastName)); string spec = string.Join(",", item.ParentsInfo?.Select(x => x.WorkPlace)); string additionalRelation = string.Join(",", item.ParentsInfo?.Select(x => x.Relation.Name).ToList()); string[] splitString = name.Split(','); string motherFName = splitString[0].Trim(); string fatherFName = splitString[1].Trim(); string[] splitString1 = lName.Split(','); string motherLName = splitString1[0].Trim(); string fatherLName = splitString1[1].Trim(); string[] splitString3 = spec.Split(','); string motherSpec = splitString3[0].Trim(); string fatherSpec = splitString3[1].Trim(); string[] splitString4 = additionalRelation.Split(','); string additionalRels = splitString4[0].Trim(); string[] row3 = { motherFName, motherLName, motherSpec }; string[] row4 = { fatherFName, fatherLName, fatherSpec }; var listView = new ListViewItem(row); listView.Font = new Font("Microsoft Sans Serif", 10, FontStyle.Bold); listViewStud.Items.Add(listView); var listView1 = new ListViewItem(row2); listView1.Font = new Font("Microsoft Sans Serif", 10, FontStyle.Bold); secondRow.Items.Add(listView1); var listView3 = new ListViewItem(row3); listView3.Font = new Font("Microsoft Sans Serif", 10, FontStyle.Bold); motherInfoList.Items.Add(listView3); var listView4 = new ListViewItem(row4); listView4.Font = new Font("Microsoft Sans Serif", 10, FontStyle.Bold); fatherInfo.Items.Add(listView4); var listView5 = new ListViewItem(additionalRels); listView5.Font = new Font("Microsoft Sans Serif", 10, FontStyle.Bold); additionalRel.Items.Add(listView5); var Pclient = new StudentsServiceAppClient(); foreach (var item1 in Pclient.ParentsInfosInfoList()) { string phonesPar = string.Join(",", item1.Phones.Select(x => x.PhoneNumber.ToString()).ToList()); string[] splitString6 = phonesPar.Split(','); string phoneRel = splitString6[0].Trim(); var listView6 = new ListViewItem(phoneRel); listView6.Font = new Font("Microsoft Sans Serif", 10, FontStyle.Bold); relationsPhones.Items.Add(listView6); } } } } }