private void button1_Click(object sender, EventArgs e) { PupilGroup pupilGroup = (PupilGroup)comboBox1.SelectedItem; int selectedIndex = comboBox1.SelectedIndex; switch (mode) { case 1: DBWork.deleteUsersFromPupilGroup(pupilGroup.Id); comboBox1.SelectedIndex = 0; comboBox1.Items.RemoveAt(selectedIndex); System.Windows.Forms.MessageBox.Show("Данные удалены"); break; case 2: String passwords = DBWork.getUserPasswords(pupilGroup.Id); if (saveFileDialog.ShowDialog() == DialogResult.Cancel) { return; } String filename = saveFileDialog.FileName; System.IO.File.WriteAllText(filename, passwords); break; } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); DBWork.Init(); loginForm = new LoginForm(); Application.Run(loginForm); }
private void EndTestButton_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex > 0 && comboBox2.SelectedIndex > 0 && comboBox3.SelectedIndex > 0 && comboBox4.SelectedIndex > 0 && comboBox5.SelectedIndex > 0) { if (checkUniqueIds()) { List <Int32> questionAnswers = new List <Int32>(); questionAnswers.Add(((User)comboBox1.SelectedItem).Id); questionAnswers.Add(((User)comboBox2.SelectedItem).Id); questionAnswers.Add(((User)comboBox3.SelectedItem).Id); questionAnswers.Add(((User)comboBox4.SelectedItem).Id); questionAnswers.Add(((User)comboBox5.SelectedItem).Id); answers.Add(new Answer(currentUser.Id, currentQuestionIndex + 1, questionAnswers)); currentQuestionIndex++; if (currentQuestionIndex == 4) { EndTestButton.Text = "Завершить"; } if (currentQuestionIndex < 5) { TextQuestion.Text = questions.ElementAt(currentQuestionIndex).ToString(); comboBox1.SelectedIndex = 0; comboBox2.SelectedIndex = 0; comboBox3.SelectedIndex = 0; comboBox4.SelectedIndex = 0; comboBox5.SelectedIndex = 0; } else { try { DBWork.commitAnswers(answers); System.Windows.Forms.MessageBox.Show("Спасибо за прохождение теста!"); Program.returnToLoginForm(); this.Close(); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Ошибка при сохранении результатов! Обратитесь к администратору"); Program.returnToLoginForm(); this.Close(); } } } else { System.Windows.Forms.MessageBox.Show("Все ответы должны отличаться друг от друга"); } } else { System.Windows.Forms.MessageBox.Show("Выберите варианты во всех пяти ответах"); } }
private void loadClassmates() { List <User> users = DBWork.getClassmates(currentUser.ClassId); User defaultUser = new User(0, 0, "Выберите одноклассника", 0, 0); this.comboBox1.Items.Add(defaultUser); foreach (User user in users) { if (currentUser.Id != user.Id) { this.comboBox1.Items.Add(user); } } ; this.comboBox2.Items.Add(defaultUser); foreach (User user in users) { if (currentUser.Id != user.Id) { this.comboBox2.Items.Add(user); } } ; this.comboBox3.Items.Add(defaultUser); foreach (User user in users) { if (currentUser.Id != user.Id) { this.comboBox3.Items.Add(user); } } ; this.comboBox4.Items.Add(defaultUser); foreach (User user in users) { if (currentUser.Id != user.Id) { this.comboBox4.Items.Add(user); } } ; this.comboBox5.Items.Add(defaultUser); foreach (User user in users) { if (currentUser.Id != user.Id) { this.comboBox5.Items.Add(user); } } ; }
private void loadPupilGroups() { pupilGroups = DBWork.getAllPupilGroups(); PupilGroup defaultGroup = new PupilGroup(0, "Все классы", -1); this.comboBox1.Items.Add(defaultGroup); foreach (PupilGroup group in pupilGroups) { this.comboBox1.Items.Add(group); } }
public TeacherForm(User user) { InitializeComponent(); currentUser = user; group = DBWork.getPupilGroup(currentUser.ClassId); this.Text += " " + currentUser.ToString() + " " + group.ToString(); results = new Dictionary <User, List <Answer> >(); totalTests = 0; totalK = 0; N = 0; questions = DBWork.getAllQuestions(); statuses = DBWork.getAllStatuses(); countResults(); fillTable(); saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Text Files(*.txt)|*.txt"; }
public QuestionForm(User user) { InitializeComponent(); currentUser = user; group = DBWork.getPupilGroup(currentUser.ClassId); this.Text += " " + currentUser.ToString() + " " + group.ToString(); questions = DBWork.getAllQuestions(); answers = new List <Answer>(); currentQuestionIndex = 0; loadClassmates(); TextQuestion.Text = questions.ElementAt(currentQuestionIndex).ToString(); comboBox1.SelectedIndex = 0; comboBox2.SelectedIndex = 0; comboBox3.SelectedIndex = 0; comboBox4.SelectedIndex = 0; comboBox5.SelectedIndex = 0; }
private void AddListUsers_Click(object sender, EventArgs e) { if (openFileDialog.ShowDialog() == DialogResult.Cancel) { return; } String filename = openFileDialog.FileName; try { StreamReader reader = new StreamReader(filename); int count = 1; String errorMessage = ""; while (!reader.EndOfStream) { try { String nextLine = reader.ReadLine(); String[] values = nextLine.Split(';'); String fio = values[0] + " " + values[1] + " " + values[2]; int number = Int32.Parse(values[3]); String litera = values[4]; bool isTeacher = false; if (count == 1) { isTeacher = true; } String password = DBWork.generatePassword(6); DBWork.addUser(fio, litera, number, isTeacher, password); } catch (Exception ex) { errorMessage += "\nОшибка в строке " + count; } count++; } System.Windows.Forms.MessageBox.Show("Обработано " + count + " строк " + errorMessage); } catch (IOException ioe) { System.Windows.Forms.MessageBox.Show(ioe.Message); } }
private void processLogin() { int userId = DBWork.loginUser(PasswordInput.Text); if (userId == 0) { System.Windows.Forms.MessageBox.Show("Неверный пароль!"); } else if (userId == 1) { AdminForm adminForm = new AdminForm(); adminForm.Show(); this.Hide(); } else { User user = DBWork.getUserDetails(userId); if (user == null) { System.Windows.Forms.MessageBox.Show("Ошибка логина. Обратитесь к администратору"); } else { if (user.IsTeacher) { TeacherForm teacherForm = new TeacherForm(user); teacherForm.Show(); this.Hide(); } else { QuestionForm questionForm = new QuestionForm(user); questionForm.Show(); this.Hide(); } } } }
private void countResults() { results = DBWork.getAllResultsByTeacher(currentUser); N = results.Count; foreach (User user in results.Keys) { if (results[user].Count == 5) { totalTests++; } } CountUsers.Text = totalTests + ""; foreach (User currentUser in results.Keys) { foreach (User user in results.Keys) { if (currentUser.Id != user.Id) { foreach (Answer answer in results[user]) { if (answer.contains(currentUser.Id)) { if (questions.ElementAt(answer.QuestionId - 1).IsGood) { currentUser.addP(); } else { currentUser.addC(); } } } } } if (currentUser.P > 0) { if (currentUser.P >= currentUser.C) { if ((double)currentUser.C / (double)currentUser.P < 0.5) { currentUser.StatusId = 1; //звезда } else { currentUser.StatusId = 2; //среднестатусный } } else { currentUser.StatusId = 3; //пренебрегаемый } } else { if (currentUser.C == 0) { currentUser.StatusId = 4; //изолируемый } else { currentUser.StatusId = 5; //изгой } } } foreach (User currentUser in results.Keys) { foreach (Answer answer in results[currentUser]) { for (int i = 0; i < answer.Answers.Count; i++) { int userId = answer.getAnswerAt(i); foreach (User user in results.Keys) { if (user.Id == userId) { foreach (Answer userAnswer in results[user]) { if (answer.QuestionId == userAnswer.QuestionId && userAnswer.contains(currentUser.Id)) { totalK++; } } } } } } } Reciprocity.Text = totalK + ""; totalC = (double)totalK / ((double)N * ((double)N - 1) / 2); Welfare.Text = totalC + ""; }