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

📄 entity.cpp

📁 1.通过鼠标拖拽和弹出对话框完成实体、属性、联系的绘制以及各参数设定 2.对绘制的实体、属性、联系提供合法性检查 3.对绘制的图形进行拖动、重设大小、删除 4.通过属性对话框对实体、属性、联系的
💻 CPP
字号:
#include "stdafx.h"
#include "Entity.h"
#include "Relation.h"
Redata::Redata()
{
	data=NULL;
	next=NULL;
}
MyEntity::MyEntity(CString name,int x1,int y1,int x2,int y2,int f)
{
	this->selecting=0;
	this->name=name;
	this->e1=*(new CPoint(x1,y1));
	this->e2=*(new CPoint(x2,y2));
	this->type=1;
	this->flag=f;
	this->firstAttribute=NULL;
	this->firstRelation=new Redata();
	this->nextelement=NULL;
}
void MyEntity::addAttribute(Attribute *a)
{
	Attribute* first=this->firstAttribute;
	if(first==NULL)
	{
		firstAttribute=a;
		return;
	}
	while(first->next!=NULL)
	{
		first=first->next;
	}
	first->next=a;
}
void MyEntity::removeAttribute(Attribute *a)
{
	Attribute* first=this->firstAttribute;
	if(first==a)
	{
		firstAttribute=first->next;
		return;
	}
	while(first->next!=NULL)
	{
		if(first->next==a)
		{
			first->next=a->next;
			return;
		}
		first=first->next;
	}
}
void MyEntity::addRelation(Relation *a)
{
	Redata* first=this->firstRelation;
	if(first->data==NULL)
	{
		firstRelation->data=a;
		return;
	}
	while(first->next!=NULL)
	{
           first=first->next;
	}
	Redata* temp=new Redata();
	temp->data=a;
	first->next=temp;
}
void MyEntity::removeRelation(Relation *a)
{
	Redata* first=this->firstRelation;
	if(first->data==a)
	{
		firstRelation=first->next;
		delete first;
		return;
	}
	while(first->next!=NULL)
	{
		if(first->next->data==a)
		{
			Redata* temp=first->next;
			first->next=first->next->next;
			delete temp;
			return;
		}
		first=first->next;
	}
}
int MyEntity::isDeleted()
{
	if(this->firstAttribute==NULL&&this->firstRelation->data==NULL)
	{
		return 1;
	}
	else if(this->firstAttribute!=NULL)
	{
		return 0;
	}
	else
	{
		return 2;
	}
}
void MyEntity::paint(CDC& g)
{
	CPen pen(PS_SOLID,2,RGB(255,0,0));
	if(this->selecting==1)
	{
	    g.SelectObject(pen);
	}
	g.Rectangle(e1.x,e1.y,e2.x,e2.y);
	if(this->flag==2)
	{
		g.Rectangle(e1.x+5,e1.y+5,e2.x-5,e2.y-5);
	}
	g.TextOut(e1.x+7,(e1.y+e2.y)/2-10,name);
	CPen pen2(PS_SOLID,1,RGB(0,0,0));
	g.SelectObject(pen2);
	g.Rectangle(0,0,0,0);
	pen.DeleteObject();
	pen2.DeleteObject();
}
void MyEntity::serial(CArchive& ar)
{

}
Attribute* MyEntity::mainkey()
{
	Attribute* main=NULL;
	Attribute* temp=NULL;
	Attribute* first=this->firstAttribute;
	while(first!=NULL)
	{
		if(first->mainkey==1&&first->flag==1)
		{
			if(main==NULL)
			{
				main=first;
			}
			else
			{
				temp=main;
				while(temp->nextmain!=NULL)
				{
					temp=temp->nextmain;
				}
				temp->nextmain=first;
			}
		}
		first=first->next;
	}
	return main;
}
void MyEntity::emptymain()
{
	Attribute* first=this->firstAttribute;
	while(first!=NULL)
	{
		first->nextmain=NULL;
		first=first->next;
	}
}

⌨️ 快捷键说明

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