private void btnAddPerson_Click(object sender, EventArgs e) { var view = CompositionRoot.Resolve <DirectoryPersonsView>(); //(new IParameter[] { new ConstructorArgument("isStandard", false) }); if (view.ShowDialog() == DialogResult.OK) { if (view.SelectedPersons != null) { var isEq = false; foreach (var personId in PartyPersons.Select(d => d.Person_PersonId)) { if (view.SelectedPersons.Select(p => p.Person_PersonId).Contains(personId)) { isEq = true; } } if (!isEq) { PartyPersons.AddRange(view.SelectedPersons); //if (dataGridViewPersons.RowCount > 0) //{ // if (!PartyPersons.Any(p => p.IsResponsible == true)) // { // dataGridViewPersons.Rows[0].Cells["isResponsibleDataGridViewCheckBoxColumn"].Value = true; // //PartyPersons[0].IsResponsible = true; // } //} //if (PartyPersons.Count > 0) //{ // if (!PartyPersons.Any(p => p.IsResponsible == true)) // { // PartyPersons[0].IsResponsible = true; // } //} bindingSourcePersons.DataSource = PartyPersons; bindingSourcePersons.ResetBindings(true); SetStateForChange(); } else { MessageBox.Show(string.Format("Сотрудники не добавлены. Один или несколько сотрудников уже содержатся в данной партии."), DirectoryName, MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
/// <summary> /// Очистка формы. /// </summary> private void ClearForm() { PartyPersons.Clear(); textBoxName.Clear(); dataGridViewPersons.Rows.Clear(); //_savePosition = 0; if (_editDGVPersons != null) { _editDGVPersons.Clear(); } textBoxName.Focus(); }
private void btnDelPerson_Click(object sender, EventArgs e) { var countRow = dataGridViewPersons.SelectedRows.Count; if (countRow > 0) { //var persons = new List<Person>(); var ids = new List <int>(); foreach (DataGridViewRow row in dataGridViewPersons.SelectedRows) { ids.Add(row.Index); } PartyPersons.RemoveRange(ids.Min(), ids.Count); //PartyPersons.OrderBy(p => p.Name).ToList(); //if (PartyPersons.Count > 0) //{ // foreach (var person in PartyPersons) // { // person.IsResponsible = false; // } // var partyPerson = PartyPersons[0]; //.IsResponsible; // if (partyPerson != null) // { // if (partyPerson.Party_PartyId != 0) // { // if (_editDGVPersons != null) // _editDGVPersons.Add(e.RowIndex); // SetButtonEnabled(false); // _isEdit = true; // } // } //} bindingSourcePersons.DataSource = PartyPersons; bindingSourcePersons.ResetBindings(true); SetStateForChange(); } }
private bool IsEditPersons() { var isEditDirections = false; if (PartyPersons != null) { foreach (var personId in PartyPersons.Select(d => d.Person_PersonId)) { if (!CurrentParty.PartyPersons.Select(pp => pp.Person).Select(p => p.PersonId).Contains(personId)) { isEditDirections = true; } } foreach (var curPersonId in CurrentParty.PartyPersons.Select(pp => pp.Person).Select(p => p.PersonId)) { if (!PartyPersons.Select(p => p.Person_PersonId).Contains(curPersonId)) { isEditDirections = true; } } } return(isEditDirections); }
/// <summary> /// Сохранение изменений. /// </summary> private void SaveChange() { if (_isEdit) { if (UpdateParty != null) { SavePosition(); var deletePersons = new List <PartyPerson>(); foreach (var curPerson in CurrentParty.PartyPersons) { if (!PartyPersons.Select(p => p.Person).Select(p => p.PersonId).Contains(curPerson.Person.PersonId)) { deletePersons.Add(new PartyPerson { Party_PartyId = CurrentParty != null ? CurrentParty.PartyId : 0, Person_PersonId = curPerson.Person_PersonId, IsResponsible = curPerson.IsResponsible }); } } var addPersons = new List <PartyPerson>(); foreach (var person in PartyPersons) { if (!CurrentParty.PartyPersons.Select(pp => pp.Person).Select(p => p.PersonId).Contains(person.Person_PersonId)) { addPersons.Add(new PartyPerson { Party_PartyId = CurrentParty != null ? CurrentParty.PartyId : 0, Person_PersonId = person.Person_PersonId, IsResponsible = person.IsResponsible }); } } var editPersons = new List <PartyPerson>(); foreach (var index in _editDGVPersons.Distinct()) { //if (dataGridViewPersons.RowCount) if (dataGridViewPersons.RowCount > index) { var partyPerson = dataGridViewPersons.Rows[index].DataBoundItem as PartyPerson; if (partyPerson != null) { if ((!addPersons.Select(d => d.Person_PersonId).Contains(partyPerson.Person_PersonId) || !deletePersons.Select(d => d.Person_PersonId).Contains(partyPerson.Person_PersonId)) && partyPerson.Party_PartyId != 0) { editPersons.Add(new PartyPerson { Party_PartyId = CurrentParty != null ? CurrentParty.PartyId : 0, Person_PersonId = partyPerson.Person_PersonId, IsResponsible = partyPerson.IsResponsible }); } } } } DeletePersons = deletePersons; AddPersons = addPersons; EditPersons = editPersons; UpdateParty(Party, AddPersons, DeletePersons, EditPersons); GetAllPartys(); SelectObject(); } } else { if (SaveParty != null) { SaveParty(Party, PartyPersons); } GetAllPartys(); SelectObject(); } _isEdit = true; SetButtonEnabled(true); }