BLL层_DataBinder对象以及_DataBinder.Rows[0].EndEdit方法详解
作者:C/S框架网|www.cscode.ne  发布日期:2020/09/07 16:27:18
  BLL层_DataBinder对象以及_DataBinder.Rows[0].EndEdit方法详解


开发框架基础资料(单表资料)界面,在保存数据前会调用_DataBinder.Rows[0].EndEdit方法更新DataTable的缓存数据。

流程:用户点【保存】按钮 --> 调用BLL.Update方法 --> 调用_DataBinder.Rows[0].EndEdit方法。


贴图图片-QQ图片20200907160537


_DataBinder对象

_DataBinder对象是个DataTable,用户点击【查看】或【编辑】按钮时创建的DataTable对象,里面只有一条记录,用于缓存当前编辑记录的临时数据。


DoBindingSummaryEditor方法

创建_DataBinder对象后,会调用DoBindingSummaryEditor方法绑定当前界面所有文本编辑框的数据源。


DoBindingEditorPanel方法

框架提供 DoBindingEditorPanel 方法,自动绑定编辑区域的数据源,编辑区域通常使用Panel组件容器。

绑定规则(文本编辑框命名规则):txt+字段名,或者chk+字段名。

统一命名后,打循环遍历当前Panel内所有txtXXX的组件,自动绑定数据源。


C# Code:

for (int i = 0; i <= editorPanel.Controls.Count - 1; i++)
{
  
if (editorPanel.Controls[i] is BaseEdit)
  {
    BaseEdit edit
= editorPanel.Controls[i] as BaseEdit;
    
if (edit.Name.Substring(0, 3) == "txt")
    {
      fieldName
= edit.Name.Substring(3, edit.Name.Length - 3);
      DataBinder.BindingTextEditBase(edit, dataSource, fieldName);
    }
  }
  
}

//来源:C/S框架网 | www.csframework.com | QQ:23404761




详细解释:

数据编辑页面的文本编辑框数据源是绑定_DataBinder对象的,一个文本编辑框绑定一个字段的数据,用户录入资料后,会自动写入_DataBinder对象对应的字段里面。使用_DataBinder.Rows[0].EndEdit方法是告诉DataTable对象已修改完成,同时将当前焦点所在的文本编辑框的数据写入到DataTable对象。


参考:DataRow.EndEdit方法元数据:

C# Code:

//
// 摘要:
// Ends the edit occurring on the row.
//
// 异常:
// T:System.Data.InRowChangingEventException:
// The method was called inside the System.Data.DataTable.RowChanging event.
//
// T:System.Data.ConstraintException:
// The edit broke a constraint.
//
// T:System.Data.ReadOnlyException:
// The row belongs to the table and the edit tried to change the value of a read-only
// column.
//
// T:System.Data.NoNullAllowedException:
// The edit tried to put a null value into a column where System.Data.DataColumn.AllowDBNull
// is false.
[EditorBrowsable(EditorBrowsableState.Advanced)]
public void EndEdit();

//来源:C/S框架网 | www.csframework.com | QQ:23404761




上一篇 下一篇