예제 #1
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            stu = db.Students.First(x => x.studentnumber == studentID);

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

            bool problem = false;

            if (db.Students.Where(x => x.email == stu.email && x.studentnumber != studentID).Any())
            {
                problem = true;
            }
            else if (!String.IsNullOrWhiteSpace(txtCard.Text))
            {
                if (db.Students.Where(x => x.cardnumber == stu.cardnumber && x.studentnumber != studentID).Any())
                {
                    problem = true;
                }
            }

            if (problem)
            {
                UniversalError ue = new UniversalError("Error!", "Some of the information you've entered is already associated with another account.");
                ue.ShowDialog();
            }
            else
            {
                db.SaveChanges();

                SignIn           si = new SignIn();
                UniversalSuccess us = new UniversalSuccess("Yay!", "Your information has been saved.");
                us.ShowDialog();
                this.Close();
                si.Show();
            }
        }
예제 #2
0
        private void btnReturn_Click(object sender, RoutedEventArgs e)
        {
            bool isConfirmed = db.Admins.Where(x => x.pin == txtPIN.Password.ToString()).Any();
            int  recordID;
            bool isRecord;

            if (string.IsNullOrWhiteSpace(txtID.Text))
            {
                txtID.Background = Brushes.LightPink;
                UniversalError ue = new UniversalError("Error!", "Please enter the ID of the record that's being returned");
                ue.ShowDialog();
            }
            else
            {
                recordID = Int32.Parse(txtID.Text);
                isRecord = db.Loans.Where(x => x.id == recordID && x.studentID == studentId).Any();

                if (!isRecord)
                {
                    UniversalError ue = new UniversalError("Error!", "Either that's an invalid record ID, or that record doesn't belong to this student.");
                    ue.ShowDialog();
                }
                else
                {
                    if (!isConfirmed)
                    {
                        txtPIN.Background = Brushes.LightPink;
                        UniversalError ue = new UniversalError("Error!", "The Admin's password is incorrect.");
                        ue.ShowDialog();
                    }
                    else
                    {
                        Loan ln = db.Loans.Where(x => x.id == recordID).First();
                        ln.active = false;
                        db.SaveChanges();
                        UniversalSuccess us = new UniversalSuccess("Success!", "The item has been returned.");
                        us.ShowDialog();
                        this.Close();
                    }
                }
            }
        }
예제 #3
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();
                }
            }
        }
예제 #4
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();
                    }
                }
            }
        }
예제 #5
0
        private void btnGo_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtFirst.Text))
            {
                //Do nothing, because the user didn't input anything.
            }
            else
            {
                bool isRegistered = db.Students.Where(x => x.studentnumber == txtFirst.Text || x.cardnumber == txtFirst.Text).Any();

                if (isRegistered)
                {
                    Student stu = new Student();
                    Session ses = new Session();

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

                    bool activeSession = db.Sessions.Where(x => x.studentID == stu.studentnumber && x.active == true).Any();

                    if (activeSession)
                    {
                        ses = db.Sessions.Where(x => x.studentID == stu.studentnumber && x.active == true).First();
                        var sessionDate      = ses.date;
                        var sessionStateTime = ses.starttime;
                        var studentID        = ses.studentID;
                        var kioskID          = ses.kioskID;

                        Session ses2 = new Session();

                        ses2.kioskID   = kioskID;
                        ses2.starttime = sessionStateTime;
                        ses2.date      = sessionDate;
                        ses2.studentID = studentID;
                        ses2.endtime   = DateTime.Now.TimeOfDay;
                        ses2.active    = false;

                        db.Sessions.Remove(ses);
                        db.Sessions.Add(ses2);
                        db.SaveChanges();

                        txtFirst.Text = "";

                        UniversalSuccess us = new UniversalSuccess("Signed Out!", "You have been signed out.");
                        us.ShowDialog();
                    }
                    else
                    {
                        ses.studentID = stu.studentnumber;
                        ses.kioskID   = 1;
                        ses.date      = DateTime.Today.Date;
                        ses.starttime = DateTime.Now.TimeOfDay;
                        ses.endtime   = DateTime.Now.TimeOfDay;
                        ses.active    = true;

                        db.Sessions.Add(ses);
                        db.SaveChanges();

                        txtFirst.Text = "";

                        UniversalSuccess us = new UniversalSuccess("Signed In!", "You are now signed in.");
                        us.ShowDialog();
                    }
                }
                else
                {
                    MainWindow registerWindow = new MainWindow();
                    this.Close();
                    registerWindow.ShowDialog();
                }
            }
        }