这个三层架构应用程序的业务逻辑代码是什么? [英] what is the business logic code for this three tier architecture application?

查看:116
本文介绍了这个三层架构应用程序的业务逻辑代码是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表示层

Presentation Layer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using DAL;

namespace _3_tiersample
{
    public partial class RegistrationForm : System.Web.UI.Page
    {
        classBLL Objbal = new classBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
         
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                string Output = string.Empty;
                classBLL Objbalregistration = new classBLL();
                Objbalregistration.Name = TextBox1.Text;
                Objbalregistration.Roll_Number = Convert.ToInt32(TextBox2.Text);
                Objbalregistration.Email_Id = TextBox3.Text;
                Objbalregistration.Mobile_Number = TextBox4.Text;
                Objbalregistration.InsertUserDetails(Objbal);
                Console.WriteLine("Data Inserted");
            }
            catch(Exception Ex)
            {
                Console.WriteLine(Ex);
            }
        }

    }
}



商业逻辑层


Business Logic Layer

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


namespace BLL
{
    public class classBLL
    {
        private string _Name;
        private int _Roll_Number;
        private string _Email_Id;
        public string _Mobile_Number;


        public string Name
        {
            set { _Name = value; }
            get { return _Name; }
        }
        public int Roll_Number
        {
            set { _Roll_Number = value; }
            get { return _Roll_Number; }
        }
        public string Email_Id
        {
            set { _Email_Id = value; }
            get { return _Email_Id; }
        }
        public string Mobile_Number
        {
            set { _Mobile_Number = value; }
            get { return _Mobile_Number; }
        }

    }
}





数据访问层



Data Access Layer

using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using BLL;

namespace DAL
{
    public class classDAL
    {
        string connection = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
     
        public void InsertUserDetails(classBLL Objbal)
      {
          SqlConnection con = new SqlConnection(connection);
          SqlCommand cmd = new SqlCommand("sp_InsertEmpdetails", con);
          cmd.CommandType = CommandType.StoredProcedure;
          con.Open();
          try
          {
              cmd.Parameters.AddWithValue("@Name", Objbal.Name);
              cmd.Parameters.AddWithValue("@Roll_Number", Objbal.Roll_Number);
              cmd.Parameters.AddWithValue("@Email_Id", Objbal.Email_Id);
              cmd.Parameters.AddWithValue("@Mobile_Number", Objbal.Mobile_Number);
              Console.WriteLine( "data saved");
          }
          catch (Exception Ex)
          {
              Console.WriteLine(Ex);
          }
          finally
          {
              con.Dispose();
          }

      }
       
    }  
}



在上面的代码中我写了Dataaccesslayer中的业务逻辑层代码我的意思是我的业务规则是将数据插入数据库,但我已经在数据访问层编写了逻辑,但我希望它在业务逻辑层中编写。在业务逻辑中编写的代码是什么(实时每个人都用来在业务逻辑层中编写业务逻辑代码)

帮助我,让我感到困惑

提前致谢


In the above code i have written the business Logic Layer code in Dataaccesslayer i mean my business rule is to insert the data into database but i have written the logic in data access layer but i want it to write in business logic layer.what is the code to write within the business logic layer.(in real time everyone used to write the business logic code with in the Business logic layer right)
Help me Out i'am getting Confused
Thanks in advance

推荐答案

您的问题中业务逻辑层的代码块实际上是实体(为其他层上使用的字段创建变量)。那里缺少方法 InsertUserDetails 。因此,在您的ClassCLL中,您必须创建该方法&你应该将值传递给数据访问层。



将值从页面传递到数据访问层不是一个好方法。所以你必须为businesslogics创建一个层。

The code-block of "Business Logic Layer" from your question is actually Entities(creating variables for fields to be used on other layers). And the method InsertUserDetails is missing there. So in your ClassCLL you have to create that method & you should pass values to Data Access Layer.

Passing values from page to Data Access Layer is not a good method. So you have to create a layer for businesslogics.
Quote:

这个三层架构应用程序?

你应该知道层和层之间的差异。图层。

图层和层架构的差异 [ ^ ]

3 Layer vs 3 Tier Architecture | 3层和3层架构之间的区别 [ ^ ]

这个是终极的

Dude,我的业务逻辑在哪里? [ ^ ]



这里有几篇关于你主题的文章

C#Web应用程序中的3层体系结构 [ ^ ]

Three La在C#.NET中的架构 [ ^ ]

N-层级架构和技巧 [ ^ ]

And you should know about differences between tiers & layers.
Difference in layer and tier architecture[^]
3 Layer vs 3 Tier Architecture | Difference Between 3 Layer and 3 Tier Architecture[^]
And this one is ultimate
Dude, where's my business logic?[^]

Here few articles on your topic
3-Tier Architecture in C# Web Application[^]
Three Layer Architecture in C# .NET[^]
N-Tier Architecture and Tips[^]


在这里参考CP链接....

ASP-Net-Tier-architecture
refer CP link here....
ASP-Net-Tier-architecture


请参考以下链接....



ASP.NET 3层架构 [ ^ ]



谢谢,

-RG
Please refer the below link here....

ASP.NET 3 Tier Architecture[^]

Thanks,
-RG


这篇关于这个三层架构应用程序的业务逻辑代码是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆