|
Yes, there are some things like that.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
If so please help me understand ,i goggled a lot but i could not able to find.
Thanks
Kod.
|
|
|
|
|
Sacha's suggestion would be easier to work with. Alternatively, you could add an attribute to the enum-value. See the DisplayNameAttribute[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
I'm trying to make a small program in c#, that will downsample image to specified amount of colors (using K-means). Then, user will be able to hide\show colored areas(clusters) in image. I've implemented image clustering algorithm and I also have info about main colors, but how to implement show/hide color function? Example below
for this moment program only simplifies image (in this example 5 colors)
http://s1.postimg.org/olgtkizu7/image1.jpg[^]
this is what I want to have
http://s17.postimg.org/wbc522yrz/image2.jpg[^]
|
|
|
|
|
How would you "show/hide" a color? What do you expect to see in its place?
If you have a 16-color bitmap, simply upscale it to 32-bit depth and let the user adjust the palette of the colors of the bitmap. That would replace it with another color.
If you mean "hide" as in making it transparant, there's this thing called opacity. It usually uses a predefined color to denote what area's should be transparent.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
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);
}
}
|
|
|
|
|
These methods are not able to change. They have different functions in the CRUD operations. So, minimizing them won't help you in anything. Also you have not shared your BLL code, just the DAL code.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Hi Afzaal, this codeproject textbox don't allow me to post too much codes in this Q&A, so I will post BLL code in the following. When I code these methods, I found I have to write same DAL, BLL again and again except of some different sql parameters. I think if I can input these parameters and the DAL and BLL code just write once. It will save a lot of time and energies and avoid a lot of errors.
public class UserBLL
{
private UserDAL userdal = new UserDAL();
public DataTable GetAllUser()
{
return userdal.SelectAllUser();
}
public bool AddUser(UserModel user)
{
if (userdal.InsertUser(user) > 0)
return true;
else
return false;
}
public bool DeleteUser(UserModel user)
{
if (userdal.DeleteUser(user) > 0)
return true;
else
return false;
}
public bool UpdateUser(UserModel user)
{
if (userdal.UpdateUser(user) > 0)
return true;
else
return false;
}
}
public class UserModel
{
public string UserID
{
get;
set;
}
public string Name
{
get;
set;
}
public string Sex
{
get;
set;
}
public string DptName
{
get;
set;
}
public string Phone
{
get;
set;
}
public string Major
{
get;
set;
}
public string University
{
get;
set;
}
public string Tutor
{
get;
set;
}
public string EnrollYear
{
get;
set;
}
public string College
{
get;
set;
}
public string Content
{
get;
set;
}
public string Pass
{
get;
set;
}
}
|
|
|
|
|
I don't think you should be making any further changes or fixes to your code, it is already in a compact shape.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Thank you very much, Afzaal. Do you know some other more advanced architectures than the three layered one ? This must be old fashioned architecture I learn. 
|
|
|
|
|
MVC pattern is wonderful architecture, old is gold... You should continue using it. What bad is into it? I don't find any reason to why not use it.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
OK! I should be confident with my code! Thank you again, Afzaal!!! I will study the wonderful MVC and some front-end framework to make my system more amazing!
|
|
|
|
|
One thing you could do is more to an ORM system like Entity Framework so you don't have to write all your own CRUD code. EF essentially becomes your DAL, you don't need to write your own.
|
|
|
|
|
Thank you, F-ES Sitecore. I even used EF in my project but one interesting thing is in Chinese developing community many developers don't advise me to use EF because they believe EF isn't stable. Thank you for your adivces and I will look into EF seriously!!!
|
|
|
|
|
There's nothing wrong with using EF. It won't be as fast as things like ado.net that you're currently using, but you have to weigh that up against development time and simplicity. It's not slow, just slower than ado.net and for most people the performance is still fine. You do have to keep an eye on things like lazy loading as how you use EF can affect the performance of it, but you'll find all that out if you look into it.
|
|
|
|
|
Thank you again and again! You give me another view looking at EF. Thank you again!!!
|
|
|
|
|
You might want to take a look at Dapper[^], which is used on the StackExchange family of sites. Since your SQL column names seem to match the property names on your UserModel class, it should be fairly simple to use:
private IDbConnection CreateConnection()
{
return new SqlConnection("YOUR CONNECTION STRING HERE");
}
public IEnumerable<UserModel> SelectAllUser()
{
const string sql = @"SELECT [UserID], [Password], [Name], [Sex], [Phone],"
+ "[Tutor], [DptName], [College], [University],"
+ "[Major], [EnrollYear], [Cntnt] "
+ "FROM [TrainingExam].[dbo].[ExprmntUser]";
using (var connection = CreateConnection())
{
return connection.Query<UserModel>(sql);
}
}
public int InsertUser(UserModel user)
{
const string sql = @"INSERT INTO [TrainingExam].[dbo].[ExprmntUser] VALUES ("
+ "@UserID, @Pass, @Name, @Sex, @Phone, @Tutor, @DptName, @College, @University, @Major, @EnrollYear, @Content)";
using (var connection = CreateConnection())
{
return connection.Execute(sql, user);
}
}
public int DeleteUser(UserModel user)
{
const string sql = @"DELETE FROM [TrainingExam].[dbo].[ExprmntUser] WHERE UserID = @UserID";
using (var connection = CreateConnection())
{
return connection.Execute(sql, user);
}
}
public int UpdateUser(UserModel user)
{
const 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";
using (var connection = CreateConnection())
{
return connection.Execute(sql, user);
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Wow, it is really cool!!! Dapper can use my code smoothly!!! Thank you very much!!!
|
|
|
|
|
Hi, Richar! I can't visit Dapper. It seems that Github is blocked. Could you give me independent Dapper site ???
|
|
|
|
|
You can install the package from NuGet:
https://www.nuget.org/packages/Dapper/[^]
However, all of the documentation is on GitHub, which seems to be blocked in China.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you, Richard. I have download Dapper with Nuget Package Manager. I learn Dapper right now!
|
|
|
|
|
Hey,
I would like to discuss the value of using Unsigned value types for ensure the validy of your buissnes logic.
Just to name some exampels.
Does it make sense to let the Linq Extention 'Skip' or 'Take' be, accepting values smaller then 0? No not for me, but then why it allows this behavior by taking a int instead of an uint? Don't mention that the uint takes less memory but this is not the point.
I meant that the same space in memory can hold a bigger number ( for int ) then the signed as we got a bit more to store our data. ( sory for the vague explanation )
I Developed a network lib ( currently not OpenSource but soon ) that takes a Port. i saw that other libs are using an int at this point. This is absolute bad from my point of view. The only valid value type here is the Ushort ( 0 to 65,535 ). It does not allow a non Positiv number and limits the parameter to the buissnes logic. So why are thees value types not used that often?
modified 27-Mar-15 5:35am.
|
|
|
|
|
|
|