1總合了n種資料訪問層……——……不是很成熟
2. 由於鄙人的懶惰缺少了-傳遞參數(這部分設計完了但是~~懶得寫分析原諒哈),這部分主要採用緩衝參數的設計.
3.缺少DAL.SqlClient.SqlParametersAll.SqlText枚舉的定義他用來封裝所有的預存程序的名稱
4.將要呈現給大家的是一部分中的部分哈~~原因鄙人懶惰~~造成的~~檢討中
public ExecState Exec(DAL.SqlClient.SqlParametersAll.SqlText commandText)
{
ExecState ren = new ExecState();
System.Data.SqlClient.SqlConnection sqlCon=new System.Data.SqlClient.SqlConnection(this.ConnectionString);
System.Data.SqlClient.SqlCommand sqlCommand = new System.Data.SqlClient.SqlCommand(
Enum.GetName(typeof(DAL.SqlClient.SqlParametersAll.SqlText), commandText), sqlCon);
sqlCommand.CommandType = CommandType.StoredProcedure;
try
{
sqlCon.Open();
sqlCommand.Transaction = sqlCon.BeginTransaction();
//---------------------記錄影響的行數
ren.State.Add("NonQuery", sqlCommand.ExecuteNonQuery());
//---尋找輸出參數
this.SelectOuputParameters(ren, sqlCommand.Parameters);
//--成功提交
sqlCommand.Transaction.Commit();
}
catch (System.Data.SqlClient.SqlException exp)
{
//--失敗了復原
sqlCommand.Transaction.Rollback();
}
finally
{
if (sqlCon.State == ConnectionState.Open)
{
sqlCon.Close();
sqlCon.Dispose();
}
}
return ren;
}
//--尋找輸出參數
/**//// <summary>
/// 尋找輸出參數,不用返回資料因為是按引用傳遞的
/// </summary>
/// <param name="ren"></param>
/// <param name="SelectPr"></param>
private void SelectOuputParameters(ExecState ren, System.Data.SqlClient.SqlParameterCollection SelectPr)
{
foreach (System.Data.SqlClient.SqlParameter OnLyPr in SelectPr)
{
if (OnLyPr.Direction ==ParameterDirection.InputOutput || OnLyPr.Direction == ParameterDirection.Output)
{
ren.State.Add(OnLyPr.ParameterName, OnLyPr.Value);
}
}
}
}
//------------執行後的狀態
public class ExecState
{
//-----------------------------------------儲存對應的資料存放區在那個組中
public System.Collections.Generic.Dictionary<string, object> State = new System.Collections.Generic.Dictionary<string,object>();
}
}