📄 minewinddlg.cpp
字号:
// MineWindDlg.cpp : implementation file
//
#include "stdafx.h"
#include "mineDabse.h"
#include "MineWindDlg.h"
#include "Stack.h"
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CMineDabseApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CMineWindDlg dialog
CMineWindDlg::CMineWindDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMineWindDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMineWindDlg)
m_intVexNum = 0;
m_intArcNum = 0;
m_strVexName = _T("");
//}}AFX_DATA_INIT
}
void CMineWindDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMineWindDlg)
DDX_Control(pDX, IDC_EDITVEXVALUEs, m_vexValues);
DDX_Text(pDX, IDC_EDITVEXVALUEs, m_strVexName);
DDX_Control(pDX, IDC_BUTTONMODIFY, m_modify);
DDX_Control(pDX, IDC_BUTTONDEL, m_delete);
DDX_Control(pDX, IDC_LIST1, m_list);
DDX_Control(pDX, IDC_VEXNUM, m_vexNum);
DDX_Text(pDX, IDC_VEXNUM, m_intVexNum);
DDX_Text(pDX, IDC_ARCNUM, m_intArcNum);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMineWindDlg, CDialog)
//{{AFX_MSG_MAP(CMineWindDlg)
ON_WM_SHOWWINDOW()
ON_BN_CLICKED(IDINSERT, OnInsert)
ON_BN_CLICKED(IDC_BUTTONDEL, OnButtondel)
ON_BN_CLICKED(IDC_BUTTONMODIFY, OnButtonmodify)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMineWindDlg message handlers
void CMineWindDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData(true);
CString str,strSql;
try{
CString strSql="delete * from vexAcrNum";
theApp.m_pConnection->Execute(strSql.AllocSysString(),NULL,adOptionUnspecified);
if(0==m_intArcNum||0==m_intVexNum)
AfxMessageBox("顶点和弧的个数不能为空");//判断顶点表的个数和输入的是否相同
str="insert into vexAcrNum(vexNum,arcNum) values (%d,%d)";
strSql.Format(str,m_intVexNum,m_intArcNum);
theApp.m_pConnection->Execute(strSql.AllocSysString(),NULL,adOptionUnspecified);
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
UpdateData(true);
//countLine=m_inputVexValue.GetLineCount(); //顶点的值,IDC_INPUTVEX中的行数
// Dump every line of text of the edit control.
CDialog::OnOK();
}
void CMineWindDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
// TODO: Add your message handler code here
m_vexNum.SetFocus();
}
BOOL CMineWindDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
// m_list.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EDITLABELS);
//从数据库中装载数据
try{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open("SELECT * FROM vexAcrNum",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if(!m_pRecordset->adoEOF)
{
_variant_t vVexnum = m_pRecordset->GetCollect("vexNum");
_variant_t vArcnum = m_pRecordset->GetCollect("ArcNum");
m_intArcNum=vArcnum.iVal;
m_intVexNum=vVexnum.iVal;
//CString str=(BSTR)vVexnum.pbstrVal;
}
else{//弧顶点表为空,顶点名表清空
// m_pRecordset->Open("SELECT * FROM vexArcNum",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
CString strSql="delete * from vexTable";
theApp.m_pConnection->Execute(strSql.AllocSysString(),NULL,adOptionUnspecified);
// CString str="delete * from vexAcrNum";
//theApp.m_pConnection->Execute(strSql.AllocSysString(),NULL,adOptionUnspecified);
}
m_pRecordset->Close();
}
catch(_com_error e){
AfxMessageBox(e.ErrorMessage());
}
m_list.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
m_list.InsertColumn(0,"顶点序号",LVCFMT_LEFT,120);
m_list.InsertColumn(1,"顶点的值",LVCFMT_LEFT,120);
try{
// m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open("SELECT * FROM vexTable",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
_variant_t vVexName,vOrderNum;
while(!m_pRecordset->adoEOF)
{
vOrderNum=m_pRecordset->GetCollect("id");
int nItem=m_list.InsertItem(0xffff,(_bstr_t)vOrderNum);
vVexName = m_pRecordset->GetCollect("vexName");
m_list.SetItem(nItem,1,1,(_bstr_t)vVexName,NULL,0,0,0);
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
m_list.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
}
catch(_com_error e){
AfxMessageBox(e.ErrorMessage());
}
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CMineWindDlg::OnInsert()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if (m_strVexName.IsEmpty()){
AfxMessageBox("顶点值不能为空");
return;
}
int i=0;
try{
// m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open("SELECT * FROM vexTable",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
_variant_t vOrderNum;
while(!m_pRecordset->adoEOF)
{
vOrderNum = m_pRecordset->GetCollect("id");
int temp_int=vOrderNum.iVal;
if (i==temp_int)
i++;
else break;
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
m_list.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
}
catch(_com_error e){
AfxMessageBox(e.ErrorMessage());
}
CString str,strSql;
str="insert into vexTable(id,vexName) values ('%d','%s')";
strSql.Format(str,i,m_strVexName);
theApp.m_pConnection->Execute(strSql.AllocSysString(),NULL,adOptionUnspecified);
_variant_t vVexName = m_strVexName,vOrderNum;
vOrderNum=(long)(m_list.GetItemCount()+1);
int nItem=m_list.InsertItem(0xffff,(_bstr_t)vOrderNum);
// int nItem=m_list.InsertItem(0xffff,(_bstr_t)vVexName);
m_list.SetItem(nItem,1,1,(_bstr_t)vVexName,NULL,0,0,0);
m_strVexName="";
m_vexValues.SetFocus();
UpdateData(false);
}
void CMineWindDlg::OnButtondel()
{
// TODO: Add your control notification handler code here
CString str,strSql;
str="delete * from vexTable where vexName='%s'";
strSql.Format(str,m_strVexName);
theApp.m_pConnection->Execute(strSql.AllocSysString(),NULL,adOptionUnspecified);
m_list.DeleteItem(current_sel);
m_strVexName="";
UpdateData(false);
m_delete.EnableWindow(false);
}
void CMineWindDlg::OnButtonmodify()
{
// TODO: Add your control notification handler code here
CString str,strSql;
UpdateData(true);
str="update vexTable set vexName='%s' where id=%d";
strSql.Format(str,m_strVexName,id);
theApp.m_pConnection->Execute(strSql.AllocSysString(),NULL,adOptionUnspecified);
_variant_t vVexName = m_strVexName;
m_list.SetItem(current_sel,1,1,(_bstr_t)vVexName,NULL,0,0,0);
m_modify.EnableWindow(false);
UpdateData(false);
}
void CMineWindDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CListCtrl* pListCtrl = (CListCtrl*) GetDlgItem(IDC_LIST1);
ASSERT(pListCtrl != NULL);
POSITION pos = pListCtrl->GetFirstSelectedItemPosition();
if (pos == NULL)
TRACE0("No items were selected!\n");
else
{
// while (pos)
//{
current_sel = pListCtrl->GetNextSelectedItem(pos);
m_strVexName=m_list.GetItemText(current_sel,1);
id=atoi(m_list.GetItemText(current_sel,0));
UpdateData(false);
// TRACE1("Item %d was selected!\n", nItem);
// you could do your own processing on nItem here
//}
}
/* NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
int current_sel= pNMListView->iItem;
if(m_list.GetItemState(current_sel,LVIS_SELECTED)==LVIS_SELECTED)
{
m_strVexTail=m_list.GetItemText(current_sel,1);
m_strVexHead=m_list.GetItemText(current_sel,2);
UpdateData(false);
}*/
m_modify.EnableWindow(true);
m_delete.EnableWindow(true);
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -