Exemple #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtFirst.Text) || txtFirst.Text == "REQUIRED")
            {
                txtFirst.Background = Brushes.LightPink;
                txtFirst.Text       = "REQUIRED";
            }
            else if (string.IsNullOrWhiteSpace(txtLast.Text) || txtLast.Text == "REQUIRED")
            {
                txtLast.Background = Brushes.LightPink;
                txtLast.Text       = "REQUIRED";
            }
            else if (string.IsNullOrWhiteSpace(txtEmail.Text) || txtEmail.Text == "REQUIRED")
            {
                txtEmail.Background = Brushes.LightPink;
                txtEmail.Text       = "REQUIRED";
            }
            else if (string.IsNullOrWhiteSpace(txtID.Text) || txtID.Text == "REQUIRED")
            {
                txtID.Background = Brushes.LightPink;
                txtID.Text       = "REQUIRED";
            }
            else if (string.IsNullOrWhiteSpace(txtPIN.Password.ToString()))
            {
                txtPIN.Background = Brushes.LightPink;
            }
            else
            {
                alreadyRegistered = false;

                if (db.Students.Where(x => x.studentnumber == txtID.Text).Any())
                {
                    alreadyRegistered = true;
                }
                else if (db.Students.Where(x => x.email == txtEmail.Text).Any())
                {
                    alreadyRegistered = true;
                }
                else if (!String.IsNullOrWhiteSpace(txtCard.Text))
                {
                    if (db.Students.Where(x => x.cardnumber == txtCard.Text).Any())
                    {
                        alreadyRegistered = true;
                    }
                }

                if (alreadyRegistered)
                {
                    UniversalError ue = new UniversalError("Error!", "Some of the information you included is already associated with another account.");
                    ue.ShowDialog();
                }
                else
                {
                    stu = new Student();

                    stu.firstname     = txtFirst.Text.ToLower().Trim();
                    stu.lastname      = txtLast.Text.ToLower().Trim();
                    stu.middleinitial = txtMI.Text.ToLower().Trim();
                    stu.email         = txtEmail.Text.ToLower().Trim();
                    stu.phone         = txtPhone.Text.Trim();
                    stu.studentnumber = txtID.Text.Trim();
                    stu.cardnumber    = txtCard.Text.Trim();
                    stu.pinnumber     = txtPIN.Password.ToString().Trim();

                    db.Students.Add(stu);
                    db.SaveChanges();

                    txtFirst.Text = "";
                    txtMI.Text    = "";
                    txtLast.Text  = "";
                    txtMI.Text    = "";
                    txtEmail.Text = "";
                    txtPhone.Text = "";
                    txtID.Text    = "";
                    txtCard.Text  = "";
                    txtPIN.Clear();

                    txtFirst.Background = Brushes.White;
                    txtLast.Background  = Brushes.White;
                    txtEmail.Background = Brushes.White;
                    txtID.Background    = Brushes.White;
                    txtPIN.Background   = Brushes.White;

                    UniversalSuccess us     = new UniversalSuccess("Account Created!", "To sign in, enter your student number or card number on the home screen.");
                    SignIn           signIn = new SignIn();
                    us.ShowDialog();
                    this.Close();
                    signIn.ShowDialog();
                }
            }
        }
Exemple #2
0
        private void btnCheckOut_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrWhiteSpace(txtID.Text))
            {
                txtID.Background = Brushes.LightPink;
            }
            else if (String.IsNullOrWhiteSpace(cmbEquipment.Text))
            {
                cmbEquipment.Background = Brushes.LightPink;
            }
            else if (String.IsNullOrWhiteSpace(txtPin.Password.ToString()))
            {
                txtPin.Background = Brushes.LightPink;
            }
            else if (String.IsNullOrWhiteSpace(txtAdminPin.Password.ToString()))
            {
                txtAdminPin.Background = Brushes.LightPink;
            }
            else
            {
                Student stu         = new Student();
                bool    isConfirmed = false;

                stu = db.Students.Where(x => x.studentnumber == txtID.Text || x.cardnumber == txtID.Text).First();

                if (txtPin.Password.ToString() != stu.pinnumber)
                {
                    UniversalError ue = new UniversalError("Error!", "This is not the correct pin number for " + stu.firstname + "'s account.");
                    ue.ShowDialog();
                    txtPin.Background = Brushes.LightPink;
                }
                else
                {
                    isConfirmed = db.Admins.Where(x => x.pin == txtAdminPin.Password.ToString()).Any();

                    if (!isConfirmed)
                    {
                        UniversalError ue = new UniversalError("Error!", "The Admin's password is incorrect.");
                        ue.ShowDialog();
                        txtAdminPin.Background = Brushes.LightPink;
                    }
                    else
                    {
                        //Create a new loan here and add it to the database.
                        Loan loan = new Loan(stu.studentnumber);
                        loan.studentID     = stu.studentnumber;
                        loan.description   = txtNote.Text;
                        loan.tagnumber     = txtTag.Text;
                        loan.loandate      = DateTime.Today.Date;
                        loan.serialnumber  = txtSerial.Text;
                        loan.equipmenttype = cmbEquipment.Text;
                        loan.active        = true;

                        db.Loans.Add(loan);
                        db.SaveChanges();

                        SignIn           pop = new SignIn();
                        UniversalSuccess us  = new UniversalSuccess("Success!", "The item has been checked out.");
                        us.ShowDialog();
                        this.Close();
                        pop.Show();
                    }
                }
            }
        }