COleDateTimeSpan ts1(3, 1, 5, 12); // 3 days, 1 hour, 5 min, and 12 sec
 COleDateTimeSpan ts2(100.0 / (24 * 3600.0)); // 100 seconds
 COleDateTimeSpan ts3 = ts1 + ts2;
 ASSERT(ts3.GetSeconds() == 52); // 6 mins, 52 secs   
void CDlgBundleTimeList::OnOK()
{
	INT nIndex = m_BundleTimeList.GetSelectionMark();

	if (nIndex >= 0)
	{	
		//取得绑定数据
		INT nBtIndex = m_BundleTimeList.GetItemData(nIndex);
		
		m_nBundleTimeId = NetbarBundleTime.GetAt(nBtIndex).GetBundleTimeId();

		m_nBundleTimeClassId = NetbarBundleTime.GetAt(nBtIndex).IsNowEnabled() ? 0 : 1;

		//开始时间
		m_strStartTime = NetbarBundleTime.GetAt(nBtIndex).GetStartTime(TRUE).Left(5);
		//结束时间
		m_strEndTime = NetbarBundleTime.GetAt(nBtIndex).GetEndTime(TRUE).Left(5);
		//包时扣费类型
		m_nBundleTimeType = NetbarBundleTime.GetAt(nBtIndex).GetBundleTimeType();

		COleDateTimeSpan RemainTime;

		if (NetbarBundleTime.GetAt(nBtIndex).GetStartTime().IsEmpty())
		{
			RemainTime = COleDateTimeSpan(0, NetbarBundleTime.GetAt(nBtIndex).GetTimePass(), 0, 0);
		}
		else
		{
			COleDateTime StartTime, EndTime, CurTime = COleDateTime::GetCurrentTime();
			
			StartTime.ParseDateTime(NetbarBundleTime.GetAt(nBtIndex).GetStartTime(TRUE));
			StartTime.SetDateTime(CurTime.GetYear(), CurTime.GetMonth(), CurTime.GetDay(),
				StartTime.GetHour(), StartTime.GetMinute(), StartTime.GetSecond());

			EndTime.ParseDateTime(NetbarBundleTime.GetAt(nBtIndex).GetEndTime(TRUE));
			EndTime.SetDateTime(CurTime.GetYear(), CurTime.GetMonth(), CurTime.GetDay(),
				EndTime.GetHour(), EndTime.GetMinute(), EndTime.GetSecond());

			if (StartTime > EndTime) //跨天包时
			{
				if (CurTime < EndTime)
				{
					StartTime -= COleDateTimeSpan(1, 0, 0, 0); //减去一天
				}
				else
				{
					EndTime += COleDateTimeSpan(1, 0, 0, 0); //加上一天
				}
			}
			
			if (CurTime < StartTime) //包时还没开始
			{
				RemainTime = COleDateTimeSpan(0, NetbarBundleTime.GetAt(nBtIndex).GetTimePass(), 0, 0);
			}
			else if (CurTime > EndTime) //包时已经过期,只能开始算明天的包时
			{

			}
			else //包时正在进行
			{
				RemainTime = EndTime - CurTime;
			}

			//AfxMessageBox(StartTime.Format(_T("%Y-%m-%d %H:%M:%S")));
			//AfxMessageBox(EndTime.Format(_T("%Y-%m-%d %H:%M:%S")));
			//AfxMessageBox(m_strRemainTime);
		} 
		
		//m_strRemainTime = RemainTime.Format(_T("%H:%M:%S"));

		m_strRemainTime.Format(_T("%02d:%02d:%02d"), 
			(long)RemainTime.GetTotalHours(), RemainTime.GetMinutes(), RemainTime.GetSeconds());

		//包时金额
		m_nBundleTimeMoney = NetbarBundleTime.GetAt(nBtIndex).GetBundleTimeMoney();

		CBCGPDialog::OnOK();
	}
}