大佬教程收集整理的这篇文章主要介绍了CSLA4.0在SILVERLIGHT5.0中 构建可编辑的BusinessListBase对象,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
CSLA4.0在SILVERLIGHT5.0中 构建可编辑的BusinessListBase对象
--服务器端类库
namespace Library
{
[serializable]
#if !SILVERLIGHT
[Csla.Server.objectFactory("DataAccess.ShopRepository,DataAccess","","FetchCollection","updateCollection","deleteCollection",null)]
#endif
public class ShopCollection : BusinessListBase<ShopCollection,ShopEdit>
{
public static void GetAll(EventHandler<DataPortalResult<ShopCollection>> callBACk)
{
DataPortal.beginFetch<ShopCollection>(callBACk);
}
public ShopEdit NewShopEdit()
{
var shop = ShopEdit.NewShopEdit();
Add(shop);
OnAddedNew(shop);
return shop;
}
}
}
/******************************************************************************
----------------------------------------------------------------
模块名称: ShopEdit[只读数据模型]
编者 : 李春雷 创建日期: 2012年08月02日
功能描述:
----------------------------------------------------------------
修改日期: 修改人:
修改内容:
----------------------------------------------------------------
******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla;
using Csla.serialization;
namespace Library
{
/// <sumMary>
/// <para>ShopEdit Object</para>
/// <para>SumMary description for ShopEdit.</para>
/// <para><see cref="member"/></para>
/// <REMARKs></REMARKs>
/// </sumMary>
[serializable]
#if !SILVERLIGHT
[Csla.Server.objectFactory("DataAccess.ShopRepository,DataAccess")]
#endif
public class ShopEdit : BusinessBase<ShopEdit>
{
#region Public Properties
public static PropertyInfo<String> IdProperty = RegisterProperty<String>(c => c.Id);
public String Id
{
get { return GetProperty(IdProperty); }
set { SetProperty(IdProperty,value); }
}
public static PropertyInfo<String> NameProperty = RegisterProperty<String>(c => c.Name);
public String Name
{
get { return GetProperty(NameProperty); }
set { SetProperty(NameProperty,value); }
}
public static PropertyInfo<String> REMARKProperty = RegisterProperty<String>(c => c.REMARK);
public String REMARK
{
get { return GetProperty(REMARKProperty); }
set { SetProperty(REMARKProperty,value); }
}
public static PropertyInfo<String> CreaterProperty = RegisterProperty<String>(c => c.Creater);
public String Creater
{
get { return GetProperty(CreaterProperty); }
set { SetProperty(CreaterProperty,value); }
}
public static PropertyInfo<datetiR_506_11845@e> CreateDateProperty = RegisterProperty<datetiR_506_11845@e>(c => c.CreateDatE);
public datetiR_506_11845@e CreateDate
{
get { return GetProperty(CreateDateProperty); }
set { SetProperty(CreateDateProperty,value); }
}
#endregion
#region Method
public static void GetById(String id,EventHandler<DataPortalResult<ShopEdit>> callBACk)
{
DataPortal.beginFetch<ShopEdit>(id,callBACk);
}
public static ShopEdit NewShopEdit()
{
var shop = new ShopEdit();
shop.CreateDate = datetiR_506_11845@e.Now;
shop.MarkAsChild();
return shop;
}
public static void Create(EventHandler<DataPortalResult<ShopEdit>> callBACk) {
DataPortal.beginCreate<ShopEdit>(callBACk);
}
#if !SILVERLIGHT
public static ShopEdit GetById(String id)
{
return DataPortal.Fetch<ShopEdit>(id);
}
#endif
#endregion
}
}
--数据访问层,采用工厂模式
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla;
using Library;
using Dapper;
using Csla.Reflection;
namespace DataAccess
{
public class ShopRepository : Csla.Server.objectFactory
{
public ShopList FetchList()
{
var result = (ShopList)MethodCaller.CreateInstance(typeof(ShopList));
String sqlstr = "SELECT Id,[Name],REMARK,Creater,CreateDate FROM dbo.ShopInfo order by [Name]";
var query = Database.Dbservice.Query<ShopInfo>(sqlstr);
result.RaiseListChangedEvents = false;
result.AddRange(query);
result.RaiseListChangedEvents = true;
return result;
}
public ShopCollection FetchCollection()
{
var result = (ShopCollection)MethodCaller.CreateInstance(typeof(ShopCollection));
String sqlstr = "SELECT Id,CreateDate FROM dbo.ShopInfo order by [Name]";
var query = Database.Dbservice.Query<ShopEdit>(sqlstr);
foreach (var item in query)
{
MarkAsChild(item);
MarkOld(item);
}
result.RaiseListChangedEvents = false;
result.AddRange(query);
result.RaiseListChangedEvents = true;
return result;
}
#region insert,update,delete
public ShopEdit Create()
{
var result = new ShopEdit();
MarkAsChild(result);
MarkNew(result);
checkRules(result);
return result;
}
//public ShopEdit Create()
//{
// var obj = (ShopEdit)MethodCaller.CreateInstance(typeof(ShopEdit));
// MarkNew(obj);
// checkRules(obj);
// return obj;
//}
public ShopEdit Fetch(String id)
{
String sqlstr = "SELECT Id,CreateDate FROM dbo.ShopInfo" +
" WHERE id=@id";
var result = Database.Dbservice.Query<ShopEdit>(sqlstr,new { id }).SingLeorDefault();
MarkOld(result);
return result;
}
public ShopEdit update(ShopEdit obj)
{
if (obj.Isdeleted)
{
if (!obj.IsNew)
{
// delete data
delete(obj.Id);
return Create();
}
MarkNew(obj);
}
else
{
String sqlstr = "";
if (obj.IsNew)
{
sqlstr = "INSERT INTO dbo.ShopInfo(Id,CreateDatE) " +
"VALUES (@Id,@Name,@REMARK,@Creater,getdate())";
}
else
{
sqlstr = "updatE dbo.ShopInfo " +
"SET [Name] = @Name," +
"REMARK = @REMARK" +
" WHERE id=@id";
}
Database.Dbservice.Execute(sqlstr,obj);
MarkOld(obj);
}
return obj;
}
public void delete(String id)
{
String sqlstr = "delete from shopinfo where id=@id";
Database.Dbservice.Execute(sqlstr,new { id });
}
public ShopCollection updateCollection(ShopCollection obj)
{
obj.RaiseListChangedEvents = false;
foreach (var item in GetdeletedList<ShopEdit>(obj))
update(item);
foreach (var item in obj)
update(item);
GetdeletedList<ShopEdit>(obj).Clear();
obj.RaiseListChangedEvents = true;
return obj;
}
public ShopCollection deleteCollection(ShopCollection obj)
{
foreach (var item in obj)
{
delete(item.Id);
}
return obj;
}
#endregion
}
}
--silverlight端
ShopCollection shops;
private void ToolbarButton_SaveClick(object sender,RoutedEventArgs E)
{
shops.beginSave((o,eE) =>
{
if (ee.Error != null)
Windowsmanager.ShowModal("出错","原因:" + ee.Error.messagE);
else
Windowsmanager.ShowModal("保存成功","所有数据已经成功保存");
});
maingrid.columns[0].IsReadOnly = true;
}
private void ToolbarButton_AddClick(object sender,RoutedEventArgs E) { var d = shops.NewShopEdit(); }
以上是大佬教程为你收集整理的CSLA4.0在SILVERLIGHT5.0中 构建可编辑的BusinessListBase对象全部内容,希望文章能够帮你解决CSLA4.0在SILVERLIGHT5.0中 构建可编辑的BusinessListBase对象所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。