⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trainteckitbookview.cpp

📁 实现铁路订票系统的订票
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		m_MSFGrid_tec.SetRow(iRow);
		m_MSFGrid_tec.SetCol(4);
		m_MSFGrid_tec.SetText(m_pteckitinforSet->m_to);
		

		strtemp=m_pteckitinforSet->m_start_time.Format("%Y-%m-%d %H:%M:%S");
		m_MSFGrid_tec.SetRow(iRow);
		m_MSFGrid_tec.SetCol(5);
		m_MSFGrid_tec.SetText(strtemp);
		
		strtemp.Format("%d",m_pteckitinforSet->m_seat_count);
		m_MSFGrid_tec.SetRow(iRow);
		m_MSFGrid_tec.SetCol(6);
		m_MSFGrid_tec.SetText(strtemp);
		
		strtemp.Format("%d",m_pteckitinforSet->m_seat_pri);
		m_MSFGrid_tec.SetRow(iRow);
		m_MSFGrid_tec.SetCol(7);
		m_MSFGrid_tec.SetText(strtemp);
		
		strtemp.Format("%d",m_pteckitinforSet->m_bed_count);	
		m_MSFGrid_tec.SetRow(iRow);
		m_MSFGrid_tec.SetCol(8);
		m_MSFGrid_tec.SetText(strtemp);

		strtemp.Format("%d",m_pteckitinforSet->m_bed_pri);
		m_MSFGrid_tec.SetRow(iRow);
		m_MSFGrid_tec.SetCol(9);
		m_MSFGrid_tec.SetText(strtemp);

		iRow++;
		m_pteckitinforSet->MoveNext();

	}
	m_MSFGrid_tec.SetRow(1);    m_MSFGrid_tec.SetCol(1);
    m_pteckitinforSet->MoveFirst();

}
	
void CTrainteckitbookView::OnBUTTONsearch()	//////////////////////   1  查询功能的实现
{
	// TODO: Add your control notification handler code here
	UpdateData(true);

	m_pteckitinforSet->m_strFilter.Format("from ='%s'AND to='%s' ", m_fromw_s,m_tow_s);//设置查询条件
	
//	TRACE("SQL:%s",m_pteckitinforSet->m_strFilter);

	if(!(m_pteckitinforSet->IsOpen()))
	{
		m_pteckitinforSet->Open();                               // 打开记录集
	}
	if(!(m_pteckitinforSet->IsBOF()))                            // 游标置于第一个记录
	{
		
		m_pteckitinforSet->MoveFirst();
	}
	if(m_pteckitinforSet->Requery())
	{
		Beep(100,100);
		ShowTecInfor();                                            //显示查询结果                              
	}

}


void CTrainteckitbookView::OnBUTTONbook()                          //   2  订票功能的实现
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	m_pteckitinforSet->m_strFilter="train_num=? AND start_time=?";  //参数化条件查询
	m_pteckitinforSet->train_num_u_b = m_train_num_b;
	m_pteckitinforSet->start_time_u_b= m_start_time_b;

//	TRACE("SQL:%s",m_pteckitinforSet->m_strFilter);

	if(!(m_pteckitinforSet->IsOpen()))
	{
		m_pteckitinforSet->Open();                               // 打开记录集
	}
	if(!(m_pteckitinforSet->IsBOF()))
	{
		m_pteckitinforSet->MoveFirst();
	}
	if(m_pteckitinforSet->Requery())
	{
		if(!NoRecord(m_pteckitinforSet))                        //record   exist
		{
			CTicketDlg dlg;
			{
				m_pteckitinforSet->Edit();
				LPCTSTR  lpsz[TYPE_COUNT] = {"硬座","卧铺"};
				if(SelChange_b == false)
				{
					AfxMessageBox("请选择票的类型!",0,0);
					return;
					
				}
				SelChange_b = false ;	


				int j = m_ticketype_b.CompareNoCase(lpsz[0]);       // j == 0;
				if(0 == j )
				{
					if(m_pteckitinforSet->m_seat_count != 0)
					{	
						dlg.m_ticketype_t		        = _T("硬座");
						dlg.m_seat_num_t				=  m_pteckitinforSet->m_seat_count ;
						m_pteckitinforSet->m_seat_count =  m_pteckitinforSet->m_seat_count -1;
					}
					else
					{
						AfxMessageBox("对不起!你要的硬座票已卖完!",0,0);
						return;
					}
				}
						
				else
				{   
					j = m_ticketype_b.CompareNoCase(lpsz[1]);
					if(0 == j)
					{
						if(m_pteckitinforSet->m_bed_count != 0)
						{
							dlg.m_ticketype_t	= _T("卧铺");
							dlg.m_seat_num_t	= m_pteckitinforSet->m_bed_count +m_pteckitinforSet->m_seat_count;
							m_pteckitinforSet->m_bed_count = m_pteckitinforSet->m_bed_count -1;
						}
						else
						{
							AfxMessageBox("对不起!你要的卧铺票已卖完!",0,0);
							return;
						}
					}
				}
/////////////////////打印所定车票的信息
				
				CString 	temp ;
				CString ss2 = m_pteckitinforSet->m_train_num.Right (3); 
				ss2.MakeReverse ();   
				int len = m_pteckitinforSet->m_train_num.GetLength();
				temp.Format(_T("%d%d%d"),len,len*dlg.m_seat_num_t,dlg.m_seat_num_t);

				dlg.m_from_t			= m_pteckitinforSet->m_from;
				dlg.m_to_t				= m_pteckitinforSet->m_to;
				dlg.m_train_num_t		= m_pteckitinforSet->m_train_num ;
				dlg.m_ticket_num_t		= m_pteckitinforSet->m_train_num+temp+ss2;
				dlg.m_start_time_t		= m_pteckitinforSet->m_start_time.Format("%Y-%m-%d %H:%M:%S");
				if(dlg.DoModal() == IDOK)
				{
					m_train_num_b = _T("")	;
					AfxMessageBox("订票成功!",0,0);
				}
				m_pteckitinforSet->Update();
				m_pteckitinforSet->Requery();
				ShowTecInfor();                                               //更新显示
				UpdateData(FALSE);
			}

		}
		else
		{
			AfxMessageBox("对不起!没有你要查询的记录!",0,0);
			return;
		}
	}

}

void CTrainteckitbookView::OnBUTTONbounce() /////////////////////////////      3  退票功能的实现
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	CString 	temp ;
	CString ss2 = m_trainnum_bounce.Right (3); 
	ss2.MakeReverse ();   
	int len = m_trainnum_bounce.GetLength();
	temp.Format(_T("%d%d%d"),len,len*m_seatnum_bounce,m_seatnum_bounce);
	CString ticket_num_bounce = m_trainnum_bounce+temp+ss2;
	int j = ticket_num_bounce.CompareNoCase(m_ticketnum_bounce);            // 核对用户的输入信息
	if(0 != j)
	{
		AfxMessageBox("对不起!你不能退票!请验证你所输入的信息!",0,0);
		return;
	}
	m_pteckitinforSet->m_strFilter.Format("train_num='%s'",m_trainnum_bounce);
	if(!(m_pteckitinforSet->IsOpen()))
	{
		m_pteckitinforSet->Open();			// 打开记录集
	}
	if(!(m_pteckitinforSet->IsBOF()))
	{
		
		m_pteckitinforSet->MoveFirst();
	}
	if(m_pteckitinforSet->Requery())
	{
		Beep(100,100);
	
	}
	if(!NoRecord(m_pteckitinforSet))		//record   exist
	{

		m_pteckitinforSet->Edit();
		LPCTSTR  lpsz[TYPE_COUNT] = {"硬座","卧铺"};
		if(SelChange_bounce == false)
		{
			AfxMessageBox("请选择票的类型!",0,0);
			return;
				
		}
		SelChange_bounce	= false ;	
		int j = m_ticketype_bounce.CompareNoCase(lpsz[0]);// j == 0;
		if(0 == j )
		{	
			m_pteckitinforSet->m_seat_count =  m_pteckitinforSet->m_seat_count +1;
		}
		else
		{   
			j = m_ticketype_bounce.CompareNoCase(lpsz[1]);
			if(0 == j)
			{
				m_pteckitinforSet->m_bed_count = m_pteckitinforSet->m_bed_count +1;
			}
		}
		CTime time  = CTime::GetCurrentTime();
		CTimeSpan timespan = m_pteckitinforSet->m_start_time -time ;
		CTimeSpan deathline_span(0,1,0,0);
		if(timespan <deathline_span)
		{	
			AfxMessageBox("对不起!你不能退票!已超过退票期!",0,0);
			return;
		}
		m_pteckitinforSet->Update();
		m_pteckitinforSet->Requery();
		ShowTecInfor();
		AfxMessageBox("退票成功!",0,0);
	}
	else
	{
		AfxMessageBox("对不起!你不能退票!请验证你所输入的信息!",0,0);
		return;
	}
}

void CTrainteckitbookView::OnBUTTONcancelbounce() ////////////////////////// 取消退票
{
	// TODO: Add your control notification handler code here
	m_trainnum_bounce	= _T("");
	m_ticketnum_bounce	= _T("");
	m_seatnum_bounce	= 0;
	SelChange_bounce	= false ;
	UpdateData(false);
}


void CTrainteckitbookView::OnSelchangeCOMBOticketypeb() 
{
	// TODO: Add your control notification handler code here
	int nIndex = m_CBticketype_b.GetCurSel();
	if(nIndex != CB_ERR)
	{
		m_CBticketype_b.GetLBText(nIndex,m_ticketype_b);
		SelChange_b = true;
	}
}
void CTrainteckitbookView::OnSelchangeCOMBOCBticketypebounce() 
{
	// TODO: Add your control notification handler code here
	int nIndex = m_CBticketype_bounce.GetCurSel();
	if(nIndex != CB_ERR)
	{
		m_CBticketype_bounce.GetLBText(nIndex,m_ticketype_bounce);
		SelChange_bounce = true;
	}
	
}

bool CTrainteckitbookView::NoRecord(CRecordset *pSet)       // 检查记录集是否为空
{
	CRecordsetStatus   rstatus;				               //status   variable   
    m_pteckitinforSet->GetStatus(rstatus);	              //get   crecordset   status   
    if(rstatus.m_lCurrentRecord >=0)		              //record   exist   
		return false;
	else
		return true;

}

void CTrainteckitbookView::OnBUTTONmodefy()                    // 4 修改票务,从数据库中清除作废的车票
{
	// TODO: Add your control notification handler code here
	CPass dlg;
	CString passw("123456");
	if(dlg.DoModal()==IDOK)
	{
		UpdateData(true);
		int j = dlg.m_password.CompareNoCase(passw);            //验证管理员密码
		if(0 == j)
		{
			if(!(m_pteckitinforSet->IsOpen()))
			{
				m_pteckitinforSet->Open();                      // 打开记录集
			}
			if(!(m_pteckitinforSet->IsBOF()))
			{
			m_pteckitinforSet->MoveFirst();
			}
			if(m_pteckitinforSet->Requery())
			{
				Beep(100,100);
			}
			if(!NoRecord(m_pteckitinforSet))                  //record   exist
			{
				while(!	m_pteckitinforSet->IsEOF())
				{
					CTime time  = CTime::GetCurrentTime();
					CTimeSpan timespan = time - m_pteckitinforSet->m_start_time ;
					CTimeSpan deathline_span(0,0,30,0);
//					if(timespan.GetTotalHours() >=1)
					if(timespan > deathline_span)              //已作废的车票
					{
						CRecordsetStatus status;
						m_pteckitinforSet->GetStatus(status);
						m_pteckitinforSet->Delete();
						m_pteckitinforSet->MoveNext();
					//	m_pteckitinforSet->Update();
						m_pteckitinforSet->Requery();
					}
					else
						m_pteckitinforSet->MoveNext();
				}
			}
		}
					
		else
		{
			AfxMessageBox("对不起!你没有权限!",0,0);
			dlg.m_password = _T("");
			UpdateData(false);
			return;
		}
		ShowTecInfor();
	}
//////////////////////////////////////////////////////////////////////////选择了取消操作
	else 
	{
		dlg.m_password = _T("");
		UpdateData(false);
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -