#region using System; using System.Collections; using System.Data; using CSFrameworkV5.Core; #endregion namespace CSFrameworkV5.Business { /// *************************************************************************/ /// * /// * 文件名 :bllBase.cs /// * 程序说明 : 业务逻辑层基类 /// * 原创作者 :www.csframework.com /// * /// * Copyright 2006-2021 C/S框架网 www.csframework.com /// **************************************************************************/ /// /// 业务逻辑层基类 /// public class bllBase { /// /// 删除资料表的空行,在保存前使用。 /// /// 资料表 /// 检查的字段,当这些字段都为空或值为零的情况下,删除此行 public int RemoveEmptyRow(DataTable dataTable, string[] checkFields) { var isEmpty = false; IList list = new ArrayList(); //枚举资料表:获取空的资料行 foreach (DataRow R in dataTable.Rows) { //被删除的行,不处理 if (R.RowState == DataRowState.Deleted) continue; isEmpty = true; foreach (var field in checkFields) //此字段有值 if (R[field] != DBNull.Value && R[field].ToStringEx() != "") { isEmpty = false; break; } if (isEmpty) list.Add(R); //增加空的资料行 } //处理删除的记录 foreach (DataRow R in list) //如果当前记录是新增状态,彻底删除,不提交数据了 if (R.RowState == DataRowState.Added) dataTable.Rows.Remove(R); else R.Delete(); //用户修改了当前记录,几乎清空了数据,因此打上删除标记,提交后台删除 return list.Count; } /// /// 数字类型设置预设值0 /// /// protected void SetNumericDefaultValue(DataSet ds) { foreach (DataTable t in ds.Tables) SetNumericDefaultValue(t); } /// /// 数字类型设置预设值0 /// /// protected void SetNumericDefaultValue(DataTable dt) { var names = ",int,int16,int32,int64,decimal,float,double,"; foreach (DataColumn col in dt.Columns) if (names.IndexOf(col.DataType.Name.ToLower()) > 0) col.DefaultValue = 0.00; } } }