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

📄 databasedoc.cpp

📁 1.通过鼠标拖拽和弹出对话框完成实体、属性、联系的绘制以及各参数设定 2.对绘制的实体、属性、联系提供合法性检查 3.对绘制的图形进行拖动、重设大小、删除 4.通过属性对话框对实体、属性、联系的
💻 CPP
字号:
// databaseDoc.cpp : implementation of the CDatabaseDoc class
//

#include "stdafx.h"
#include "database.h"
#include "databaseDoc.h"
#include "Attribute.h"
#include "Element.h"
#include "Entity.h"
#include "Relation.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDatabaseDoc

IMPLEMENT_DYNCREATE(CDatabaseDoc, CDocument)

BEGIN_MESSAGE_MAP(CDatabaseDoc, CDocument)
	//{{AFX_MSG_MAP(CDatabaseDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDatabaseDoc construction/destruction

CDatabaseDoc::CDatabaseDoc()
{
	// TODO: add one-time construction code here
	this->diagram=new Diagram();

}

CDatabaseDoc::~CDatabaseDoc()
{
}

BOOL CDatabaseDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;
		diagram->selected=NULL;
		diagram->Delete();

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CDatabaseDoc serialization
void CDatabaseDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
		ar<<diagram->count;
		Element* first=diagram->firstElement;
		while(first!=NULL)
		{
			ar<<first->type;
			if(first->type==1)
			{
				MyEntity* my1=(MyEntity* )first;
				ar<<my1->name;
				ar<<my1->flag;
				ar<<my1->e1.x;
				ar<<my1->e1.y;
				ar<<my1->e2.x;
				ar<<my1->e2.y;
			}
			if(first->type==2)
			{
				Relation* my2=(Relation* )first;
				ar<<my2->name;
				ar<<my2->flag;
				ar<<my2->entity1->name;
				ar<<my2->entity2->name;
				ar<<my2->e1.x;
				ar<<my2->e1.y;
				ar<<my2->e2.x;
				ar<<my2->e2.y;
			}
			if(first->type==3)
			{
				Attribute* my3=(Attribute* )first;
				ar<<my3->name;
				ar<<my3->nametype;
				ar<<my3->father->name;
				ar<<my3->flag;
				ar<<my3->mainkey;
				ar<<my3->e1.x;
				ar<<my3->e1.y;
				ar<<my3->e2.x;
				ar<<my3->e2.y;
				ar<<my3->canempty;
				ar<<my3->datelength;
			}
			first=first->nextelement;
		}
	}
	else
	{
		// TODO: add loading code here
		diagram->selected=NULL;
		diagram->Delete();
		int count;
		int type;
		int flag;
		int x1;
		int y1;
		int x2;
		int y2;
		int mainkey;
		int canempty;
		int datalength;
		CString name;
		CString nametype;
		CString father1name;
		CString father2name;
		ar>>count;
		for(int i=0;i<count;i++)
		{
           ar>>type;
		   if(type==1)
		   {
			   ar>>name;
			   ar>>flag;
			   ar>>x1;
			   ar>>y1;
			   ar>>x2;
			   ar>>y2;
			   MyEntity* mye=new MyEntity(name,x1,y1,x2,y2,flag);
			   diagram->addElement(mye);
		   }
		   if(type==2)
		   {
			   ar>>name;
			   ar>>flag;
			   ar>>father1name;
			   ar>>father2name;
			   ar>>x1;
			   ar>>y1;
			   ar>>x2;
			   ar>>y2;
			   Element* e1=diagram->father(father1name,2);
			   Element* e2=diagram->father(father2name,2);
			   MyEntity* m1=(MyEntity* )e1;
			   MyEntity* m2=(MyEntity* )e2;
			   Relation* myr=new Relation(name,flag,m1,m2,x1,y1,x2,y2);
			   diagram->addElement(myr);
			   m1->addRelation(myr);
			   m2->addRelation(myr);
		   }
		   if(type==3)
		   {
			   	ar>>name;
				ar>>nametype;
				ar>>father1name;
				ar>>flag;
				ar>>mainkey;
				ar>>x1;
				ar>>y1;
				ar>>x2;
				ar>>y2;
				ar>>canempty;
				ar>>datalength;
				Element* e=diagram->father(father1name,1);
				Attribute* mya=new Attribute(name,nametype,e,flag,mainkey,x1,y1,x2,y2,canempty,datalength);
				diagram->addElement(mya);
				e->addAttribute(mya);
		   }
		}
	}
}

/////////////////////////////////////////////////////////////////////////////
// CDatabaseDoc diagnostics

#ifdef _DEBUG
void CDatabaseDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CDatabaseDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDatabaseDoc commands

⌨️ 快捷键说明

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