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

📄 dataview.cpp

📁 用于数据结构课程设计,双向链表,并且用了MFC做图形界面
💻 CPP
字号:
// DataView.cpp : implementation of the CDataView class
//

#include "stdafx.h"
#include "danlianbiao.h"

#include "DataDoc.h"
#include "DataView.h"

#include <afx.h>
#include <afxcoll.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDataView

IMPLEMENT_DYNCREATE(CDataView, CFormView)

BEGIN_MESSAGE_MAP(CDataView, CFormView)
	//{{AFX_MSG_MAP(CDataView)
	ON_BN_CLICKED(IDC_OK, OnOk)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	ON_BN_CLICKED(IDC_INSERT, OnInsert)
	ON_BN_CLICKED(IDC_SEARCH, OnSearch)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDataView construction/destruction

CDataView::CDataView()
	: CFormView(CDataView::IDD)
{
	//{{AFX_DATA_INIT(CDataView)
	m_Show = _T("");
	m_Data1 = _T("");
	m_Data2 = _T("");
	m_Data3 = _T("");
	m_Data4 = _T("");
	m_Data5 = _T("");
	m_Data6 = _T("");
	m_Data7 = _T("");
	m_Data8 = _T("");
	m_Data9 = _T("");
	m_Insertnum = _T("");
	m_InsertString = _T("");
	m_Deletenum = _T("");
	m_SearchString = _T("");
	m_SearchShow = _T("");
	//}}AFX_DATA_INIT

}

CDataView::~CDataView()
{
}

void CDataView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDataView)
	DDX_Text(pDX, IDC_SHOW, m_Show);
	DDV_MaxChars(pDX, m_Show, 100);
	DDX_Text(pDX, IDC_DATA1, m_Data1);
	DDX_Text(pDX, IDC_DATA2, m_Data2);
	DDX_Text(pDX, IDC_DATA3, m_Data3);
	DDX_Text(pDX, IDC_DATA4, m_Data4);
	DDX_Text(pDX, IDC_DATA5, m_Data5);
	DDX_Text(pDX, IDC_DATA6, m_Data6);
	DDX_Text(pDX, IDC_DATA7, m_Data7);
	DDX_Text(pDX, IDC_DATA8, m_Data8);
	DDX_Text(pDX, IDC_DATA9, m_Data9);
	DDX_Text(pDX, IDC_INSERTNUM, m_Insertnum);
	DDV_MaxChars(pDX, m_Insertnum, 1);
	DDX_Text(pDX, IDC_INSERTSTRING, m_InsertString);
	DDV_MaxChars(pDX, m_InsertString, 8);
	DDX_Text(pDX, IDC_DELETENUM, m_Deletenum);
	DDV_MaxChars(pDX, m_Deletenum, 1);
	DDX_Text(pDX, IDC_SEARCHSTRING, m_SearchString);
	DDX_Text(pDX, IDC_SEARCHSHOW, m_SearchShow);
	//}}AFX_DATA_MAP
}

BOOL CDataView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CDataView::OnInitialUpdate()
{   



}

/////////////////////////////////////////////////////////////////////////////
// CDataView diagnostics

#ifdef _DEBUG
void CDataView::AssertValid() const
{
	CFormView::AssertValid();
}

void CDataView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CDataDoc* CDataView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDataDoc)));
	
	return (CDataDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDataView message handlers

void CDataView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{ 
	
	
}


void CDataView::OnOk() 
{  
	UpdateData(true);

    CNode *pNode;
	CObList CNodeList;
	
	
	for(int i=0;i<10;i++){
		pNode=new CNode;
		CNodeList.AddTail (pNode);}
	POSITION pos=CNodeList.GetHeadPosition();
	pNode=(CNode*)CNodeList.GetHeadPosition();
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=m_Data1;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=m_Data2;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=m_Data3;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=m_Data4;
    pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=m_Data5;
    pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=m_Data6;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=m_Data7; 
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=m_Data8; 
    pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=m_Data9;

	pNode=(CNode*)CNodeList.GetHeadPosition();
    POSITION poss=CNodeList.GetHeadPosition ();

	CString str,str1,str2,str3,str4,str5,str6,str7,str8,str9;	
	 pNode=(CNode*)CNodeList.GetNext(poss);
     str1=pNode->data;
	 
	 pNode=(CNode*)CNodeList.GetNext(poss);
	 str2=pNode->data;
	 pNode=(CNode*)CNodeList.GetNext(poss);
	 str3=pNode->data;
	 pNode=(CNode*)CNodeList.GetNext(poss);
	 str4=pNode->data;
	 pNode=(CNode*)CNodeList.GetNext(poss);
	 str5=pNode->data;
	 pNode=(CNode*)CNodeList.GetNext(poss);
	 str6=pNode->data;
	 pNode=(CNode*)CNodeList.GetNext(poss);
	 str7=pNode->data;
	 pNode=(CNode*)CNodeList.GetNext(poss);
	 str8=pNode->data;
	 pNode=(CNode*)CNodeList.GetNext(poss);
	 str9=pNode->data;
	 
	 GetDlgItemText(IDC_DATA1,str1);
	 GetDlgItemText(IDC_DATA2,str2);
     GetDlgItemText(IDC_DATA3,str3);
     GetDlgItemText(IDC_DATA4,str4);
     GetDlgItemText(IDC_DATA5,str5);
     GetDlgItemText(IDC_DATA6,str6);
     GetDlgItemText(IDC_DATA7,str7);
     GetDlgItemText(IDC_DATA8,str8);
     GetDlgItemText(IDC_DATA9,str9);
	 str=str1+" "+str2+" "+str3+" "+str4+" "+str5+" "+str6+" "+str7+" "+str8+" "+str9;
	
    SetDlgItemText(IDC_SHOW,str);


	

	
}
void CDataView::OnDelete()
{
     UpdateData(true);
	 CString str,str1,str2,str3,str4,str5,str6,str7,str8,str9;
	 str=m_Show;
	
	GetDlgItemText(IDC_SHOW,str);
 
        int	nPoss=str.Find(' ');
	    str1=str.Left(nPoss);
	    str=str.Right(str.GetLength()-nPoss-1);
		
		nPoss=str.Find(' ');
		str2=str.Left(nPoss);
		str=str.Right(str.GetLength()-nPoss-1);
		
		nPoss=str.Find(' ');
		str3=str.Left(nPoss);
		str=str.Right(str.GetLength()-nPoss-1);

		nPoss=str.Find(' ');
		str4=str.Left(nPoss);
		str=str.Right(str.GetLength()-nPoss-1);
		

		nPoss=str.Find(' ');
		str5=str.Left(nPoss);
		str=str.Right(str.GetLength()-nPoss-1);
		
        nPoss=str.Find(' ');
		str6=str.Left(nPoss);
		str=str.Right(str.GetLength()-nPoss-1);
		
	    nPoss=str.Find(' ');
		str7=str.Left(nPoss);
		str=str.Right(str.GetLength()-nPoss-1);
	
		nPoss=str.Find(' ');
		str8=str.Left(nPoss);
		str=str.Right(str.GetLength()-nPoss-1);
       
		
		str9=str;
	
	
	     CNode *pNode;
	CObList CNodeList;
	
	
	for(int i=0;i<10;i++){
		pNode=new CNode;
		CNodeList.AddTail (pNode);}
	POSITION pos=CNodeList.GetHeadPosition();
	pNode=(CNode*)CNodeList.GetHeadPosition();
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str1;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str2;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str3;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str4;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str5;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str6;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str7;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str8;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str9;

	

int a=GetDlgItemText(IDC_DELETENUM,m_Deletenum);

	


if(a<=2&&m_Deletenum!="0")
{

if(m_Deletenum=="1")
a=1;
if(m_Deletenum=="2")
a=2;
if(m_Deletenum=="3")
a=3;
if(m_Deletenum=="4")
a=4;
if(m_Deletenum=="5")
a=5;	 
if(m_Deletenum=="6")
a=6;
if(m_Deletenum=="7")
a=7;
if(m_Deletenum=="8")
a=8;
if(m_Deletenum=="9")
a=9;







pos=CNodeList.GetHeadPosition ();
  
	for(int j=1;j<a;j++)
	{
		pNode=(CNode*)CNodeList.GetNext(pos);
	}
    if(!CNodeList.IsEmpty()){
			 
			  CNode *ps;
				   ps=(CNode*)CNodeList.GetAt(pos);
				   CNodeList.RemoveAt(pos);
			  
			   delete ps;}

	CString st,st1,st2,st3,st4,st5,st6,st7,st8,st9;

pos=CNodeList.GetHeadPosition();
	pNode=(CNode*)CNodeList.GetNext(pos);
st1=pNode->data;
pNode=(CNode*)CNodeList.GetNext(pos);
st2=pNode->data;
pNode=(CNode*)CNodeList.GetNext(pos);
 st3=pNode->data;
	 pNode=(CNode*)CNodeList.GetNext(pos);
	 st4=pNode->data;
	 pNode=(CNode*)CNodeList.GetNext(pos);
	 st5=pNode->data;
	 pNode=(CNode*)CNodeList.GetNext(pos);
	 st6=pNode->data;
	 pNode=(CNode*)CNodeList.GetNext(pos);
	 st7=pNode->data;
	 pNode=(CNode*)CNodeList.GetNext(pos);
	 st8=pNode->data;
	 pNode=(CNode*)CNodeList.GetNext(pos);
	 st9=pNode->data;
	 

	 
st=st1+" "+st2+" "+st3+" "+st4+" "+st5+" "+st6+" "+st7+" "+st8+" "+st9;

SetDlgItemText(IDC_SHOW,st);
}
else
{CString text;
	text.Format("您输入的位置不合理!按OK键恢复您之前输入的数据");
	SetDlgItemText(IDC_SHOW,text);
}


	





}

void CDataView::OnInsert() 
{
	UpdateData(true);
	 CString str,str1,str2,str3,str4,str5,str6,str7,str8,str9;
	 str.Format("%d",m_Show);
	
	
	GetDlgItemText(IDC_SHOW,str);
 
    int	nPoss=str.Find(' ');
	  

	
	    str1=str.Left(nPoss);
	    str=str.Right(str.GetLength()-nPoss-1);
		
		nPoss=str.Find(' ');
		str2=str.Left(nPoss);
		str=str.Right(str.GetLength()-nPoss-1);
		
		nPoss=str.Find(' ');
		str3=str.Left(nPoss);
		str=str.Right(str.GetLength()-nPoss-1);

		nPoss=str.Find(' ');
		str4=str.Left(nPoss);
		str=str.Right(str.GetLength()-nPoss-1);
		

		nPoss=str.Find(' ');
		str5=str.Left(nPoss);
		str=str.Right(str.GetLength()-nPoss-1);
		
        nPoss=str.Find(' ');
		str6=str.Left(nPoss);
		str=str.Right(str.GetLength()-nPoss-1);
		
	    nPoss=str.Find(' ');
		str7=str.Left(nPoss);
		str=str.Right(str.GetLength()-nPoss-1);
	
		nPoss=str.Find(' ');
		str8=str.Left(nPoss);
		str=str.Right(str.GetLength()-nPoss-1);

        str9=str;

       
	
	     CNode *pNode;
	CObList CNodeList;
	
	
	for(int i=0;i<10;i++){
		pNode=new CNode;
		CNodeList.AddTail (pNode);}
	POSITION pos=CNodeList.GetHeadPosition();
	pNode=(CNode*)CNodeList.GetHeadPosition();
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str1;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str2;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str3;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str4;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str5;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str6;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str7;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str8;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str9;
    
	

    GetDlgItemText(IDC_INSERTSTRING,m_InsertString);
int a=GetDlgItemText(IDC_INSERTNUM,m_Insertnum);

if(a<2&&m_Insertnum!="0")
{

if(m_Insertnum=="1")
a=1;
if(m_Insertnum=="2")
a=2;
if(m_Insertnum=="3")
a=3;
if(m_Insertnum=="4")
a=4;
if(m_Insertnum=="5")
a=5;	 
if(m_Insertnum=="6")
a=6;
if(m_Insertnum=="7")
a=7;
if(m_Insertnum=="8")
a=8;
if(m_Insertnum=="9")
a=9;



pos=CNodeList.GetHeadPosition ();
  
	for(int j=1;j<a;j++)
	{
		pNode=(CNode*)CNodeList.GetNext(pos);
	}
  	 
	 
	 pNode=(CNode*)CNodeList.GetAt(pos);
			 CNode *pNode=new CNode;
			 pNode->data=m_InsertString;
			 pos=CNodeList.InsertBefore(pos,pNode);
	 
	 
	CString st,st1,st2,st3,st4,st5,st6,st7,st8,st9,st10;

pos=CNodeList.GetHeadPosition();
	pNode=(CNode*)CNodeList.GetNext(pos);
st1=pNode->data;
pNode=(CNode*)CNodeList.GetNext(pos);
st2=pNode->data;
pNode=(CNode*)CNodeList.GetNext(pos);
 st3=pNode->data;
	 pNode=(CNode*)CNodeList.GetNext(pos);
	 st4=pNode->data;
	 pNode=(CNode*)CNodeList.GetNext(pos);
	 st5=pNode->data;
	 pNode=(CNode*)CNodeList.GetNext(pos);
	 st6=pNode->data;
	 pNode=(CNode*)CNodeList.GetNext(pos);
	 st7=pNode->data;
	 pNode=(CNode*)CNodeList.GetNext(pos);
	 st8=pNode->data;
	 pNode=(CNode*)CNodeList.GetNext(pos);
	 st9=pNode->data;
     pNode=(CNode*)CNodeList.GetNext(pos);
	 st10=pNode->data;
     

	 
st=st1+" "+st2+" "+st3+" "+st4+" "+st5+" "+st6+" "+st7+" "+st8+" "+st9
      +" "+st10;

SetDlgItemText(IDC_SHOW,st);
	 }



else
{CString text;
	text.Format("您输入的位置不合理!按OK键恢复您之前输入的数据");
	SetDlgItemText(IDC_SHOW,text);
}


	
}

void CDataView::OnSearch() 
{
	UpdateData(true);
	 CString str,str1,str2,str3,str4,str5,str6,str7,str8,str9,str10;
	 str=m_Show;
	 int count=0;
	
	GetDlgItemText(IDC_SHOW,str);
 
    int	nPoss=str.Find(' ');
	  

	
	    str1=str.Left(nPoss);count++;
	    str=str.Right(str.GetLength()-nPoss-1);
		
		nPoss=str.Find(' ');
		str2=str.Left(nPoss);count++;
		str=str.Right(str.GetLength()-nPoss-1);
		
		nPoss=str.Find(' ');
		str3=str.Left(nPoss);count++;
		str=str.Right(str.GetLength()-nPoss-1);

		nPoss=str.Find(' ');
		str4=str.Left(nPoss);count++;
		str=str.Right(str.GetLength()-nPoss-1);
		

		nPoss=str.Find(' ');
		str5=str.Left(nPoss);count++;
		str=str.Right(str.GetLength()-nPoss-1);
		
        nPoss=str.Find(' ');
		str6=str.Left(nPoss);count++;
		str=str.Right(str.GetLength()-nPoss-1);
		
	    nPoss=str.Find(' ');
		str7=str.Left(nPoss);count++;
		str=str.Right(str.GetLength()-nPoss-1);
	
		nPoss=str.Find(' ');
		str8=str.Left(nPoss);count++;
		str=str.Right(str.GetLength()-nPoss-1);
       
	

		str9=str;count++;

	CNode *pNode;
	CObList CNodeList;
	
	
	for(int i=0;i<11;i++){
		pNode=new CNode;
		CNodeList.AddTail (pNode);}
	POSITION pos=CNodeList.GetHeadPosition();
	pNode=(CNode*)CNodeList.GetHeadPosition();
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str1;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str2;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str3;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str4;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str5;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str6;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str7;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str8;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pNode->data=str9;
	pNode=(CNode*)CNodeList.GetNext(pos);
	pos=CNodeList.GetTailPosition();

GetDlgItemText(IDC_SEARCHSTRING,m_SearchString);
pos=CNodeList.GetHeadPosition();
pNode=(CNode*)CNodeList.GetNext(pos);
int num=1;
while(pos!=(CNodeList.GetTailPosition())&&pNode->data!=(m_SearchString))
{pNode=(CNode*)CNodeList.GetNext(pos);
num++;}
if(pos==CNodeList.GetTailPosition()&&((pNode->data)!=(m_SearchString)))
{CString t;
 t.Format("Not Found!");
 SetDlgItemText(IDC_SEARCHSHOW,t);
}


else if(pNode->data==m_SearchString)
{
CString tt;
tt.Format("%d",num);	
SetDlgItemText(IDC_SEARCHSHOW,tt);
}
}

⌨️ 快捷键说明

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