//Закрытый метод для обработки события удаления строки из таблицы private static void UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { var list = e.Row.Cells; //Id; //"ФИО"; //"Звание"; //"Год рождения"; //"Домашний адрес"; //"Место работы"; //"Явиться по адресу"; //"Компания"; //"ВУС №"; string GroupName = list[0].Value.ToString(); Member member = new Member() { FIO = list[1].Value.ToString(), Rank = list[2].Value.ToString(), YearOfBirth = list[3].Value.ToString(), HomeAddress = list[4].Value.ToString(), PlaceOfWork = list[5].Value.ToString(), TurnoutAddress = list[6].Value.ToString(), Company = list[7].Value.ToString(), VusNumber = list[8].Value.ToString() }; var group = GroupsArray.FindGroup(GroupName); group.RemoveMember(member); SQLite.RemoveMemberFromDB(GroupName, member); //MessageBox.Show("Deleted"); }
private void button1_Click(object sender, EventArgs e) { string GroupName = GroupNameTextBox.Text; if (GroupName.Length > 0) { GroupsArray.LastGroupName = GroupName; if (!GroupsArray.IsCreated(GroupName)) { GroupsArray.CreateNewGroup(GroupName); EditableControls.GroupList.Items.Add(GroupName); } Blank win = new Blank(); win.ShowDialog(); this.DialogResult = DialogResult.OK; } else { MessageBox.Show("Введите номер", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void RemoveButton_Click(object sender, EventArgs e) { try { var dataGrid = (DataGridView)EditableControls.GroupsTab.SelectedTab.Controls[0]; Member memb; string Group_Name; foreach (DataGridViewRow row in dataGrid.SelectedRows) { Group_Name = row.Cells[0].Value.ToString(); //MessageBox.Show(Group_Name); memb = new Member() { FIO = row.Cells[1].Value.ToString(), Rank = row.Cells[2].Value.ToString(), YearOfBirth = row.Cells[3].Value.ToString(), HomeAddress = row.Cells[4].Value.ToString(), PlaceOfWork = row.Cells[5].Value.ToString(), TurnoutAddress = row.Cells[6].Value.ToString(), Company = row.Cells[7].Value.ToString(), VusNumber = row.Cells[8].Value.ToString() }; //TODO: //Удалить из БД SQLite.RemoveMemberFromDB(Group_Name, memb); //Удалить из программного хранилища var membs = GroupsArray.FindGroup(Group_Name).members; for (int i = 0; i < membs.Count; i++) { var member = membs[i]; if ( (member.FIO == memb.FIO) && (member.Rank == memb.Rank) && (member.YearOfBirth == memb.YearOfBirth) && (member.HomeAddress == memb.HomeAddress) && (member.PlaceOfWork == memb.PlaceOfWork) && (member.TurnoutAddress == memb.TurnoutAddress) && (member.Company == memb.Company) && (member.VusNumber == memb.VusNumber) ) { membs.RemoveAt(i); break; } } //Удалить из таблицы dataGrid.Rows.Remove(row); } } catch (Exception) { } #region Удаление группы List <string> CheckedGroupNames = new List <string>(); foreach (var CheckedGroupName in GroupList.CheckedItems) { CheckedGroupNames.Add(CheckedGroupName.ToString()); SQLite.RemoveGroupFromDB(CheckedGroupName.ToString()); } //TODO: реализовать удаление из ListCheckBox, удаление вкладок и удаление из хранилища данных foreach (var GroupName in CheckedGroupNames) { try { GroupsArray.RemoveGroup(GroupName); EditableControls.RemoveCheckedListItem(GroupName); EditableControls.RemoveTabPage(GroupName); } catch (Exception) { } } #endregion }
//Закрытый метод для обработки события изменения данных в ячейки таблицы private static void CellEdited(object sender, DataGridViewCellEventArgs e) { /*Нужно обработать изменение данных в ячейке * 1. Столбцы в строке должны быть заполнены * 2. Находим название группы * 3. Идентифицируем человека (по фио, датам и т.д.) * 4. узнаем параметр который изменился */ DataGridView dataGrid = (DataGridView)sender; int Col = e.ColumnIndex; int Row = e.RowIndex; bool IsFilled = true; List <string> listParams = new List <string>(); for (int i = 0; i < dataGrid.ColumnCount; i++) { string value = dataGrid.Rows[Row].Cells[i].Value.ToString(); if (value == "") { IsFilled = false; } listParams.Add(value); } //Если строка заполнена полностью if (IsFilled) { string GroupName = dataGrid.Rows[Row].Cells[0].Value.ToString(); var group = GroupsArray.FindGroup(GroupName); int count = 0; int pointer = 0; foreach (var memb in group.members) { count = 0; //Ищем совпадение по 7 пунктам из 8 if (memb.FIO == listParams[1]) { count++; } else { pointer = 1; } if (memb.Rank == listParams[2]) { count++; } else { pointer = 2; } if (memb.YearOfBirth == listParams[3]) { count++; } else { pointer = 3; } if (memb.HomeAddress == listParams[4]) { count++; } else { pointer = 4; } if (memb.PlaceOfWork == listParams[5]) { count++; } else { pointer = 5; } if (memb.TurnoutAddress == listParams[6]) { count++; } else { pointer = 6; } if (memb.Company == listParams[7]) { count++; } else { pointer = 7; } if (memb.VusNumber == listParams[8]) { count++; } else { pointer = 8; } //Если нашли, то записываем измененный параметр в память if (count == 7) { MessageBox.Show("Success"); switch (pointer) { case 1: memb.FIO = listParams[1]; SQLite.UpdateMemberInfo("FIO", listParams[1], "Adress", listParams[4]); break; case 2: memb.Rank = listParams[2]; SQLite.UpdateMemberInfo("_rank", listParams[2], "FIO", listParams[1]); break; case 3: memb.YearOfBirth = listParams[3]; break; case 4: memb.HomeAddress = listParams[4]; SQLite.UpdateMemberInfo("Adress", listParams[4], "FIO", listParams[1]); break; case 5: memb.PlaceOfWork = listParams[5]; SQLite.UpdateMemberInfo("WorkPlace", listParams[5], "FIO", listParams[1]); break; case 6: memb.TurnoutAddress = listParams[6]; SQLite.UpdateMemberInfo("TurnoutAdress", listParams[6], "FIO", listParams[1]); break; case 7: memb.Company = listParams[7]; SQLite.UpdateMemberInfo("Company", listParams[7], "FIO", listParams[1]); break; case 8: memb.VusNumber = listParams[8]; SQLite.UpdateMemberInfo("Vus", listParams[8], "FIO", listParams[1]); break; default: break; } } //ВВОД ПОСРЕДСТВОМ ДОБАВЛЕНИЯ НОВОЙ СТРОКИ НЕ ПРЕДУСМОТРЕН } } //Id; //"ФИО"; //"Звание"; //"Год рождения"; //"Домашний адрес"; //"Место работы"; //"Явиться по адресу"; //"Компания"; //"ВУС №"; }
private void AddButton_Click(object sender, EventArgs e) { //Массив параметров string[] List = { VusNumbtextBox.Text, FIOtextBox.Text, RankComboBox.SelectedItem.ToString(), $"{DateOfBirth.Value.Day:0#}.{DateOfBirth.Value.Month:0#}.{DateOfBirth.Value.Year}", HomeAdresstextBox.Text, WorkPlacetextBox.Text, TurnoutAddresstextBox.Text, CompanytextBox.Text }; bool IsEmptyField = false; foreach (var item in List) { if (item.Length == 0) { IsEmptyField = true; } } if (IsEmptyField) { MessageBox.Show("Заполните все поля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var member = new Member() { VusNumber = List[0], FIO = List[1], Rank = List[2], YearOfBirth = List[3], HomeAddress = List[4], PlaceOfWork = List[5], TurnoutAddress = List[6], Company = List[7] }; GroupsArray.AddMemberToTheGroup(GroupsArray.LastGroupName, member); Group group = GroupsArray.FindGroup(GroupsArray.LastGroupName); if (!EditableControls.IsContained(GroupsArray.LastGroupName)) { EditableControls.CreateNewTab(group); } else //if (EditableControls.IsContained(GroupsArray.LastGroupName)) { EditableControls.AddMemberToTab(GroupsArray.LastGroupName, member); } SQLite.AddMemberToDB(GroupsArray.LastGroupName, member); this.Close(); } }
private void button1_Click(object sender, EventArgs e) { //Выбран один человек if ((ListMembersDataGridView.SelectedRows.Count == 1) && (GroupsCheckedList.CheckedItems.Count == 0)) { string[] list = { ListMembersDataGridView.SelectedRows[0].Cells[0].Value.ToString(), ListMembersDataGridView.SelectedRows[0].Cells[1].Value.ToString(), ListMembersDataGridView.SelectedRows[0].Cells[2].Value.ToString(), ListMembersDataGridView.SelectedRows[0].Cells[3].Value.ToString(), ListMembersDataGridView.SelectedRows[0].Cells[4].Value.ToString(), ListMembersDataGridView.SelectedRows[0].Cells[5].Value.ToString(), ListMembersDataGridView.SelectedRows[0].Cells[6].Value.ToString(), ListMembersDataGridView.SelectedRows[0].Cells[7].Value.ToString(), ListMembersDataGridView.SelectedRows[0].Cells[8].Value.ToString() }; SaveToWord.SaveMember(list); } //Выбрано несколько человек if ((ListMembersDataGridView.SelectedRows.Count > 1) && (GroupsCheckedList.CheckedItems.Count == 0)) { List <string[]> list = new List <string[]>(); for (int i = 0; i < ListMembersDataGridView.SelectedRows.Count; i++) { string[] l = { ListMembersDataGridView.SelectedRows[i].Cells[0].Value.ToString(), ListMembersDataGridView.SelectedRows[i].Cells[1].Value.ToString(), ListMembersDataGridView.SelectedRows[i].Cells[2].Value.ToString(), ListMembersDataGridView.SelectedRows[i].Cells[3].Value.ToString(), ListMembersDataGridView.SelectedRows[i].Cells[4].Value.ToString(), ListMembersDataGridView.SelectedRows[i].Cells[5].Value.ToString(), ListMembersDataGridView.SelectedRows[i].Cells[6].Value.ToString(), ListMembersDataGridView.SelectedRows[i].Cells[7].Value.ToString(), ListMembersDataGridView.SelectedRows[i].Cells[8].Value.ToString() }; list.Add(l); } SaveToWord.SaveMembers(list); } //Если выбраны группы одна или больше if ((ListMembersDataGridView.SelectedRows.Count == 0) && (GroupsCheckedList.CheckedItems.Count > 0)) { List <string[]> list = new List <string[]>(); List <Group> groups = new List <Group>(); //Ищем группы for (int i = 0; i < GroupsCheckedList.CheckedItems.Count; i++) { groups.Add(GroupsArray.FindGroup(GroupsCheckedList.CheckedItems[i].ToString())); //MessageBox.Show(GroupsArray.FindGroup(GroupsCheckedList.CheckedItems[i].ToString()).Id); } //нашли все выделенные группы //Заполняем список людей для печати foreach (var group in groups) { foreach (var member in group.members) { string[] l = { group.Id, member.VusNumber, member.FIO, member.Rank, member.YearOfBirth, member.HomeAddress, member.PlaceOfWork, member.TurnoutAddress, member.Company }; list.Add(l); } } SaveToWord.SaveMembers(list); } if ((ListMembersDataGridView.SelectedRows.Count > 0) && (GroupsCheckedList.CheckedItems.Count > 0)) { List <string[]> list = new List <string[]>(); List <Group> groups = new List <Group>(); //Ищем группы for (int i = 0; i < GroupsCheckedList.CheckedItems.Count; i++) { groups.Add(GroupsArray.FindGroup(GroupsCheckedList.CheckedItems[i].ToString())); //MessageBox.Show(GroupsArray.FindGroup(GroupsCheckedList.CheckedItems[i].ToString()).Id); } //нашли все выделенные группы //Заполняем список людей для печати из групп foreach (var group in groups) { foreach (var member in group.members) { string[] l = { group.Id, member.VusNumber, member.FIO, member.Rank, member.YearOfBirth, member.HomeAddress, member.PlaceOfWork, member.TurnoutAddress, member.Company }; list.Add(l); } } for (int i = 0; i < ListMembersDataGridView.SelectedRows.Count; i++) { string[] l = { ListMembersDataGridView.SelectedRows[i].Cells[0].Value.ToString(), ListMembersDataGridView.SelectedRows[i].Cells[1].Value.ToString(), ListMembersDataGridView.SelectedRows[i].Cells[2].Value.ToString(), ListMembersDataGridView.SelectedRows[i].Cells[3].Value.ToString(), ListMembersDataGridView.SelectedRows[i].Cells[4].Value.ToString(), ListMembersDataGridView.SelectedRows[i].Cells[5].Value.ToString(), ListMembersDataGridView.SelectedRows[i].Cells[6].Value.ToString(), ListMembersDataGridView.SelectedRows[i].Cells[7].Value.ToString(), ListMembersDataGridView.SelectedRows[i].Cells[8].Value.ToString() }; list.Add(l); } SaveToWord.SaveMembers(list); } }
public static void FirstInitialize() { if (!File.Exists(database)) { SQLiteConnection.CreateFile(database); } string StartCommand = DataBaseCommands.CreateTableListMembers(); string request = DataBaseCommands.SelectAll(); command = new SQLiteCommand(StartCommand, connection); command1 = new SQLiteCommand(request, connection); try { connection.Open(); command.ExecuteNonQuery(); using (DbDataReader reader = command1.ExecuteReader()) { string GroupName, _VusNumber, _FIO, _rank, _YearOfBirth, _HomeAddress, _PlaceOfWork, _TurnoutAddress, _Company; if (reader.HasRows) { while (reader.Read()) { GroupName = reader.GetString(0); _VusNumber = reader.GetString(1); _FIO = reader.GetString(2); _rank = reader.GetString(3); _YearOfBirth = reader.GetString(4).Split(' ')[0]; _HomeAddress = reader.GetString(5); _PlaceOfWork = reader.GetString(6); _TurnoutAddress = reader.GetString(7); _Company = reader.GetString(8); GroupsArray.LastGroupName = GroupName; if (!GroupsArray.IsCreated(GroupName)) { GroupsArray.CreateNewGroup(GroupName); EditableControls.GroupList.Items.Add(GroupName); } var member = new Member() { VusNumber = _VusNumber, FIO = _FIO, Rank = _rank, YearOfBirth = _YearOfBirth, HomeAddress = _HomeAddress, PlaceOfWork = _PlaceOfWork, TurnoutAddress = _TurnoutAddress, Company = _Company }; GroupsArray.AddMemberToTheGroup(GroupsArray.LastGroupName, member); Group group = GroupsArray.FindGroup(GroupsArray.LastGroupName); if (!EditableControls.IsContained(GroupsArray.LastGroupName)) { EditableControls.CreateNewTab(group); } else { EditableControls.AddMemberToTab(GroupsArray.LastGroupName, member); } } } } connection.Close(); } catch (Exception e) { MessageBox.Show("Error: " + e.Message); } }
private void AddButton_Click(object sender, EventArgs e) { //Массив параметров string[] List = { FIOtextBox.Text, RankComboBox.SelectedItem.ToString(), $"{DateOfBirth.Value.Day:0#}.{DateOfBirth.Value.Month:0#}.{DateOfBirth.Value.Year}", HomeAdresstextBox.Text, WorkPlacetextBox.Text, TurnoutAddresstextBox.Text, CompanytextBox.Text, VusNumbtextBox.Text }; bool IsChanged = false; for (int i = 0; i < List.Length; i++) { if (pars[i] != List[i]) { IsChanged = true; } } //Если внесли изменения if (IsChanged) { //MessageBox.Show("Changed"); Member OldMember = new Member() { FIO = pars[0], Rank = pars[1], YearOfBirth = pars[2], HomeAddress = pars[3], PlaceOfWork = pars[4], TurnoutAddress = pars[5], Company = pars[6], VusNumber = pars[7] }; Member NewMember = new Member() { FIO = FIOtextBox.Text, Rank = RankComboBox.SelectedItem.ToString(), YearOfBirth = $"{DateOfBirth.Value.Day:0#}.{DateOfBirth.Value.Month:0#}.{DateOfBirth.Value.Year}", HomeAddress = HomeAdresstextBox.Text, PlaceOfWork = WorkPlacetextBox.Text, TurnoutAddress = TurnoutAddresstextBox.Text, Company = CompanytextBox.Text, VusNumber = VusNumbtextBox.Text }; //TODO: //Обновить в списке var group = GroupsArray.FindGroup(GroupName); for (int i = 0; i < group.members.Count; i++) { var memb = group.members[i]; if ( (memb.FIO == OldMember.FIO) && (memb.Rank == OldMember.Rank) && (memb.YearOfBirth == OldMember.YearOfBirth) && (memb.HomeAddress == OldMember.HomeAddress) && (memb.PlaceOfWork == OldMember.PlaceOfWork) && (memb.TurnoutAddress == OldMember.TurnoutAddress) && (memb.Company == OldMember.Company) && (memb.VusNumber == OldMember.VusNumber) ) { group.members[i].FIO = OldMember.FIO; group.members[i].Rank = OldMember.Rank; group.members[i].YearOfBirth = OldMember.YearOfBirth; group.members[i].HomeAddress = OldMember.HomeAddress; group.members[i].PlaceOfWork = OldMember.PlaceOfWork; group.members[i].TurnoutAddress = OldMember.TurnoutAddress; group.members[i].Company = OldMember.Company; group.members[i].VusNumber = OldMember.VusNumber; break; } } //Обновить таблицу for (int i = 0; i < List.Length; i++) { dataGrid.SelectedRows[0].Cells[i + 1].Value = List[i]; } //Обновить БД SQLite.UpdateMemberInfo(OldMember, NewMember); Close(); } if (!IsChanged) { //MessageBox.Show("Not changed"); Close(); } }