public static Dictionary <Model.Subject, Model.Teacher> GetTeacherWithSubjectBySection(int idSection) { Dictionary <Model.Subject, Model.Teacher> dictionnary = new Dictionary <Model.Subject, Model.Teacher>(); if (Connect()) { string sql = "SELECT teacher.*, subject.* FROM teacher, link, subject WHERE teacher.id = link.id_teacher ANd link.id_subject = subject.id AND link.id_section = @id"; SqlParameter idParam = new SqlParameter("@id", idSection); DataTable dataTable = ExecuteQuery(sql, idParam); foreach (DataRow dataRow in dataTable.Rows) { //dictionnary.Add(dataRow.ItemArray[4], dataRow.ItemArray[1] + " " + dataRow.ItemArray[2]); Model.Subject subject = new Model.Subject(); subject.Id = (int)dataRow.ItemArray[3]; subject.Name = (string)dataRow.ItemArray[4]; Model.Teacher teacher = new Model.Teacher(); teacher.Id = (int)dataRow.ItemArray[0]; teacher.FirstName = (string)dataRow.ItemArray[1]; teacher.LastName = (string)dataRow.ItemArray[2]; dictionnary.Add(subject, teacher); } } Close(); return(dictionnary); }
private void BindData(int id) { List <Model.Subject> sub = new List <Model.Subject>(); var s = _repository.GetSubject(id); var ss = s.Select(x => x.Subjects).ToList(); ss.ForEach(x => { x.ForEach(y => { Model.Subject subj = new Model.Subject(); subj.Id = y.Id; subj.SubjectName = y.SubjectName; subj.InstructorName = y.InstructorName; subj.SubjectTimeFrom = y.SubjectTimeFrom; subj.SubjectTimeTo = y.SubjectTimeTo; subj.RoomNumber = y.RoomNumber; sub.Add(subj); }); } ); GridView1.DataSource = sub.ToList(); GridView1.DataBind(); }
public void OnSubjectSelection() { // Get selected subject currentSubject = data.Subjects.Where(x => x.subject_id == view.SelectedSubjectID).Single(); PrepareDataForView(); view.GradesRadioButtonEnabledState = true; view.NotesRadioButtonEnabledState = true; if (view.SelectedGradesView) { view.AverageGradeButtonEnabled = true; } }
public static Model.Subject GetOne(int id) { Model.Subject model = null; if (Connect()) { string sql = "SELECT * FROM subject WHERE id=@id"; SqlParameter idParam = new SqlParameter("@id", id); DataTable dataTable = ExecuteQuery(sql, idParam); foreach (DataRow dataRow in dataTable.Rows) { model = new Model.Subject(); model.Id = int.Parse(dataRow["id"].ToString()); model.Name = dataRow["name"].ToString(); } } Close(); return(model); }
public bool InsertSubject(StudentViewModel student) { bool inserted = false; using (StudentDbContext _context = new StudentDbContext()) { Student _student = new Student(); Model.Subject s = new Model.Subject(); using (var trans = _context.Database.BeginTransaction()) { try { Student stud = _context.Students.FirstOrDefault(x => x.Id == student.StudentId); stud.Subjects = new List <Model.Subject>(); if (stud != null) { s.SubjectName = student.SubjectName; s.InstructorName = student.InstructorName; s.RoomNumber = student.Roomno; s.SubjectTimeFrom = student.SubjTimeFrom; s.SubjectTimeTo = student.SubjTimeTo; } stud.Subjects.Add(s); _context.SaveChanges(); trans.Commit(); inserted = true; } catch (DbEntityValidationException) { trans.Rollback(); return(false); } } } return(inserted); }
public static List <Model.Subject> GetTeacherSubjectList(int idTeacher) { List <Model.Subject> subjectList = new List <Model.Subject>(); if (Connect()) { string sql = $"SELECT subject.* FROM subject, teacher_subject, teacher WHERE subject.Id=teacher_subject.Id_subject AND teacher_subject.Id_teacher = teacher.Id AND teacher.Id = @id"; SqlParameter idParam = new SqlParameter("@id", idTeacher); DataTable dataTable = ExecuteQuery(sql, idParam); foreach (DataRow dataRow in dataTable.Rows) { Model.Subject model = new Model.Subject(); model.Id = int.Parse(dataRow["id"].ToString()); model.Name = dataRow["name"].ToString(); subjectList.Add(model); } } return(subjectList); }
public static List <Model.Subject> GetSectionSubjectList(int idSection) { List <Model.Subject> subjectList = new List <Model.Subject>(); if (Connect()) { string sql = $"SELECT subject.* FROM subject, section_subject" + $" WHERE subject.id=section_subject.id_subject" + $" AND section_subject.id_section=@id"; SqlParameter idParam = new SqlParameter("@id", idSection); DataTable dataTable = ExecuteQuery(sql, idParam); foreach (DataRow dataRow in dataTable.Rows) { Model.Subject model = new Model.Subject(); model.Id = int.Parse(dataRow["id"].ToString()); model.Name = dataRow["name"].ToString(); subjectList.Add(model); } } return(subjectList); }
public static List <Model.Subject> GetAll(Predicate <Model.Subject> filter = null) { List <Model.Subject> list = new List <Model.Subject>(); if (Connect()) { string sql = "SELECT * FROM subject"; DataTable dataTable = ExecuteQuery(sql); foreach (DataRow dataRow in dataTable.Rows) { Model.Subject model = new Model.Subject(); model.Id = int.Parse(dataRow["id"].ToString()); model.Name = dataRow["name"].ToString(); list.Add(model); } } Close(); if (filter != null) { list = list.FindAll(filter); } return(list); }
private void AddSubjectDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { ///// Validate Data. ///// Make Object. Model.Subject subject = new Model.Subject(); subject.Name = SubName.Text; subject.attended = (int)AttendList.SelectedItem; subject.held = (int)HeldList.SelectedItem; subject.minreq = (int)PercentReq.SelectedItem; subject.updateNow(); ///// Add into Database. try { var path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "App.db"); var db = new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path); db.CreateTable<Model.Subject>(); db.Insert(subject); RefreshView(); } catch (Exception) { throw; } }
public Model.Subject Update(Model.Subject subjects) { SubjectRepository s = new(new CollegeDBContext()); return(s.Update(subjects)); }
public int Insert(Model.Subject subjects) { SubjectRepository s = new(new CollegeDBContext()); return(s.Insert(subjects)); }
public void OnSaveClick() { string typeOfProfile = view.typeOfProfile; var regexString = new Regex("^[А-я]+$"); var regexInt = new Regex("^[0-9]+$"); var regexPassword = new Regex("^.{8,25}$"); var regexUserName = new Regex("^[A-Za-z0-9_]+$"); Random random = new Random(); int randomNum = random.Next(); switch (typeOfProfile) { case "Учител": if (view.UserNameTextBox != string.Empty && view.TextBoxSubject != string.Empty && view.FirstNTextBox != string.Empty && view.LastNTextBox != string.Empty && view.Password != string.Empty && regexString.IsMatch(view.FirstNTextBox) && regexString.IsMatch(view.LastNTextBox) && regexString.IsMatch(view.TextBoxSubject) && regexUserName.IsMatch(view.UserNameTextBox)) { var existingTeacher = data.Teachers.Where(x => x.username == view.UserNameTextBox).SingleOrDefault(); if (existingTeacher != null) { view.Message("Това потребителско име вече е заето. Моля, изберете друго.", "Внимание", Views.MessageIcon.Warning); return; } if (!regexPassword.IsMatch(view.Password)) { view.Message("Паролата трябва да е с дължина между 8 и 25 символа.", "Внимание", Views.MessageIcon.Warning); return; } Utilities.IPasswordHash passHasher = new Utilities.PasswordHash(); var passHash = passHasher.Generate(view.PasswordTextBox.ToString()); var teacher = new Model.Teacher() { username = view.UserNameTextBox, teacher_firstN = view.FirstNTextBox, teacher_lastN = view.LastNTextBox, password_hash = passHash }; data.Teachers.Add(teacher); var teacherid = teacher.teacher_id; var subject = new Model.Subject() { subject_name = view.TextBoxSubject, teacher_id = teacherid }; data.Subjects.Add(subject); } else { view.Message("Моля попълнете всички полета коректно.", "Грешка", Views.MessageIcon.Error); return; } break; case "Ученик": if (view.ComboBoxGrade != null && view.FirstNTextBox != string.Empty && view.LastNTextBox != string.Empty && view.PINTextBox != string.Empty && regexInt.IsMatch(view.PINTextBox) && regexString.IsMatch(view.FirstNTextBox) && regexString.IsMatch(view.LastNTextBox)) { var student = new Model.Student() { student_firstN = view.FirstNTextBox, student_lastN = view.LastNTextBox, grade = view.ComboBoxGrade, student_PIN = view.PINTextBox, code = randomNum.ToString() }; data.Students.Add(student); } else { view.Message("Моля попълнете всички полета коректно.", "Грешка", Views.MessageIcon.Error); return; } break; } try { data.SaveChanges(); if (typeOfProfile == "Учител") { view.Message("Успешно направен профил на учител!", "Успех", Views.MessageIcon.Information); } else { view.Message(String.Format("Успешно направен профил на ученик с код: {0}", randomNum.ToString()), "Успех", Views.MessageIcon.Information); string path = "StudentsProfiles.txt"; string studentInfo = String.Concat(view.PINTextBox + " ", view.FirstNTextBox + " ", view.LastNTextBox + " ", randomNum.ToString(), "\n"); File.AppendAllText(path, studentInfo); } view.ClearText(); } catch (Exception) { view.Message("В момента изпитваме технически затруднения. Възможно е вашите промени да не са запазени. Моля, опитайте отново по-късно. Съжаляваме за причененото неудобство.", "Грешка", Views.MessageIcon.Error); return; } }
public void Put(Model.Subject subjects) { Business.Subject c = new(); c.Update(subjects); }
public void Post(Model.Subject subjects) { Business.Subject c = new(); c.Insert(subjects); }
public static void FillCollections() { //read file var reader = new StreamReader(File.OpenRead(@"Teacher.csv")); //create object Teachers = new List <Teacher>(); bool ignoreLine = true; string[] word; while (!reader.EndOfStream) { var line = reader.ReadLine(); word = line.Split(','); if (ignoreLine) { ignoreLine = false; continue; } //pass parameters into object Model.Teacher Teacher1 = new Model.Teacher(int.Parse(word[0]), word[1], word[2]); Teachers.Add(Teacher1); //add collection into object } { //reade subject file var S1 = new StreamReader(File.OpenRead(@"Subject.csv")); Subjects = new List <Subject>(); bool L2 = true; string[] subword; while (!S1.EndOfStream) { var line = S1.ReadLine(); subword = line.Split(','); if (L2) { L2 = false; continue; } Model.Subject Subject1 = new Model.Subject(int.Parse(subword[0]), subword[1]); Subjects.Add(Subject1); } { //reade tutorial file var T1 = new StreamReader(File.OpenRead(@"Tutorial.csv")); Tutorials = new List <Tutorial>(); bool L3 = true; string[] TWord; while (!T1.EndOfStream) { var line = T1.ReadLine(); TWord = line.Split(','); if (L3) { L3 = false; continue; } if (TWord.Length == 4) { System.Console.WriteLine(line); Model.Tutorial Tutorial1 = new Model.Tutorial(int.Parse(TWord[0]), int.Parse(TWord[1]), int.Parse(TWord[2]), int.Parse(TWord[3])); Tutorials.Add(Tutorial1); } } } } }