Ejemplo n.º 1
0
        ITestEntities itestentities = new ITestEntities(); //подключение БД

        public UserWindow()
        {
            InitializeComponent();

            try
            {
                #region Проверка на первый вход
                int save_check = 0; //для проверки на сохранения
                foreach (var entry in itestentities.Accounts)
                {
                    if (SetClass.Id == entry.Id && entry.Level == 0)
                    {
                        MessageBox.Show("Вы впервые вошли! Совeтую вам заглянуть в Помощь", "Авторизация", MessageBoxButton.OK, MessageBoxImage.Information);
                        break;
                    }
                }
                #endregion

                #region Обработка информации о Уровне
                int max = 0; //кол-во слов
                foreach (var words in itestentities.Words)
                {
                    max++;
                }

                int mymax = 0; //кол-во слов в словаре
                foreach (var maxwords in itestentities.My_Dictionary)
                {
                    if (maxwords.Id_account == SetClass.Id)
                    {
                        mymax++;
                    }
                }

                int   countlvl    = 5;            //~верхний предел уровня
                int   arrcountlvl = countlvl + 1; //уровень для дальнейших решений
                int[] lvl         = new int[arrcountlvl]; for (int i = 1; i < arrcountlvl; i++)
                {
                    lvl[i] = i;                      //массив для уровня и цикл для заполнения кол-ва уровней
                }
                int[] lvldiv = new int[arrcountlvl]; //массив для определения уровня (деления)

                int j = 0;
                for (int i = 1; i < arrcountlvl; i++) //цикл для вычисления деления для каждого уровня (Например: кол-во слов - 30, уровень 1 - до 6 слов, уровень 2 - до 12 слов и т. д.)
                {
                    if (i != 1)
                    {
                        j = i - 1; lvldiv[i] = max / countlvl + lvldiv[j];
                    }
                    else
                    {
                        lvldiv[i] = max / countlvl;
                    }
                }

                save_check = 0;                             //для проверки на сохранения
                foreach (var acc in itestentities.Accounts) //определение уровня с помощью деления
                {
                    if (SetClass.Id == acc.Id)
                    {
                        if (mymax == 0)
                        {
                            save_check++; acc.Level = 1; break;
                        }
                        else
                        {
                            for (int i = 1; i < arrcountlvl; i++)
                            {
                                if (mymax <= lvldiv[i])
                                {
                                    save_check++; acc.Level = lvl[i]; break;
                                }
                            }
                            break;
                        }
                    }
                }

                if (save_check != 0)
                {
                    itestentities.SaveChanges();
                }
                #endregion

                #region Обработка информации о Очках
                List <int> Themes = new List <int>(); //создаём List и записываем в него Id каждой темы
                foreach (var themes in itestentities.Themes)
                {
                    Themes.Add(themes.Id);
                }

                int[] maxwordsTheme = new int[Themes.Count]; //создаём массив и записываем в него кол-во слов в каждой теме
                for (int i = 0; i < Themes.Count; i++)
                {
                    foreach (var wtheme in itestentities.Words)
                    {
                        if (Themes[i] == wtheme.Id_themes)
                        {
                            maxwordsTheme[i]++;
                        }
                    }
                }

                int score = 0; int[] mywordsTheme = new int[Themes.Count]; //создаём переменную и массив, в массив записываем кол-во слов каждой темы из словаря, в переменную записываем очки
                for (int i = 0; i < Themes.Count; i++)
                {
                    foreach (var wtheme in itestentities.Words)
                    {
                        foreach (var mywords in itestentities.My_Dictionary)
                        {
                            if (SetClass.Id == mywords.Id_account && mywords.Id_word == wtheme.Id && Themes[i] == wtheme.Id_themes)
                            {
                                mywordsTheme[i]++; break;
                            }
                        }
                    }
                    score += mywordsTheme[i];
                }

                for (int i = 0; i < Themes.Count; i++) //при всех правильных ответах одной темы прибавляется 10 очков
                {
                    if (maxwordsTheme[i] == mywordsTheme[i] && maxwordsTheme[i] != 0)
                    {
                        score += 10;
                    }
                }

                save_check = 0;
                foreach (var acc in itestentities.Accounts)
                {
                    if (acc.Id == SetClass.Id && acc.Score != score)
                    {
                        save_check++; acc.Score = score; break;
                    }
                }

                if (save_check != 0)
                {
                    itestentities.SaveChanges();
                }
                #endregion

                #region Загрузка информации из БД
                foreach (var acc in itestentities.Accounts)
                {
                    if (acc.Id == SetClass.Id)
                    {
                        textBlock_nick.Text  = acc.Login;
                        textBlock_level.Text = acc.Level.ToString();
                        textBlock_score.Text = acc.Score.ToString();
                        image_ava.Source     = new BitmapImage(new Uri(ImagesClass.NumberImage(acc.Id_ava).ToString(), UriKind.Relative));
                        break;
                    }
                }
                #endregion
            }
            catch (Exception)
            {
                MessageBox.Show("Ошибка! Обратитесь к разработчику", "The Intellect Text", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        int check_access            = 0;                   //для проверки прав пользователя

        public StatisticsWindow()
        {
            InitializeComponent();

            CheckAccess();

            try
            {
                #region Загрузка информации из БД
                if (check_access == 0)
                {
                    foreach (var login in itestentities.Accounts)
                    {
                        if (login.Id == SetClass.Id)
                        {
                            textBlock_nick.Text  += login.Login;
                            textBlock_level.Text += login.Level;
                            textBlock_score.Text += login.Score;
                            image_ava.Source      = new BitmapImage(new Uri(ImagesClass.NumberImage(login.Id_ava).ToString(), UriKind.Relative));
                            break;
                        }
                    }
                }
                else
                {
                    Title = "The Intellect Test | Подробные данные";
                    textBlock_stu.Text = "Данные";

                    foreach (var login in itestentities.Accounts)
                    {
                        if (login.Id == SetClass.Id)
                        {
                            textBlock_nick.Text        += login.Login;
                            textBlock_level.Opacity     = 0;
                            textBlock_score.Opacity     = 0;
                            textBlock_stuthemes.Opacity = 0;
                            Bordinf.Opacity             = 0;
                            image_ava.Source            = new BitmapImage(new Uri(ImagesClass.NumberImage(login.Id_ava).ToString(), UriKind.Relative));
                            break;
                        }
                    }
                }
                #endregion

                #region Обработка статистики
                List <int> Themes = new List <int>(); //создаём List и записываем в него Id каждой темы
                foreach (var themes in itestentities.Themes)
                {
                    Themes.Add(themes.Id);
                }

                int[] maxwordsTheme = new int[Themes.Count]; //создаём массив и записываем в него кол-во слов в каждой теме
                for (int i = 0; i < Themes.Count; i++)
                {
                    foreach (var wtheme in itestentities.Words)
                    {
                        if (Themes[i] == wtheme.Id_themes)
                        {
                            maxwordsTheme[i]++;
                        }
                    }
                }

                int[] mySection = new int[3]; int j = -1;       //создаём массив и переменную, массив для записи кол-ва слов в каждом разделе, переменную для условия в цикле

                if (check_access == 0)                          //пользователь
                {
                    int[] mywordsTheme = new int[Themes.Count]; //создаём массив и записываем кол-во слов каждой темы из словаря
                    for (int i = 0; i < Themes.Count; i++)
                    {
                        foreach (var wtheme in itestentities.Words)
                        {
                            foreach (var mywords in itestentities.My_Dictionary)
                            {
                                if (SetClass.Id == mywords.Id_account && mywords.Id_word == wtheme.Id && Themes[i] == wtheme.Id_themes)
                                {
                                    mywordsTheme[i]++; break;
                                }
                            }
                        }
                    }

                    while (j < mySection.Length) //вычисляем кол-во изученных слов в каждом разделе
                    {
                        foreach (var section in itestentities.Section)
                        {
                            j++;
                            if (j < 3)
                            {
                                for (int i = 0; i < Themes.Count; i++)
                                {
                                    foreach (var themes in itestentities.Themes)
                                    {
                                        if (Themes[i] == themes.Id && themes.Id_section == section.Id)
                                        {
                                            mySection[j] += mywordsTheme[i]; break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    int check_stu = 0;
                    for (int i = 0; i < Themes.Count; i++) //при всех правильных ответах одной темы меняется значение
                    {
                        if (maxwordsTheme[i] == mywordsTheme[i] && maxwordsTheme[i] != 0)
                        {
                            check_stu++;
                        }
                    }
                    textBlock_stuthemes.Text += check_stu;

                    foreach (var themes in itestentities.Themes) //добавление изученных слов по тематикам
                    {
                        for (int i = 0; i < Themes.Count; i++)
                        {
                            if (themes.Id == Themes[i] && themes.Name == textBlock_phil.Text)
                            {
                                textBlock_phil.Text += string.Format(": {0}", mywordsTheme[i]);
                            }
                            else if (themes.Id == Themes[i] && themes.Name == textBlock_rus.Text)
                            {
                                textBlock_rus.Text += string.Format(": {0}", mywordsTheme[i]);
                            }
                            else if (themes.Id == Themes[i] && themes.Name == textBlock_bio.Text)
                            {
                                textBlock_bio.Text += string.Format(": {0}", mywordsTheme[i]);
                            }
                            else if (themes.Id == Themes[i] && themes.Name == textBlock_it.Text)
                            {
                                textBlock_it.Text += string.Format(": {0}", mywordsTheme[i]);
                            }
                        }
                    }
                }
                else //администратор
                {
                    while (j < mySection.Length) //вычисляем кол-во слов в каждом разделе
                    {
                        foreach (var section in itestentities.Section)
                        {
                            j++;
                            if (j < 3)
                            {
                                for (int i = 0; i < Themes.Count; i++)
                                {
                                    foreach (var themes in itestentities.Themes)
                                    {
                                        if (Themes[i] == themes.Id && themes.Id_section == section.Id)
                                        {
                                            mySection[j] += maxwordsTheme[i]; break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    foreach (var themes in itestentities.Themes) //отображение изученных слов по тематикам
                    {
                        for (int i = 0; i < Themes.Count; i++)
                        {
                            if (themes.Id == Themes[i] && themes.Name == textBlock_phil.Text)
                            {
                                textBlock_phil.Text += string.Format(": {0}", maxwordsTheme[i]);
                            }
                            else if (themes.Id == Themes[i] && themes.Name == textBlock_rus.Text)
                            {
                                textBlock_rus.Text += string.Format(": {0}", maxwordsTheme[i]);
                            }
                            else if (themes.Id == Themes[i] && themes.Name == textBlock_bio.Text)
                            {
                                textBlock_bio.Text += string.Format(": {0}", maxwordsTheme[i]);
                            }
                            else if (themes.Id == Themes[i] && themes.Name == textBlock_it.Text)
                            {
                                textBlock_it.Text += string.Format(": {0}", maxwordsTheme[i]);
                            }
                        }
                    }
                }

                foreach (var section in itestentities.Section) //отображение кол-во слов в разделах
                {
                    for (int i = 0; i < mySection.Length; i++)
                    {
                        if (i == 0 && section.Name == textBlock_gen.Text)
                        {
                            textBlock_gen.Text += string.Format(": {0}", mySection[i]);
                        }
                        else if (i == 1 && section.Name == textBlock_spec.Text)
                        {
                            textBlock_spec.Text += string.Format(": {0}", mySection[i]);
                        }
                        else if (i == 2 && section.Name == textBlock_user.Text)
                        {
                            textBlock_user.Text += string.Format(": {0}", mySection[i]);
                        }
                    }
                }
                #endregion
            }
            catch (Exception)
            {
                MessageBox.Show("Ошибка! Обратитесь к разработчику", "The Intellect Text", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 3
0
        ITestEntities itestentities = new ITestEntities(); //подключение БД

        public AdminWindow()
        {
            InitializeComponent();

            try
            {
                int check_save = 0;

                #region Загрузка информации из БД
                foreach (var acc in itestentities.Accounts)
                {
                    if (acc.Id == SetClass.Id)
                    {
                        textBlock_nick.Text = acc.Login;
                        image_ava.Source    = new BitmapImage(new Uri(ImagesClass.NumberImage(acc.Id_ava).ToString(), UriKind.Relative));
                        break;
                    }
                }
                #endregion

                #region Очистка данных
                check_save = 0;
                foreach (var acc in itestentities.Accounts)
                {
                    if (acc.Id == SetClass.Id)
                    {
                        acc.Level = 0; acc.Score = 0; check_save++;
                    }
                }

                if (check_save == 0)
                {
                    itestentities.SaveChanges();
                }
                #endregion

                #region Кол-во пользоватлей
                int users = 0;
                foreach (var userss in itestentities.Accounts)
                {
                    users++;
                }
                textBlock_users.Text += users;
                #endregion

                #region Кол-во разделов
                int section = 0;
                foreach (var sectionn in itestentities.Section)
                {
                    section++;
                }
                textBlock_section.Text += section;
                #endregion

                #region Кол-во тематик
                int themes = 0;
                foreach (var themess in itestentities.Themes)
                {
                    themes++;
                }
                textBlock_themes.Text += themes;
                #endregion

                #region Кол-во слов
                int words = 0;
                foreach (var wordss in itestentities.Words)
                {
                    words++;
                }
                textBlock_words.Text += words;
                #endregion
            }
            catch (Exception)
            {
                MessageBox.Show("Ошибка! Обратитесь к разработчику", "The Intellect Text", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }