📄 modifydlg.cpp
字号:
if(Dlg.m_linename == "")
{
AfxMessageBox("请输入线路名");
being = false;
return;
}
m_edit = Dlg.m_linename;
m_combo = "线路";
}
else
{
being = false;
return;
}
UpdateData(FALSE);
OnLook();//查询,显示该线路
if(being == false)
return;
if(deleteline == false)//如果是修改函数,就把数据取出来
{
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, temp;
m_pRecordset->MoveFirst();
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("线路");
if(m_edit ==(LPCSTR)_bstr_t(var))
{
m_7 = m_edit;
temp = m_pRecordset->GetCollect("起点站");
m_1 = (LPCSTR)_bstr_t(temp);
temp = m_pRecordset->GetCollect("终点站");
m_2 = (LPCSTR)_bstr_t(temp);
temp = m_pRecordset->GetCollect("发车时间");
m_3 = (LPCSTR)_bstr_t(temp);
temp = m_pRecordset->GetCollect("结束时间");
m_4 = (LPCSTR)_bstr_t(temp);
temp = m_pRecordset->GetCollect("汽车类型");
m_5 = (LPCSTR)_bstr_t(temp);
temp = m_pRecordset->GetCollect("票价");
m_6 = (LPCSTR)_bstr_t(temp);
break;
}
m_pRecordset->MoveNext();
}
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return;
}
try//取站点
{
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open(_variant_t("SELECT * FROM " + m_edit), // 查询站点表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
if(!m_pRecordset->BOF)
{
_variant_t var;
CString temp;
m_pRecordset->MoveFirst();
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("站点");
temp = (LPCSTR)_bstr_t(var);
line =line + temp + "++";
m_pRecordset->MoveNext();
}
line = line.Left(line.GetLength() - 2);
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return;
}
}
try
{
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open(_variant_t("SELECT * FROM " + m_edit), // 查询站点表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return;
}
CYesDlg dlg;
if(dlg.DoModal() == IDOK)//确定修改
{
m_list1.DeleteAllItems();//删除列中个项
m_list2.DeleteAllItems();
m_list1.DeleteColumn(0);//删除第一行
m_list1.DeleteColumn(0);
m_list2.DeleteColumn(0);
try
{
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open(_variant_t("SELECT * FROM " + m_edit), // 查询站点表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return;
}
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);
////////////////////////////////////////////////////
//删除站点表
try
{
_variant_t RecordsAffected;
CString strSQL;
strSQL.Format("SELECT COUNT(*) FROM %s where ID > 0", v);
m_pRecordset1 =m_pConnection->Execute((_bstr_t)strSQL,
&RecordsAffected,
adCmdText);
_variant_t vIndex = (long)0;
_variant_t vCount = m_pRecordset1->GetCollect(vIndex);
m_pRecordset1->Close();
if(vCount.intVal > 1)//如果该站点不止一条线路,则删除记录
{
_variant_t RecordsAffected;
strSQL.Format("DELETE FROM %s WHERE 线路 = \'%s\'",v , m_edit);
m_pConnection->Execute((_bstr_t)strSQL,
&RecordsAffected,
adCmdText);
strSQL.Format("UPDATE 站点总表 SET 通过线路数 = 通过线路数-1 WHERE 站点 = \'%s\'", v);
m_pConnection->Execute((_bstr_t)strSQL,
&RecordsAffected,
adCmdText);
}
else//如果只有一条线路,则直接删除表,同时删除该站点
{
try
{
_variant_t RecordsAffected;
strSQL.Format("DROP TABLE %s", v);
m_pConnection->Execute((_bstr_t)strSQL,
&RecordsAffected,
adCmdText);
strSQL.Format("DELETE FROM 站点总表 WHERE 站点 = \'%s\'", v);
m_pConnection->Execute((_bstr_t)strSQL,
&RecordsAffected,
adCmdText);
strSQL.Format("UPDATE 总数 SET 站点数 = 站点数 - 1");
m_pConnection->Execute((_bstr_t)strSQL,
&RecordsAffected,
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return;
}
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return;
}
m_pRecordset->Delete(adAffectCurrent);//删除线路表中当前这条站点记录
////////////////////////////////////////////////////
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
try
{
_variant_t RecordsAffected;
CString strSQL;
////删除线路总表中该线路
strSQL.Format("DELETE FROM 线路总表 WHERE 线路 = \'%s\'", m_edit);
m_pConnection->Execute((_bstr_t)strSQL,
&RecordsAffected,
adCmdText);
////删除本线路表
strSQL.Format("DROP TABLE %s", m_edit);
m_pConnection->Execute((_bstr_t)strSQL,
&RecordsAffected,
adCmdText);
strSQL.Format("UPDATE 总数 SET 线路数 = 线路数 - 1");
m_pConnection->Execute((_bstr_t)strSQL,
&RecordsAffected,
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return;
}
}
if(deleteline == true)
AfxMessageBox("删除成功");
}
void CModifyDlg::OnModifyline()
{
// TODO: Add your control notification handler code here
//删除该线路数据
deleteline = false;
OnDeleteline();
deleteline = true;
if(being == false)
return;
///////////////////////
//添加
addline = false;
OnAddline();
addline = true;
being = true;
}
void CModifyDlg::OnModifystation()
{
// TODO: Add your control notification handler code here
_variant_t var;
CString v, t;
int m_nIndex = 0, length;
CInputStationDlg Dlg;
if(Dlg.DoModal() == IDOK)
{
if(Dlg.m_name == "")
{
AfxMessageBox("请输入站点");
return;
}
m_edit = Dlg.m_name;
m_combo = "站点";
}
else
return;
UpdateData(FALSE);
OnLook();//查询,显示该线路
if(being == false)
return;
AfxMessageBox("站点修改只能修改同义站点!");
CAdd1Dlg dlg;
dlg.m_edit1 = "";
while((t = m_list2.GetItemText(m_nIndex++, 0)) != "")//把原来的同义站点取出来
{
length = t.GetLength();
t = t.Right(length - 9);
dlg.m_edit1 = dlg.m_edit1 + t + "++";
}
dlg.m_edit1 = dlg.m_edit1.Left(dlg.m_edit1.GetLength() - 2);
UpdateData(FALSE);//更新视图
if(dlg.DoModal() == IDOK)
{
m_list2.DeleteAllItems();
try//删除原有记录,重新添加
{
_variant_t RecordsAffected;
CString strSQL;
////删除线路总表中该线路
strSQL.Format("DELETE FROM 同义站点表 WHERE ID = \'%s\'", m_edit);
m_pConnection->Execute((_bstr_t)strSQL,
&RecordsAffected,
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return;
}
////////////////////////////////////////////////////
int num = 0;
CString first, name;
int length = 0, hang = 0;
while(dlg.m_edit1 != "")
{
length = dlg.m_edit1.GetLength();
if(length != 0 && dlg.m_edit1.Find("+") == -1)
{
first = dlg.m_edit1;
dlg.m_edit1 = "";
}
else
{ first = dlg.m_edit1.Left(dlg.m_edit1.Find("+"));
dlg.m_edit1 = dlg.m_edit1.Right(length-(dlg.m_edit1.Find("+")+2));
}
try//添加同义站点
{
CString strSQL;
strSQL.Format("INSERT INTO 同义站点表(ID, 站点名) VALUES (\'%s\' , \'%s\')", m_edit, first);
_variant_t RecordsAffected;
m_pConnection->Execute((_bstr_t)strSQL,
&RecordsAffected,
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return;
}
first = " " + first;
m_list2.InsertItem(hang++, first);
num++;
}
UpdateData(FALSE);//更新视图
AfxMessageBox("修改成功");
}
}
/*void CModifyDlg::OnButton2()
{
// TODO: Add your control notification handler code here
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;
CString temp;
m_pRecordset->MoveFirst();
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("站点");
temp = (LPCSTR)_bstr_t(var);
try
{
_variant_t RecordsAffected;
CString strSQL;
strSQL.Format("SELECT COUNT(*) FROM %s where ID > 0", temp);
m_pRecordset1 =m_pConnection->Execute((_bstr_t)strSQL,
&RecordsAffected,
adCmdText);
_variant_t vIndex = (long)0;
_variant_t vCount = m_pRecordset1->GetCollect(vIndex);
int num = vCount.intVal;
m_pRecordset1->Close();
strSQL.Format("UPDATE 站点总表 SET 通过线路数 = %d WHERE 站点 = \'%s\'", num, temp);
m_pConnection->Execute((_bstr_t)strSQL,
&RecordsAffected,
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return;
}
m_pRecordset->MoveNext();
}
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return;
}
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -