WinForm开发-界面控件到实体,实体到界面控件自动绑定
2016-05-25 09:19
435 查看
在WinForm开发中,我们是不是为绑定界面控件的数据而每个控件每个控件的赋值?在保存修改时是不是也是每个控件每个控件的赋值到实体中?字段一多,那简直就是噩梦。有没有像Web中那样方便的方法直接就自动映射了呢?现在不用如此繁琐,在RDIFramework.NET开发框架的WinForm部分新增了界面控件到实体,实体到界面控件自动绑定,一句话就搞定了,非常的方便。主要是引用“RDIFramework.WinForm.Utilities.dll”dll文件,再调用下面两个方法即可:
1、实体到界面控件的自动映射:FormBinding.BindObjectToControls(TestEntity, this);
2、界面控件到实体的自动映射:FormBinding.BindControlsToObject(TestEntity, this);
效果如下图所示:
下面给出上面的测试界面的全部代码供大家参考:
相关文章列表:
RDIFramework.NET — 基于.NET的快速信息化系统开发框架 — 系列目录
一路走来数个年头,感谢RDIFramework.NET框架的支持者与使用者,大家可以通过下面的地址了解详情。
RDIFramework.NET官方网站:http://www.rdiframework.net/
RDIFramework.NET官方博客:http://blog.rdiframework.net/
同时需要说明的,以后的所有技术文章以官方网站为准,欢迎大家收藏!
RDIFramework.NET框架由专业团队长期打造、一直在更新、一直在升级,请放心使用!
欢迎关注RDIFramework.net框架官方公众微信(微信号:guosisoft),及时了解最新动态。
扫描二维码立即关注
1、实体到界面控件的自动映射:FormBinding.BindObjectToControls(TestEntity, this);
2、界面控件到实体的自动映射:FormBinding.BindControlsToObject(TestEntity, this);
效果如下图所示:
下面给出上面的测试界面的全部代码供大家参考:
using System; namespace RDIFramework.Test { using RDIFramework.Utilities; using RDIFramework.WinForm.Utilities; public partial class FrmFormBindingTest : BaseForm { ExampleEntity TestEntity = new ExampleEntity(); public FrmFormBindingTest() { InitializeComponent(); } public override void FormOnLoad() { base.FormOnLoad(); BindCategory(); FormBinding.BindObjectToControls(TestEntity, this); } private void BindCategory() { BasePageLogic.BindCategory(base.UserInfo, ProductCategory, "ProductCategory"); BasePageLogic.BindCategory(base.UserInfo, comboBox1, "Gender"); } private void btnEntityToControl_Click(object sender, EventArgs e) { FormBinding.BindObjectToControls(TestEntity, this); } private void btnControlToEntity_Click(object sender, EventArgs e) { FormBinding.BindControlsToObject(TestEntity, this); this.richTextBox1.Text = TestEntity.ToString(); } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } } public class ExampleEntity { public string Text1 { get; set; } public string Text2 { get; set; } public string comboBox1 { get; set; } public string ProductCategory { get; set; } public DateTime? DateTime1 { get; set; } public decimal? MaskText1 { get; set; } public int? Int1 { get; set; } public int Enabled1 { get; set; } public ExampleEntity() { Text1 = "ValueText1"; Text2 = "ValueText2"; DateTime1 = BusinessLogic.ConvertToDateTime(DateTime.Now.AddDays(-2)); MaskText1 = BusinessLogic.ConvertToNullableDecimal(12345.12); Int1 = 124; Enabled1 = 1; comboBox1 = "男"; ProductCategory = "其他"; } public override string ToString() { string returnValue = "Text1: " + Text1 + "\r Text2: " + Text2; returnValue += "\r comboBox1:" + comboBox1 + "\r Int1:" + Int1.ToString() + "\r DateTime1:" + DateTime1.ToString() ; returnValue += "\r ProductCategory:" + ProductCategory + "\r MaskText1:" + MaskText1.ToString() + "\r Enabled1:" + Enabled1.ToString(); return returnValue.ToString(); } } }
相关文章列表:
RDIFramework.NET — 基于.NET的快速信息化系统开发框架 — 系列目录
一路走来数个年头,感谢RDIFramework.NET框架的支持者与使用者,大家可以通过下面的地址了解详情。
RDIFramework.NET官方网站:http://www.rdiframework.net/
RDIFramework.NET官方博客:http://blog.rdiframework.net/
同时需要说明的,以后的所有技术文章以官方网站为准,欢迎大家收藏!
RDIFramework.NET框架由专业团队长期打造、一直在更新、一直在升级,请放心使用!
欢迎关注RDIFramework.net框架官方公众微信(微信号:guosisoft),及时了解最新动态。
扫描二维码立即关注
相关文章推荐
- Scrum项目7.0
- Java SoftReference StrongReference WeakReference
- 户口迁出程序
- Kodi 皮肤修改 Kodi定制
- 表单设计中<input>的size属性与maxlength属性的区别
- Android基础学习【历史流程重走】 ---- Sqlite数据库使用及ListView的使用与优化(三)
- 乱码小结
- 在IE11(Win10)中检查up6.2配置
- Mac原生双拼布局
- 【无私分享:从入门到精通ASP.NET MVC】从0开始,一起搭框架、做项目(6) 控制器基类 主要做登录用户、权限认证、日志记录等工作
- iOS学习笔记44-Swift(四)枚举和结构体
- Java Web前端到后台常用框架介绍
- Play框架功能测试 (functional test in play framework)
- 多台web服务器之间共享session
- jsonp的简单例子
- 在Linux CentOS 6.6上安装Python 2.7.9
- Android布局属性详解
- 用openAL播放ffmpeg解码的buffer突然加速问题
- 引导页
- Play Framework 错误信息显示 (error message display In play framework)