1)业务逻辑层:DynamicDataBusi.cs
以下是代码片段: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using MEntities; using System.Data.SqlClient; namespace BBusiness { public class DynamicDataBusi { public DynamicDataTable GetDynamicDataTable(string strSQL, string ConnStr) { SqlConnection theConn = new SqlConnection(ConnStr); DataTable theTable = new HDatabase.DynamicDataAccess().GetDataTable(strSQL, theConn); DynamicDataTable theDynamicTable = new DynamicDataTable(); if (theTable != null) { foreach (DataColumn col in theTable.Columns) { DynamicDataColumn theCol = new DynamicDataColumn(); theCol.Caption = col.Caption; theCol.DataType = col.DataType.Name; theCol.FieldName = col.ColumnName; theCol.Length = col.MaxLength; theCol.FormatString = ""; theDynamicTable.Columns.Add(theCol); } foreach (DataRow row in theTable.Rows) { DynamicDataRow theRow = new DynamicDataRow(); for (int i = 0; i < theTable.Columns.Count; i++) { DynamicDataField theDataField = new DynamicDataField(); theDataField.FieldName = theTable.Columns[i].ColumnName; theDataField.DataType = theTable.Columns[i].DataType.Name; theDataField.Value = row[i]; theRow.DataFields.Add(theDataField); } theDynamicTable.Rows.Add(theRow); } } return theDynamicTable; } } } |
所有要提供给客户端得实体的打包,以及服务端得实体缓存之类的都可以封装到这一层。业务逻辑层另外的最主要的功能就是业务逻辑的处理了,简单的新增,修改,删除和查询都可在这里封装,有的虽然只是简单的调用数据访问层,但也不要让服务层直接调用。因为在这一层可以增加很多功能,比如冲突检测,逻辑检查等。