Silverlight实战示例4(兼集合属性的妙用)--业务逻辑与服务层

Silverlight实战示例4(兼集合属性的妙用)--业务逻辑与服务层,第1张

概述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 (DaTarow row in thetable.Rows)
                {
                    DynamicdaTarow theRow = new DynamicdaTarow();
                    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);
        }

    }
}

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

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

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

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

 

 


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

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

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

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1069362.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存