VB.Net程序设计:代码简化过程(备忘录)
来源:互联网 发布:淘宝交易指数在哪里看 编辑:程序博客网 时间:2024/06/08 15:16
写代码时候,第一次是为了实现需要功能。
w.IsHasSpecialTime = TruedMints = ComClass.TimesLapse(dSub.ToDate, dSub.FromDate).TotalMinutesIf w.TimePeriod IsNot Nothing ThenFor Each d In AttTimeListIf ComClass.TimeInScope(d, ComClass.TimesCombine(w.Day, w.TimePeriod.CheckInTime1Date), ComClass.TimesCombine(w.Day, w.TimePeriod.CheckInTime2Date)) Thenw.AttInDate = dExit ForEnd IfNextIf w.IsOverDay ThenFor i As Integer = AttTimeList2Day.Count - 1 To 0 Step -1d = AttTimeList2Day.Item(i)If ComClass.TimeInScope(d, ComClass.TimesCombine(w.Day.AddDays(1), w.TimePeriod.CheckOutTime1Date), ComClass.TimesCombine(w.Day.AddDays(1), w.TimePeriod.CheckOutTime2Date)) Thenw.AttOutDate = dExit ForEnd IfNextElseFor i As Integer = AttTimeList.Count - 1 To 0 Step -1d = AttTimeList.Item(i)If ComClass.TimeInScope(d, ComClass.TimesCombine(w.Day, w.TimePeriod.CheckOutTime1Date), ComClass.TimesCombine(w.Day, w.TimePeriod.CheckOutTime2Date)) Thenw.AttOutDate = dExit ForEnd IfNextEnd IfIf w.AttInDate = MinDate OrElse w.AttOutDate = MinDate Thenw.IsCalculate = Truew.AttHours = 0w.InValidHours = (w.TimePeriod.WorkMinutes - dMints) / 60dSub.ValidHours = dMints / 60ElseIf w.AttInDate > MinDate And w.AttOutDate > MinDate Thenw.IsCalculate = Truew.AttHours = (w.TimePeriod.WorkMinutes - dMints) / 60dSub.ValidHours = dMints / 60End IfEnd If
处理效果还是可以,不过代码很长很长。同时间有10几个类似这样的代码段。加上其他内容差不多1000多行代码。
于是就想简化点。弄了好久才得出简化结果。 10几个类似的代码段慢慢改。剩下800多行了。
w.IsHasSpecialTime = TruedMints = ComClass.TimesLapse(dSub.ToDate, dSub.FromDate).TotalMinutesgetAttIn(w, ComClass.TimesCombine(w.Day, w.TimePeriod.CheckInTime1Date), ComClass.TimesCombine(w.Day, w.TimePeriod.CheckInTime2Date))If w.IsOverDay ThengetAttOut2Day(w, ComClass.TimesCombine(w.Day.AddDays(1), w.TimePeriod.CheckOutTime1Date), ComClass.TimesCombine(w.Day.AddDays(1), w.TimePeriod.CheckOutTime2Date))ElsegetAttOut1Day(w, ComClass.TimesCombine(w.Day, w.TimePeriod.CheckOutTime1Date), ComClass.TimesCombine(w.Day, w.TimePeriod.CheckOutTime2Date))End IfIf w.AttInDate = MinDate OrElse w.AttOutDate = MinDate Thenw.IsCalculate = Truew.AttHours = 0w.InValidHours = (w.TimePeriod.WorkMinutes - dMints) / 60dSub.ValidHours = dMints / 60ElseIf w.AttInDate > MinDate And w.AttOutDate > MinDate Thenw.IsCalculate = Truew.AttHours = (w.TimePeriod.WorkMinutes - dMints) / 60dSub.ValidHours = dMints / 60End If
结果中间过程有点问题,忽略了很多节点判断,分析,于是结构重新调整,增加几个函数过程。
继续简化,优化。结果不知道能简化成多少行,但是单从字符多少来看,已经减少了很多字符了。
dMints = ComClass.TimesLapse(dSub.ToDate, dSub.FromDate).TotalMinutesWith w.IsHasSpecialTime = True.CalcWorkTimeRange()End WithgetAttTime(w)If w.AttInDate = MinDate OrElse w.AttOutDate = MinDate Thenw.AttHours = 0w.InValidHours = ToHour(w.WorkMinutes - dMints)dSub.ValidHours = ToHour(dMints)ElseIf w.AttInDate > MinDate And w.AttOutDate > MinDate Thenw.AttHours = ToHour(w.WorkMinutes - dMints)dSub.ValidHours = ToHour(dMints)End If
期待能得出自己想要的结果。
加油!
- VB.Net程序设计:代码简化过程(备忘录)
- VB.Net程序设计:XPTable基本操作代码段(备忘录)
- VB备忘录(6)过程与函数
- VB.Net程序设计:常用程序集合(代码)
- 网址备忘录(VB,文件操作)代码
- Vb.Net程序设计:代码片段集
- VB.Net程序设计:辅助代码段1
- VB.Net程序设计:Action(Of)代码段
- vb.net程序设计规范(2)
- vb.net 程序设计规范(1)
- vb.net程序设计规范(2)
- vb.net 程序设计规范
- VB.Net程序设计:多行代码字符串修改器
- VB.Net程序设计:小代码段图片被锁住问题
- VB.Net程序设计:CodeStringHelper多行代码批量修改器
- MSMQ的VB操作代码/步骤(简化版)
- 测试的小段代码vb.net-sql存储过程
- VB备忘录(5)算法
- u-boot 使用 jffs2 文件系统加载内核 备忘
- 如何在android中调用数据库资源
- 设计一个移动应用的本地缓存机制
- 剑指offer第6题 二叉树重建 九度OJ1385
- 杭电4515
- VB.Net程序设计:代码简化过程(备忘录)
- 如何卸载鼠标右键ATI Catalyst Tm Control Center菜单
- 指针函数与函数指针的区别
- glassfish不能远程登录问题
- word excel powerpoint 图片压缩的方法
- Ubuntu Linux 创建DEB文件方法
- Asp.Net使用org.in2bits.MyXls.dll操作excel的应用!(转)
- acmer的26个字母品质
- js操作Cookie,实现历史浏览记录