public StudentsView(Student s) { InitializeComponent(); db = new AspireDB(); stud = db.Students.SingleOrDefault(Student => Student.ID == s.ID); student_name.Text = s.Name; student_id.Text = s.StudentID; course_name.Text = s.Course.Name; }
private void deletebtn_Click(object sender, EventArgs e) { AspireDB db = new AspireDB(); Subject x = db.Subjects.SingleOrDefault(Subjects => Subjects.SubjectID == su.SubjectID && Subjects.Name == su.Name && Subjects.CourseID == su.CourseID); db.Subjects.Remove(x); db.SaveChanges(); SubjectControl.Instance.FooterMessage("Subject Deleted"); SubjectControl.Instance.CreateList(); }
private void saveimgbtn_Click(object sender, EventArgs e) { AspireDB db = new AspireDB(); db.Configuration.ProxyCreationEnabled = false; List <Level> cour = db.Levels.ToList(); String str = HelpMe.GetJson(cour); Console.Write(str); HelpMe.SaveFileNow(str, "Levels"); }
public void CreateList() { if (levels_layout.Controls.Count > 0) { levels_layout.Controls.Clear(); } AspireDB db = new AspireDB(); List <Level> clist = db.Levels.ToList(); foreach (Level lvl in clist) { LevelView lv = new LevelView(lvl); levels_layout.Controls.Add(lv); } db.Database.Connection.Close(); }
private void deletebtn_Click(object sender, EventArgs e) { MsgBoxDialog md = new MsgBoxDialog(); DialogResult result = md.Showw("Deleting Course Will Delete following data as well!\n1. All the Student with same course.\n2. All the Subjects within the course."); if (result == DialogResult.OK) { AspireDB db = new AspireDB(); Course x = db.Courses.SingleOrDefault(Course => Course.CourseID == _cs.CourseID && Course.Name == _cs.Name && Course.Level == _cs.Level); // Deleting Cources foreach (Subject s in db.Subjects.Where(Subject => Subject.CourseID == x.CourseID)) { db.Entry(s).State = System.Data.Entity.EntityState.Deleted; } db.SaveChanges(); // Deleting Students foreach (Student s in db.Students.Where(Student => Student.CourseID == x.CourseID)) { db.Entry(s).State = System.Data.Entity.EntityState.Deleted; } db.SaveChanges(); // Deleting Course db.Entry(x).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); // SubjectControl.Instance.CreateList(); SubjectControl.Instance.FilterBoxUpdate(); SubjectControl.Instance.FooterMessage(x.Name + " Deleted -> Subjects Deleted "); StudentControl.Instance.CreateList(); StudentControl.Instance.FooterMessage(x.Name + " Deleted -> Students Deleted "); CourseControl.Instance.FooterMessage("Course Deleted"); CourseControl.Instance.CreateList(); } else { } }
private void loadimgbtn_Click(object sender, EventArgs e) { // Opens File and match extension -> If Extension do not match it shows msg string json = HelpMe.OpenFileNow("Levels"); // Load Data from Json File Opened List <Level> css = HelpMe.GetDataFromJson <Level>(json); AspireDB db = new AspireDB(); db.Levels.SqlQuery(" DBCC CHECKIDENT('Course', RESEED, 0)"); int count = 0; foreach (Level s in css) { // Check for Exsisting Subjects if (db.Levels.Count(x => x.LevelName == s.LevelName) <= 0) { db.Levels.Add(s); count++; } } string msg; try { db.SaveChanges(); msg = "File Loaded ( " + count + " Rows Added )"; } catch (Exception ee) { count = 0; msg = "File Not Loaded"; new MsgBox("Invalid File"); MessageBox.Show(ee.Message); } //Update list and Show Footer Message LevelControl.Instance.CreateList(); LevelControl.Instance.FooterMessage(msg); }
private void Addcoursebtn_Click(object sender, EventArgs e) { if (ValidateChildren()) { AspireDB db = new AspireDB(); Level lvl = new Level(); string hash = level_name.Text.ToString(); Level got = db.Levels.SingleOrDefault(x => x.LevelName == hash); if (got != null) { new MsgBox("Duplicate entry"); return; } lvl.LevelName = level_name.Text.ToString(); db.Levels.Add(lvl); db.SaveChanges(); message.Text = "Done"; LevelControl.Instance.CreateList(); LevelControl.Instance.FooterMessage("Course Added"); } }
private void deletebtn_Click(object sender, EventArgs e) { MsgBoxDialog md = new MsgBoxDialog(); DialogResult result = md.Showw("Are you sure ?"); if (result == DialogResult.OK) { try { AspireDB db = new AspireDB(); Level l = db.Levels.SingleOrDefault(x => x.LevelName == _lvl.LevelName); db.Levels.Remove(l); db.SaveChanges(); LevelControl.Instance.CreateList(); LevelControl.Instance.FooterMessage(l.LevelName + " Deleted"); } catch (Exception ee) { MsgBoxDialog md2 = new MsgBoxDialog(); DialogResult res = md2.Showw("Failed to Delete Level !"); } } }