silverlight   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Silverlight实战示例4(兼集合属性的妙用)--业务逻辑与服务层大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

1)业务逻辑层:DynamicDataBusi.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using MEntities; using System.Data.SqlClient; namespace BBusiness {
1)业务逻辑层:DynamicDataBusi.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MEntities;
using System.Data.sqlClient;
namespace BBusiness
{
    public class DynamicDataBusi
    {
        public DynamicDataTable GetDynamicDataTable(String strsql,String ConnStr)
        {
            sqlConnection theConn = new sqlConnection(ConnStr);
            DataTable theTable = new HDatabase.DynamicDataAccess().GetDataTable(strsql,theConn);
            DynamicDataTable theDynamicTable = new DynamicDataTable();
            if (theTable != null)
            {
                foreach (Datacolumn col in theTable.columns)
                {
                    DynamicDatacolumn theCol = new DynamicDatacolumn();
                    theCol.Caption = col.Caption;
                    theCol.Datatype = col.DataType.Name;
                    theCol.FieldName = col.columnName;
                    theCol.Length = col.MaxLength;
                    theCol.FormatString = "";
                    theDynamicTable.columns.Add(theCol);
                }
                foreach (Da@R_953_2301@w row in theTable.Rows)
                {
                    DynamicDa@R_953_2301@w theRow = new DynamicDa@R_953_2301@w();
                    for (int i = 0; i < theTable.columns.Count; i++)
                    {
                        Dynamicdatafield thedatafield = new Dynamicdatafield();
                        thedatafield.FieldName = theTable.columns[i].columnName;
                        thedatafield.DataType = theTable.columns[i].DataType.Name;
                        thedatafield.Value = row[i];
                        theRow.datafields.Add(thedatafield);
                    }
                    theDynamicTable.Rows.Add(theRow);

                }
            }
            return theDynamicTable;
        }
    }
}
所有要提供给客户端得实体的打包,以及服务端得实体缓存之类的都可以封装到这一层。业务逻辑层另外的最主要的功能就是业务逻辑的处理了,简单的新增,修改删除查询都可在这里封装,有的然只是简单的调用数据访问层,但也不要让服务层直接调用。因为在这一层可以增加很多功能,比如冲突检测,逻辑检查等。

2)RIA 服务层:DynamicDataservice


namespace RIAservices.Web
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.serviceModel.Domainservices.HosTing;
    using System.serviceModel.Domainservices.Server;
    using MEntities;
    using BBusiness;
    // TODO: 创建包含应用程序逻辑的方法
    [EnableClientAccess()]
    public class DynamicDataservice : Domainservice
    {
        static String conn = "Data source=127.0.0.1;Initial Catalog=DEVTEST;Persist Security Info=True;User ID=sa;password=tian777888";
       
        [Invoke]
        public DynamicDataTable GetDynamicTable(String strsql)
        {
            //在这里检查调用是否合法
            return new DynamicDataBusi().GetDynamicDataTable(strsql,conn);
        }

    }
}

大家要注意,我的@L_618_45@连接出现在这一层,纯粹是巧合,@L_618_45@连接应该放到数据访问层或者配置文件里,如果是比较复杂的应用,比如SaaS,还并需用单独的类进行管理。

另外注意,这里我没有直接将服务层放在承载silverlight客户端得webapp上,而是建立的RIA服务类库。

到这里,服务端的实现就完成了,编译后,客户端就可以看到我们的实体,并可调用服务方法
后面,我们继续建立客户端的应用。

友情提示:以上代码经过实测,绝对可以OK的。另外注意你们的WCF RIA services 至少要到SP1,否则会有编译错误.

 

 


原文链接http://www.voidcn.com/article/p-aneyytpq-bcq.html

大佬总结

以上是大佬教程为你收集整理的Silverlight实战示例4(兼集合属性的妙用)--业务逻辑与服务层全部内容,希望文章能够帮你解决Silverlight实战示例4(兼集合属性的妙用)--业务逻辑与服务层所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。