Three-layer structural system display layerlogic layerdata layer in ASP.NET

xiaoxiao2021-04-09  518

The display layer is usually made up by .aspx / .aspx.cs file, used to display the data page, the page layer should be the method logic layer in the logical layer directly call the logical layer is an intermediate layer, used to connect the page Layers and data layers, it is necessary to provide interfaces to the page layer. At the same time, it is also necessary to call the method from the data layer to use the data layer to be the best. Generally, the data is operated. This three-layer system is explained. Try it. Page layer [default.aspx]: only one DataGrid control and the final result of the Label control page

DEFAULT.ASPX.CS file

using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls Using system.Web.ui.htmlcontrols; Using Lemongtree.bl; Namespace Services {///

///_Default's summary description. /// public class _default: System.Web.UI.Page {protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.DataGrid DataGrid1; private void Page_Load (object sender, System.eventargs e) {// Place the user code here to initialize the page if (! Page.ispostback) {setup ("SELECT * FROM FAVOR", DataGrid1);}} private void setup (String SQL, DATAGRID DG) { BLAYER BL = New BLAYER ("Server = Lemongtree; UID = SA; PWD = SA; Database = BBS"); bl.ShowDataGrid (SQL, DG); label1.text = bl.Error;}

#Region Web Form Designer Generated Code Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // InitializeComponent (); base.onit (e);} ///

/// Designer Supports the required method - Do not use the code editor to modify the // / this method. /// private void InitializeComponent () {this.DataGrid1.PageIndexChanged = new System.Web.UI.WebControls.DataGridPageChangedEventHandler (this.DataGrid1_PageIndexChanged); this.Load = new System.EventHandler (this.Page_Load) } #Endregion

Private void DataGrid1_pageIndexchanged (Object Source, System.Web.ui.WebControls.DataGridPageChangedeventArgs E) {}}}

Logic layer [bl.cs]

using System; using System.Text; using System.Data; using System.Data.SqlClient; using LemongTree.DB; using System.Web.UI.WebControls; namespace LemongTree.BL {///

/// BL of Abstract. /// public class BLayer {private string strconn; private SqlConnection objConn; private DBMaster dbm; private string ErrMsg; public BLayer (string strconn) {// // TODO: Add constructor logic here // this .strconn = strconn; this.objConn = new SqlConnection (strconn); dbm = new dBMaster (strconn);} public string error {get {return ErrMsg;}} public void showDataGrid (string strsql, DataGrid dgrd) {dgrd.DataSource = DBM.DataSet (STRSQL); errmsg = dbm.error; DGRD.DATABIND (); }}} Data layer [db.cs]

转载请注明原文地址:https://www.9cbs.com/read-133191.html

New Post(0)