Exemple #1
0
        public static int executeQuery(string query)
        {
            // Initialization.
            int           rowCount      = 0;
            string        strConn       = HomeBusinessLogic.getcon();
            SqlConnection sqlConnection = new SqlConnection(strConn);
            SqlCommand    sqlCommand    = new SqlCommand();

            try
            {
                // Settings.
                sqlCommand.CommandText    = query;
                sqlCommand.CommandType    = CommandType.Text;
                sqlCommand.Connection     = sqlConnection;
                sqlCommand.CommandTimeout = 2 * 3600; //// Setting timeeout for longer queries to 12 hours.

                // Open.
                sqlConnection.Open();

                // Result.
                rowCount = sqlCommand.ExecuteNonQuery();

                // Close.
                sqlConnection.Close();
            }
            catch (Exception ex)
            {
                // Close.
                sqlConnection.Close();

                throw ex;
            }

            return(rowCount);
        }
Exemple #2
0
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string email    = this.txtEmail.Text;
                string password = this.txtPassword.Password;

                // Verification.
                if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
                {
                    MessageBox.Show("This field can not be empty. Please fill all fields", "Fail", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                if (formvalid == false)
                {
                    MessageBox.Show("Please use valid email format", "Fail", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                password = HomeBusinessLogic.GetStringSha256Hash(password);

                string        strConn       = HomeBusinessLogic.getcon();
                SqlConnection sqlConnection = new SqlConnection(strConn);
                sqlConnection.Open();

                string Get_Data = "SELECT id, name, email, phoneNumber FROM Users where email = '"
                                  + email + "' and password = '******' and role = 'admin'";
                SqlCommand cmd = sqlConnection.CreateCommand();
                cmd.CommandText = Get_Data;
                SqlDataAdapter sda = new SqlDataAdapter(cmd);

                DataSet ds = new DataSet();
                sda.Fill(ds);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    MessageBox.Show("Login successful", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
                    Uri uri = new Uri("/Views/HomePage.xaml", UriKind.Relative);
                    this.NavigationService.Navigate(uri);
                }
                else
                {
                    MessageBox.Show("Login unsuccessful. Please enter admin email and password", "Fail", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);

                // Display Message
                MessageBox.Show("Something went wrong, Please try again later.", "Fail", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }