private void CheckAnswer(object obj) { List <Question> listAnswers = new List <Question>(); string questions = string.Empty; string answers = string.Empty; string koeff = string.Empty; foreach (var quest in Questions) { listAnswers.Add(quest); questions += quest.QuestionId + ","; answers += quest.Answer + ","; var ans = _repo.GetTrueAnswer(quest); koeff += ans + ","; } var mark = _repo.CheckAnswer(listAnswers); MessageBox.Show($"Вы заработали {mark} баллов", "Оценка", MessageBoxButton.OK, MessageBoxImage.Information); var studProgress = new StudentProgress { StudentId = UserId, Mark = mark, TestId = _test.TestId, Questions = questions, Answers = answers, Koeff = koeff }; _repo.AddMark(studProgress); }
public KoeffVM(StudentProgress progress, IRepo repo) { _repo = repo; GetKoeff(progress); Paint(); }
/// <summary> /// Get a student user from the database /// </summary> /// <param name="username">Username of the student</param> /// <returns>A student object with the necessary values</returns> internal static Student Get(string username) { using (SQLiteConnection conn = new SQLiteConnection("Data source=" + Database.DATABASE_NAME + ";")) { try { conn.Open(); string name, surname; int level; using (SQLiteCommand cmd = new SQLiteCommand(conn)) { cmd.CommandText = "SELECT * FROM users WHERE username=@username;"; cmd.Parameters.AddWithValue("@username", username); using (SQLiteDataReader reader = cmd.ExecuteReader()) { if (!reader.HasRows) { return(null); } reader.Read(); name = reader.GetString(reader.GetOrdinal("name")); surname = reader.GetString(reader.GetOrdinal("surname")); } } using (SQLiteCommand cmd = new SQLiteCommand(conn)) { cmd.CommandText = "SELECT * FROM students WHERE username=@username;"; cmd.Parameters.AddWithValue("@username", username); using (SQLiteDataReader reader = cmd.ExecuteReader()) { reader.Read(); level = reader.GetInt32(reader.GetOrdinal("level")); } } StudentProgress progress = StudentProgressMapper.Get(username); Student student = new Student(username, name, surname, level, progress); return(student); } catch (Exception e) { Console.WriteLine("Exception at StudentMapper - Get: " + e.Message); return(null); } } }
public void AddMark(StudentProgress progress) { var stud = db.StudProgress.FirstOrDefault(x => x.StudentId == progress.StudentId && x.TestId == progress.TestId); if (stud != null) { stud.Mark = progress.Mark; stud.Questions = progress.Questions; stud.Answers = progress.Answers; } else { db.StudProgress.Add(progress); } db.SaveChanges(); }
/// <summary> /// Get a student's progress from the database /// </summary> /// <param name="username">Username of the student</param> /// <returns>A StudentProgress object with the necessary values</returns> internal static StudentProgress Get(string username) { using (SQLiteConnection conn = new SQLiteConnection("Data source=" + Database.DATABASE_NAME + ";")) { try { conn.Open(); using (SQLiteCommand cmd = new SQLiteCommand(conn)) { cmd.CommandText = "SELECT * FROM studentProgress WHERE username=@username;"; cmd.Parameters.AddWithValue("@username", username); using (SQLiteDataReader reader = cmd.ExecuteReader()) { // Because we search with username which is unique if (reader.HasRows) { reader.Read(); List <int> prop = new List <int>(); for (int i = 1; i <= 10; i++) { int temp = reader.GetInt32(reader.GetOrdinal("propaideia" + i.ToString())); prop.Add(temp); } int final = reader.GetInt32(reader.GetOrdinal("finalExam")); StudentProgress progress = new StudentProgress(username, prop, final); return(progress); } else { return(null); } } } } catch (Exception e) { Console.WriteLine("Exception at ProgressReportMapper - Get: " + e.Message); return(null); } } }
/// <summary> /// Updates a student's progress in the database /// </summary> /// <param name="progress">Progress object to be updated.</param> /// <returns>True if operation is successful</returns> internal static bool Update(StudentProgress progress) { using (SQLiteConnection conn = new SQLiteConnection("Data source=" + Database.DATABASE_NAME + ";")) { try { conn.Open(); using (SQLiteCommand cmd = new SQLiteCommand(conn)) { cmd.CommandText = "UPDATE studentProgress SET propaideia1=@propaideia1," + "propaideia2=@propaideia2," + "propaideia3=@propaideia3," + "propaideia4=@propaideia4," + "propaideia5=@propaideia5," + "propaideia6=@propaideia6," + "propaideia7=@propaideia7," + "propaideia8=@propaideia8," + "propaideia9=@propaideia9," + "propaideia10=@propaideia10," + "finalExam=@finalExam " + "WHERE username=@username;"; cmd.Parameters.AddWithValue("@username", progress.Username); for (int i = 1; i <= 10; i++) { cmd.Parameters.AddWithValue("@propaideia" + i.ToString(), progress.PropaideiaProgress[i - 1]); } cmd.Parameters.AddWithValue("@finalExam", progress.FinalExam); cmd.ExecuteNonQuery(); } return(true); } catch (Exception e) { Console.WriteLine("Exception at StudentProgressMapper - Update: " + e.Message); return(false); } } }
/// <summary> /// Deletes a student's progress /// </summary> /// <param name="progress">Data of the student's progress to be deleted</param> /// <returns>True if operation is successful</returns> internal static bool Delete(StudentProgress progress) { using (SQLiteConnection conn = new SQLiteConnection("Data source=" + Database.DATABASE_NAME + ";")) { try { conn.Open(); using (SQLiteCommand cmd = new SQLiteCommand(conn)) { cmd.CommandText = "DELETE FROM studentProgress WHERE username=@username;"; cmd.Parameters.AddWithValue("@username", progress.Username); cmd.ExecuteNonQuery(); } return(true); } catch (Exception e) { Console.WriteLine("Exception at StudentProgress - Delete: " + e.Message); return(false); } } }
public IList <StudentProgress> GetAllStudentProgress(int courseId) { IList <StudentProgress> students = new List <StudentProgress>(); using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); string SQL = "select sli.StudentId, count(sli.StudentId) completed "; SQL += "from StudentLineItem sli "; SQL += "inner join CurriculaLineItem cli on "; SQL += " cli.Id = sli.CurriculaLineItemId "; SQL += "inner join Curricula curr on "; SQL += " curr.Id = cli.CurriculaId "; SQL += "inner join Course c on "; SQL += " c.Id = curr.CourseId "; SQL += "where c.Id = @courseId "; SQL += "group by sli.StudentId "; SqlCommand cmd = new SqlCommand(SQL, conn); cmd.Parameters.AddWithValue("@courseId", courseId); var reader = cmd.ExecuteReader(); while (reader.Read()) { var student = new StudentProgress() { StudentId = Convert.ToInt32(reader["StudentId"]), CoursesComplete = Convert.ToInt32(reader["completed"]), }; students.Add(student); } } return(students); }
private void GetKoeff(StudentProgress progress) { var test = _repo.GetTests(progress.TestId); var studKoeffs = new List <bool>(); var testKoeffs = new List <double>(); foreach (var koeff in progress.Koeff.Split(',')) { if (!string.IsNullOrEmpty(koeff)) { studKoeffs.Add(bool.Parse(koeff)); } } foreach (var koeff in test.Koeff.Split(',')) { if (!string.IsNullOrEmpty(koeff)) { var num = koeff.Replace('.', ','); testKoeffs.Add(double.Parse(num)); } } var list = new List <double>(); foreach (var koeff in studKoeffs) { if (koeff) { foreach (var koef in testKoeffs) { list.Add(koef); } } else { for (int i = 0; i < 5; i++) { list.Add(0); } } } var a = new List <double>(); var b = new List <double>(); var c = new List <double>(); var d = new List <double>(); var f = new List <double>(); for (int i = 0; i < testKoeffs.Count; i++) { var lists = list.Skip(i).Take(5).Sum(); for (int j = 0; j < 5; j++) { switch (i) { case 0: a.Add(list[i]); break; case 1: b.Add(list[i]); break; case 2: c.Add(list[i]); break; case 3: d.Add(list[i]); break; case 4: f.Add(list[i]); break; } } } A = a.Sum() / a.Count; B = b.Sum() / b.Count; C = c.Sum() / c.Count; D = d.Sum() / d.Count; F = f.Sum() / f.Count; }
public DetailsVM(string student, StudentProgress prog, IRepo repo) { Student = student; _repo = repo; GetAnswers(prog); }
private void AddMainInfo_btn_Click(object sender, EventArgs e) // Add main info student { try { using (StudentsServiceAppClient client = new StudentsServiceAppClient()) { Phone newPhone = new Phone(); newPhone.PhoneNumber = MobTelField.Text; List <Phone> phone = new List <Phone>(); phone.Add(newPhone); StudentProgress newProgress = new StudentProgress(); newProgress.Progress = float.Parse(ProgressAddField.Text); Adress newAdress = new Adress(); newAdress.Address = AddressAddField.Text; Group newGroup = new Group(); newGroup.Speciality = GroupAddField.Text; Phone newParentsPhone = new Phone(); newParentsPhone.PhoneNumber = PhonesRelatonsAddFielad.Text; List <Phone> relationsPhones = new List <Phone>(); relationsPhones.Add(newParentsPhone); ParentsInfo newMotheInfo = new ParentsInfo(); ParentsInfo newFatherInfo = new ParentsInfo(); Relation newRelationInfo = new Relation(); newRelationInfo.Name = RelationField.Text; newMotheInfo.FirstName = MotherNameField.Text; newMotheInfo.LastName = MotherLastNameField.Text; newMotheInfo.WorkPlace = MotherWorkPlace.Text; newMotheInfo.Relation = newRelationInfo; newMotheInfo.Phones = relationsPhones; newFatherInfo.FirstName = FatherNameField.Text; newFatherInfo.LastName = FatherLastNameField.Text; newFatherInfo.WorkPlace = FatherWorkPlaseField.Text; newFatherInfo.Relation = newRelationInfo; List <ParentsInfo> parents = new List <ParentsInfo>(); parents.Add(newMotheInfo); parents.Add(newFatherInfo); //parents.Add(newRelationInfo); StudentInfo newStudentInfo = new StudentInfo { FirstName = NameField.Text, LastName = LastNameField.Text, Surname = surnameAddField.Text, NumberRecordBook = Convert.ToInt32(NumbRecBookAddField.Text), Sex = SexField.Text, Age = Convert.ToInt32(AgeField.Text), Birthdate = DateTime.Parse(DateOfBirthField.Text), StudentPhones = phone, StudentProgress = newProgress, Adress = newAdress, Group = newGroup, ParentsInfo = parents, }; client.AddNewStudent(newStudentInfo); client.Close(); } string message = "Студент був доданий"; string caption = "Додання студента до БД"; MessageBoxButtons button = MessageBoxButtons.OK; MessageBox.Show(message, caption, button); } catch (Exception ex) { string message = ex.Message; string caption = "Помилка!"; MessageBoxButtons button = MessageBoxButtons.OK; MessageBox.Show(message, caption, button); } }