CSLA4.0在SILVERLIGHT5.0中 构建可编辑的BusinessListBase对象
来源:互联网 发布:淘宝一件代发怎么退货 编辑:程序博客网 时间:2024/06/05 15:12
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<DateTime> CreateDateProperty = RegisterProperty<DateTime>(c => c.CreateDate);
public DateTime 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 = DateTime.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, [Name], Remark, Creater, 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, [Name], Remark, Creater, 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, [Name], Remark, Creater, 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.3组件和仿以然胜甲的展示前台开发的Silverlight5.0简单数据增删改(CRUD)
- VC6.0中基于MSFlexGrid的可编辑表格
- VC6.0中基于MSFlexGrid的可编辑表格
- Silverlight5.0新特性一览
- SilverLight5.0现重大缺陷
- Silverlight5 + .NET4.0 + IIS6 发布
- CSLA4.0框架中使用序列化与反序列化serialize
- Silverlight5在Tomcat上的部署
- 在VC++6.0下构建可直接编辑的列表控件类
- 在VC++6.0下构建可直接编辑的列表控件类
- 在VC++6.0下构建可直接编辑的列表控件类
- 在VC++6.0下构建可直接编辑的列表控件类
- 在VC++6.0下构建可直接编辑的列表控件类
- SpannableString 在EditText 中可编辑可点
- ICloneable接口(构建可克隆的对象)
- 构建可克隆的对象(icloneable)
- Silverlight5.0正式发布附下载地址
- 从初学者的角度分析学习makefile,看完后能让你读懂绝大部分makefile文件!
- plsq
- plsq
- 火狐+Chrome+IE页面禁止缓存处理
- C# Maximum request length exceeded. 产生错误的原因,以及解决方法.
- CSLA4.0在SILVERLIGHT5.0中 构建可编辑的BusinessListBase对象
- Linux下core文件调试方法
- POJ 3126 Prime Path
- imac wifi 链接不了 dns查找失败 感叹号
- poj 189
- cocoa应用程序嵌入浏览器控件
- register,volatile关键字
- #include<queue> 【c++】
- 101条伟大的计算机编程名言