I get some source codes from a textbook and rewrite them making a small system. It can CRUD user. Now I find it low efficency for coding. For example, UserDAL contains a lot of SQL scripts and they are easy to make error. UserBLL is too simple. I do not know how to improve coding efficiency. Could you give me any advices ?
The following is UserDAL source code, I intend to post UserBLL and UserModel source code but code-project remind me too long:
public class UserDAL
{
SQLHelper db = new SQLHelper();
public DataTable SelectAllUser()
{
string sql = @"SELECT [UserID],[Password],[Name],[Sex],[Phone]," +
"[Tutor],[DptName],[College],[University]," +
"[Major],[EnrollYear],[Cntnt] " +
"FROM [TrainingExam].[dbo].[ExprmntUser]";
return db.GetDataTable(sql);
}
public int InsertUser(UserModel user)
{
string sql = @"INSERT INTO [TrainingExam].[dbo].[ExprmntUser] VALUES(" +
"@UserID, @Pass, @Name, @Sex, @Phone, @Tutor, @DptName, @College, @University, @Major, @EnrollYear, @Content)";
SqlParameter[] parameters =
{
new SqlParameter("@UserID", user.UserID),
new SqlParameter("@Pass", user.Pass),
new SqlParameter("@Name", user.Name),
new SqlParameter("@Sex", user.Sex),
new SqlParameter("@Phone", user.Phone),
new SqlParameter("@Tutor", user.Tutor),
new SqlParameter("@DptName", user.DptName),
new SqlParameter("@College", user.College),
new SqlParameter("@University", user.University),
new SqlParameter("@Major", user.Major),
new SqlParameter("@EnrollYear", user.EnrollYear),
new SqlParameter("@Content", user.Content)
};
return db.ExecuteNonQuery(sql, parameters);
}
public int DeleteUser(UserModel user)
{
string sql = @"DELETE FROM [TrainingExam].[dbo].[ExprmntUser] WHERE UserID=@UserID";
SqlParameter parameter = new SqlParameter("@UserID", user.UserID);
return db.ExecuteNonQuery(sql, parameter);
}
public int UpdateUser(UserModel user)
{
string sql = @"UPDATE [TrainingExam].[dbo].[ExprmntUser] SET UserID=@UserID, Name=@Name, Sex=@Sex, Phone=@Phone, EnrollYear=@EnrollYear, " +
"Tutor=@Tutor, Major=@Major, DptName=@DptName, College=@College, University=@University, Content=@Content " +
"WHERE UserID=@UserID";
SqlParameter[] parameters =
{
new SqlParameter("@UserID", user.UserID),
new SqlParameter("@Name", user.Name),
new SqlParameter("@Sex", user.Sex),
new SqlParameter("@Phone", user.Phone),
new SqlParameter("@EnrollYear", user.EnrollYear),
new SqlParameter("@Tutor", user.Tutor),
new SqlParameter("@Major", user.Major),
new SqlParameter("@DptName", user.DptName),
new SqlParameter("@College", user.College),
new SqlParameter("@University", user.University),
new SqlParameter("@Content", user.Content),
new SqlParameter("@UserID", user.UserID)
};
return db.ExecuteNonQuery(sql, parameters);
}
}
|