C#.NET 权限管理系统组件 - 大数据只获取更新部分数据列的标准例子
2013-02-16 19:12 通用C#系统架构 阅读(1727) 评论(1) 编辑 收藏 举报程序的运行效果如下:
1:获取时,只获取需要的列,不需要的列不获取,主要原因是:因为数据量大获取所有的列传输的数据量大,有些敏感数据未必需要都传输在网络上,其次是更新数据时的版本问题尽量避免,你也在改他也在改,隐藏的数据列也更新了,并不是很好甚至可能引起一些没必要的错误。
#region public DataTable GetAddressDataTableByPage(BaseUserInfo userInfo, string organizeId, string searchValue, out int recordCount, int pageIndex = 0, int pageSize = 100, string sort = null) /// <summary> /// 获取内部通讯录 /// </summary> /// <param name="userInfo">用户</param> /// <param name="organizeId">组织机构主键</param> /// <param name="search">查询内容</param> /// <param name="pageSize">分页的条数</param> /// <param name="pageIndex">当前页数</param> /// <returns>数据表</returns> public DataTable GetAddressDataTableByPage(BaseUserInfo userInfo, string organizeId, string searchValue, out int recordCount, int pageIndex = 0, int pageSize = 100, string sort = null) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif DataTable dataTable = new DataTable(BaseStaffEntity.TableName); using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); // 这里是不获取所有的列,只获取自己需要的列的标准方法 BaseStaffManager staffManager = new BaseStaffManager(dbHelper, userInfo); staffManager.SelectField = "Id, RealName, DepartmentName, DutyName, OfficePhone, Mobile, ShortNumber, Email, OICQ, Description"; dataTable = staffManager.GetAddressDataTableByPage(organizeId, searchValue, out recordCount, pageSize, pageIndex, sort); dataTable.TableName = BaseStaffEntity.TableName; BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.StaffService_GetAddressPageDT, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return dataTable; } #endregion
2:更新时,只更新数据有变化的记录,没有变化的记录不进行更新。
#region private void BatchSave() 批量保存 /// <summary> /// 批量保存 /// </summary> private void BatchSave() { // 去掉未修改的数据,提高运行速度 for (int i = this.DTStaff.Rows.Count - 1; i >= 0; i--) { if (this.DTStaff.Rows[i].RowState == DataRowState.Unchanged) { this.DTStaff.Rows.RemoveAt(i); } } DotNetService.Instance.StaffService.BatchUpdateAddress(this.UserInfo, this.DTStaff); this.Search(); if (BaseSystemInfo.ShowInformation) { // 批量保存,进行提示 MessageBox.Show(AppMessage.MSG0012, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); } } #endregion
/// <summary> /// 批量更新通讯地址 /// </summary> /// <param name="userInfo">用户</param> /// <param name="dtStaff">数据表</param> /// <returns>影响行数</returns> public int BatchUpdateAddress(BaseUserInfo userInfo, DataTable dtStaff) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif int returnValue = 0; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); // 这里是只更新部分字段的例子 foreach (DataRow dr in dtStaff.Rows) { SQLBuilder sqlBuilder = new SQLBuilder(dbHelper); sqlBuilder.BeginUpdate(BaseStaffEntity.TableName); // 这里是界面上显示的字段,需要更新的字段 sqlBuilder.SetValue(BaseStaffEntity.FieldOfficePhone, dr[BaseStaffEntity.FieldOfficePhone].ToString()); sqlBuilder.SetValue(BaseStaffEntity.FieldMobile, dr[BaseStaffEntity.FieldMobile].ToString()); sqlBuilder.SetValue(BaseStaffEntity.FieldShortNumber, dr[BaseStaffEntity.FieldShortNumber].ToString()); sqlBuilder.SetValue(BaseStaffEntity.FieldEmail, dr[BaseStaffEntity.FieldEmail].ToString()); sqlBuilder.SetValue(BaseStaffEntity.FieldOICQ, dr[BaseStaffEntity.FieldOICQ].ToString()); sqlBuilder.SetValue(BaseStaffEntity.FieldDescription, dr[BaseStaffEntity.FieldDescription].ToString()); sqlBuilder.SetWhere(BaseStaffEntity.FieldId, dr[BaseStaffEntity.FieldId].ToString()); returnValue += sqlBuilder.EndUpdate(); } BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.StaffService_BatchUpdateAddress, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return returnValue; }
希望能对需要的人起点儿参考作用。
将权限管理、工作流管理做到我能力的极致,一个人只能做好那么很少的几件事情。