.net(五) 业务层实现

目录

1、IBusiness

2、Service

3、Business

4、webservice接口


业务层实现主要业务逻辑接口IBLL(Interface business logic layer )、BLL(接口实现层)以及DAL(数据交互层)。

新建Business文件夹,分别添加Business、IBusiness、Service工程,每个下可以添加具体类。

为了方便管理一般三个工程类前缀名相同,可以是某人、某个工程的名称,后缀分别为BLL,IBLL,DAL。

以NorthWind为例:

业务层处于接口与底层数据库操作之间。

编写一个测试demo,实现接口访问业务层访问数据层。

1、IBusiness

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace IBussiness
{
    public interface  NorthWindIBLL
    {
        string test(string str);
    }
}

2、Service

添加DataAccess.DataBase.SqlServer,Utilities;

using System.Data;
using DataAccess.DataBase.SqlServer;
using Utilities;
namespace DAL
{
   public class NorthWindDAL
    {
        public string test(string str)
        {
            string opSql = "select*from Products where SupplierID>10";

            DataTable da = SqlServerHelper.ExectuteDataTable(SqlServerHelper.connString, CommandType.Text, opSql, null);

            //string strJson = ConvertToJson.ToJSON(da);
            
            string strJson = ConvertJson.ToJson(da);
            return strJson;
        }
    }
}

 

3、Business

业务是实现层,添加DataAccess.DataBase.SqlServer;

类继承接口

using System;
using IBussiness;
using DAL;


namespace Bussiness
{
    public class NorthWindBLL:NorthWindIBLL
    {
        private readonly NorthWindDAL dal = new NorthWindDAL();
        //test
        public string test(string str)
        {
            try
            {
                string strJson = dal.test(str);
                return "{\"erron\":0,\"errmsg\":\"成功!\",\"data\":" + strJson + "}";
            }
            catch (Exception e)
            {

                return e.Message.ToString();

            }

        }
    }
}

 

4、webservice接口

添加Bussiness、IBussiness引用。

[WebMethod(Description = "接口-业务-数据")]
        //test
        public string test(string str)
        {
            string result = string.Empty;
            NorthWindIBLL bll = new NorthWindBLL();

            result = bll.test(str);

            return result;

        }

运行结果:

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HySmiley

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值