我现在是把系统内所有的接口方法都写在一个文件里面。
- C# code
namespace VCShop.Data{ using System; using System.Collections.Generic; using System.Data; using System.Runtime.InteropServices; using System.Web.UI.WebControls; using System.Xml; using VCShop.Entity; public interface IDataProvider { object AddCommendUserScore(string orderID, string username, string type, string content); int AddProductASk(ProductAsk ask); int AddProductReivewBadCount(string id); int AddProductReivewGoodCount(string id); int AddProductReview(ProductReview review); int AddProductShopCut(ProductShopCut scut); int AddUserScore(string username, string score, string type, string content); int BindCouponUser(string Number, string Username); int CalcelOrderByUser(string ordernum, string remark); int CancelGroupBuy(long id, string Username); int ChangeAdminPassword(string Uid, string Password); int ChangeOrderIDInsert(string orderid, string tablename); int ChangeOrderIDUpdate(string id, string orderid, string tablename); int ChangeOrderUsedScore(string OrderNumber, string UsedScore); int ChangeUserScore(string username, string score, string content); bool CheckFittingExits(string id, string guid, string prop, string fittingproductid); int CheckIdCombo(Page src); DataTable CheckIsBlackIP(string ip); string CheckIsLastClass(string categoryid); bool CheckNameExits(string tablename, string name, string value); string CheckOrderProductExist(string PropertysID, string IsChangeSale, string IsFitting, string ProductID, string IsScore, string OrderNumber); int CheckPriceCard(string ids);……………………………… }}
所有的数据访问层的实现代码,也是写在一个文件里面
- C# code
namespace VCShop.Data.MsSql{ public class DataProvider : IDataProvider { private string strFilePath = ""; private const string strRoot = "/BaseConfig/"; public virtual object AddCommendUserScore(string orderID, string username, string type, string content) { return DbHelper.ExecuteNonQuery(string.Format("AddCommendUserScore N'{0}', N'{1}', N'{2}', N'{3}'", new object[] { orderID, username, type, content })); } public virtual int AddProductASk(ProductAsk ask) { StringBuilder builder = new StringBuilder(); builder.Append(" INSERT INTO [Web_ProductAsk]").Append("([Type]").Append(",[ProductID]").Append(",[UserName]").Append(",[Content]").Append(",[Pleased]").Append(",[Displeased]").Append(")VALUES ").Append("(''").Append("," + ask.ProductID.ToString()).Append(",'" + ask.UserName + "'").Append(",'" + ask.Content + "'").Append(",0").Append(",0").Append(")"); return DbHelper.ExecuteNonQuery(builder.ToString()); }…………………… }}
这样问题出现了,会发现每个文件里面的代码量,会非常大,我想问的是,这样的执行效率,和把,按照不同的功能,把这些接口,和接口实现,分为不同的类,在执行效率上面,区别大不大。
------解决方案--------------------------------------------------------
首先把类似的这些代码简化下吧:
builder.Append(" INSERT INTO [Web_ProductAsk]").Append("([Type]").Append(",[ProductID]").Append(",[UserName]").Append(",[Content]").Append(",[Pleased]").Append(",[Displeased]").Append(")VALUES ").Append("(''").Append("," + ask.ProductID.ToString()).Append(",'" + ask.UserName + "'").Append(",'" + ask.Content + "'").Append(",0").Append(",0").Append(")");