惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
A
About on SuperTechFans
IT之家
IT之家
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Blog — PlanetScale
Blog — PlanetScale
aimingoo的专栏
aimingoo的专栏
云风的 BLOG
云风的 BLOG
The GitHub Blog
The GitHub Blog
Vercel News
Vercel News
G
Google Developers Blog
J
Java Code Geeks
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
Cloudbric
Cloudbric
L
LINUX DO - 最新话题
MyScale Blog
MyScale Blog
H
Heimdal Security Blog
PCI Perspectives
PCI Perspectives
Attack and Defense Labs
Attack and Defense Labs
S
Security @ Cisco Blogs
Latest news
Latest news
I
Intezer
L
Lohrmann on Cybersecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
月光博客
月光博客
T
Threatpost
博客园 - 【当耐特】
S
Schneier on Security
P
Privacy International News Feed
G
GRAHAM CLULEY
T
Tenable Blog
AWS News Blog
AWS News Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
博客园 - Franky
Engineering at Meta
Engineering at Meta
美团技术团队
S
Secure Thoughts
T
Troy Hunt's Blog
Microsoft Security Blog
Microsoft Security Blog
SecWiki News
SecWiki News
V
Visual Studio Blog
人人都是产品经理
人人都是产品经理
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Cisco Talos Blog
Cisco Talos Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Martin Fowler
Martin Fowler
Webroot Blog
Webroot Blog
Google DeepMind News
Google DeepMind News
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - weekzero

百度编辑器ueditor批量上传图片或者批量上传文件时,文件名称和内容不符合,错位问题 代码漏洞扫描描述Cross Site History Manipulation解决办法[dongcoder.com] iis重写模块实现程序自动二级域名,微软提供的URL重写2.0版本适用IIS以上 借助微软提供的url重写类库URLRewriter.dll(1.0)实现程序自动二级域名,域名需要泛解析 AspNetPager控件报错误: Syntax error, unrecognized expression: input#ctl00$ContentPlaceHolder1$Aspnetpager1_input问题解决[摘] 精准定位才能赢得人心 IIS7.5打开GZip压缩,同时启用GZip压缩JS/CSS文件的设置方法 c#变量缺少using引用,如何快速加上using,加Using的快捷键 chart.js插件生成折线图时数据普遍较大时Y轴数据不从0开始的解决办法 要用于尝试,广东移动间接实现“流量不清零” jquery中ajax在firefox浏览器下“object XMLDocument”返回结果的解决办法 mvc中Url.RouteUrl或者Html.RouteLink实现灵活超链接,使href的值随路由名称或配置的改变而改变 mvc中多参数URL会很长,首次加载不传参数让url很短,路由规则实现方法 《舌尖上的中国》第二季今日首播了,天猫食品也跟着首发,借力使力 Ubuntu 14.04 (Trusty Tahr) LTS发布,附下载地址,各种镜像 System.Data.OleDb操作access数据库类 大数据量下,分页的解决办法 winform设置button的边框颜色,或取消边框颜色,不显示边框 winform里操作打开在panel里的form窗体,子窗体操作同级子窗体或者父窗体的方法
cWeb开发框架,基于asp.net的cWeb应用开发平台介绍(二)
weekzero · 2014-01-09 · via 博客园 - weekzero

cWeb是基于微软的.Net Framework 4框架,数据库是sql server 2008 r2。

cWeb开发框架下载,点击这里去下载

cWeb开发框架借鉴三层架构理论分为三层,分别是:cData、cBN和cWeb。cData是数据层,cBN是业务处理层,cWeb是业务展示层。解决方案如图示:

  

一、cData数据层

cData数据层,数据库字段的映射类。在其他开发框架中常见于datatable和dataview,也就是将数据库表映射成datatable,dataview继承datatable,并将其他如视图等的字段映射在dataview中。在类似于petshop等开发框架中分层可谓详细,虽然现在硬件的发展可以不用考虑继承、映射、调用等等的运行时间,但是对于大数据量下即使很小的优化都会起到极大的作用,所以直接的就是高效率的,简化后数据层都融合在了一起。

data层数据示例:

using System;

namespace AA.cData
{
    /// <summary>
    /// t_info 的摘要说明。
    /// </summary>
    [Serializable]
    public class t_infoDV
    {
        /// <summary>
        /// t_infoDV
        /// </summary>
        public t_infoDV()
        {
        }

        //============================数据库字段=================================//

        private long _ID = -1;
        /// <summary>
        /// ID
        /// </summary>
        public long ID
        {
            get
            {
                return _ID;
            }
            set
            {
                _ID = value;
            }
        }

        private string _t_info_title = null;
        /// <summary>
        /// t_info_title
        /// </summary>
        public string t_info_title
        {
            get
            {
                return _t_info_title;
            }
            set
            {
                _t_info_title = value;
            }
        }

        private DateTime _t_info_createtime = System.DateTime.MinValue;
        /// <summary>
        /// t_info_createtime
        /// </summary>
        public DateTime t_info_createtime
        {
            get
            {
                return _t_info_createtime;
            }
            set
            {
                _t_info_createtime = value;
            }
        }




        //============================扩展字段==================================//

        private string _t_info_title_like = null;
        /// <summary>
        /// t_info_title [模糊查询]
        /// </summary>
        public string t_info_title_like
        {
            get
            {
                return _t_info_title_like;
            }
            set
            {
                _t_info_title_like = value;
            }
        }



    }
}

二、cBN业务处理层

cBN业务处理层,也可以叫业务逻辑层。是数据层之上用来处理业务逻辑的方法,将除了web之外的所有业务处理都可以放在这个层里,比如添加、修改、删除、各种查询等方法,在web层仅仅调用一下就可以实现功能,也体现了业务逻辑通用原则,这样同样的业务处理就可以重复调用,提高了开发效率,减少了代码的冗长重复。

 BN层示例:

using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using System.Data.SqlClient;

using cDB;
using AA.cData;

namespace AA.cBN
{
    /// <summary>
    /// t_info 的摘要说明。
    /// </summary>
    public class t_infoBN
    {
        DataInfo cDI;

        /// <summary>
        /// t_infoBN
        /// </summary>
        public t_infoBN()
        {
            cDI = new DataInfo();
        }


        #region [添加|修改|删除]

        /// <summary>
        /// [添加]
        /// </summary>
        /// <param name="tDV"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public int Add(t_infoDV tDV, out string msg)
        {
            try
            {
                mCommand oCommand = new mCommand();

                oCommand.SqlTxt = "Insert into t_info(t_info_title,t_info_createtime)" +
                                    " values(@t_info_title,@t_info_createtime)";


                SqlParameter[] SqlItems = new SqlParameter[2];

                SqlItems[0] = new SqlParameter("@t_info_title", SqlDbType.NVarChar);
                SqlItems[0].Value = tDV.t_info_title;

                SqlItems[1] = new SqlParameter("@t_info_createtime", SqlDbType.DateTime);
                SqlItems[1].Value = tDV.t_info_createtime;




                oCommand.AddParameter(SqlItems);

                int iResult = cDI.iCommandSql(oCommand);

                if (iResult > -1)
                {
                    msg = "添加成功!";
                }
                else
                {
                    msg = "添加失败!";
                }

                return iResult;

            }
            catch //(Exception ex)
            {
                //msg = ex.Message;
                msg = "添加失败(异常)!";
                return -11;     //-11表示异常
            }
        }

        /// <summary>
        /// [修改]
        /// </summary>
        /// <param name="tDV"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public int Edit(t_infoDV tDV, out string msg)
        {

            try
            {
                mCommand oCommand = new mCommand();

                oCommand.SqlTxt = "update t_info set " +
                                    "t_info_title=@t_info_title," +
                                    "t_info_createtime=@t_info_createtime " +
                                    "where ID=@ID";


                SqlParameter[] SqlItems = new SqlParameter[3];

                SqlItems[0] = new SqlParameter("@t_info_title", SqlDbType.NVarChar);
                SqlItems[0].Value = tDV.t_info_title;

                SqlItems[1] = new SqlParameter("@t_info_createtime", SqlDbType.DateTime);
                SqlItems[1].Value = tDV.t_info_createtime;

                SqlItems[2] = new SqlParameter("@ID", SqlDbType.BigInt);
                SqlItems[2].Value = tDV.ID;


                oCommand.AddParameter(SqlItems);

                int iResult = cDI.iCommandSql(oCommand);

                if (iResult > -1)
                {
                    msg = "修改成功!";
                }
                else
                {
                    msg = "修改失败!";
                }

                return iResult;

            }
            catch //(Exception ex)
            {
                //msg = ex.Message;
                msg = "添加失败(异常)!";
                return -11;     //-11表示异常
            }
        }

        /// <summary>
        /// [删除]
        /// </summary>
        /// <param name="tDV"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public int Del(t_infoDV tDV, out string msg)
        {
            try
            {
                mCommand oCommand = new mCommand();
                oCommand.SqlTxt = "delete t_info where ID=@ID";
                SqlParameter[] SqlItems = new SqlParameter[1];

                SqlItems[0] = new SqlParameter("@ID", SqlDbType.BigInt);
                SqlItems[0].Value = tDV.ID;

                oCommand.AddParameter(SqlItems);

                int iResult = cDI.iCommandSql(oCommand);

                if (iResult > -1)
                {
                    msg = "删除成功!";
                }
                else
                {
                    msg = "删除失败!";
                }

                return iResult;
            }
            catch //(Exception ex)
            {
                //msg = ex.Message;
                msg = "删除失败(异常)!";
                return -11;     //-11表示异常
            }
        }
        #endregion


        #region [查询]
        /// <summary>
        /// [返回数据分页]
        /// </summary>
        /// <param name="tDV"></param>
        /// <param name="sqlWhere">where语句</param>
        /// <returns></returns>
        public DataTable GetDataList(t_infoDV tDV, string sqlWhere)
        {

            DataTable DTe = new DataTable();

            mCommand oCommand = new mCommand();

            StringBuilder SqlTxtPrefiex = new StringBuilder(" select ISNULL(count(ID),0) as Counts from View_t_info where 1 = 1 " + sqlWhere + " ");
            SqlParameter tSqlItem = null;


            if (tDV.t_info_title != null)
            {
                SqlTxtPrefiex.Append(" and t_info_title = @t_info_title");
                tSqlItem = new SqlParameter("@t_info_title", SqlDbType.NVarChar);
                tSqlItem.Value = tDV.t_info_title;
                oCommand.SqlParameters.Add(tSqlItem);
            }

            if (tDV.t_info_title_like != null)
            {
                SqlTxtPrefiex.Append(" and t_info_title like @t_info_title_like");
                tSqlItem = new SqlParameter("@t_info_title_like", SqlDbType.NVarChar);
                tSqlItem.Value = "%" + tDV.t_info_title_like + "%";
                oCommand.SqlParameters.Add(tSqlItem);
            }



            oCommand.SqlTxt = SqlTxtPrefiex.ToString();

            DTe = cDI.GetTable(oCommand);
            return DTe;
        }

        /// <summary>
        /// [返回数据]
        /// </summary>
        /// <param name="tDV"></param>
        /// <param name="column">显示的列,默认为【*】全部</param>
        /// <param name="sqlWhere">where语句</param>
        /// <param name="beginIndex">开始记录</param>
        /// <param name="endIndex">结束记录</param>
        /// <param name="Order">排序,如【order by ID desc】</param>
        /// <returns></returns>
        public DataTable GetDataList(t_infoDV tDV, string column, string sqlWhere, long beginIndex, long endIndex, string Order)
        {
            if (string.IsNullOrEmpty(column))
                column = " * ";

            mCommand oCommand = new mCommand();

            StringBuilder cSqlTxtPrefiex = new StringBuilder("select * from NoPagedTable WHERE rowIndex>=@beginIndex and rowIndex<=@endIndex");

            SqlParameter[] SqlItems = new SqlParameter[2];

            SqlItems[0] = new SqlParameter("@beginIndex", SqlDbType.BigInt);
            SqlItems[0].Value = beginIndex;

            SqlItems[1] = new SqlParameter("@endIndex", SqlDbType.BigInt);
            SqlItems[1].Value = endIndex;

            oCommand.SqlParameters.AddRange(SqlItems);


            if (Order == string.Empty)
            {
                Order = " order by ID DESC ";
            }

            StringBuilder SqlTxtPrefiex = new StringBuilder(
                "WITH NoPagedTable AS " +
                "(" +
                "SELECT ROW_NUMBER() OVER (" + Order + ") AS rowIndex," + column + " FROM View_t_info where 1 = 1 " + sqlWhere + " ");

            SqlParameter tSqlItem = null;

            if (tDV.t_info_title != null)
            {
                SqlTxtPrefiex.Append(" and t_info_title = @t_info_title");
                tSqlItem = new SqlParameter("@t_info_title", SqlDbType.NVarChar);
                tSqlItem.Value = tDV.t_info_title;
                oCommand.SqlParameters.Add(tSqlItem);
            }

            if (tDV.t_info_title_like != null)
            {
                SqlTxtPrefiex.Append(" and t_info_title like @t_info_title_like");
                tSqlItem = new SqlParameter("@t_info_title_like", SqlDbType.NVarChar);
                tSqlItem.Value = "%" + tDV.t_info_title_like + "%";
                oCommand.SqlParameters.Add(tSqlItem);
            }



            SqlTxtPrefiex.Append(")");

            oCommand.SqlTxt = SqlTxtPrefiex.ToString() + cSqlTxtPrefiex.ToString();

            return cDI.GetTable(oCommand);
        }

        /// <summary>
        /// [返回DataTable]
        /// </summary>
        /// <param name="tDV"></param>
        /// <param name="topNum">返回行数,默认【0】全部</param>
        /// <param name="column">显示的列,默认为【*】全部</param>
        /// <param name="sqlWhere">where语句</param>
        /// <param name="order">排序,如【order by ID desc】</param>
        /// <returns></returns>
        public DataTable GetDataTable(t_infoDV tDV, int topNum, string column, string sqlWhere, string order)
        {
            if (string.IsNullOrEmpty(column))
                column = " * ";

            string topNumSql = "";
            if (topNum > 0)
                topNumSql = " top " + topNum.ToString();

            DataTable DT = new DataTable();

            mCommand oCommand = new mCommand();

            StringBuilder SqlTxtPrefiex = new StringBuilder(" select " + topNumSql + " " + column + " from View_t_info where 1 = 1 " + sqlWhere + " ");
            SqlParameter tSqlItem = null;

            if (tDV.ID != -1)
            {
                SqlTxtPrefiex.Append(" and ID=@ID");
                tSqlItem = new SqlParameter("@ID", SqlDbType.BigInt);
                tSqlItem.Value = tDV.ID;
                oCommand.SqlParameters.Add(tSqlItem);
            }


            if (tDV.t_info_title != null)
            {
                SqlTxtPrefiex.Append(" and t_info_title = @t_info_title");
                tSqlItem = new SqlParameter("@t_info_title", SqlDbType.NVarChar);
                tSqlItem.Value = tDV.t_info_title;
                oCommand.SqlParameters.Add(tSqlItem);
            }

            if (tDV.t_info_title_like != null)
            {
                SqlTxtPrefiex.Append(" and t_info_title like @t_info_title_like");
                tSqlItem = new SqlParameter("@t_info_title_like", SqlDbType.NVarChar);
                tSqlItem.Value = "%" + tDV.t_info_title_like + "%";
                oCommand.SqlParameters.Add(tSqlItem);
            }



            if (string.IsNullOrEmpty(order))
                order = " order by ID desc ";

            SqlTxtPrefiex.Append(" " + order + " ");


            oCommand.SqlTxt = SqlTxtPrefiex.ToString();

            DT = cDI.GetTable(oCommand);
            return DT;
        }


        #endregion


    }
}

三、cWeb业务展示层

cWeb业务展示层,用于业务逻辑展示的层,调用BN层的函数直接显示在web页面中。

web层示例:

infolist.aspx.cs代码如下:

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

using System.Data;

using AA.cData;
using AA.cBN;
using cPage;

namespace AA.cWeb.manage.info
{
    public partial class infolist : System.Web.UI.Page
    {
        cUser cu = new cUser();

        public int p = 1;   //页码


        protected void Page_Load(object sender, EventArgs e)
        {
            #region [判断是否登录]
            if (!cu.isLogin())
            {
                cGlobal.frameGoUrl(this, "../../default.aspx");
                return;
            }
            #endregion

            #region 分页获得页码
            string _p = Request.QueryString["p"];

            if (string.IsNullOrEmpty(_p))
                _p = "1";

            if (cGlobal.IsIntType(_p))
            {
                p = Convert.ToInt32(_p);
            }
            else
            {
                cGlobal.showBoxBack(this, "页码不正确!");
                return;
            }
            #endregion

            #region [判断是具有访问权限]
            if (!cDataCommon.userPagePower(cu.userID, "0202"))
            {
                cGlobal.showBoxBack(this, "您没有权限访问!");
                return;
            }
            #endregion

            #region [获得在【系统设置=》角色管理=》权限设置】中点击某一菜单后,“菜单功能权限设置”设置的功能]
            string userPageFunctionPower = cDataCommon.userPageFunctionPower(cu.userID, "0202");
            //判断是否具有“添加”功能
            if (userPageFunctionPower.IndexOf("|add|") > -1)
                btnAdd.Visible = true;
            else
                btnAdd.Visible = false;
            #endregion

            
            if (!Page.IsPostBack)
            {

                dataBind();
            }

        }

        protected void dataBind()
        {
            string _url = "infolist.aspx?p=[#p#]";
            int _pageNum = 10;                              // 中间页码数量
            int _pageSize = 10;                             //每页记录数
            int _beginIndex = 0;
            int _endIndex = 0;

            t_infoBN tBN = new t_infoBN();
            t_infoDV tDV = new t_infoDV();


            DataTable rcDT = tBN.GetDataList(tDV, "");

            lblpage.Text = mPage.getPage(Convert.ToInt32(rcDT.Rows[0][0].ToString()), _pageSize, _pageNum, p, out _beginIndex, out _endIndex, _url);

            DataTable DT = tBN.GetDataList(tDV, "", "", _beginIndex, _endIndex, "");

            rlist.DataSource = DT;
            rlist.DataBind();

        }
        

        protected void rlist_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemIndex > -1)
            {
                ((LinkButton)e.Item.FindControl("lnkbtnDel")).Attributes["onclick"] = "return confirm('确认要删除吗?');";
            }
        }

        protected void rlist_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "del")
            {
                try
                {
                    long _ID = Convert.ToInt64(((HiddenField)(e.Item.FindControl("hfID"))).Value);

                    t_sys_logBN tBN = new t_sys_logBN();
                    t_sys_logDV tDV = new t_sys_logDV();

                    tDV.ID = _ID;

                    string msg = "";
                    int iResult = -2;

                    iResult = tBN.Del(tDV, out msg);


                    if (iResult >= 0)   //0,执行完成,>1,执行完成影响的记录数
                    {
                        cGlobal.showBoxGo(this, "删除成功!", Request.Url.ToString());
                    }
                    else
                    {
                        cGlobal.showBoxBack(this, "删除失败!");
                    }

                }
                catch
                {
                    cGlobal.showBoxBack(this, "数据格式不正确(异常)");
                }
            }
        }

    }
}

更详细的介绍和cWeb源代码,去这里下载

原帖地址:cWeb开发框架,基于asp.net的cWeb应用开发平台介绍(二)

bubufx提供,禁止转载。