예제 #1
0
 public bool SetNewPassword(ResetPassword model)
 {
     try
     {
         ISqlConnectionService _sqlConnService = new SqlConnectionService();
         SqlCommand            cmd;
         try
         {
             _sqlConnService.OpenConnection();
             cmd             = new SqlCommand("SP_SetNewPassword", _sqlConnService.CreateConnection());
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.AddWithValue("@ID", model.UserID);
             cmd.Parameters.AddWithValue("@Password", Utility.MD5(model.Password));
             cmd.Parameters.AddWithValue("@StatementType", model.UserType);
             cmd.ExecuteNonQuery();
         }
         catch (Exception ex)
         {
             string message = ex.InnerException != null ? ex.InnerException.InnerException.Message : ex.Message;
             throw new Exception(message);
         }
         finally
         {
             _sqlConnService.CloseConnection();
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     return(true);
 }
        /// <summary>
        /// Creates the database .mdf file
        /// </summary>
        public void CreateDatabase()
        {
            // Credit for database creation code: https://support.microsoft.com/en-us/help/307283/how-to-create-a-sql-server-database-programmatically-by-using-ado-net
            // Credit for finding the working and current directory: https://stackoverflow.com/a/11882118

            String str;

            // Open SqlConnection with specific database creation string
            _connService.OpenCreateDatabaseConnection();

            str = "CREATE DATABASE CoronaStatsDB ON PRIMARY " +
                  "(NAME = CoronaStatsDB_Data, " +
                  "FILENAME = '" + _connService.ProjectDirectory + "\\CoronaStatsDB.mdf', " +
                  "SIZE = 10MB, MAXSIZE = 512MB, FILEGROWTH = 10%) " +
                  "LOG ON (NAME = CoronaStatsDB_log, " +
                  "FILENAME = '" + _connService.ProjectDirectory + "\\CoronaStatsDB_log.ldf', " +
                  "SIZE = 1MB, " +
                  "MAXSIZE = 5MB, " +
                  "FILEGROWTH = 10%)";

            SqlCommand myCommand = new SqlCommand(str, _connService.Conn);

            try
            {
                myCommand.ExecuteNonQuery();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Corona Statistics Database Helper");
            }

            // Close database SqlConnection
            _connService.CloseConnection();
        }
예제 #3
0
        public bool StoredProceduresLoaded()
        {
            // help on checking if the stored procedure exists: https://stackoverflow.com/a/13797842
            _connService.OpenConnection();


            string query = "select * from sysobjects where type='P'";
            int    storedProcedureCount = Directory.GetFiles(_connService.StoredProcedureDirectory).Length;
            int    numOfFiles           = 0;

            using (SqlCommand command = new SqlCommand(query, _connService.Conn))
            {
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        numOfFiles++;
                    }
                }
            }
            _connService.CloseConnection();

            if (storedProcedureCount == numOfFiles)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }