📄 userutility.cs
字号:
SqlCommand cmdUpdate = new SqlCommand("Community_UsersUpdateUserRoles", conPortal);
cmdUpdate.CommandType = CommandType.StoredProcedure;
cmdUpdate.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
cmdUpdate.Parameters.Add("@username", username);
cmdUpdate.Parameters.Add("@role", SqlDbType.NVarChar);
// execute the commands
conPortal.Open();
cmdDelete.ExecuteNonQuery();
foreach (string role in roles) {
cmdUpdate.Parameters["@role"].Value = role;
cmdUpdate.ExecuteNonQuery();
}
conPortal.Close();
}
//*********************************************************************
//
// UpdateRole Method
//
// Modifies a role in the database.
//
//*********************************************************************
public static void UpdateRole(string originalRoleName, string newRoleName, string newRoleDescription) {
SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
SqlCommand cmdUpdate = new SqlCommand("Community_UsersUpdateRole", conPortal);
cmdUpdate.CommandType = CommandType.StoredProcedure;
cmdUpdate.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
cmdUpdate.Parameters.Add("@originalRoleName", originalRoleName);
cmdUpdate.Parameters.Add("@newRoleName", newRoleName);
cmdUpdate.Parameters.Add("@newRoleDescription", newRoleDescription);
conPortal.Open();
cmdUpdate.ExecuteNonQuery();
conPortal.Close();
}
//*********************************************************************
//
// DeleteRole Method
//
// Deletes a role from the database.
//
//*********************************************************************
public static void DeleteRole(string roleName) {
SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
SqlCommand cmdUpdate = new SqlCommand("Community_UsersDeleteRole", conPortal);
cmdUpdate.CommandType = CommandType.StoredProcedure;
cmdUpdate.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
cmdUpdate.Parameters.Add("@roleName", roleName);
conPortal.Open();
cmdUpdate.ExecuteNonQuery();
conPortal.Close();
}
//*********************************************************************
//
// RegisterUser Method
//
// Registers a new user for a community in the database.
//
//*********************************************************************
public static int RegisterUser(ProfileInfo profile) {
SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
SqlCommand cmdAdd = new SqlCommand("Community_UsersRegisterUser", conPortal);
cmdAdd.CommandType = CommandType.StoredProcedure;
cmdAdd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
cmdAdd.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
cmdAdd.Parameters.Add("@username", profile.Username);
cmdAdd.Parameters.Add("@password", profile.Password);
cmdAdd.Parameters.Add("@email", profile.Email);
cmdAdd.Parameters.Add("@firstName", profile.FirstName);
cmdAdd.Parameters.Add("@lastName", profile.LastName);
cmdAdd.Parameters.Add("@timezone", profile.Timezone);
cmdAdd.Parameters.Add("@occupation", profile.Occupation);
cmdAdd.Parameters.Add("@location", profile.Location);
cmdAdd.Parameters.Add("@interests", profile.Interests);
cmdAdd.Parameters.Add("@msn", profile.MSN);
cmdAdd.Parameters.Add("@yahoo", profile.Yahoo);
cmdAdd.Parameters.Add("@aim", profile.AIM);
cmdAdd.Parameters.Add("@icq", profile.ICQ);
cmdAdd.Parameters.Add("@url", profile.Url);
cmdAdd.Parameters.Add("@fakeEmail", profile.FakeEmail);
cmdAdd.Parameters.Add("@enableNewsletter", profile.EnableNewsletter);
cmdAdd.Parameters.Add("@enableNotifications", profile.EnableNotifications);
conPortal.Open();
cmdAdd.ExecuteNonQuery();
int retVal = (int)cmdAdd.Parameters["@RETURN_VALUE"].Value;
conPortal.Close();
return retVal;
}
//*********************************************************************
//
// UpdateProfile Method
//
// Updates a user profile information in the database.
//
//*********************************************************************
public static int UpdateProfile(ProfileInfo profile) {
SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
SqlCommand cmdUpdate = new SqlCommand("Community_UsersUpdateProfile", conPortal);
cmdUpdate.CommandType = CommandType.StoredProcedure;
cmdUpdate.Parameters.Add("@RETURN_VALUE", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
cmdUpdate.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
cmdUpdate.Parameters.Add("@userID", profile.ID);
cmdUpdate.Parameters.Add("@username", profile.Username);
cmdUpdate.Parameters.Add("@password", profile.Password);
cmdUpdate.Parameters.Add("@email", profile.Email);
cmdUpdate.Parameters.Add("@firstName", profile.FirstName);
cmdUpdate.Parameters.Add("@lastName", profile.LastName);
cmdUpdate.Parameters.Add("@timezone", profile.Timezone);
cmdUpdate.Parameters.Add("@occupation", profile.Occupation);
cmdUpdate.Parameters.Add("@location", profile.Location);
cmdUpdate.Parameters.Add("@interests", profile.Interests);
cmdUpdate.Parameters.Add("@msn", profile.MSN);
cmdUpdate.Parameters.Add("@yahoo", profile.Yahoo);
cmdUpdate.Parameters.Add("@aim", profile.AIM);
cmdUpdate.Parameters.Add("@icq", profile.ICQ);
cmdUpdate.Parameters.Add("@url", profile.Url);
cmdUpdate.Parameters.Add("@fakeEmail", profile.FakeEmail);
cmdUpdate.Parameters.Add("@enableNewsletter", profile.EnableNewsletter);
cmdUpdate.Parameters.Add("@enableNotifications", profile.EnableNotifications);
conPortal.Open();
cmdUpdate.ExecuteNonQuery();
int retVal = (int)(cmdUpdate.Parameters["@RETURN_VALUE"].Value);
conPortal.Close();
return retVal;
}
//*********************************************************************
//
// GetProfile Method
//
// Retrieves a user profile from the database.
//
//*********************************************************************
public static ProfileInfo GetProfile(string username) {
ProfileInfo profile = null;
SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
SqlCommand cmdGet = new SqlCommand("Community_UsersGetProfile", conPortal);
cmdGet.CommandType = CommandType.StoredProcedure;
cmdGet.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
cmdGet.Parameters.Add("@username", username);
conPortal.Open();
SqlDataReader dr = cmdGet.ExecuteReader();
if (dr.Read())
profile = PopulateProfileFromSqlDataReader(dr);
conPortal.Close();
return profile;
}
//*********************************************************************
//
// GetProfileFromEmail Method
//
// Gets a user profile from the database from a user email
// address.
//
//*********************************************************************
public static ProfileInfo GetProfileFromEmail(string email) {
ProfileInfo profile = null;
SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
SqlCommand cmdGet = new SqlCommand("Community_UsersGetProfileFromEmail", conPortal);
cmdGet.CommandType = CommandType.StoredProcedure;
cmdGet.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
cmdGet.Parameters.Add("@email", email);
conPortal.Open();
SqlDataReader dr = cmdGet.ExecuteReader();
if (dr.Read())
profile = PopulateProfileFromSqlDataReader(dr);
conPortal.Close();
return profile;
}
//*********************************************************************
//
// GetPasswordFromUsername Method
//
// Gets a user password from the username.
//
//*********************************************************************
public static string GetPasswordFromUsername(string username) {
SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
SqlCommand cmdGet = new SqlCommand("Community_UsersGetPasswordFromUsername", conPortal);
cmdGet.CommandType = CommandType.StoredProcedure;
cmdGet.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
cmdGet.Parameters.Add("@username", username);
conPortal.Open();
string password = (string)cmdGet.ExecuteScalar();
conPortal.Close();
return password;
}
//*********************************************************************
//
// PopulateProfileInfoFromSqlDataReader Method
//
// Creates a ProfileInfo object from a SqlDataReader.
//
//*********************************************************************
private static ProfileInfo PopulateProfileFromSqlDataReader(SqlDataReader dr) {
ProfileInfo profile = new ProfileInfo();
profile.ID = (int)dr[ "User_ID" ];
profile.Username = (string)dr[ "User_Username" ];
profile.Password = (string)dr[ "User_Password" ];
profile.Email = (string)dr[ "User_Email" ];
profile.FirstName = (string)dr[ "User_FirstName" ];
profile.LastName = (string)dr[ "User_LastName" ];
profile.Timezone = (int)dr[ "User_Timezone" ];
profile.Occupation = (string)dr[ "User_Occupation" ];
profile.Location = (string)dr[ "User_Location" ];
profile.Interests = (string)dr[ "User_Interests" ];
profile.MSN = (string)dr[ "User_MSN" ];
profile.Yahoo = (string)dr[ "User_Yahoo" ];
profile.AIM = (string)dr[ "User_AIM" ];
profile.ICQ = (string)dr[ "User_ICQ" ];
profile.Url = (string)dr[ "User_URL" ];
profile.FakeEmail = (string)dr[ "user_fakeEmail" ];
profile.DatabaseQuota = (int)dr[ "user_databaseQuota" ];
profile.DatabaseQuotaUsed = (int)dr[ "user_databaseQuotaUsed" ];
profile.DateCreated = (DateTime)dr["user_dateCreated"];
profile.LastLogin = (DateTime)dr["user_lastLogin"];
profile.EnableNewsletter = (bool)dr["user_enableNewsletter"];
profile.EnableNotifications = (bool)dr["user_enableNotifications"];
return profile;
}
//*********************************************************************
//
// UpdateUserQuota Method
//
// Modifies a user's total availabe database disk quota
// in the database.
//
//*********************************************************************
public static void UpdateUserQuota(string username, int userQuota) {
SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
SqlCommand cmdUpdate = new SqlCommand("Community_UsersUpdateUserQuota", conPortal);
cmdUpdate.CommandType = CommandType.StoredProcedure;
cmdUpdate.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
cmdUpdate.Parameters.Add("@username", username);
cmdUpdate.Parameters.Add("@userQuota", userQuota);
conPortal.Open();
cmdUpdate.ExecuteNonQuery();
conPortal.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -