Exemple #1
0
        private void BtnLogin_Click(object sender, RoutedEventArgs e)
        {
            string queryCheckCredentials = string.Format("SELECT users.emp_id AS EMP_ID, " +
                                                         "users.role_id as ROLE_ID, " +
                                                         "users.password AS PASSWORD, " +
                                                         "users_information.status AS STATUS " +
                                                         "FROM users LEFT JOIN users_information " +
                                                         "ON users.emp_id = users_information.emp_id " +
                                                         "WHERE users.emp_id = @empID AND users_information.emp_id = @empID " +
                                                         "AND users.password = @password");

            string queryLogInRecord = string.Format("INSERT INTO timelog" +
                                                    "(emp_id, log_time, log_status) " +
                                                    "VALUES" +
                                                    "(@emp_id, @log_time, @log_status)");

            try
            {
                if (SqlQueries.Login(queryCheckCredentials, Convert.ToInt32(txtEmpID.Text), txtPassword.Password) == true)
                {
                    if (SqlQueries.Logger(queryLogInRecord, Globals.Emp_ID, btnLogin.Content.ToString()))
                    {
                        MessageBox.Show("Logged in");

                        MainWindow mw = new MainWindow();

                        this.Close();
                        mw.ShowDialog();
                    }
                }
                else
                {
                    txtEmpID.Clear();
                    txtPassword.Clear();
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }
        // button to logout
        // sets logout data to true to close application
        private void BtnLogout_Click(object sender, RoutedEventArgs e)
        {
            string queryLoggerOut = string.Format("INSERT INTO timelog" +
                                                  "(emp_id, log_time, log_status) " +
                                                  "VALUES(@emp_id, @log_time, @log_status)");

            if (cartTotal == 0)
            {
                if (SqlQueries.Logger(queryLoggerOut, Globals.Emp_ID, btnLogout.Content.ToString()) == true)
                {
                    MessageBox.Show("Logging Out");

                    lblEmpID.Content    = " ";
                    lblEmployee.Content = " ";

                    Login login = new Login();

                    logout = true;

                    if (logout == true)
                    {
                        this.Close();
                    }


                    login.Show();
                }
                else
                {
                    MessageBox.Show("Something went wrong logging out");
                }
            }
            else
            {
                MessageBox.Show("Transaction Ongoing");
            }
        }