/// <summary> /// 批量进行保存 /// </summary> /// <param name="dataTable">数据表</param> /// <returns>影响行数</returns> public override int BatchSave(DataTable dataTable) { int returnValue = 0; BaseFileEntity fileEntity = new BaseFileEntity(); foreach (DataRow dataRow in dataTable.Rows) { // 删除状态 if (dataRow.RowState == DataRowState.Deleted) { string id = dataRow[BaseFileEntity.FieldId, DataRowVersion.Original].ToString(); if (id.Length > 0) { returnValue += this.Delete(id); } } // 被修改过 if (dataRow.RowState == DataRowState.Modified) { string id = dataRow[BaseFileEntity.FieldId, DataRowVersion.Original].ToString(); if (id.Length > 0) { fileEntity.GetFrom(dataRow); // 判断是否允许编辑 returnValue += this.UpdateEntity(fileEntity); } } // 添加状态 if (dataRow.RowState == DataRowState.Added) { fileEntity.GetFrom(dataRow); returnValue += this.AddEntity(fileEntity).Length > 0 ? 1 : 0; } if (dataRow.RowState == DataRowState.Unchanged) { continue; } if (dataRow.RowState == DataRowState.Detached) { continue; } } return(returnValue); }
/// <summary> /// 批量进行保存 /// </summary> /// <param name="result">数据表</param> /// <returns>影响行数</returns> public override int BatchSave(DataTable dt) { int result = 0; BaseFileEntity entity = new BaseFileEntity(); foreach (DataRow dr in dt.Rows) { // 删除状态 if (dr.RowState == DataRowState.Deleted) { string id = dr[BaseFileEntity.FieldId, DataRowVersion.Original].ToString(); if (id.Length > 0) { result += this.Delete(id); } } // 被修改过 if (dr.RowState == DataRowState.Modified) { string id = dr[BaseFileEntity.FieldId, DataRowVersion.Original].ToString(); if (id.Length > 0) { entity.GetFrom(dr); // 判断是否允许编辑 result += this.UpdateObject(entity); } } // 添加状态 if (dr.RowState == DataRowState.Added) { entity.GetFrom(dr); result += this.AddObject(entity).Length > 0 ? 1 : 0; } if (dr.RowState == DataRowState.Unchanged) { continue; } if (dr.RowState == DataRowState.Detached) { continue; } } return(result); }