⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 outboxes.cs

📁 手机串口编程 手机串口编程 手机串口编程
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;

namespace JB.GraduateDesign.ESM.DataAccess
{
	using JB.GraduateDesign.ESM.Entity;
	using JB.GraduateDesign.ESM.Common;

	/// <summary>
	/// OutBoxes 的摘要说明。
	/// </summary>
	public class OutBoxes : IDisposable
	{
		private DataBaseOperate _dbo;

		public OutBoxes()
		{
			_dbo = new DataBaseOperate();
		}

		public bool DeleteOutBox ( int[] outBoxIds  )
		{
			SqlParameter[] sqlParams = 
			{
				new SqlParameter ( "@OutBoxId", SqlDbType.Int )
			};
			
			try
			{
				_dbo.StartTransation();
				for ( int i = 0; i < outBoxIds.Length; i++ )
				{
					sqlParams[0].Value = outBoxIds[i];
					 _dbo.Execute ( "DeleteOutBox", sqlParams ); 
				}
				_dbo.Commit();
			}
			catch ( Exception e )
			{
				throw new ApplicationException ( "访问数据库发生错误。", e );
			}
			return true;

		}

		public OutBoxData SelectOutBox ( int sendUserId, int outBoxId )
		{
			OutBoxData data = new OutBoxData();
			SqlParameter[] sqlParams = 
			{
				new SqlParameter ( "@SendUserId", SqlDbType.Int )
			};

			sqlParams[0].Value = sendUserId;
			try
			{
				_dbo.Search ( "SelectOutBox", data.OutBox, sqlParams );
			}
			catch ( Exception e )
			{
				throw new ApplicationException ( "访问数据库发生错误。", e ); 
			}

			SqlParameter[] sqlParams1 = 
			{
				new SqlParameter ( "@OutBoxId", SqlDbType.Int ),
				new SqlParameter ( "@SendUserId", SqlDbType.Int )
			};

			sqlParams1[0].Value = outBoxId;
			sqlParams1[1].Value = sendUserId;
			try
			{
				_dbo.Search ( "SelectOutBoxDetail", data.OutBoxDetail, sqlParams1 );

			}
			catch ( Exception e )
			{
				throw new ApplicationException ( "访问数据库发生错误。", e ); 
			}
	
			return data;
		}
 

		public bool InsertOutBox( OutBoxData data )
		{
			SqlParameter[] sqlParams =
			{
				new SqlParameter( "@SendUserId", SqlDbType.Int ),
				new SqlParameter( "@SendTime", SqlDbType.DateTime ),
				new SqlParameter( "@Message", SqlDbType.VarChar, 70 ),
				new SqlParameter( "@Status", SqlDbType.Int ),
				new SqlParameter( "@Type", SqlDbType.Int )
			};

		
			SqlParameter[] sqlParams1 = 
			{
				new SqlParameter( "@OutBoxId", SqlDbType.Int ),
				new SqlParameter( "@ReceiverId", SqlDbType.Int )
			};

			int index = 0;
			sqlParams[ index++ ].Value = data.OutBox[0].SendUserId;
			sqlParams[ index++ ].Value = data.OutBox[0].SendTime;
			sqlParams[ index++ ].Value = data.OutBox[0].Message;
			sqlParams[ index++ ].Value = data.OutBox[0].Status;
			sqlParams[ index++ ].Value = data.OutBox[0].Type;

			int outBoxMessageId = 0; 
			try
			{
				_dbo.StartTransation();

				outBoxMessageId = Convert.ToInt32 ( _dbo.Execute( "InsertOutBox", sqlParams ));
				for( int i = 0; i < data.OutBoxDetail.Count; i ++ )
				{
					int index1 = 0;
					sqlParams1[ index1++ ].Value = outBoxMessageId;
					sqlParams1[ index1++ ].Value = data.OutBoxDetail[i].ReceiverId;

					_dbo.Execute( "InsertOutBoxDetail", sqlParams1 );
					
				}
				_dbo.Commit();
			}
			catch( Exception e )
			{
				throw new ApplicationException( "执行数据库操作发生错误。", e );
			}
			return true;
		}

		#region IDisposable 成员

		public void Dispose()
		{
			Dispose(true);
			GC.SuppressFinalize(true); 
		}

		protected virtual void Dispose(bool disposing)
		{
			if (! disposing)
				return;

			if ( _dbo != null)
			{
				_dbo.Dispose();
				_dbo = null;
			}
		}

		#endregion
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -