那些 Cynthia 教我的事 之 PMSec (二)
2024-10-19 06:16:43
一、在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);
}
四、 λ 表达式
好复杂的说,不老明白的,计入λ 番外篇吧。
( ^_^ )/~~
最新文章
- IT
- java udp与tcp
- 深入分析Java Web技术内幕(修订版)
- .NET Core 单元测试 MSTest
- MongoDB Sharding、库、collection设计学习汇总
- 攻城狮在路上(叁)Linux(十九)--- 磁盘分区
- Hadoop实战3:MapReduce编程-WordCount统计单词个数-eclipse-java-ubuntu环境
- 重新组织 vs 重新生成索引
- 理解Javascript__undefined和null
- Intra Luma Prediction
- spark sql 基本用法
- js中style,currentStyle和getComputedStyle的区别以及获取css样式操作方法
- Django auth认证系统
- 【ShareCode】不错的技术文章 -- 如何使用异或(XOR)运算找到数组中缺失的数?
- django models数据库操作
- SQL Server孤立账户解决办法
- C#导入Excel数据常见问题
- getImplementationVersion-获取版本号
- spring mvc静态资源请求和<;mvc:annotation-driven>;
- 【spring cloud】spring cloud集成zipkin报错:Prometheus requires that all meters with the same name have the same set of tag keys.
热门文章
- iOS archive(归档)的总结
- 常用网站--前端开发类+网页设计类+平面素材类+flash类
- (转) eclipse debug (调试) 学习心得
- (原)调用jpeglib对图像进行压缩
- Dx 1 error; aborting Conversion to Dalvik format failed with error 1
- (转)使用scp命令在linux操作系统之间传递文件
- KEIL CRACK及 0xFD Bug修正方法
- C#开发SQLServer的Geometry和Geography存储
- logstash 处理tomcat日志
- C语言随笔_fopen