private void ButtonAddCourse_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (ctx = new YZYDbContextAzure())
                {
                    Register existRecord = ctx.Registers.Where(r => r.UserID == curUser.UserID && r.CourseID == curOpenCour.CourseID).FirstOrDefault();
                    if (existRecord != null)
                    {
                        MessageBox.Show("You have registered this course before.");
                        return;
                    }

                    Register newRecord = new Register {
                        UserID = curUser.UserID, CourseID = curOpenCour.CourseID, RegisterStatus = RegisterStatusEnum.Pending
                    };
                    ctx.Registers.Add(newRecord);
                    ctx.SaveChanges();
                    this.InitializeComponent();
                    LoadData();
                    ClearField();
                }
            }
            catch (SystemException ex)
            {
                MessageBox.Show("Failed to connect to database: " + ex.Message);
            }
        }
Example #2
0
        private void PayButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                List <string> errList = new List <string>();
                if (curUser == null)
                {
                    return;
                }

                if (tbPayAccount.Text.Length < 5 || tbPayAccount.Text.Length > 30)
                {
                    errList.Add("Account must be 5 -30 characters");
                }


                if (tbAmount.Text.Length == 0)
                {
                    errList.Add("Account can not be empty");
                }


                if (!decimal.TryParse(tbAmount.Text, out decimal amount) && tbAmount.Text.Length > 0)
                {
                    errList.Add("Account must be a valid number");
                }


                if (errList.Count > 0)
                {
                    string errStr = "";

                    foreach (string r in errList)
                    {
                        errStr += $"{r}\n";
                    }

                    MessageBox.Show($"Error found:\n{errStr}");
                    return;
                }


                using (YZYDbContextAzure ctx = new YZYDbContextAzure())
                {
                    Payment payment = new Payment {
                        UserID = curUser.UserID, PayAccount = tbPayAccount.Text, Amount = amount, PayDate = DateTime.Today
                    };
                    ctx.Payments.Add(payment);
                    ctx.SaveChanges();
                    this.InitializeComponent();
                    LoadData();
                    ClearField();
                }
            }
            catch (SystemException ex)
            {
                MessageBox.Show($"Fetal Error: {ex.Message}");
                Environment.Exit(1);
            }
        }
        public void UserPorfile_updateMethod_test()
        {
            YZYDbContextAzure ctx;

            ctx = new YZYDbContextAzure();
            User   testUser = ctx.Users.Where(r => r.UserID == 2).FirstOrDefault();
            string expName  = "Olivia";

            Assert.AreEqual(expName, testUser.FName);
        }
        public void UserPorfileID_test()
        {
            YZYDbContextAzure ctx;

            ctx = new YZYDbContextAzure();
            //GlobalSettings.userID = 2;
            User testUser  = ctx.Users.Where(r => r.UserID == 2).FirstOrDefault();
            int  expResult = 2;

            Assert.AreEqual(expResult, testUser.UserID);
        }
Example #5
0
 public ProfileViewModel()
 {
     Log.setLogOnFile();
     try
     {
         ctx = new YZYDbContextAzure();
     }
     catch (SystemException ex)
     {
         Log.WriteLine(ex.Message);
         Environment.Exit(1);
     }
     LoadUser();
     UpdateCommand = new YZYCommand(this.OnUpdate, this.CanUpdate);
 }
Example #6
0
 public StudentRegisterViewModel()
 {
     try
     {
         database = new YZYDbContextAzure();
     }
     catch (SystemException ex)
     {
         Log.WriteLine(ex.Message);
         Environment.Exit(1);
     }
     Users = new ObservableCollection <User>();
     //RegisterCommand = new YZYCommand(this.OnAdd, this.CanAdd);
     RegisterCommand = new YZYCommand(this.OnAdd);
 }
Example #7
0
 public StudentSearchTeacherViewModel()
 {
     Log.setLogOnFile();
     try
     {
         ctx = new YZYDbContextAzure();
     }
     catch (SystemException ex)
     {
         Log.WriteLine(ex.Message);
         Environment.Exit(1);
     }
     Users = new ObservableCollection <User>();
     LoadUser();
     //SearchCommand = new YZYCommand(this.OnSearch, this.CanExecute);
 }
 public TeacherDialogViewModel(int selectedCourseID)
 {
     _selectedCourseID = selectedCourseID;
     Log.setLogOnFile();
     try
     {
         ctx = new YZYDbContextAzure();
     }
     catch (SystemException ex)
     {
         Log.WriteLine(ex.Message);
         Environment.Exit(1);
     }
     Registers = new ObservableCollection <Register>();
     LoadRegistrations();
     UpdateGradeCommand = new YZYCommand(this.OnUpdateGrade, this.CanUpdateGrade);
 }
Example #9
0
        public PaymentManagementDialog()
        {
            try
            {
                using (ctx = new YZYDbContextAzure())
                {
                    //TODO set curUser = login user in the login dialog
                    curUser = ctx.Users.Where(r => r.UserID == GlobalSettings.userID).FirstOrDefault();
                }
            }
            catch (SystemException ex)
            {
                MessageBox.Show("Failed to connect to database: " + ex.Message);;
            }

            InitializeComponent();
        }
Example #10
0
 public TeacherViewModel()
 {
     Log.setLogOnFile();
     try
     {
         ctx = new YZYDbContextAzure();
     }
     catch (SystemException ex)
     {
         Log.WriteLine(ex.Message);
         Environment.Exit(1);
     }
     Courses = new ObservableCollection <Course>();
     LoadCourse();
     UpdateCommand = new YZYCommand(this.OnUpdate, this.CanUpdate);
     //UpdateGradeCommand = new YZYCommand(this.OnUpdateGrade, this.CanUpdateGrade);
 }
 public StudentSearchCoursViewModel()
 {
     Log.setLogOnFile();
     try
     {
         ctx = new YZYDbContextAzure();
     }
     catch (SystemException ex)
     {
         Log.WriteLine(ex.Message);
         Environment.Exit(1);
     }
     Courses         = new ObservableCollection <Course>();
     Categories      = new List <Category>();
     CategoryStrings = new List <string>();
     LoadCourse();
     SearchCommand = new YZYCommand(this.OnSearch);
 }
        private void Button_Sign_Click(object sender, RoutedEventArgs e)
        {
            var loginDlg = new SignInDialog();

            loginDlg.Owner = this;
            if (loginDlg.ShowDialog() == true)
            {
                string email    = loginDlg.tbEmail.Text;
                string password = loginDlg.tbPassword.Password;
                try
                {
                    YZYDbContextAzure ctx = new YZYDbContextAzure();
                    User loginUser        = ctx.Users.ToList().Where(u => (u.Email == email && u.Password == password)).FirstOrDefault();
                    if (loginUser != null)
                    {
                        if (loginUser.UserRole == UserRoleEnum.Student)
                        {
                            GlobalSettings.userRole  = UserRoleEnum.Student;
                            GlobalSettings.userID    = loginUser.UserID;
                            btManageCourse.IsEnabled = true;
                            btProfile.IsEnabled      = true;
                            btPayment.IsEnabled      = true;
                            btLogin.Visibility       = Visibility.Hidden;
                            User curUser = ctx.Users.Where(r => r.UserID == GlobalSettings.userID).FirstOrDefault();
                            tbWelcomeUsername.Text = "Welcome" + " " + curUser.FullName;
                        }
                        else
                        {
                            MessageBox.Show("You are not allowed to login from Student Desktop", "Login", MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Invalid Password or UserName, Please try again", "Login", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
                catch (SystemException ex)
                {
                    //System.Windows.MessageBox.Show("Hello, Succuess!", "My App");
                    Log.WriteLine(ex.Message);
                    Environment.Exit(1);
                }
            }
        }
Example #13
0
        //public YZYCommand RegisterCommand { get; set; }

        public SearchAccountViewModel()
        {
            Log.setLogOnFile();
            try
            {
                ctx = new YZYDbContextAzure();
            }
            catch (SystemException ex)
            {
                Log.WriteLine(ex.Message);
                Environment.Exit(1);
            }
            Users = new ObservableCollection <User>();
            LoadCourse();
            DeleteCommand = new YZYCommand(this.OnDelete, this.CanExecute);
            UpdateCommand = new YZYCommand(this.OnUpdate, this.CanExecute);
            AddCommand    = new YZYCommand(this.OnAdd, this.CanAdd);
            //RegisterCommand = new YZYCommand(this.OnRegister, this.CanRegister);
        }
 private void ButtonDeleteRegister_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (ctx = new YZYDbContextAzure())
         {
             Register existRecord = ctx.Registers.Where(r => r.RegisterID == curRegister.RegisterID).FirstOrDefault();
             ctx.Registers.Remove(existRecord);
             ctx.SaveChanges();
             this.InitializeComponent();
             LoadData();
             ClearField();
         }
     }
     catch (SystemException ex)
     {
         MessageBox.Show("Failed to connect to database: " + ex.Message);
     }
 }
Example #15
0
        private void LoadData()
        {
            try
            {
                using (ctx = new YZYDbContextAzure())
                {
                    decimal totalTuition;
                    decimal paidTuition;

                    if (ctx.Registers.Where(r => r.UserID == curUser.UserID).FirstOrDefault() == null)
                    {
                        totalTuition = 0;
                    }
                    else
                    {
                        totalTuition = ctx.Registers.Include("Course").Where(r => r.UserID == curUser.UserID).Sum(r => r.Cours.Tuition);
                    }
                    if (ctx.Payments.Where(r => r.UserID == curUser.UserID).FirstOrDefault() == null)
                    {
                        paidTuition = 0;
                    }
                    else
                    {
                        paidTuition = ctx.Payments.Where(r => r.UserID == curUser.UserID).Sum(r => r.Amount);
                    }



                    decimal balance = totalTuition - paidTuition;

                    lbTuitionTotal.Content = totalTuition == 0?"0":String.Format("{0:.##}", totalTuition);
                    lbPaidTuition.Content  = paidTuition == 0?"0":String.Format("{0:.##}", paidTuition);
                    lbBalance.Content      = balance == 0?"0":String.Format("{0:.##}", balance);

                    lvPayments.ItemsSource = ctx.Payments.Where(r => r.UserID == curUser.UserID).OrderBy(p => p.PayDate).ToList();
                }
            }
            catch (SystemException ex)
            {
                MessageBox.Show("Failed to connect to database: " + ex.Message);
            }
        }
        private void LoadData()
        {
            try
            {
                using (ctx = new YZYDbContextAzure())
                {
                    //TODO set curUser = login user in the login dialog
                    curUser = ctx.Users.Where(r => r.UserID == GlobalSettings.userID).FirstOrDefault();



                    lvRegisters.ItemsSource   = ctx.vStudentRegisters.Where(r => r.UserID == curUser.UserID).OrderBy(c => c.StartDate).ToList();
                    lvOpenCourses.ItemsSource = ctx.vOpenCourses.OrderBy(r => r.StartDate).ToList();
                }
            }
            catch (SystemException ex)
            {
                MessageBox.Show("Failed to connect to database: " + ex.Message);
            }
        }
Example #17
0
 public SearchCourseViewModel()
 {
     Log.setLogOnFile();
     try
     {
         ctx = new YZYDbContextAzure();
     }
     catch (SystemException ex)
     {
         Log.WriteLine(ex.Message);
         Environment.Exit(1);
     }
     Courses         = new ObservableCollection <Course>();
     Categories      = new List <Category>();
     CategoryStrings = new List <string>();
     LoadCourse();
     DeleteCommand = new YZYCommand(this.OnDelete, this.CanDelete);
     UpdateCommand = new YZYCommand(this.OnUpdate, this.CanExecute);
     AddCommand    = new YZYCommand(this.OnAdd, this.CanExecute);
 }
        private void LoadData()
        {
            try
            {
                using (ctx = new YZYDbContextAzure())
                {
                    //TODO set curUser = login user in the login dialog
                    curUser = ctx.Users.Where(r => r.UserID == GlobalSettings.userID).FirstOrDefault();

                    tbNewCell.Text       = curUser.Cell;
                    tbNewCity.Text       = curUser.City;
                    tbNewEmail.Text      = curUser.Email;
                    tbNewPassword.Text   = curUser.Password;
                    tbNewGender.Text     = Enum.GetName(typeof(GenderEnum), curUser.Gender);
                    tbNewPhone.Text      = curUser.Phone;
                    tbNewPostalCode.Text = curUser.PostalCode;
                    tbNewProvince.Text   = curUser.Province;
                    tbNewSIN.Text        = curUser.UserSIN;
                    tbNewStreetName.Text = curUser.StreetName;
                    tbNewStreetNo.Text   = curUser.StreetNo;
                    tbFirstName.Text     = curUser.FName;
                    tbMiddleName.Text    = curUser.MName;
                    tbLastName.Text      = curUser.LName;
                    tbUserRole.Text      = Enum.GetName(typeof(UserRoleEnum), curUser.UserRole);

                    if (curUser.Photo != null)
                    {
                        using (MemoryStream stream = new MemoryStream(curUser.Photo))
                        {
                            imageViewer.Source = BitmapFrame.Create(stream,
                                                                    BitmapCreateOptions.None,
                                                                    BitmapCacheOption.OnLoad);
                        }
                    }
                }
            }
            catch (SystemException ex)
            {
                MessageBox.Show("Failed to connect to database: " + ex.Message);
            }
        }
Example #19
0
        public MainWindow()
        {
            Log.setLogOnFile();

            CultureInfo culture = new CultureInfo(ConfigurationManager.AppSettings["DefaultCulture"]);

            Thread.CurrentThread.CurrentCulture   = culture;
            Thread.CurrentThread.CurrentUICulture = culture;

            var loginDlg = new AdminLoginDialog();

            if (loginDlg.ShowDialog() == true)
            {
                string email    = loginDlg.tbEmail.Text;
                string password = loginDlg.tbPassword.Password;
                if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
                {
                    GlobalSettings.userRole = UserRoleEnum.Student;
                    GlobalSettings.userID   = -1;
                }
                else
                {
                    try
                    {
                        YZYDbContextAzure ctx = new YZYDbContextAzure();
                        User loginUser        = ctx.Users.ToList().Where(u => (u.Email == email && u.Password == password)).FirstOrDefault();
                        if (loginUser != null)
                        {
                            if (loginUser.UserRole == UserRoleEnum.Admin)
                            {
                                GlobalSettings.userRole = UserRoleEnum.Admin;
                                GlobalSettings.userID   = loginUser.UserID;
                            }
                            else if (loginUser.UserRole == UserRoleEnum.Teacher)
                            {
                                GlobalSettings.userRole = UserRoleEnum.Teacher;
                                GlobalSettings.userID   = loginUser.UserID;
                            }
                            else
                            {
                                GlobalSettings.userRole = UserRoleEnum.Student;
                                GlobalSettings.userID   = -1;
                            }
                        }
                    }
                    catch (SystemException ex)
                    {
                        Log.WriteLine(ex.Message);
                        Environment.Exit(1);
                    }
                }
            }
            else
            {
                GlobalSettings.userRole = UserRoleEnum.Student;
                GlobalSettings.userID   = -1;
            }

            InitializeComponent();

            switch (ConfigurationManager.AppSettings["DefaultCulture"])
            {
            case "zh-Hans":
                LanguageToggle.IsChecked = true;
                break;

            case "en":
                LanguageToggle.IsChecked = false;
                break;
            }

            ucCourse.Visibility  = Visibility.Hidden;
            ucAccount.Visibility = Visibility.Hidden;
            ucTeacher.Visibility = Visibility.Hidden;

            switch (GlobalSettings.userRole)
            {
            case UserRoleEnum.Admin:
                ucCourse.Visibility  = Visibility.Visible;
                ucAccount.Visibility = Visibility.Visible;
                break;

            case UserRoleEnum.Teacher:
                ucTeacher.Visibility = Visibility.Visible;
                break;
            }
        }
        private void btSubmit_Click(object sender, RoutedEventArgs e)
        {
            //validations
            List <string> errList = new List <string>();

            if (!Regex.IsMatch(tbNewSIN.Text, @"^[0-9]{9}$"))
            {
                errList.Add("SIN must be 9 numbers");
            }

            if (!Enum.TryParse(tbNewGender.Text, out GenderEnum gender))
            {
                errList.Add("Gender must be: Female, Male, Other or Unknown");
            }

            if (!Regex.IsMatch(tbNewStreetName.Text, @"^[\w\d\s\.\-]{2,50}$"))
            {
                errList.Add("Street name must be 2 - 50 characters");
            }

            if (!Regex.IsMatch(tbNewStreetNo.Text, @"^[\w\d\s\.\-]{2,50}$"))
            {
                errList.Add("Street number must be 2 - 50 characters");
            }

            if (!Regex.IsMatch(tbNewCity.Text, @"^[\w\d\s\.\-]{2,30}$"))
            {
                errList.Add("City must be 2 - 30 characters");
            }

            List <string> provinceList = new List <string>()
            {
                "QC", "ON", "BC", "NL", "PE", "NS", "NB", "MB", "SK", "AB", "YT", "NT", "NU"
            };

            if (!provinceList.Any(s => tbNewProvince.Text.ToUpper().Equals(s)))
            {
                errList.Add("Province must be a 2 characters  Canadian province abbreviation");
            }

            if (!Regex.IsMatch(tbNewPostalCode.Text, @"^[A-Z][0-9][A-Z][0-9][A-Z][0-9]$"))
            {
                errList.Add("Postal code must be 6 character, in the format L0L0L0");
            }

            if (!Regex.IsMatch(tbNewPhone.Text, @"^[0-9]{10}$"))
            {
                errList.Add("Phone must be 10 numbers");
            }

            if (!Regex.IsMatch(tbNewCell.Text, @"^[0-9]{10}$"))
            {
                errList.Add("Cell must be 10 numbers");
            }

            if (!Regex.IsMatch(tbNewEmail.Text, @"^[\w\d\s\.\-\@]{2,20}$"))
            {
                errList.Add("Email must be less than 20 characters");
            }

            if (!Regex.IsMatch(tbNewPassword.Text, @"^[\w\d\s\.\-\@]{2,20}$"))
            {
                errList.Add("Password must be less than 20 characters");
            }


            if (errList.Count > 0)
            {
                string errStr = "";

                foreach (string r in errList)
                {
                    errStr += $"{r}\n";
                }

                MessageBox.Show($"Error found:\n{errStr}");
                return;
            }

            //check if password and/or confirmed password have been edited, if yes check if they are matched
            if (isPasswordModified == true)
            {
                if (!tbNewPassword.Text.Equals(tbNewConfirmPassword.Text))
                {
                    MessageBox.Show("Password didn't matched the confirmed password. please check.");
                    return;
                }
            }

            try
            {
                using (ctx = new YZYDbContextAzure())
                {
                    User udUser = ctx.Users.Where(r => r.UserID == curUser.UserID).FirstOrDefault();



                    udUser.Cell       = tbNewCell.Text;
                    udUser.City       = tbNewCity.Text;
                    udUser.Email      = tbNewEmail.Text;
                    udUser.Password   = tbNewPassword.Text;
                    udUser.Gender     = gender;
                    udUser.Phone      = tbNewPhone.Text;
                    udUser.PostalCode = tbNewPostalCode.Text;
                    udUser.Province   = tbNewProvince.Text;
                    udUser.UserSIN    = tbNewSIN.Text;
                    udUser.StreetName = tbNewStreetName.Text;
                    udUser.StreetNo   = tbNewStreetNo.Text;



                    if (isPictureModified == true)
                    {
                        udUser.Photo = curPictureArr;
                    }

                    ctx.SaveChanges();
                    MessageBox.Show("Profile updated");
                    this.InitializeComponent();
                    LoadData();
                }
            }
            catch (SystemException ex)
            {
                MessageBox.Show("Failed to connect to database: " + ex.Message);
            }
        }