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

📄 shujukuview.cpp

📁 编译器
💻 CPP
字号:
// shujukuView.cpp : implementation of the CShujukuView class
//

#include "stdafx.h"
#include "shujuku.h"
#include "MidNode.h"
#include "Parse.h"
#include "shujukuDoc.h"
#include "shujukuView.h"
#include "SQL.h"
#include "iostream.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CShujukuView

IMPLEMENT_DYNCREATE(CShujukuView, CView)

BEGIN_MESSAGE_MAP(CShujukuView, CView)
	//{{AFX_MSG_MAP(CShujukuView)
	ON_COMMAND(ID_SQL, OnSql)
	ON_COMMAND(ID_PAR, OnPar)
	ON_COMMAND(ID_LOG, OnLog)
	ON_COMMAND(ID_YOU, OnYou)
	ON_COMMAND(ID_RES, OnRes)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShujukuView construction/destruction

CShujukuView::CShujukuView()
{
	// TODO: add construction code here

}

CShujukuView::~CShujukuView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CShujukuView drawing

void CShujukuView::OnDraw(CDC* pDC)
{
	CShujukuDoc* pDoc = GetDocument();
	int p[20]={0};
	p[0]=1;
	int t[21]={0};
	int k=1;
	int j=1;
	if(pDoc->i==0)
	{
		pDoc->query->count(1,&p[1]);
	    pDoc->query->drawTree(p,pDC,1,t);
	//	MessageBox("没有输入数据",NULL,MB_OK);
	}
    if(pDoc->i==1)
	{
	  pDoc->node->drawlog(0,pDC,1);
	}
	if(pDoc->i==2)
	{
	  pDoc->start->drawlog(0,pDC,1);
	}
    if(pDoc->i==3)
	{
	  pDoc->start->result(k,pDC,j);
	}

    ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CShujukuView printing

BOOL CShujukuView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CShujukuView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CShujukuView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CShujukuView diagnostics

#ifdef _DEBUG
void CShujukuView::AssertValid() const
{
	CView::AssertValid();
}

void CShujukuView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CShujukuView message handlers

void CShujukuView::OnSql() 
{
	// TODO: Add your command handler code here
	SQL dialog;
	dialog.DoModal();
	CShujukuDoc *pDoc =(CShujukuDoc*)GetDocument();
	pDoc->sql=new char[strlen(dialog.v)];
	strcpy(pDoc->sql,dialog.v);
	if(strcmp(pDoc->sql,"")!=0)
	{
		Parse *parse=new Parse(pDoc->sql);
	    pDoc->query=parse->parser();
		if(!pDoc->query)
			MessageBox("输入的语句有误",NULL,MB_OK);
	}
   else
	   MessageBox("没有输入数据",NULL,MB_OK);
 
}

void CShujukuView::OnPar() 
{
	// TODO: Add your command handler code here
	
   	CShujukuDoc *pDoc =(CShujukuDoc*)GetDocument();
	parTreeVisitor *partreevisit=new parTreeVisitor();
	pDoc->query->accept(partreevisit);
    pDoc->node=partreevisit->getLogTree();
	pDoc->i=0;
	Invalidate();
}

void CShujukuView::OnLog() 
{
	// TODO: Add your command handler code here
	CShujukuDoc *pDoc =(CShujukuDoc*)GetDocument();
	jieDian* node1=pDoc->node;
	pDoc->j=0;
	while(((JiDian*)node1)->left)
	{node1=((JiDian*)node1)->left;pDoc->j++;}
	((JiDian*)((JiDian*)node1)->parent)->left=((JiDian*)node1)->right;
     ((leaf1*)((JiDian*)node1)->right)->parent=((JiDian*)node1)->parent;
	pDoc->i=1;
	Invalidate();
}

void CShujukuView::OnYou() 
{
	// TODO: Add your command handler code here
	CShujukuDoc *pDoc =(CShujukuDoc*)GetDocument();
	if(pDoc->j==2)
	{
		MessageBox("不用优化",NULL,MB_OK);
		pDoc->start=pDoc->node;
	}
	else
	{
	pDoc->i=2;
	youhuaTreeVisiter* visite=new youhuaTreeVisiter();
	pDoc->node->accept(visite);
	pDoc->start=visite->getyouhuaTree();
	Invalidate();
	}
}

void CShujukuView::OnRes() 
{
	// TODO: Add your command handler code here
	CShujukuDoc *pDoc =(CShujukuDoc*)GetDocument();
	pDoc->i=3;
	Invalidate();
}

⌨️ 快捷键说明

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