PageRenderTime 49ms CodeModel.GetById 16ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 0ms

/EQT_V1/EQT.DAL/DaTuser.auto.cs

http://sgsoft-las.googlecode.com/
C# | 994 lines | 812 code | 80 blank | 102 comment | 27 complexity | 401dc9fa3ba09300eadc69225176c1ac MD5 | raw file
Possible License(s): LGPL-2.1
  1#region DaTuser
  2/*----------------------------------------------------------------
  3// ????DaTuser.cs
  4// ??????Tuser??????
  5//
  6// 
  7// ?????2009-02-27
  8//
  9// ????? 
 10// ????? 
 11//----------------------------------------------------------------*/
 12using System;
 13using System.Collections;
 14using System.Collections.Generic;
 15using System.Data;
 16using System.Globalization;
 17using System.Text;
 18using System.Xml;
 19using System.Data.Common;
 20using Microsoft.Practices.EnterpriseLibrary.Data;
 21using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
 22//using Microsoft.Practices.EnterpriseLibrary.Logging;
 23using EQT.Model; 
 24//using IDataLayer;
 25
 26namespace EQT.Dal
 27{
 28    public	partial  class DaTuser   //?????????,ITuser 
 29    {   
 30	
 31		//???????????????????
 32		//???????????????SQL Server??????????????????ID??????entiry?
 33		//??????????????????
 34		#region SQL const
 35		private const  string SQL_INSERT="INSERT INTO TUser (UID ,Emp_ID ,Display_Name ,PWD ,Status ,Create_Time ,Update_Time ) VALUES "
 36			+"(@Uid,@Emp_Id,@Display_Name,@Pwd,@Status,@Create_Time,@Update_Time)";
 37		private const string SQL_UPDATE="UPDATE TUser SET Emp_ID=@Emp_ID, Display_Name=@Display_Name, PWD=@PWD, Status=@Status, Create_Time=@Create_Time, Update_Time=@Update_Time WHERE UID=@UID";
 38		private const string SQL_DELETE="DELETE FROM TUser WHERE UID=@UID";
 39		private const string SQL_SELECT="SELECT UID ,Emp_ID ,Display_Name ,PWD ,Status ,Create_Time ,Update_Time  from TUser  ";
 40		private const string SQL_SELECT_ONE="SELECT UID ,Emp_ID ,Display_Name ,PWD ,Status ,Create_Time ,Update_Time  from TUser  WHERE UID=@UID";                              
 41		#endregion
 42		
 43        private Database db;
 44		
 45		#region Constructor
 46	 
 47		/// <summary>
 48        /// ???????????????????????
 49        /// </summary>
 50		public DaTuser ()
 51		{ 
 52			db=DatabaseFactory.CreateDatabase();
 53		}
 54		/// <summary>
 55        /// ?????databaseName??????
 56        /// </summary>
 57        /// <param name="databaseName">??????????????</param>
 58		public DaTuser (string databaseName)
 59		{ 
 60            this.db = DatabaseFactory.CreateDatabase(databaseName);
 61		} 
 62		
 63		public DaTuser (Database db)
 64		{ 
 65            this.db = db;
 66		} 
 67		
 68		#endregion
 69		
 70		//???CRUD??????????????????
 71
 72	    #region Add
 73		
 74		///build the command object.It never throw exception.
 75		private DbCommand ConstructAddCommand()
 76		{
 77			DbCommand dbCommand = db.GetSqlStringCommand(SQL_INSERT);
 78			 
 79			//????:Uid	
 80			db.AddInParameter(dbCommand,"Uid",DbType.AnsiString);
 81			//????:Emp_Id	
 82			db.AddInParameter(dbCommand,"Emp_Id",DbType.AnsiString);
 83			//????:Display_Name	
 84			db.AddInParameter(dbCommand,"Display_Name",DbType.String);
 85			//????:Pwd	
 86			db.AddInParameter(dbCommand,"Pwd",DbType.AnsiString);
 87			//????:Status	
 88			db.AddInParameter(dbCommand,"Status",DbType.Int32);
 89			//????:Create_Time	
 90			db.AddInParameter(dbCommand,"Create_Time",DbType.DateTime);
 91			//????:Update_Time	
 92			db.AddInParameter(dbCommand,"Update_Time",DbType.DateTime);
 93			return dbCommand;
 94		}		
 95		private DbCommand ConstructAddCommand(MoTuser entity)
 96		{
 97			DbCommand dbCommand=db.GetSqlStringCommand(SQL_INSERT);
 98			 
 99			//????:Uid	
100			db.AddInParameter(dbCommand,"Uid",DbType.AnsiString,entity.Uid);
101			//????:Emp_Id	
102			db.AddInParameter(dbCommand,"Emp_Id",DbType.AnsiString,entity.Emp_Id);
103			//????:Display_Name	
104			db.AddInParameter(dbCommand,"Display_Name",DbType.String,entity.Display_Name);
105			//????:Pwd	
106			db.AddInParameter(dbCommand,"Pwd",DbType.AnsiString,entity.Pwd);
107			//????:Status	
108			db.AddInParameter(dbCommand,"Status",DbType.Int32,entity.Status);
109			//????:Create_Time	
110			db.AddInParameter(dbCommand,"Create_Time",DbType.DateTime,entity.Create_Time);
111			//????:Update_Time	
112			db.AddInParameter(dbCommand,"Update_Time",DbType.DateTime,entity.Update_Time);
113			 
114			return dbCommand;
115		}
116	
117	    /// <summary>
118		///????????????????commit
119		/// </summary>
120	    public int Add(MoTuser entity,DbTransaction trans)
121	    {	try
122            {
123				DbCommand dbCommand=ConstructAddCommand(entity);			
124				return db.ExecuteNonQuery(dbCommand,trans);
125			}
126			catch(DbException ex)
127			{				
128				HandleDbException(ex,entity);				
129			}
130			return 0;
131			
132	    }		
133	    public int Add(MoTuser entity) 
134        {	
135			try
136            {
137				DbCommand dbCommand=ConstructAddCommand(entity);			
138				return db.ExecuteNonQuery(dbCommand);
139			}
140			catch(DbException ex)
141			{				
142				HandleDbException(ex,entity);		
143			}
144			return 0;
145	    }
146		
147		public int Add(List<MoTuser> entity,DbTransaction trans)
148		{
149			int rc=0;		
150            DbCommand dbCommand=ConstructAddCommand();
151			int j=0;
152			try
153			{
154			   for(j=0;j<entity.Count;j++)
155			   {	
156				//????:Uid	
157				db.SetParameterValue(dbCommand,"Uid",entity[j].Uid);
158				//????:Emp_Id	
159				db.SetParameterValue(dbCommand,"Emp_Id",entity[j].Emp_Id);
160				//????:Display_Name	
161				db.SetParameterValue(dbCommand,"Display_Name",entity[j].Display_Name);
162				//????:Pwd	
163				db.SetParameterValue(dbCommand,"Pwd",entity[j].Pwd);
164				//????:Status	
165				db.SetParameterValue(dbCommand,"Status",entity[j].Status);
166				//????:Create_Time	
167				db.SetParameterValue(dbCommand,"Create_Time",entity[j].Create_Time);
168				//????:Update_Time	
169				db.SetParameterValue(dbCommand,"Update_Time",entity[j].Update_Time);
170				rc+=db.ExecuteNonQuery(dbCommand,trans);
171			   }
172			}
173			catch(DbException ex)
174			{
175				HandleDbException(ex,entity[j]);				
176			}			 
177            return rc;
178		}		
179		public int Add(List<MoTuser> entity)
180		{
181			int rc = 0;			
182			using (DbConnection cnn = db.CreateConnection())
183            {    
184				DbTransaction trans=null;
185				try
186				{
187					cnn.Open();
188					using(trans = cnn.BeginTransaction())
189					{
190						rc=Add(entity,trans);//This function throw customer exception.
191						trans.Commit();
192					}
193					cnn.Close();
194				}
195				catch(DbException ex)
196				{
197					if(trans!=null)trans.Rollback();		
198					HandleDbException(ex);	
199				}
200				///TODO:catch customer exception.
201				//catch
202				//{
203				//	
204				//}
205			}
206			return rc;
207		}
208		
209        public int Add(DataTable dt, DbTransaction trans)
210		{
211			int rc=0;		 
212            DbCommand dbCommand =ConstructAddCommand();	
213			int j=0;
214			try
215			{
216			   for(j=0;j<dt.Rows.Count;j++)
217			   {	
218					//????:Uid	
219					db.SetParameterValue(dbCommand,"Uid",dt.Rows[j]["Uid"]);
220					//????:Emp_Id	
221					db.SetParameterValue(dbCommand,"Emp_Id",dt.Rows[j]["Emp_Id"]);
222					//????:Display_Name	
223					db.SetParameterValue(dbCommand,"Display_Name",dt.Rows[j]["Display_Name"]);
224					//????:Pwd	
225					db.SetParameterValue(dbCommand,"Pwd",dt.Rows[j]["Pwd"]);
226					//????:Status	
227					db.SetParameterValue(dbCommand,"Status",dt.Rows[j]["Status"]);
228					//????:Create_Time	
229					db.SetParameterValue(dbCommand,"Create_Time",dt.Rows[j]["Create_Time"]);
230					//????:Update_Time	
231					db.SetParameterValue(dbCommand,"Update_Time",dt.Rows[j]["Update_Time"]);
232					rc+=db.ExecuteNonQuery(dbCommand,trans);
233			   }
234			}
235			catch(DbException ex)
236			{				
237				HandleDbException(ex,dt.Rows[j]);				
238			}	
239			 
240            return rc;
241		}		
242		public int Add(DataTable dt)
243        {
244			int rc=0;
245            using (DbConnection cnn = db.CreateConnection())
246            { 
247				DbTransaction trans=null;
248				try
249                {
250					cnn.Open();
251					using(trans = cnn.BeginTransaction())
252					{
253						rc = Add(dt, trans);
254						trans.Commit();
255						cnn.Close();
256					}
257				}
258				catch(DbException ex)
259				{	
260					if(trans!=null)trans.Rollback();
261					HandleDbException(ex);	
262				}	
263				///TODO:catch customer exception.
264				//catch
265				//{
266				//	
267				//}
268            }
269            return rc;
270        }
271		#endregion
272		
273		#region Update
274		private DbCommand ConstructUpdateCommand()
275		{
276			DbCommand dbCommand=db.GetSqlStringCommand(SQL_UPDATE);
277		    
278			db.AddInParameter(dbCommand,"Emp_Id",DbType.AnsiString);
279			db.AddInParameter(dbCommand,"Display_Name",DbType.String);
280			db.AddInParameter(dbCommand,"Pwd",DbType.AnsiString);
281			db.AddInParameter(dbCommand,"Status",DbType.Int32);
282			db.AddInParameter(dbCommand,"Create_Time",DbType.DateTime);
283			db.AddInParameter(dbCommand,"Update_Time",DbType.DateTime);
284		 
285			db.AddInParameter(dbCommand,"Uid",DbType.AnsiString);
286			 
287			return dbCommand;
288		}
289		private DbCommand ConstructUpdateCommand(MoTuser entity)
290		{
291			DbCommand dbCommand=db.GetSqlStringCommand(SQL_UPDATE);
292		    
293			db.AddInParameter(dbCommand,"Emp_Id",DbType.AnsiString,entity.Emp_Id);
294			db.AddInParameter(dbCommand,"Display_Name",DbType.String,entity.Display_Name);
295			db.AddInParameter(dbCommand,"Pwd",DbType.AnsiString,entity.Pwd);
296			db.AddInParameter(dbCommand,"Status",DbType.Int32,entity.Status);
297			db.AddInParameter(dbCommand,"Create_Time",DbType.DateTime,entity.Create_Time);
298			db.AddInParameter(dbCommand,"Update_Time",DbType.DateTime,entity.Update_Time);
299		 
300			db.AddInParameter(dbCommand,"Uid",DbType.AnsiString,entity.Uid);
301			 
302			return dbCommand;
303		}
304		/// <summary>
305		/// ???????????:??????????
306		/// </summary>	
307	    public int Update(MoTuser entity,DbTransaction trans)
308	    {	    			
309		    try
310            {			
311				DbCommand dbCommand=ConstructUpdateCommand(entity);
312				return db.ExecuteNonQuery(dbCommand,trans);
313			}
314			catch(DbException ex)
315			{				
316				HandleDbException(ex,entity);		
317			}
318			return 0;
319		}		
320		public int Update(MoTuser entity)
321		{
322			try
323            {			
324				DbCommand dbCommand=ConstructUpdateCommand(entity);
325				return db.ExecuteNonQuery(dbCommand);
326			}
327			catch(DbException ex)
328			{				
329				HandleDbException(ex,entity);		
330			}
331			return 0;			
332		}		
333		public int Update(List<MoTuser> entity,DbTransaction trans)
334		{
335			int rc=0;			 
336            DbCommand dbCommand=ConstructUpdateCommand();
337			int j=0;
338			try
339			{
340			    for(j=0;j<entity.Count;j++)
341				{	
342					db.SetParameterValue(dbCommand,"Uid",entity[j].Uid);
343					db.SetParameterValue(dbCommand,"Emp_Id",entity[j].Emp_Id);
344					db.SetParameterValue(dbCommand,"Display_Name",entity[j].Display_Name);
345					db.SetParameterValue(dbCommand,"Pwd",entity[j].Pwd);
346					db.SetParameterValue(dbCommand,"Status",entity[j].Status);
347					db.SetParameterValue(dbCommand,"Create_Time",entity[j].Create_Time);
348					db.SetParameterValue(dbCommand,"Update_Time",entity[j].Update_Time);
349					rc+=db.ExecuteNonQuery(dbCommand,trans);
350				}
351			}
352			catch(DbException ex)
353			{				
354				HandleDbException(ex,entity[j]);		
355			}			 
356			return rc;			
357		}		
358		public int Update(List<MoTuser> entity)
359		{
360			int rc = 0;	
361			using (DbConnection cnn = db.CreateConnection())
362            {   
363				DbTransaction trans=null;
364				try
365				{          
366					cnn.Open();
367					using(trans = cnn.BeginTransaction())
368					{
369					rc=Update(entity,trans);
370					trans.Commit();		
371					}
372					cnn.Close();
373				}
374				catch(DbException ex)
375				{
376					if(trans!=null)trans.Rollback();	
377					HandleDbException(ex);	
378				}				
379			}
380			return rc;
381		}		
382		public int Update(DataTable dt, DbTransaction trans)
383		{
384			int rc=0;			 
385            DbCommand dbCommand=ConstructUpdateCommand();		
386			int j=0;
387		    try
388		    {
389			    for(j=0;j<dt.Rows.Count;j++)
390				{	
391					db.SetParameterValue(dbCommand,"Uid",dt.Rows[j]["Uid"]);
392					db.SetParameterValue(dbCommand,"Emp_Id",dt.Rows[j]["Emp_Id"]);
393					db.SetParameterValue(dbCommand,"Display_Name",dt.Rows[j]["Display_Name"]);
394					db.SetParameterValue(dbCommand,"Pwd",dt.Rows[j]["Pwd"]);
395					db.SetParameterValue(dbCommand,"Status",dt.Rows[j]["Status"]);
396					db.SetParameterValue(dbCommand,"Create_Time",dt.Rows[j]["Create_Time"]);
397					db.SetParameterValue(dbCommand,"Update_Time",dt.Rows[j]["Update_Time"]);
398					rc+=db.ExecuteNonQuery(dbCommand,trans);
399				}
400			}
401			catch(DbException ex)
402			{				
403				HandleDbException(ex,dt.Rows[j]);		
404			}		
405            return rc;
406			
407		}		
408		public int Update(DataTable dt)
409        {
410			if(dt==null ||dt.Rows.Count==0) return 0;
411            int rc=0;       
412            using (DbConnection cnn = db.CreateConnection())
413            {
414				DbTransaction trans=null;
415				try
416                {
417					cnn.Open();
418					using(trans = cnn.BeginTransaction())
419					{
420						rc = Add(dt, trans);
421						trans.Commit();						
422					}   
423					cnn.Close();                  
424                }
425                catch(DbException ex)
426				{
427					if(trans!=null)trans.Rollback();	
428					HandleDbException(ex);	
429				}		
430                
431            }
432            return rc;
433        }
434		#endregion
435		
436		#region Update By DataSet
437		private void PrepareDataAdapterCommand(out DbCommand dbInsertCommand,
438		                     out DbCommand dbUpdateCommand,out DbCommand dbDeleteCommand)
439		{
440			dbInsertCommand = db.GetSqlStringCommand(SQL_INSERT);
441			#region set insert cmd parameters
442			db.AddInParameter(dbInsertCommand, "Uid",DbType.AnsiString, "Uid", DataRowVersion.Current);
443			db.AddInParameter(dbInsertCommand, "Emp_Id",DbType.AnsiString, "Emp_Id", DataRowVersion.Current);
444			db.AddInParameter(dbInsertCommand, "Display_Name",DbType.String, "Display_Name", DataRowVersion.Current);
445			db.AddInParameter(dbInsertCommand, "Pwd",DbType.AnsiString, "Pwd", DataRowVersion.Current);
446			db.AddInParameter(dbInsertCommand, "Status",DbType.Int32, "Status", DataRowVersion.Current);
447			db.AddInParameter(dbInsertCommand, "Create_Time",DbType.DateTime, "Create_Time", DataRowVersion.Current);
448			db.AddInParameter(dbInsertCommand, "Update_Time",DbType.DateTime, "Update_Time", DataRowVersion.Current);
449			#endregion
450			dbUpdateCommand = db.GetSqlStringCommand(SQL_UPDATE);
451			#region Set update cmd value parameters
452			db.AddInParameter(dbUpdateCommand, "Emp_Id", DbType.AnsiString, "Emp_Id", DataRowVersion.Current);
453			db.AddInParameter(dbUpdateCommand, "Display_Name", DbType.String, "Display_Name", DataRowVersion.Current);
454			db.AddInParameter(dbUpdateCommand, "Pwd", DbType.AnsiString, "Pwd", DataRowVersion.Current);
455			db.AddInParameter(dbUpdateCommand, "Status", DbType.Int32, "Status", DataRowVersion.Current);
456			db.AddInParameter(dbUpdateCommand, "Create_Time", DbType.DateTime, "Create_Time", DataRowVersion.Current);
457			db.AddInParameter(dbUpdateCommand, "Update_Time", DbType.DateTime, "Update_Time", DataRowVersion.Current);
458			#endregion
459			#region set update cmd pk where parameters
460			db.AddInParameter(dbUpdateCommand, "Uid", DbType.AnsiString, "Uid", DataRowVersion.Current);
461			#endregion			
462			dbDeleteCommand = db.GetSqlStringCommand(SQL_DELETE);
463			#region set delete cmd pk where parameters
464			db.AddInParameter(dbDeleteCommand, "Uid", DbType.AnsiString, "Uid", DataRowVersion.Current);
465			#endregion
466		}
467		
468		
469		
470		/// <summary>
471		/// ??DataSet??????????
472		/// </summary>
473		public int UpdateByDataSet(DataSet dst, string strTableName, DbTransaction trans)
474		{
475			DbCommand dbInsertCommand = null;			
476			DbCommand dbUpdateCommand = null;
477			DbCommand dbDeleteCommand = null;
478			PrepareDataAdapterCommand(out dbInsertCommand,out dbUpdateCommand,out dbDeleteCommand);
479			try
480            {
481			    return db.UpdateDataSet(dst, strTableName, dbInsertCommand, dbUpdateCommand, dbDeleteCommand, trans);
482			}
483			catch(DbException ex)
484			{			
485				trans.Rollback();
486				HandleDbException(ex);				
487			}
488			return 0;//TODO:Should return Application Specific Error Code.
489		}
490		
491		/// <summary>
492		/// ??DataSet???????????
493		/// </summary>
494		public int UpdateByDataSet(DataSet dst, string strTableName)
495		{
496			DbCommand dbInsertCommand = null;			
497			DbCommand dbUpdateCommand = null;
498			DbCommand dbDeleteCommand = null;
499			PrepareDataAdapterCommand(out dbInsertCommand,out dbUpdateCommand,out dbDeleteCommand);
500			try
501            {
502			    return db.UpdateDataSet(dst, strTableName, dbInsertCommand, dbUpdateCommand, dbDeleteCommand, UpdateBehavior.Transactional);			
503			}
504			catch(DbException ex)
505			{	
506				HandleDbException(ex);				
507			}
508			return 0;//TODO:Should return Application Specific Error Code.			
509		}
510		
511		
512		
513		#endregion 
514		
515		#region Delete
516		
517		private DbCommand ConstructDeleteCommand()
518		{
519			DbCommand dbCommand=db.GetSqlStringCommand(SQL_DELETE);
520			 
521			db.AddInParameter(dbCommand,"Uid",DbType.AnsiString);
522			 
523			return dbCommand;
524		}		
525		private DbCommand ConstructDeleteCommand(MoTuser entity)
526		{
527			DbCommand dbCommand=db.GetSqlStringCommand(SQL_DELETE);
528			 
529			db.AddInParameter(dbCommand,"Uid",DbType.AnsiString,entity.Uid);
530		 
531			return dbCommand;
532		}
533		
534		/// <summary>
535		/// delete by pk(entity)
536		/// </summary>	
537		public int Delete(MoTuser entity,DbTransaction trans)
538		{	try
539            {
540				DbCommand dbCommand=ConstructDeleteCommand(entity);			
541				return db.ExecuteNonQuery(dbCommand,trans);
542			}
543			catch(DbException ex)
544			{			
545				trans.Rollback();
546				HandleDbException(ex,entity);				
547			}
548			return 0;
549		}	
550		public int Delete(MoTuser entity)
551		{
552			try
553            {
554				DbCommand dbCommand=ConstructDeleteCommand(entity);			
555				return db.ExecuteNonQuery(dbCommand);
556			}
557			catch(DbException ex)
558			{				
559				HandleDbException(ex,entity);				
560			}
561			return 0;
562		}		
563		/// <summary>
564		/// mul-delete
565		/// </summary>	
566		public int Delete(List<MoTuser> entities,DbTransaction trans)
567		{
568			int rc=0;	
569			int j=0;
570			DbCommand dbCommand=ConstructDeleteCommand();		
571			try
572			{
573			    for(j=0;j<entities.Count;j++)
574				{	
575					db.SetParameterValue(dbCommand,"Uid",entities[j].Uid);
576					rc+=db.ExecuteNonQuery(dbCommand,trans);
577				}
578			}
579			catch(DbException ex)
580			{	
581				if(trans!=null)trans.Rollback();
582				HandleDbException(ex,entities[j]);				
583			}			 
584			return rc;			
585		}		
586		public int Delete(List<MoTuser> entities)
587		{
588			int rc = 0;			
589			using (DbConnection cnn = db.CreateConnection())
590            {      
591				DbTransaction trans=null;
592				try
593				{
594					cnn.Open();
595					using(trans = cnn.BeginTransaction())
596					{
597						rc=Delete(entities,trans);
598						trans.Commit();
599					}               
600					cnn.Close();
601				}
602				catch(DbException ex)
603				{	
604					if(trans!=null)trans.Rollback();
605					HandleDbException(ex);				
606				}	
607			}
608			return rc;
609		}
610		
611		
612		public int Delete(DataTable dt,DbTransaction trans)
613		{
614			int rc=0;			
615			int j=0;
616			DbCommand dbCommand=ConstructDeleteCommand();		
617			try
618			{
619			    for(j=0;j<dt.Rows.Count;j++)
620				{	
621					db.SetParameterValue(dbCommand,"Uid",dt.Rows[j]["Uid"]);
622					rc+=db.ExecuteNonQuery(dbCommand,trans);
623				}
624			}
625			catch(DbException ex)
626			{	
627				if(trans!=null)trans.Rollback();
628				HandleDbException(ex,dt.Rows[j]);				
629			}			 
630			return rc;			
631		 	
632		}		
633		public int Delete(DataTable dt)
634		{
635			int rc=0;
636		    using (DbConnection cnn = db.CreateConnection())
637            {
638				DbTransaction trans=null;
639				try
640				{
641					cnn.Open();				
642					using(trans = cnn.BeginTransaction())
643					{
644						rc = Delete(dt, trans);
645						trans.Commit();
646					}
647					cnn.Close();
648                }
649                catch(DbException ex)
650				{	
651					if(trans!=null)trans.Rollback();
652					HandleDbException(ex);				
653				}
654                
655            }
656            return rc;
657		}		
658		/// <summary>
659		/// ??????????
660		/// </summary>	
661		public int Delete(string Uid,DbTransaction trans)
662		{			 
663			try
664			{
665				DbCommand dbCommand=db.GetSqlStringCommand(SQL_DELETE);
666				 
667				db.AddInParameter(dbCommand,"Uid",DbType.AnsiString,Uid);
668				 
669				return db.ExecuteNonQuery(dbCommand,trans);
670			}
671			catch(DbException ex)
672			{	
673				if(trans!=null)trans.Rollback();
674				HandleDbException(ex);				
675			}	
676			return 0;
677		}	
678		
679		public int Delete(string Uid)
680		{
681			try
682			{
683				DbCommand dbCommand=db.GetSqlStringCommand(SQL_DELETE);
684				 
685				db.AddInParameter(dbCommand,"Uid",DbType.AnsiString,Uid);
686				 
687				return db.ExecuteNonQuery(dbCommand);
688			}
689			catch(DbException ex)
690			{			 
691				HandleDbException(ex);				
692			}	
693			return -1;
694		}
695		#endregion
696		
697		#region Query All by condition
698		/// <summary>
699		/// ????WHERE????????,?condition????????
700		/// </summary>		
701		public DataSet Query(string condition)
702		{			
703			try
704			{
705				return db.ExecuteDataSet(CommandType.Text,String.IsNullOrEmpty(condition)?SQL_SELECT:SQL_SELECT+condition);	 
706			}
707			catch(DbException ex)
708			{			 
709				HandleDbException(ex);				
710			}	
711            return new DataSet();
712		}		
713	    public DataSet Query(string condition, DbTransaction trans)
714        {   
715            try
716            {
717                return db.ExecuteDataSet(trans, CommandType.Text, String.IsNullOrEmpty(condition) ? SQL_SELECT : SQL_SELECT + condition);
718            }
719            catch(DbException ex)
720			{			 
721				HandleDbException(ex);				
722			}	
723            return new DataSet();
724        }
725		#endregion
726		
727		#region GetEntity(s)
728		/// <summary>
729		///????????????
730		/// </summary>
731	    public MoTuser GetEntity(string mUid )
732		{			 
733			MoTuser entity = new MoTuser();
734			entity.Uid=mUid;
735			if(GetEntityEx(entity))
736			{
737				return entity;
738			}
739			else
740			{
741				return null;
742			}
743		}
744		
745		public MoTuser GetEntity(string mUid ,DbTransaction trans)
746		{			 
747			MoTuser entity = new MoTuser();
748			entity.Uid=mUid;
749			if(GetEntityEx(entity,trans))
750			{
751				return entity;
752			}
753			else
754			{
755				return null;
756			}
757		}
758		
759		private DbCommand ConstructSelectOneCommand(Database db,MoTuser entity)
760		{
761			DbCommand dbCommand=db.GetSqlStringCommand(SQL_SELECT_ONE);
762			 
763			db.AddInParameter(dbCommand,"Uid",DbType.AnsiString,entity.Uid);
764			return dbCommand;
765		}
766		private DbCommand ConstructSelectOneCommand(Database db)
767		{
768			DbCommand dbCommand=db.GetSqlStringCommand(SQL_SELECT_ONE);
769			 
770			db.AddInParameter(dbCommand,"Uid",DbType.AnsiString);
771			return dbCommand;
772		}
773		private void PopulateEntityByDataReader(IDataReader reader,ref MoTuser entity)
774		{
775			if (!reader.IsDBNull(0)) entity.Uid = reader.GetString(0);
776			if (!reader.IsDBNull(1)) entity.Emp_Id = reader.GetString(1);
777			if (!reader.IsDBNull(2)) entity.Display_Name = reader.GetString(2);
778			if (!reader.IsDBNull(3)) entity.Pwd = reader.GetString(3);
779			if (!reader.IsDBNull(4)) entity.Status = reader.GetInt32(4);
780			if (!reader.IsDBNull(5)) entity.Create_Time = reader.GetDateTime(5);
781			if (!reader.IsDBNull(6)) entity.Update_Time = reader.GetDateTime(6);
782		}
783		
784		/// <summary>
785		///????????????????????????????????.
786		///??????????????????????ref????
787		/// </summary>
788		public bool GetEntityEx(MoTuser entity)
789		{
790			DbCommand dbCommand=ConstructSelectOneCommand(db,entity);
791			try
792			{
793				using(IDataReader reader=db.ExecuteReader(dbCommand))
794				{   
795					if(reader.Read()) 
796					{
797						PopulateEntityByDataReader(reader,ref entity);
798						return true;
799					}
800				}
801			}
802			catch(DbException ex)
803			{	 
804				HandleDbException(ex,entity);				
805			}	
806			return false;
807		}
808		public bool GetEntityEx(MoTuser entity,DbTransaction trans)
809		{		
810			DbCommand dbCommand=ConstructSelectOneCommand(db,entity);
811			try
812			{
813				using(IDataReader reader=db.ExecuteReader(dbCommand,trans))
814				{   
815					if(reader.Read())
816					{
817						PopulateEntityByDataReader(reader,ref entity);	
818						return true;
819					}
820				}
821			} 
822			catch(DbException ex)
823			{			 
824				trans.Rollback();
825				HandleDbException(ex,entity);				
826			}	
827			return false;
828			
829		}
830		
831		public List<MoTuser> GetEntities(string condition,DbTransaction trans)
832		{
833			List<MoTuser> list=new List<MoTuser>();			
834			try
835			{				
836			    using(IDataReader reader= db.ExecuteReader(trans,CommandType.Text, String.IsNullOrEmpty(condition) ? SQL_SELECT : SQL_SELECT+ condition))
837			    {
838				    while(reader.Read())
839					{			
840						MoTuser entity=new MoTuser();
841						PopulateEntityByDataReader(reader,ref entity);	
842						list.Add(entity);
843					}
844			    }
845			}
846			catch(DbException ex)
847			{			 
848				trans.Rollback();
849				HandleDbException(ex);				
850			}	
851			return list;
852			
853		}
854		
855		
856		public List<MoTuser> GetEntities(string condition)
857		{
858			List<MoTuser> list=new List<MoTuser>();	
859			try
860			{
861				using(IDataReader reader= db.ExecuteReader(CommandType.Text, String.IsNullOrEmpty(condition) ? SQL_SELECT : SQL_SELECT+" " + condition))
862				{   
863					while(reader.Read())
864					{	
865						MoTuser entity=new MoTuser();
866						PopulateEntityByDataReader(reader,ref entity);	
867						list.Add(entity);
868					}
869				}
870			}
871			catch(DbException ex)
872			{	 
873				HandleDbException(ex);				
874			}	
875			return list;
876		}
877		#endregion
878		
879		#region Count
880		/// <summary>
881		/// ????????
882		/// </summary>
883		public int GetCount()
884		{
885			return Convert.ToInt32(db.ExecuteScalar(CommandType.Text,
886			"SELECT COUNT(*) FROM TUser "));
887		}
888		
889		public int GetCount(DbTransaction trans)
890		{
891			try
892			{
893			    return Convert.ToInt32(db.ExecuteScalar(trans,CommandType.Text,
894			    "SELECT COUNT(*) FROM TUser "));
895		    }
896		    catch(DbException ex)
897			{	 
898				HandleDbException(ex);				
899			}	
900			return -1;
901		}
902		
903		/// <summary>
904		/// ????WHERE?????
905		/// </summary>
906		public int GetCount(string condition)
907		{
908			return Convert.ToInt32(db.ExecuteScalar(CommandType.Text,String.IsNullOrEmpty(condition)?
909			"SELECT COUNT(*) FROM TUser ":"SELECT COUNT(*) FROM TUser "+condition ));
910		}
911		
912		public int GetCount(string condition,DbTransaction trans)
913		{
914			try
915			{
916			   return Convert.ToInt32(db.ExecuteScalar(trans,CommandType.Text,String.IsNullOrEmpty(condition)?
917			   "SELECT COUNT(*) FROM TUser ":"SELECT COUNT(*) FROM TUser "+condition ));
918		    }
919			catch(DbException ex)
920			{	 
921				HandleDbException(ex);				
922			}	
923			return -1;
924		}
925		#endregion
926		
927		#region Check isExist
928		/// <summary>
929		/// ????????????
930		/// </summary>
931        public bool IsExist(string mUid )
932		{
933			string sql="SELECT COUNT(*) FROM TUser  WHERE UID=@Uid  ";
934			
935			DbCommand dbCommand=db.GetSqlStringCommand(sql);
936			db.AddInParameter(dbCommand,"Uid",DbType.AnsiString,mUid);
937			return Convert.ToInt32(db.ExecuteScalar(dbCommand))>0;
938		}
939		
940		public bool IsExist(string mUid ,DbTransaction trans)
941		{			 
942			string sql="select count(*) from TUser  where UID=@Uid  ";
943			
944			DbCommand dbCommand=db.GetSqlStringCommand(sql);
945			db.AddInParameter(dbCommand,"Uid",DbType.AnsiString,mUid);
946			try
947			{
948			   return Convert.ToInt32(db.ExecuteScalar(dbCommand,trans))>0;
949			}
950			catch
951			{
952			    trans.Rollback();
953				throw;
954			}		 
955		}
956		
957		public bool IsExist(MoTuser entity,DbTransaction trans)
958		{			
959			string sql="select count(*) from TUser  where UID=@Uid  ";
960			
961			DbCommand dbCommand=db.GetSqlStringCommand(sql);
962			#region set pk where parameters
963			db.AddInParameter(dbCommand,"Uid",DbType.AnsiString,entity.Uid);
964			#endregion
965			try
966			{
967			   return Convert.ToInt32(db.ExecuteScalar(dbCommand,trans))>0;
968			}
969			catch
970			{
971			    trans.Rollback();
972				throw;
973			}		 
974		}
975		
976		public bool IsExist(MoTuser entity)
977		{
978			string sql="select count(*) from TUser  where UID=@Uid  ";
979			
980			DbCommand dbCommand=db.GetSqlStringCommand(sql);
981			#region set pk where parameters
982			db.AddInParameter(dbCommand,"Uid",DbType.AnsiString,entity.Uid);
983			#endregion
984			 
985			return Convert.ToInt32(db.ExecuteScalar(dbCommand))>0;
986			 	 
987		}
988		#endregion
989		
990
991	}
992}	
993#endregion
994