这个三层架构应用程序的业务逻辑代码是什么?

编程入门 行业动态 更新时间:2024-10-25 16:26:26
本文介绍了这个三层架构应用程序的业务逻辑代码是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

表示层

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

更多推荐

这个三层架构应用程序的业务逻辑代码是什么?

本文发布于:2023-11-05 04:03:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1559844.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   架构   逻辑   代码   业务

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!