Example #1
0
        public MainForm()
        {
            InitializeComponent();

            EditableControls.GroupList = GroupList;
            EditableControls.GroupsTab = GroupsTab;

            SQLite.FirstInitialize();

            EditableControls.ResizeColumns();


            // AddTab();
        }
Example #2
0
        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();
            }
        }
Example #3
0
        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
        }
Example #4
0
        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);
            }
        }