一、在Foreach之前要判断是否为空。

常常从数据库里取出来表就直接用了,很少记得判断是否有值。不严谨的说。

专业人员写的是酱滴。。。

           DataLayer.PMSecDataSet.PMSECRequestDataTable requestDataTable = adapter.up_PMSec_PMSECRequestSelectByMasterIDs(masterIds);

           if (requestDataTable != null && requestDataTable.Count > )
{
...
}

二、当数据库中允许为空。

话说,上次已经说过的啦。。。但是这次更加明确,要用Nullable<int>.

          Nullable<int> intNull = null;
DataLayer.PMSecDataSet.PMSECRequestDataTable requestDataTable = adapter.up_PMSec_PMSECRequestSelectByMasterIDs(masterIds); if (requestDataTable != null && requestDataTable.Count > )
{ foreach (DataLayer.PMSecDataSet.PMSECRequestRow dr in requestDataTable.Rows)
{
PMSecRequestInfo requestInfo = new PMSecRequestInfo();
requestInfo.RequestMasterID = dr.RequestMasterID;
requestInfo.EmployeeID = dr.EmployeeID;
Employee requestEmployee = new Employee(dr.EmployeeID);
requestInfo.DisplayName = requestEmployee.DisplayName;
requestInfo.StatusType = dr.StatusType;
requestInfo.CompanyID = dr.CompanyID;
requestInfo.WorkStoreID = dr.WorkStoreID;
requestInfo.JobCode = dr.JobCode;
requestInfo.RequestedSecurityLevel = dr.IsRequestedSecurityLevelNull() ? intNull : dr.RequestedSecurityLevel;
requestInfo.IsSecurityAdmin = dr.IsSecurityAdmin;
requestInfo.CreatedBy = dr.CreatedBy;
requestInfo.CreatedOn = dr.CreatedOn; requestInfoList.Add(requestInfo);
}
}

string类无需此处理。

三、操作数据库时

当含有update等更改数据库内容的语句存在时,如果下面操作仍与数据库有关,考虑到程序的扩展性,可能出现上述语句删除了某些数据,下面语句出现异常,或者产生错误结果,等等。

譬如下面两段代码,前者是我的做法,后者为Cynthia的做法,一见高下啊啊啊。我写的好像是舒克和贝塔里那只笨猫,喵,~~~~(>_<)~~~~ 。

   public void ApporveOrDeclineRequest(string masterIds, string statusType, int loginEid)
{
PMSECRequestPendingTaskTableAdapter adapter = new PMSECRequestPendingTaskTableAdapter();
adapter.up_PMSec_PMSECRequestUpdate(masterIds, statusType, loginEid); // Send Email
PandaRG.Common.OrgChart.Employee logInEmployee = new Common.OrgChart.Employee(loginEid); if (statusType == RequestStatusType.APPROVED.ToString())
{
EmailSendHelper.SentEmailbyEmailType(RequestStatusType.APPROVED, GetRequestInfoListByRequestMasterIds(masterIds), logInEmployee); }
else if(statusType==RequestStatusType.DECLINED.ToString())
{
EmailSendHelper.SentEmailbyEmailType(RequestStatusType.DECLINED, GetRequestInfoListByRequestMasterIds(masterIds), logInEmployee);
}
}
       public void UpdatePMSECRequest(string masterIds, RequestStatusType statusType, Employee loginEmployee)
{
PMSECRequestPendingTaskTableAdapter adapter = new PMSECRequestPendingTaskTableAdapter(); List<PMSecRequestInfo> requestInfoList = GetRequestInfoListByRequestMasterIds(masterIds);
adapter.up_PMSec_PMSECRequestUpdate(masterIds, statusType.ToString(), loginEmployee.EmployeeId);
EmailSendHelper.SentEmailbyEmailType(statusType, requestInfoList, loginEmployee);
}

四、 λ 表达式

好复杂的说,不老明白的,计入λ 番外篇吧。

( ^_^ )/~~

最新文章

  1. IT
  2. java udp与tcp
  3. 深入分析Java Web技术内幕(修订版)
  4. .NET Core 单元测试 MSTest
  5. MongoDB Sharding、库、collection设计学习汇总
  6. 攻城狮在路上(叁)Linux(十九)--- 磁盘分区
  7. Hadoop实战3:MapReduce编程-WordCount统计单词个数-eclipse-java-ubuntu环境
  8. 重新组织 vs 重新生成索引
  9. 理解Javascript__undefined和null
  10. Intra Luma Prediction
  11. spark sql 基本用法
  12. js中style,currentStyle和getComputedStyle的区别以及获取css样式操作方法
  13. Django auth认证系统
  14. 【ShareCode】不错的技术文章 -- 如何使用异或(XOR)运算找到数组中缺失的数?
  15. django models数据库操作
  16. SQL Server孤立账户解决办法
  17. C#导入Excel数据常见问题
  18. getImplementationVersion-获取版本号
  19. spring mvc静态资源请求和&lt;mvc:annotation-driven&gt;
  20. 【spring cloud】spring cloud集成zipkin报错:Prometheus requires that all meters with the same name have the same set of tag keys.

热门文章

  1. iOS archive(归档)的总结
  2. 常用网站--前端开发类+网页设计类+平面素材类+flash类
  3. (转) eclipse debug (调试) 学习心得
  4. (原)调用jpeglib对图像进行压缩
  5. Dx 1 error; aborting Conversion to Dalvik format failed with error 1
  6. (转)使用scp命令在linux操作系统之间传递文件
  7. KEIL CRACK及 0xFD Bug修正方法
  8. C#开发SQLServer的Geometry和Geography存储
  9. logstash 处理tomcat日志
  10. C语言随笔_fopen