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

📄 modifydlg.cpp

📁 公交查询生成系统 Find.exe可以查询指定站点间的转站方案(可实现无限转)
💻 CPP
📖 第 1 页 / 共 3 页
字号:
											adCmdText);
					m_list1.InsertColumn(0, "    记录", LVCFMT_CENTER, 60);
					m_list1.InsertColumn(1, "情况", LVCFMT_CENTER, 93);

					if(!m_pRecordset->BOF)
					m_pRecordset->MoveFirst();
					else
					{
						AfxMessageBox(m_edit+"站表内数据为空");
						return;
					}
					while(!m_pRecordset->adoEOF)
					{
						var = m_pRecordset->GetCollect("线路");
						v = (LPCSTR)_bstr_t(var);
						if(v == m_edit)
						{
							var = m_pRecordset->GetCollect("起点站");
							m_list1.InsertItem(0, "起点站");
							m_list1.SetItemText(0, 1, (LPCSTR)_bstr_t(var));
							var = m_pRecordset->GetCollect("终点站");
							m_list1.InsertItem(1, "终点站");
							m_list1.SetItemText(1, 1, (LPCSTR)_bstr_t(var));
							var = m_pRecordset->GetCollect("发车时间");
							m_list1.InsertItem(2, "发车时间");
							m_list1.SetItemText(2, 1, (LPCSTR)_bstr_t(var));
							var = m_pRecordset->GetCollect("结束时间");
							m_list1.InsertItem(3, "结束时间");
							m_list1.SetItemText(3, 1, (LPCSTR)_bstr_t(var));
							var = m_pRecordset->GetCollect("汽车类型");
							m_list1.InsertItem(4, "汽车类型");
							m_list1.SetItemText(4, 1, (LPCSTR)_bstr_t(var));
							var = m_pRecordset->GetCollect("票价");
							m_list1.InsertItem(5, "票价");
							m_list1.SetItemText(5, 1, (LPCSTR)_bstr_t(var));
							var = m_pRecordset->GetCollect("站点数");
							m_list1.InsertItem(6, "起点数");
							m_list1.SetItemText(6, 1, (LPCSTR)_bstr_t(var));
							var = m_pRecordset->GetCollect("线路总长");
							m_list1.InsertItem(7, "线路总长");
							m_list1.SetItemText(7, 1, (LPCSTR)_bstr_t(var));							
							break;
						}
						m_pRecordset->MoveNext();
					}
				}
				catch(_com_error e)
				{					
					AfxMessageBox(e.Description());
					return;
				}
				///////////////////
				//添加m_list2
				try
				{
					m_pRecordset.CreateInstance(__uuidof(Recordset));
					m_pRecordset->Open(_variant_t("SELECT * FROM " + m_edit),                // 查询站点表中所有字段
											theApp.m_pConnection.GetInterfacePtr(),	 // 获取库接库的IDispatch指针
											adOpenDynamic,
											adLockOptimistic,
											adCmdText);
					m_list2.InsertColumn(0, "             站点", LVCFMT_CENTER, 127);

					if(!m_pRecordset->BOF)
					m_pRecordset->MoveFirst();
					else
					{
						AfxMessageBox(m_edit+"站表内数据为空");
						return;
					}
					while(!m_pRecordset->adoEOF)
					{
						var = m_pRecordset->GetCollect("站点");
						v = (LPCSTR)_bstr_t(var);			
						v = "           " + v ;
						m_list2.InsertItem(n++, v);
						m_pRecordset->MoveNext();
					}				
				}
				catch(_com_error e)
				{					
					AfxMessageBox(e.Description()); 
					return;
				}
		}
}

void CModifyDlg::OnAddline() 
{
	// TODO: Add your control notification handler code here
	if(addline == true)
	{
		m_list1.DeleteAllItems();//删除列中个项
		m_list2.DeleteAllItems();
		
		m_list1.DeleteColumn(0);//删除第一行
		m_list1.DeleteColumn(0);	
		m_list2.DeleteColumn(0);

		//m_edit = "";
		m_combo = "";
		UpdateData(FALSE);//更新视图
	}

	int newstation = 0;
	bool spot = true;

	CModifyLine1Dlg dlg;
	
	if(addline == false)//如果是修改函数,就把数据填充上去
	{
		dlg.m_edit7 = m_7;
		dlg.m_edit1 = m_1;
		dlg.m_edit2 = m_2;
		dlg.m_edit3 = m_3;
		dlg.m_edit4 = m_4;
		dlg.m_edit5 = m_5;
		dlg.m_edit6 = m_6;
	}
	UpdateData(FALSE);
	if(dlg.DoModal() == IDOK)
	{

		if(dlg.m_edit1=="" || dlg.m_edit2 =="" || dlg.m_edit3 =="" || dlg.m_edit4 =="" || dlg.m_edit5 =="" || dlg.m_edit6 =="" || dlg.m_edit7 =="")
		{	
			AfxMessageBox("请添全数据!");
			return;
		}
		m_list1.InsertColumn(0, "    记录", LVCFMT_CENTER, 60);
		m_list1.InsertColumn(1, "情况", LVCFMT_CENTER, 93);

		dlg.m_edit7 = dlg.m_edit7;
		m_list1.InsertItem(0, "线路");
		m_list1.SetItemText(0, 1, dlg.m_edit7);

		m_list1.InsertItem(1, "起点站");
		m_list1.SetItemText(1, 1, dlg.m_edit1);

		m_list1.InsertItem(2, "终点站");
		m_list1.SetItemText(2, 1, dlg.m_edit2);

		m_list1.InsertItem(3, "发车时间");
		m_list1.SetItemText(3, 1, dlg.m_edit3);

		m_list1.InsertItem(4, "结束时间");
		m_list1.SetItemText(4, 1, dlg.m_edit4);

		m_list1.InsertItem(5, "汽车类型");
		m_list1.SetItemText(5, 1, dlg.m_edit5);

		m_list1.InsertItem(6, "票价");
		m_list1.SetItemText(6, 1, dlg.m_edit6);

		m_edit = dlg.m_edit7;
		m_combo = "线路";
		UpdateData(FALSE);
		//////////////////////////////////////////////////////////////
		//弹出第2个窗口
		CAdd1Dlg dlg1;
		if(addline == false)//如果是修改函数,就把数据填充上去
		{
			dlg1.m_edit1 = line;
			UpdateData(FALSE);
		}
		if(dlg1.DoModal() == IDOK)
		{
			int num = 0;
			m_list2.InsertColumn(0, "             站点", LVCFMT_CENTER, 127);
			CString first, name;
			int length = 0, hang = 0;
			while(dlg1.m_edit1 != "")
			{
				length = dlg1.m_edit1.GetLength();
				if(length != 0 && dlg1.m_edit1.Find("+") == -1)
				{	
					first = dlg1.m_edit1;
					dlg1.m_edit1 = "";
				}
				else
				{	first = dlg1.m_edit1.Left(dlg1.m_edit1.Find("+"));					
					dlg1.m_edit1 = dlg1.m_edit1.Right(length-(dlg1.m_edit1.Find("+")+2));
				} 
				first = "     " + first; 
				m_list2.InsertItem(hang++, first);
				num++;
			}
			UpdateData(FALSE);//更新视图
			char value[5];
			CString v;
			for(int j=0; j<5; j++)
				value[j] = 0;
			itoa(num, value, 10);
			v = value;
			m_list1.InsertItem(7, "站点总数");
			m_list1.SetItemText(7, 1, v);

			m_list1.InsertItem(8, "线路总长");
			m_list1.SetItemText(8, 1, v);

			////////////////////////////////////////////////////////////
			//添加线路总表
				try
				{//判断是否存在该线路
					m_pRecordset.CreateInstance(__uuidof(Recordset));
					m_pRecordset->Open(_variant_t("SELECT * FROM 线路总表"),                // 查询站点表中所有字段
											theApp.m_pConnection.GetInterfacePtr(),	 // 获取库接库的IDispatch指针
											adOpenDynamic,
											adLockOptimistic,
											adCmdText);
					if(!m_pRecordset->BOF)
					{	
						_variant_t var;
						bool have = false;
						m_pRecordset->MoveFirst();
						while(!m_pRecordset->adoEOF)
						{
							var = m_pRecordset->GetCollect("线路");
							if(dlg.m_edit7 ==(LPCSTR)_bstr_t(var))
							{
								have = true;
								break;
							}
							m_pRecordset->MoveNext();
						}
						if(have == true)
						{
							AfxMessageBox("该线路已存在!");
							m_list1.DeleteAllItems();//删除列中个项
							m_list2.DeleteAllItems();
							
							m_list1.DeleteColumn(0);//删除第一行
							m_list1.DeleteColumn(0);	
							m_list2.DeleteColumn(0);
							return;
						}
					}
				}
				catch(_com_error e)
				{					
					AfxMessageBox(e.Description()); 
					return;
				}

			try
			{
				// 写入各字段值
				m_pRecordset->AddNew();
				m_pRecordset->PutCollect("线路", _variant_t(dlg.m_edit7));
				m_pRecordset->PutCollect("起点站", _variant_t(dlg.m_edit1));
				m_pRecordset->PutCollect("终点站", _variant_t(dlg.m_edit2));
				m_pRecordset->PutCollect("发车时间", _variant_t(dlg.m_edit3));
				m_pRecordset->PutCollect("结束时间", _variant_t(dlg.m_edit4));
				m_pRecordset->PutCollect("汽车类型", _variant_t(dlg.m_edit5));
				m_pRecordset->PutCollect("票价", atol(dlg.m_edit6));
				m_pRecordset->PutCollect("站点数", atol(v));
				m_pRecordset->PutCollect("线路总长", atol(v));
				m_pRecordset->Update();
			}
			catch(_com_error e)
			{
				AfxMessageBox(e.Description()); 
				return;
			}
			////////////////////////////////////////////////////////////
			//添加线路中各站点
			_variant_t RecordsAffected; 
			try//建表                 
			{				
				_bstr_t var =(_bstr_t)("CREATE TABLE "  + dlg.m_edit7 + "(ID COUNTER,站点 TEXT)");
				m_pConnection->Execute(var, 
	       								&RecordsAffected, 
										adCmdText);

			}
			catch(_com_error e)
			{
				AfxMessageBox(e.Description()); 
				return;
			}
			UpdateData();
			try
			{
				int m_nIndex = 0;
				int length, j;
				CString strSQL, t;
				char value[5];
				CString v; 
				while((t = m_list2.GetItemText(m_nIndex++, 0)) != "")
				{
					spot = true;
					length = t.GetLength();
					t = t.Right(length - 5);
				
					for(j=0; j<5; j++)
						value[j] = 0;
					itoa(m_nIndex, value, 10);
					v = value;

					CString strSQL; 
					strSQL.Format("INSERT INTO %s(站点) VALUES (\'%s\')",m_edit, t); 
					
					TRACE("%d", m_nIndex);
					_variant_t RecordsAffected;
					
					m_pConnection->Execute((_bstr_t)strSQL,
												&RecordsAffected,
												adCmdText);

					/////////////////////////////////////////////////////////////////
					//添加各站点表,已存在的填充表内容(经过线路)			
					try//建表                 
					{
						newstation++;
						_variant_t RecordsAffected; 					
						_bstr_t var =(_bstr_t)("CREATE TABLE "  + t + "(ID COUNTER,线路 TEXT)");
						m_pConnection->Execute(var, 
	       										&RecordsAffected, 
												adCmdText);						
					}
					catch(_com_error e)
					{	
						newstation--;
						spot = false;
						goto next;
					}
			next:	try//插入站点经过的线路
					{
						CString strSQL; 
						strSQL.Format("INSERT INTO %s(线路) VALUES (\'%s\')", t, m_edit); 
						
						TRACE("%d", m_nIndex);
						_variant_t RecordsAffected;						
						m_pConnection->Execute((_bstr_t)strSQL,
													&RecordsAffected,
													adCmdText);
					}
					catch(_com_error e)
					{
						AfxMessageBox(e.Description()); 
						return;
					}
					if(spot == true)//如果站点不存在则修改站点总表
					{
						CString strSQL; 
						strSQL.Format("INSERT INTO 站点总表(站点, 通过线路数, 坐标X, 坐标Y) VALUES (\'%s\', 1, 0, 0)", t); 
						
						TRACE("%d", m_nIndex);
						_variant_t RecordsAffected;						
						m_pConnection->Execute((_bstr_t)strSQL,
													&RecordsAffected,
													adCmdText);
					}
					else//如果站点存在,则修改站点总表中信息
					{
						_variant_t RecordsAffected;
						CString strSQL; 
						strSQL.Format("UPDATE 站点总表 SET 通过线路数 = 通过线路数+1 WHERE 站点 = \'%s\'", t); 
								

						m_pConnection->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText); 
					}
				} 
			}
			catch(_com_error e)
			{	
				AfxMessageBox(e.Description()); 
				return;
			}
			//////////////////////////////////////////////////////
			//修改总表站点和线路个数
			try
			{
				_variant_t RecordsAffected;
				CString strSQL; 
				strSQL.Format("UPDATE 总数 SET 线路数 = 线路数+1, 站点数 = 站点数 + %d", newstation); 
						

				m_pConnection->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText); 

			}
			catch(_com_error e)
			{	
				AfxMessageBox(e.Description()); 
				return;
			}
		}
	if(addline == true)
		AfxMessageBox("添加成功");	
	}
	if(addline == false)//如果是修改函数,就把数据填充上去
	{
		line = "";
	}
}


void CModifyDlg::OnDeleteline() 
{
	// TODO: Add your control notification handler code here
	_variant_t var;
	CString v;
	
	CInputLineDlg Dlg;
	if(Dlg.DoModal() == IDOK)
	{

⌨️ 快捷键说明

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