private void deleteButton_Click(object sender, EventArgs e) { if (tutorsListBox.SelectedIndex == -1) { tutorErrorProvider.SetError(deleteButton, "Must select item to delete"); } else { var tutor = (Tutor)tutorsListBox.SelectedItem; var result = MessageBox.Show("Are you sure you want to delete this item", "Delete", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { using (var context = new AttendanceListContext()) { var toDeleteCourseConnection = context.CourseTutors.First(x => x.TutorId == tutor.Id); context.CourseTutors.Remove(toDeleteCourseConnection); var toDelete = context.Tutors.FirstOrDefault(a => a.Id == tutor.Id); context.Tutors.Remove(toDelete); context.SaveChanges(); } } LoadData(_id); } }
private void editButton_Click(object sender, EventArgs e) { if (tutorsListBox.SelectedIndex == -1) { tutorErrorProvider.SetError(editButton, "Must select item to edit"); } else { using (var dialog = new EditTutorForm((Tutor)tutorsListBox.SelectedItem)) { var result = dialog.ShowDialog(); if (result == DialogResult.OK) { var tutorToEdit = dialog.Result; using (var context = new AttendanceListContext()) { var a = context.Tutors.Where(c => c.Id == tutorToEdit.Id).First(); a.Name = tutorToEdit.Name; a.Company = tutorToEdit.Company; context.SaveChanges(); } } } LoadData(_id); } }
private void deleteButton_Click(object sender, EventArgs e) { if (daysOffListBox.SelectedIndex == -1) { nonCourseDayErrorProvider.SetError(deleteButton, "Must select item to delete"); } else { nonCourseDayErrorProvider.SetError(deleteButton, ""); var nonCourseDay = (NonCourseDay)daysOffListBox.SelectedItem; var result = MessageBox.Show("Are you sure you want to delete this item", "Delete", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { using (var context = new AttendanceListContext()) { var toDelete = context.NonCourseDays.FirstOrDefault(a => a.Id == nonCourseDay.Id); context.NonCourseDays.Remove(toDelete); context.SaveChanges(); } } LoadData(_id); } }
private void editButton_Click(object sender, EventArgs e) { if (attendersListBox.SelectedIndex == -1) { attendersErrorProvider.SetError(editButton, "Must select item to edit"); } else { using (var dialog = new EditAttenderForm((Attender)attendersListBox.SelectedItem)) { var result = dialog.ShowDialog(); if (result == DialogResult.OK) { var attenderToEdit = dialog.Result; using (var context = new AttendanceListContext()) { var a = context.Attenders.Where(c => c.Id == attenderToEdit.Id).First(); a.Name = attenderToEdit.Name; a.Address = attenderToEdit.Address; a.Birthdate = attenderToEdit.Birthdate; context.SaveChanges(); } } } LoadData(_id); } }
private void CourseInfoForm_FormClosing(object sender, FormClosingEventArgs e) { if (changed) { // Show messagebox to be sure user wants save changes var result = MessageBox.Show("Do you want to save changes", "Save", MessageBoxButtons.YesNoCancel); if (result == DialogResult.Yes) { using (var context = new AttendanceListContext()) { var info = context.CourseInfoes.First(x => x.Id == _id); context.Entry(info).CurrentValues.SetValues(_course); context.SaveChanges(); } } else if (result == DialogResult.Cancel) { e.Cancel = true; } } }
private void coursesComboBox_SelectedIndexChanged(object sender, EventArgs e) { selectedCourse = (CourseInfo)coursesComboBox.SelectedItem; List <NonCourseDay> daysOff; using (var context = new AttendanceListContext()) { daysOff = context.NonCourseDays .Where(x => x.CourseId == selectedCourse.Id).ToList(); } var dayOff = daysOff.Where(x => x.Date.Value.Date == DateTime.Now.Date).FirstOrDefault(); if (dayOff == default) { LoadItems(selectedCourse); } else if (dayOff.Morning.Value && dayOff.Afternoon.Value) { MessageBox.Show("This course has no class today", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (dayOff.Morning.Value && DateTime.Now < beforeAfternoon) { MessageBox.Show("This course has no class in the morning today", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (dayOff.Afternoon.Value && DateTime.Now > afterMorning) { MessageBox.Show("This course has no class in the afternoon today", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { LoadItems(selectedCourse); } }
private void BadgeInClick(object sender, EventArgs e) { var button = (Button)sender; if (button.Text == "Badge In") { int id = Int32.Parse(button.Name.Replace("IdButton", "")); Console.WriteLine(id); using (var context = new AttendanceListContext()) { context.RegistrationTimes.Add(new RegistrationTime() { AttenderId = id, CourseId = selectedCourse.Id, DateTime = DateTime.Now }); context.SaveChanges(); } button.Text = "Badge Out"; } else { button.Text = "Badge In"; } }
private void deleteButton_Click(object sender, EventArgs e) { if (attendersListBox.SelectedIndex == -1) { attendersErrorProvider.SetError(deleteButton, "Must select item to delete"); } else { var attender = (Attender)attendersListBox.SelectedItem; var result = MessageBox.Show("Are you sure you want to delete this item", "Delete", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { using (var context = new AttendanceListContext()) { var toDeleteCourseConnection = context.CourseAttenders.First(x => x.AttenderId == attender.Id); context.CourseAttenders.Remove(toDeleteCourseConnection); var registrationToDelete = context.RegistrationTimes.Where(x => x.AttenderId == attender.Id).ToList(); foreach (var item in registrationToDelete) { context.RegistrationTimes.Remove(item); } var toDelete = context.Attenders.FirstOrDefault(a => a.Id == attender.Id); context.Attenders.Remove(toDelete); context.SaveChanges(); } } LoadData(_id); } }
public BadgingForm() { InitializeComponent(); using (var context = new AttendanceListContext()) { courses = context.CourseInfoes.ToList(); } }
public CourseInfoForm(int id) { InitializeComponent(); this._id = id; using (var context = new AttendanceListContext()) { _course = context.CourseInfoes.First(x => x.Id == id); } }
private void Form1_Load(object sender, EventArgs e) { using (var context = new AttendanceListContext()) { var courseInfo = context.CourseInfoes; foreach (var item in courseInfo) { coursesListBox.Items.Add(item); } } }
void LoadData(int id) { using (var context = new AttendanceListContext()) { attenders = context.CourseAttenders.Where(x => x.CourseId == id) .Select(x => x.Attender) .ToList(); } attendersListBox.Items.Clear(); attendersListBox.Items.AddRange(attenders.ToArray()); }
private void LoadData(int id) { using (var context = new AttendanceListContext()) { tutors = context.CourseTutors.Where(x => x.CourseId == id) .Select(x => x.Tutor) .ToList(); } tutorsListBox.Items.Clear(); tutorsListBox.Items.AddRange(tutors.ToArray()); }
private void LoadData(int id) { using (var context = new AttendanceListContext()) { registrations = context.RegistrationTimes.Where(x => x.CourseId == id) .Select(x => x) .ToList(); } AttenderIds = registrations.Select(x => x.AttenderId.ToString()).Distinct().ToList(); attenderIdComboBox.Items.AddRange(AttenderIds.ToArray()); attenderIdComboBox.SelectedIndex = 0; }
void LoadData(int id) { using (var context = new AttendanceListContext()) { nonCourseDays = context.NonCourseDays.Where(x => x.CourseId == id) .Select(x => x) .ToList(); info = context.CourseInfoes.Where(x => x.Id == _id).First(); } daysOffListBox.Items.Clear(); daysOffListBox.Items.AddRange(nonCourseDays.ToArray()); }
private void RegistrationInfoForm_Load(object sender, EventArgs e) { using (var context = new AttendanceListContext()) { var dbRegistration = context.RegistrationTimes.Include("Attender") .Include("CourseInfo") .Where(x => x.Id == _id) .First(); nameTextBox.Text = dbRegistration.Attender.Name; timeTextBox.Text = dbRegistration.DateTime.Value.ToString(); courseTextBox.Text = dbRegistration.CourseInfo.Course; } }
private void addAttenderButton_Click(object sender, EventArgs e) { using (var addAttender = new AddAttenderForm()) { var result = addAttender.ShowDialog(); if (result == DialogResult.OK) { int badge = 1; var attender = addAttender.Result; while (attenders.Where(x => x.BadgeNumber == badge).Any()) { badge++; } using (var context = new AttendanceListContext()) { context.Attenders.Add(new Attender() { Name = attender.Name, Address = attender.Address, Birthdate = attender.Birthdate, BadgeNumber = badge }); context.SaveChanges(); } using (var context = new AttendanceListContext()) { int attId = context.Attenders.Where(x => x.BadgeNumber == badge) .Select(x => x.Id) .First(); context.CourseAttenders.Add(new CourseAttender() { AttenderId = attId, CourseId = _id, }); context.SaveChanges(); } LoadData(_id); } } }
private void addDayOffButton_Click(object sender, EventArgs e) { using (var dialog = new AddNonCourseDayForm()) { var result = dialog.ShowDialog(); if (result == DialogResult.OK) { var(range, morning, afternoon) = dialog.Result; var startDate = range.Start; var endDate = range.End; if (startDate < info.StartDate || endDate > info.EndDate) { nonCourseDayErrorProvider.SetError(addDayOffButton, "One of the added days is not during the course, please only add valid days"); } else { nonCourseDayErrorProvider.Clear(); while (startDate <= endDate) { using (var context = new AttendanceListContext()) { if (!nonCourseDays.Where(x => x.Date == startDate).Any()) { context.NonCourseDays.Add(new NonCourseDay() { Date = startDate, Morning = morning, Afternoon = afternoon, CourseId = _id, }); context.SaveChanges(); } } startDate = startDate.AddDays(1); } LoadData(_id); } } } }
private void LoadItems(CourseInfo selectedCourse) { using (var context = new AttendanceListContext()) { attenders = context.CourseAttenders.Where(c => c.CourseId == selectedCourse.Id) .Select(ca => ca.Attender) .ToList(); } trainingInstitutionTextBox.Text = selectedCourse.TrainingInstitution; courseTextBox.Text = selectedCourse.Course; contactTextBox.Text = selectedCourse.ContactPerson; addressTextBox.Text = selectedCourse.Address; addressRefTextBox.Text = selectedCourse.ReferenceAddress; oeNumberTextBox.Text = selectedCourse.OeNumber.ToString(); ccTextBox.Text = selectedCourse.CourseCode.ToString(); foreach (var item in attenders) { var box = new GroupBox(); var button = new Button(); button.Name = $"IdButton{item.Id}"; button.Text = "Badge In"; button.Location = new Point(box.Width / 2 - button.Width / 2, box.Height - button.Height - 5); button.Anchor = AnchorStyles.None; button.Click += BadgeInClick; var label = new Label() { Text = item.Name, Anchor = AnchorStyles.None, Font = new Font(FontFamily.GenericSansSerif, 9), TextAlign = ContentAlignment.TopCenter, Size = new Size(box.Width - 2, 18), }; label.Location = new Point(1, 20); box.Controls.Add(label); box.Controls.Add(button); attendersLayoutPanel.Controls.Add(box); } }
private void addTutorButton_Click(object sender, EventArgs e) { using (var addTutor = new AddTutorForm()) { var result = addTutor.ShowDialog(); if (result == DialogResult.OK) { var tutor = addTutor.Result; using (var context = new AttendanceListContext()) { tutor = context.Tutors.Add(new Tutor() { Name = tutor.Name, Company = tutor.Company, }); context.SaveChanges(); } using (var context = new AttendanceListContext()) { int attId = context.Tutors.Where(x => x.Id == tutor.Id) .Select(x => x.Id) .First(); context.CourseTutors.Add(new CourseTutor() { TutorId = attId, CourseId = _id, }); context.SaveChanges(); } LoadData(_id); } } }