Click here to Skip to main content
15,885,435 members
Home / Discussions / C#
   

C#

 
GeneralRe: Urgent Help:Removing all EventHandlers Pin
Shubhabrata Mohanty14-Oct-05 21:13
Shubhabrata Mohanty14-Oct-05 21:13 
QuestionA problem please help ??? Pin
snouto14-Oct-05 9:59
snouto14-Oct-05 9:59 
AnswerRe: A problem please help ??? Pin
Guffa14-Oct-05 11:59
Guffa14-Oct-05 11:59 
QuestionInvalidCast Exception in Typed Dataset Pin
sameerhanda14-Oct-05 8:09
sameerhanda14-Oct-05 8:09 
AnswerRe: InvalidCast Exception in Typed Dataset Pin
snouto14-Oct-05 10:04
snouto14-Oct-05 10:04 
GeneralRe: InvalidCast Exception in Typed Dataset Pin
sameerhanda14-Oct-05 10:10
sameerhanda14-Oct-05 10:10 
QuestionReposition a Control on Scroll Pin
miah alom14-Oct-05 8:02
miah alom14-Oct-05 8:02 
QuestionBusiness layer, Data Layer and entities Pin
tsramkumar14-Oct-05 6:46
tsramkumar14-Oct-05 6:46 
Hi I am in the process of developing a web application (well, kind of parital migration as the database storprocedures are going to be reused and the old app which was in vb6/asp is being re-written in ASP.NET) and had some questions with the data layers. I am using custom business entities to repesent business objects and these entities also have the CRUD methods for data access. I modelled it based on the Time Tracker Starter kit at http://www.asp.net and also the samples from enterprise library june 2005 version. I read numerous articles abt this and got confused.
I am not sure if it is a good approach to have the CRUD methods in the custom business entity or have it in a separate data layer component.
I have posted a sample code for a business entity that is used in my add.

Any suggestions / comments to make it a better solution would really be appreciated.

Thanks
Please
<br />
public class User<br />
{<br />
private string _oneWorldID;<br />
private string _lastName;<br />
private string _firstName;<br />
private string _middleInitial;<br />
private string _respDivName;<br />
private string _accessLevel;<br />
private string _activeInd;<br />
private int _respDiv;<br />
<br />
public enum Select<br />
{<br />
Active="Y",<br />
InActive="N",<br />
All=""<br />
}<br />
public User(string sOneWorldID)<br />
{<br />
		OneWorldID = sOneWorldID;<br />
		FirstName = LastName = MiddleInitial = string.Empty;<br />
		RespDivName = ActiveInd = string.Empty;<br />
		RespDiv = 0;<br />
}<br />
<br />
		public User()<br />
		{<br />
			User(string.Empty);<br />
		}<br />
<br />
		public string OneWorldID<br />
		{<br />
			get {return _oneWorldID;}<br />
			set {_oneWorldID = value;}<br />
		}<br />
		public string FirstName<br />
		{<br />
			get {return _firstName;}<br />
			set {_firstName = value;}<br />
		}<br />
		public string LastName<br />
		{<br />
			get {return _lastName;}<br />
			set {_lastName = value;}<br />
		}<br />
		public string MiddleInitial<br />
		{<br />
			get {return _middleInitial;}<br />
			set {_middleInitial = value;}<br />
		}<br />
		public string RespDivName<br />
		{<br />
			get {return _respDivName;}<br />
			set {_respDivName = value;}<br />
		}<br />
		public int RespDiv<br />
		{<br />
			get {return _respDiv;}<br />
			set {_respDiv = value;}<br />
		}<br />
		public string ActiveInd<br />
		{<br />
			get {return _activeInd;}<br />
			set {_activeInd = value;}<br />
		}<br />
		public string AccessLevel<br />
		{<br />
			get {return _accessLevel;}<br />
			set {_accessLevel = value;}<br />
		}<br />
<br />
public bool GetUsersDetails()<br />
{<br />
	bool bUserFound = false;<br />
        Database sqldb = DatabaseFactory.CreateDatabase("GatewaySQL");<br />
	DBCommandWrapper sqlCommandWrapper = sqldb.GetStoredProcCommandWrapper("sp_Select_User_List");<br />
<br />
	// Set up parameters<br />
	Utils.BuildParameters(	sqlCommandWrapper, <br />
				Utils.ParameterCount.SingleParameter,<br />
				new object[]{"@ONW",System.Data.DbType.AnsiStringFixedLength,4,ParameterDirection.Input,this.OneWorldID}<br />
			 );<br />
<br />
	using (IDataReader dr = sqldb.ExecuteReader(sqlCommandWrapper))<br />
	{<br />
	 while (dr.Read())<br />
		{<br />
		this.LastName = dr.GetValue(1).ToString();<br />
		this.FirstName = dr.GetValue(2).ToString();<br />
		this.MiddleInitial = dr.GetValue(3).ToString();<br />
		this.RespDivName = dr.GetValue(4).ToString();<br />
		this.ActiveInd = dr.GetValue(5).ToString();<br />
		this.AccessLevel = dr.GetValue(6).ToString();<br />
		bUserFound = true;<br />
		}<br />
	return bUserFound;<br />
	} <br />
}<br />
<br />
	<br />
public static UsersCollection GetUsers(int iRespDiv, User.Select select)<br />
{<br />
	Database sqldb = DatabaseFactory.CreateDatabase("GatewaySQL");<br />
	DBCommandWrapper sqlCommandWrapper = sqldb.GetStoredProcCommandWrapper("sp_Select_User_List");<br />
	<br />
	// Set up parameters<br />
	string sActiveInactiveInd = "";<br />
	switch (select)<br />
	{<br />
 	case User.Select.Active:<br />
	 ActiveInactiveInd = "Y";<br />
 	 break;<br />
	case User.Select.InActive:<br />
	 ActiveInactiveInd = "N";<br />
	 break;<br />
	}<br />
<br />
	Utils.BuildParameters(	sqlCommandWrapper, <br />
				Utils.ParameterCount.MultipleParameters,			        new object[]{"@iRespDiv",System.Data.DbType.Int32,4,ParameterDirection.iRespDiv},<br />
				new object[]{"@ActiveInactiveInd",System.Data.DbType.AnsiStringFixedLength,1,ParameterDirection.Input,sActiveInactiveInd}<br />
			 );<br />
<br />
	using (IDataReader dr = sqldb.ExecuteReader(sqlCommandWrapper))<br />
	{<br />
		UsersCollection  users = new UsersCollection();<br />
		while (dr.Read())<br />
		{<br />
		 User usr = new User();<br />
		 usr.OneWorldID = dr.GetValue(0).ToString();<br />
		 usr.LastName = dr.GetValue(1).ToString();<br />
		 usr.FirstName = dr.GetValue(2).ToString();<br />
		 usr.MiddleInitial = dr.GetValue(3).ToString();<br />
		 usr.AccessLevel = dr.GetValue(4).ToString();<br />
		 usr.ActiveInd = dr.GetValue(5).ToString();<br />
		}<br />
		return users;<br />
	} <br />
}<br />
<br />
public void InsertUser(string sUpdt_User_OneWorldID)<br />
{<br />
	// The insert user stored procedure inserts a new user.<br />
	try	<br />
	{<br />
	using (new  EntServicesProvider())<br />
	{<br />
	Database sqldb = DatabaseFactory.CreateDatabase("GatewaySQL");<br />
	DBCommandWrapper sqlCommandWrapper = sqldb.GetStoredProcCommandWrapper("sp_Insert_User");<br />
<br />
	// Set up parameters<br />
	Utils.BuildParameters(	sqlCommandWrapper, <br />
				Utils.ParameterCount.MultipleParameters,<br />
				new object[]{"@OWN",System.Data.DbType.StringFixedLength,9,ParameterDirection.Input,this.UserID}, <br />
				new object[]{"@firstName",System.Data.DbType.StringFixedLength,40,ParameterDirection.Input,this.FirstName},<br />
				new object[]{"@lastName",System.Data.DbType.StringFixedLength,40,ParameterDirection.Input,this.LastName},<br />
				new object[]{"@middleInitial",System.Data.DbType.StringFixedLength,40,ParameterDirection.Input,this.MiddleInitial},<br />
				new object[]{"@accessLevel",System.Data.DbType.StringFixedLength,1,ParameterDirection.Input,this.AccessLevel},<br />
				new object[]{"@activeInd",System.Data.DbType.StringFixedLength,1,ParameterDirection.Input,this.ActiveInd},<br />
				new object[]{"@respDiv",System.Data.DbType.Int16,2,ParameterDirection.InputOutput,this.RespDiv}	<br />
				);<br />
<br />
		using (IDbConnection connection = sqldb.GetConnection())<br />
		{<br />
			connection.Open();	<br />
			sqldb.ExecuteNonQuery(sqlCommandWrapper);<br />
		}<br />
		SQLTransactionLog.InsertTransaction(	"Insert",<br />
						        sUpdt_UserID,<br />
							"SQL",<br />
							"sp_Insert_User",<br />
							this.Id,<br />
						      this.RespDiv.ToString(),<br />
						"Secondary column contains User's Division ID." );<br />
												  <br />
		ContextUtil.SetComplete();<br />
		}<br />
	}<br />
	catch (Exception e)<br />
	{<br />
		ContextUtil.SetAbort();<br />
		throw new Exception (e.Message);<br />
	}<br />
}<br />
<br />
}<br />
<br />

QuestionUse function of VB.NET in C# Pin
rockxuyenmandem14-Oct-05 6:36
rockxuyenmandem14-Oct-05 6:36 
AnswerRe: Use function of VB.NET in C# Pin
Russell Jones14-Oct-05 6:50
Russell Jones14-Oct-05 6:50 
GeneralRe: Use function of VB.NET in C# Pin
miah alom14-Oct-05 7:58
miah alom14-Oct-05 7:58 
GeneralRe: Use function of VB.NET in C# Pin
mav.northwind14-Oct-05 8:51
mav.northwind14-Oct-05 8:51 
QuestionMSMQ Trigger Parameters Pin
Russell Jones14-Oct-05 6:18
Russell Jones14-Oct-05 6:18 
QuestionInternet Explorer Extension (COM) Pin
Milos Stojanovic14-Oct-05 5:44
Milos Stojanovic14-Oct-05 5:44 
QuestionScroll Panel control when mouse is dragged near the edge Pin
Gulfraz Khan14-Oct-05 4:28
Gulfraz Khan14-Oct-05 4:28 
AnswerRe: Scroll Panel control when mouse is dragged near the edge Pin
Dan Neely14-Oct-05 5:12
Dan Neely14-Oct-05 5:12 
QuestionFileSystemWatcher problem Pin
Dan Neely14-Oct-05 3:39
Dan Neely14-Oct-05 3:39 
AnswerRe: FileSystemWatcher problem Pin
Dave Kreskowiak14-Oct-05 4:39
mveDave Kreskowiak14-Oct-05 4:39 
GeneralRe: FileSystemWatcher problem Pin
Dan Neely14-Oct-05 5:06
Dan Neely14-Oct-05 5:06 
QuestionMESSAGEBOX TAB Pin
Greeky14-Oct-05 0:32
Greeky14-Oct-05 0:32 
AnswerRe: MESSAGEBOX TAB Pin
Stefan Troschuetz14-Oct-05 1:53
Stefan Troschuetz14-Oct-05 1:53 
AnswerRe: MESSAGEBOX TAB Pin
albCode14-Oct-05 21:00
albCode14-Oct-05 21:00 
QuestionIs it possible to tell when the OS starts and stops a screensaver, from inside a C# service which is running under the SYSTEM account? Pin
DUKEMAN13-Oct-05 23:40
DUKEMAN13-Oct-05 23:40 
QuestionI there any control to dispaly the incomming video from a video capturing device. Pin
sukanyavarma13-Oct-05 22:37
sukanyavarma13-Oct-05 22:37 
AnswerRe: I there any control to dispaly the incomming video from a video capturing device. Pin
snouto14-Oct-05 10:10
snouto14-Oct-05 10:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.