private void btnSave_Click(object sender, EventArgs e) { try { if (ValidateChildren(ValidationConstraints.Enabled)) { if (_currentService == null) { _currentService = new Service { Name = textName.Text, Price = float.Parse(textPrice.Text), Duration = int.Parse(textDuration.Text), PavilionId = (int)cboPavilion.SelectedValue }; servicesBindingSource.Add(_currentService); _context.Services.Add(_currentService); } else { _currentService.Name = textName.Text; _currentService.Price = (float)Convert.ToDouble(textPrice.Text); _currentService.Duration = int.Parse(textDuration.Text); _currentService.PavilionId = (int)cboPavilion.SelectedValue; servicesBindingSource.EndEdit(); } _context.SaveChanges(); pavilionsBindingSource.ResetBindings(true); _currentService = null; textName.Text = null; textPrice.Text = null; textDuration.Text = null; cboPavilion.SelectedIndex = -1; MetroFramework.MetroMessageBox.Show(this, "Success", "Message", MessageBoxButtons.OK, MessageBoxIcon.Question); } } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnAdd_Click(object sender, EventArgs e) { using (AddEditPatientForm frm = new AddEditPatientForm(new Patient())) { if (frm.ShowDialog() == DialogResult.OK) { try { patientBindingSource.Add(frm.PatientInfo); _context.Patients.Add(frm.PatientInfo); _context.SaveChanges(); MetroFramework.MetroMessageBox.Show(this, "Success", "Message", MessageBoxButtons.OK, MessageBoxIcon.Question); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void btnAdd_Click(object sender, EventArgs e) { using (AddEditUserForm frm = new AddEditUserForm(new User())) { if (frm.ShowDialog() == DialogResult.OK) { try { usersBindingSource.Add(frm.UserInfo); _context.Users.Add(frm.UserInfo); _context.SaveChanges(); AddOrRemoveTimeTables(frm.UserInfo); MetroMessageBox.Show(this, "Success", "Message", MessageBoxButtons.OK, MessageBoxIcon.Question); } catch (Exception ex) { MessageBox.Show(ex.InnerException.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void btnSave_Click(object sender, EventArgs e) { CurrentReservation.Recipe = textRecipe.Text; if (FileUploaded.FileBytes != null) { CurrentReservation.File = FileUploaded.FileBytes; CurrentReservation.FileName = FileUploaded.FileName; } _context.SaveChanges(); FileUploaded.FileBytes = null; FileUploaded.FileName = null; DialogResult = DialogResult.OK; }
private void btnDelete_Click(object sender, EventArgs e) { try { if (MetroFramework.MetroMessageBox.Show(this, "Jeni te sigurt per fshirjen e ketij rekordi?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes) { if (pavilionsBindingSource.Current is Pavilion selectedPavilion) { pavilionsBindingSource.Remove(selectedPavilion); _context.Pavilions.Remove(selectedPavilion); pavilionsBindingSource.EndEdit(); _context.SaveChanges(); } } } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnDelete_Click(object sender, EventArgs e) { try { if (MetroMessageBox.Show(this, "Jeni te sigurt per fshirjen e ketij rekordi?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes) { int id = int.Parse(gridView.SelectedRows[0].Cells[0].Value.ToString()); if (id != 0) { var reservation = _context.Reservations.SingleOrDefault(r => r.Id == id); _context.Reservations.Remove(reservation); _context.SaveChanges(); gridView.DataSource = FillTable(); } } } catch (Exception ex) { MetroMessageBox.Show(this, ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnDone_Click(object sender, EventArgs e) { int id = int.Parse(gridViewFolder.SelectedRows[0].Cells[0].Value.ToString()); if (id != 0) { var reservation = _context.Reservations.FirstOrDefault(r => r.Id == id); if (reservation.Done != true) { reservation.Done = true; _context.SaveChanges(); gridViewFolder.DataSource = FillTable(); MetroMessageBox.Show(this, "Rezervimi u plotesua!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void btnSave_Click(object sender, EventArgs e) { var selectedServiceId = (listBoxService.SelectedValue != null) ? (int)listBoxService.SelectedValue : 0; var selectedPatientId = (listBoxPatient.SelectedValue != null) ? (int)listBoxPatient.SelectedValue : 0; if (selectedServiceId == 0 || selectedPatientId == 0) { MetroMessageBox.Show(this, "Ju duhet te selektoni pacientin dhe sherbimin", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var service = _context.Services.SingleOrDefault(s => s.Id == selectedServiceId); DateTime dateTime = DateTime.Now; DateTime endTime = dateTime.AddMinutes(service.Duration); var doctorId = (from em in _context.EmergencyDoctors join u in _context.Users on em.UserId equals u.Id join p in _context.Pavilions on u.PavilionId equals p.Id where DbFunctions.TruncateTime(em.Date) == DbFunctions.TruncateTime(dateTime) where service.PavilionId == p.Id select em.UserId).FirstOrDefault(); if (doctorId == 0) { MetroMessageBox.Show(this, "Nuk ka mjek roje per diten e sotme! Kontaktoni me administratorin!", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Reservation reservation = new Reservation(); reservation.StartTime = dateTime; reservation.EndTime = endTime; reservation.UserId = doctorId; reservation.PatientId = selectedPatientId; reservation.ServiceId = service.Id; _context.Reservations.Add(reservation); _context.SaveChanges(); DialogResult = DialogResult.OK; }
private void btnSave_Click(object sender, EventArgs e) { if (ValidateStartTime()) { for (int i = 1; i <= 7; i++) { Timetable timetable = _currentUser.Timetables.First(t => t.DayOfTheWeek == i); DateTimePicker startTimePicker = (DateTimePicker)this.Controls.Find("startTimePicker" + i, true)[0]; DateTimePicker endTimePicker = (DateTimePicker)this.Controls.Find("endTimePicker" + i, true)[0]; MetroCheckBox checkDayOff = (MetroCheckBox)this.Controls.Find("checkDayOff" + i, true)[0]; timetable.DayOff = checkDayOff.Checked; if (checkDayOff.Checked) { timetable.StartTime = null; timetable.EndTime = null; } else { timetable.StartTime = startTimePicker.Value; timetable.EndTime = endTimePicker.Value; } timetablePanel.Hide(); } usersBindingSource.EndEdit(); _context.SaveChanges(); MetroMessageBox.Show(this, "Ruajtja u be me sukses", "Message", MessageBoxButtons.OK, MessageBoxIcon.Question); } else { MetroMessageBox.Show(this, "Koha e fillimit duhet te jete me e vogel se koha e mbarimit", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnGenerate_Click(object sender, EventArgs e) { var query = _context.Users.Where(u => u.RoleId == Role.Doctor || u.RoleId == Role.Nurse).ToList(); if (query.Count == 0) { MetroFramework.MetroMessageBox.Show(this, "Nuk ka asnje mjek apo infermiere", "Info", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } DateTime startDate; EmergencyDoctor lastEmergencyDoctor = _context.EmergencyDoctors.OrderByDescending(em => em.Id).FirstOrDefault(); if (lastEmergencyDoctor == null) { startDate = DateTime.Today; } else { startDate = lastEmergencyDoctor.Date.AddDays(1); } foreach (Pavilion pavilion in _context.Pavilions.ToList()) { var doctors = _context.Users.Where(u => u.RoleId == Role.Doctor && u.PavilionId == pavilion.Id) .ToList(); //if pavilion has no doctor, continue with next pavilion if (doctors.Count == 0) { continue; } var yesterday = startDate.AddDays(-1); //id of last doctor to be on emergency var lastDoctorId = (from em in _context.EmergencyDoctors join u in _context.Users on em.UserId equals u.Id where u.PavilionId == pavilion.Id && em.Date == yesterday select u.Id).SingleOrDefault(); for (int i = 0; i < 30; i++) { var currentDate = startDate.AddDays(i); int dayDoctorId; if (lastDoctorId == 0) { dayDoctorId = doctors[0].Id; } else { int lastDoctorIndex = doctors.IndexOf(doctors.FirstOrDefault(d => d.Id == lastDoctorId)); if (lastDoctorIndex == doctors.Count - 1) { dayDoctorId = doctors[0].Id; } else { dayDoctorId = doctors[lastDoctorIndex + 1].Id; } } EmergencyDoctor emergencyDoctor = new EmergencyDoctor { Date = currentDate, UserId = dayDoctorId }; _context.EmergencyDoctors.Add(emergencyDoctor); _context.SaveChanges(); lastDoctorId = dayDoctorId; } } source.DataSource = GetItems(); StyleGrid(); }
private void btnSave_Click(object sender, EventArgs e) { var selectedDoctorId = (comboBoxDoctors.SelectedValue != null) ? (int)comboBoxDoctors.SelectedValue : 0; var selectedServiceId = (listBoxService.SelectedValue != null) ? (int)listBoxService.SelectedValue : 0; var selectedPatientId = (listBoxPatient.SelectedValue != null) ? (int)listBoxPatient.SelectedValue : 0; if (selectedDoctorId == 0 || selectedServiceId == 0 || selectedPatientId == 0) { MetroMessageBox.Show(this, "Ju duhet te selektoni pacientin, sherbimin, mjekun", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // kontrollo qe time eshte available dhe mjeku nuk eshte off DateTime dateTime = new DateTime( datePicker.Value.Year, datePicker.Value.Month, datePicker.Value.Day ); dateTime = dateTime.AddHours(timePicker.Value.Hour); dateTime = dateTime.AddMinutes(timePicker.Value.Minute); var service = _context.Services.SingleOrDefault(s => s.Id == selectedServiceId); DateTime endDateTime = dateTime.AddMinutes(service.Duration); //check that doctor is working if (CheckIfNotInTimetable(selectedDoctorId)) { MetroMessageBox.Show(this, "Error", "Stafi nuk punon per diten dhe orarin e perzgjedhur", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //check that doctor is not busy var reservations = _context.Reservations .Where(r => r.UserId == selectedDoctorId) .Where(r => (dateTime >= r.StartTime && dateTime <= r.EndTime) || (endDateTime >= r.StartTime && endDateTime <= r.EndTime) || (r.StartTime >= dateTime && r.EndTime <= endDateTime)) .ToList(); if (reservations.Count != 0) { MetroMessageBox.Show(this, "Error", "Stafi eshte i zene ne kohen e perzgjedhur", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //save reservation Reservation reservation = new Reservation(); reservation.StartTime = dateTime; reservation.EndTime = endDateTime; reservation.UserId = selectedDoctorId; reservation.PatientId = selectedPatientId; reservation.ServiceId = service.Id; _context.Reservations.Add(reservation); _context.SaveChanges(); if (MetroMessageBox.Show(this, "Doni te printoni faturen?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes) { reservation.Paid = true; _context.SaveChanges(); ReservationToPrintId = reservation.Id; PrintReservation(); } DialogResult = DialogResult.OK; }