//Removes doctor from Doctors table in DataBase
 private void ButtonRemove_Click(object sender, RoutedEventArgs e)
 {
     //Check if user selected doctor
     if (DataGridListOfEmployee.SelectedIndex == -1)
     {
         MessageBox.Show("Select the row corresponding to the employee", "No row selected");
         return;
     }
     foreach (int index in ClassSQLConnections.EmployeesThatAreDoctors())
     {
         if (((ClassEmployee)DataGridListOfEmployee.SelectedItem).EmployeeId == index)
         {
             MessageBox.Show("Doctor cannot be removed. Choose another empolyee", "Choose another employee");
             return;
         }
     }
     try
     {
         ClassSQLConnections.DeleteEmployee(((ClassEmployee)DataGridListOfEmployee.SelectedItem).EmployeeId);
         LoadDataToDataGrid();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void ButtonRemove_Click(object sender, RoutedEventArgs e)
        {
            if (DataGridListOfUser.SelectedIndex == -1)
            {
                MessageBox.Show("Select the row corresponding to the user", "No row selected");
                return;
            }


            try
            {
                if (!CheckIfSelectedUserIsNotAssigned(((ClassUser)DataGridListOfUser.SelectedItem)))
                {
                    MessageBox.Show("To remove user he can't be assigned to any employee");
                    return;
                }

                ClassSQLConnections.DeleteUser(((ClassUser)DataGridListOfUser.SelectedItem).User_id);
                LoadDataToDataGridListOfUser();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 3
0
        public bool ConditionDeleteOffice()
        {
            IEnumerable <ClassTerm> query =
                from elem in ClassSqlCalendar.ListOfTerms()
                where elem.Office.OfficeId == ((ClassOffice)DataGridListOfOffice.SelectedItem).OfficeId
                select elem;

            if (query.Any())
            {
                string data = "This office cannot be removed because at this days meetings are being hosted in said of it: \n";
                foreach (ClassTerm queryResult in query)
                {
                    data += queryResult.Date.ToShortDateString() + "\n";
                }
                MessageBox.Show(data);
                return(false);
            }

            IEnumerable <ClassDoctor> query2 =
                from elem in ClassSQLConnections.DoctorList()
                where elem.OfficeNumber == ((ClassOffice)DataGridListOfOffice.SelectedItem).OfficeId
                select elem;

            if (query2.Any())
            {
                MessageBox.Show("This Office is currently occupied by " + query2.First().Name + " " + query2.First().Surname);
                return(false);
            }
            return(true);
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (DataGridListOfPermission.SelectedIndex == -1)
            {
                MessageBox.Show("Select the row corresponding to the permission", "No row selected");
                return;
            }

            int permissionId = ((ClassPermission)DataGridListOfPermission.SelectedItem).PermissionId;

            try
            {
                if (!CheckIfPermissionIsNotAssigned(permissionId))
                {
                    MessageBox.Show("To remove permission it can't be assigned to any user");
                    return;
                }

                ClassSQLConnections.DeletePermission(permissionId);
                LoadDataToDataGridListOfPermission();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 private bool CheckIfPermissionIsNotAssigned(int permissionId)
 {
     foreach (int index in ClassSQLConnections.NotAssignedPermission())
     {
         if (permissionId == index)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 6
0
 private void LoadDataToDataGrid()
 {
     //Load data to DataGrid
     try
     {
         DataGridListOfOffice.ItemsSource = ClassSQLConnections.OfficeList();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + "\n Try again later", "Error");
     }
 }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (TextBoxPermission.Text.Equals(""))
            {
                MessageBox.Show("To add new permission textbox must not be empty");
                return;
            }
            ClassPermission permission = new ClassPermission(TextBoxPermission.Text);

            ClassSQLConnections.AddPermission(permission);
            LoadDataToDataGridListOfPermission();
        }
        private bool CheckIfSelectedUserIsNotAssigned(ClassUser user)
        {
            foreach (ClassUser notAssignedUser in ClassSQLConnections.NotSpecifiedUsers())
            {
                if (user.User_id == notAssignedUser.User_id)
                {
                    return(true);
                }
            }

            return(false);
        }
        private static List <ClassDoctor> ListOfActiveDoctors()
        {
            List <ClassDoctor> allDoctorList = ClassSQLConnections.DoctorList();
            List <ClassDoctor> DoctorList    = new List <ClassDoctor>();

            foreach (ClassDoctor item in allDoctorList)
            {
                if (item.Active == true)
                {
                    DoctorList.Add(item);
                }
            }
            return(DoctorList);
        }
Esempio n. 10
0
 private void UpdateDoctor(ClassDoctor doctor, bool AddNewDoctor)
 {
     //try
     {
         if (!AddNewDoctor)
         {
             ClassSQLConnections.UpdateDoctor(doctor);
             return;
         }
         ClassSQLConnections.AddDoctor(doctor);
     }
     //catch (Exception ex)
     {
         //MessageBox.Show(ex.Message + "\n Try again later", "Error");
     }
 }
 private void UpdateUser(ClassUser user, bool AddNew)
 {
     try
     {
         if (!AddNew)
         {
             ClassSQLConnections.UpdateUser(user);
             return;
         }
         ClassSQLConnections.AddUser(user);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + "\n Try again later", "Error");
     }
 }
Esempio n. 12
0
 private void UpdateOffice(ClassOffice office, bool AddNew)
 {
     //Update  doctor info in data base
     try
     {
         //If user choose edit
         if (!AddNew)
         {
             ClassSQLConnections.UpdateOffice(office);
             return;
         }
         //If user choose add
         ClassSQLConnections.AddNewOffice(office);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + "\n Try again later", "Error");
     }
 }
Esempio n. 13
0
 private void ButtonRemove_Click(object sender, RoutedEventArgs e)
 {
     //Check if user selected doctor
     if (DataGridListOfOffice.SelectedIndex == -1)
     {
         MessageBox.Show("Select the row corresponding to the office", "No row selected");
         return;
     }
     try
     {
         if (ConditionDeleteOffice())
         {
             ClassSQLConnections.DeleteOffice(((ClassOffice)DataGridListOfOffice.SelectedItem).OfficeId);
         }
         LoadDataToDataGrid();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void Button_AcceptCalendarClick(object sender, RoutedEventArgs e)
        {
            ClassCalendar calendar = GetCalendarForSelectedCalendarInComboboxFromDataBase();

            foreach (ClassCalendarDay day in days)
            {
                if (day.IsWorkingDay == true)
                {
                    int dayId = ClassSqlCalendar.GetDayIdForCalendarDate(calendar.CalendarId, day.DateInDateTime.Day);

                    ClassSqlCalendar.CreateTerm(day.StartTime, day.EndTime, ClassSqlCalendar.GetCalendarIdForDoctor(ClassLoggedDoctor.Doctor_Id, calendar.CalendarId), dayId, ClassSQLConnections.GetOfficeIdForDoctor(ClassLoggedDoctor.Doctor_Id), ClassLoggedDoctor.Doctor_Id, day.Date);
                }
            }

            ClassSqlCalendar.UpdateCalendarStatus(ClassSqlCalendar.SelectStatusId(EnumStatus.AcceptedByTheDoctor), calendar.CalendarId);
            NavigationService.Navigate(new WindowDoctorNewCalendarEmpty());
        }
Esempio n. 15
0
 public List <ClassDoctor> DoctorList()
 {
     return(ClassSQLConnections.DoctorList());
 }
        private void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            if (workingDayFrom.SelectedItem == null || workingDayTo.SelectedItem == null || AvailableDate.SelectedItem == null)
            {
                MessageBox.Show("You cannot leave any empty combobox!");
                return;
            }

            ClassCalendar calendar = GetCalendarForCurrentDate();
            int           dayId    = ClassSqlCalendar.GetDayIdForCalendarDate(calendar.CalendarId, ((ClassCalendarDay)AvailableDate.SelectedItem).DateInDateTime.Day);

            ClassSqlCalendar.CreateTerm((TimeSpan)workingDayFrom.SelectedItem, (TimeSpan)workingDayTo.SelectedItem, ClassSqlCalendar.GetCalendarIdForDoctor(ClassLoggedDoctor.Doctor_Id, calendar.CalendarId), dayId, ClassSQLConnections.GetOfficeIdForDoctor(ClassLoggedDoctor.Doctor_Id), ClassLoggedDoctor.Doctor_Id, ((ClassCalendarDay)AvailableDate.SelectedItem).Date);
            this.DialogResult = true;
            this.Close();
        }
        private void ButtonLogging_Click(object sender, RoutedEventArgs e)
        {
            //Getting data from the form
            string login    = TextBoxLogin.Text;
            string password = PasswordBoxPassword.Password;
            bool   correctData;

            try
            {
                correctData = ClassSQLConnection.CheckLoginDetails(login, password);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\nTry again later", "Error");
                return;
            }

            //Invalid data
            if (!correctData)
            {
                failedAttempts++;
                string message = "Incorrect password or login";
                if (failedAttempts == 2)
                {
                    message += "\nNext unsuccessful attempt will block the login for five minutes";
                }
                MessageBox.Show(message, "Incorrect data");
                if (failedAttempts < 3)
                {
                    return;
                }
                //Block app
                ButtonLogging.IsEnabled       = false;
                TextBlockNextTry.Visibility   = Visibility.Visible;
                TextBoxLogin.IsEnabled        = false;
                PasswordBoxPassword.IsEnabled = false;
                TextBoxLogin.Text             = "";
                PasswordBoxPassword.Password  = "";
                //Time counting
                ClassTimer ct = new ClassTimer(5, 0, this);
                ct.StartTimer();
                return;
            }
            try
            {
                ClassPermission permission = ClassSQLConnections.GetUserType(login, password);
                if (permission.Permission == "Administrator")
                {
                    //Opening MainWindow
                    Main.OpenAdministratorWindow();
                    return;
                }
                if (permission.Permission == "Doctor")
                {
                    ClassLoggedDoctor.Doctor_Id = ClassSQLConnections.GetLoggedDoctorId(login, password);
                    Main.OpenDoctorWindow();
                    return;
                }
                Main.OpenMainWindow();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }