📄 databaseview.cpp
字号:
}
this->Invalidate(true);
}
if(flag==5)
{
CString s1;
CString s2;
CString s3;
CDialog3 a=new CDialog3();
a.father=pDoc->diagram->firstElement;
a.DoModal();
s3=a.m_relationname;
s1=a.m_entity1name;
s2=a.m_entity2name;
if(
s1==""||s2==""||s3==""||
(s3.GetAt(0)>='1'&&
s3.GetAt(0)<='9')||
s3.Find(" ")>=1||
pDoc->diagram->have(s3)==1||
pDoc->diagram->father(s1,2)==NULL||
pDoc->diagram->father(s2,2)==NULL||
a.m_relationtype==0||s2==s3)
{
MessageBox(s1+s2+"error input in the formal dialog",NULL,MB_ICONSTOP);
}
else
{
Element* e1=pDoc->diagram->father(s1,2);
MyEntity* m1=(MyEntity*)e1;
Element* e2=pDoc->diagram->father(s2,2);
MyEntity* m2=(MyEntity*)e2;
if(m1->flag==2||m2->flag==2)
{
MessageBox(s1+s2+"error input in the formal dialog",NULL,MB_ICONSTOP);
}
else
{
Relation* r=new Relation(s3,a.m_relationtype,m1,m2,p1->x,p1->y,p2->x,p2->y);
if(m1==m2)
{
CDialog5 b=new CDialog5();
b.DoModal();
r->role1=b.m_role1;
r->role2=b.m_role2;
}
pDoc->diagram->addElement(r);
if(m1!=m2)
{
m1->addRelation(r);
}
m2->addRelation(r);
}
}
this->Invalidate(true);
}
if(flag==6)
{
CString s1;
CString s2;
CString s3;
CDialog3 a=new CDialog3();
a.father=pDoc->diagram->firstElement;
a.DoModal();
s3=a.m_relationname;
s1=a.m_entity1name;
s2=a.m_entity2name;
if( s1==""||s2==""||s3==""||
(s3.GetAt(0)>='1'&&
s3.GetAt(0)<='9')||
s3.Find(" ")>=1||
pDoc->diagram->have(s3)==1||
pDoc->diagram->father(s1,2)==NULL||
pDoc->diagram->father(s2,2)==NULL||
s2==s1)
{
MessageBox("aa error input in the formal dialog",NULL,MB_ICONSTOP);
}
else
{
Element* e1=pDoc->diagram->father(s1,2);
MyEntity* m1=(MyEntity*)e1;
Element* e2=pDoc->diagram->father(s2,2);
MyEntity* m2=(MyEntity*)e2;
if(m2->flag==1||m2->firstRelation->data!=NULL)
{
MessageBox(s1+s2+"error input in the formal dialog",NULL,MB_ICONSTOP);
}
else
{
Relation* r=new Relation(s3,5,m1,m2,p1->x,p1->y,p2->x,p2->y);
pDoc->diagram->addElement(r);
m1->addRelation(r);
m2->addRelation(r);
}
}
this->Invalidate(true);
}
if(flag==7||flag==8||flag==9)
{
CDialog2 a=new CDialog2();
a.father=pDoc->diagram->firstElement;
a.DoModal();
CString s1=a.m_attributename;
CString s2=a.m_attributefather;
CString s3=a.m_datalength;
CString s4=a.m_nametype;
int i1=a.mainkey;
int i2=a.canempty;
if(
s1==""||s2==""||s4==""||
(s1.GetAt(0)>1&&s1.GetAt(0)<9)||
pDoc->diagram->have(s1)==1||
s1.Find(" ")>=1||
pDoc->diagram->father(s2,1)==NULL||
s4==""||
s3.Find(" ")>=1||((i1==0||i2==0)&&(flag==7||flag==8))
)
{
MessageBox(s1+s2+"error input in the formal dialog",NULL,MB_ICONSTOP);
}
else
{
if((s4=="char"||s4=="varchar")&&s3=="")
{
MessageBox("error input in the formal dialog",NULL,MB_ICONSTOP);
start=0;
flag=0;
this->Invalidate(true);
return;
}
for(int i=0;i<s3.GetLength();i++)
{
if(s3.GetAt(i)<'0'||s3.GetAt(i)>'9')
{
MessageBox(s1+s2+"error input in the formal dialog",NULL,MB_ICONSTOP);
start=0;
flag=0;
this->Invalidate(true);
return;
}
}
if(flag==7)
{
Attribute* attr=new Attribute(s1,s4,pDoc->diagram->father(s2,1),
1,i1,p1->x,p1->y,p2->x,p2->y,i2,atoi(s3));
pDoc->diagram->addElement(attr);
pDoc->diagram->father(s2,1)->addAttribute(attr);
}
if(flag==8)
{
Attribute* attr=new Attribute(s1,s4,pDoc->diagram->father(s2,1),
2,i1,p1->x,p1->y,p2->x,p2->y,i2,atoi(s3));
pDoc->diagram->addElement(attr);
pDoc->diagram->father(s2,1)->addAttribute(attr);
}
if(flag==9)
{
Attribute* attr=new Attribute(s1,s4,pDoc->diagram->father(s2,1),
3,i1,p1->x,p1->y,p2->x,p2->y,i2,atoi(s3));
pDoc->diagram->addElement(attr);
pDoc->diagram->father(s2,1)->addAttribute(attr);
}
}
this->Invalidate(true);
}
start=0;
flag=0;
pDoc->DeleteContents();
}
void CDatabaseView::OnResize()
{
// TODO: Add your command handler code here
flag=2;
}
void CDatabaseView::OnRelation2()
{
// TODO: Add your command handler code here
flag=6;
}
void CDatabaseView::OnRelation1()
{
// TODO: Add your command handler code here
flag=5;
}
void CDatabaseView::OnEntity2()
{
// TODO: Add your command handler code here
flag=4;
}
void CDatabaseView::OnEntity1()
{
// TODO: Add your command handler code here
flag=3;
}
void CDatabaseView::OnDelete()
{
// TODO: Add your command handler code here
CDC *g1=this->GetDC();
CDatabaseDoc* pDoc = GetDocument();
if(pDoc->diagram->selected==NULL)
{
MessageBox("select an element first",NULL,MB_ICONSTOP);
return;
}
else if(pDoc->diagram->selected->isDeleted()==0)
{
MessageBox("delete attribute first",NULL,MB_ICONSTOP);
return;
}
else if(pDoc->diagram->selected->isDeleted()==2)
{
MessageBox("delete relation first",NULL,MB_ICONSTOP);
return;
}
else
{
pDoc->diagram->removeElement(pDoc->diagram->selected);
pDoc->diagram->selected->Delete();
delete(pDoc->diagram->selected);
this->Invalidate(true);
pDoc->diagram->selected=NULL;
}
}
void CDatabaseView::OnAttribute1()
{
// TODO: Add your command handler code here
flag=7;
}
void CDatabaseView::OnAttribute2()
{
// TODO: Add your command handler code here
flag=8;
}
void CDatabaseView::OnAttribute3()
{
// TODO: Add your command handler code here
flag=9;
}
void CDatabaseView::OnChange()
{
// TODO: Add your command handler code here
CDatabaseDoc* pDoc = GetDocument();
Change *a=new Change(pDoc->diagram);
CDialog4 b=new CDialog4();
b.m_contains=a->change();
b.DoModal();
}
void CDatabaseView::OnRename()
{
// TODO: Add your command handler code here
CDatabaseDoc* pDoc = GetDocument();
if(pDoc->diagram->selected==NULL)
{
MessageBox("select element first",NULL,MB_ICONSTOP);
return;
}
CDialog1 a=new CDialog1();
a.DoModal();
CString s=a.m_entityname1;
if(s==""||(s.GetAt(0)>='1'&&s.GetAt(0)<='9')||
s.Find(" ")>=1||pDoc->diagram->have(s)==1)
{
MessageBox("error input in the formal dialog",NULL,MB_ICONSTOP);
return;
}
pDoc->diagram->selected->name=s;
this->Invalidate(true);
}
void CDatabaseView::OnPop()
{
// TODO: Add your command handler code here
CDatabaseDoc* pDoc = GetDocument();
if(pDoc->diagram->selected->type==1)
{
CDialog1 a=new CDialog1();
a.m_entityname1=pDoc->diagram->selected->name;
a.DoModal();
CString s=a.m_entityname1;
if(s==""||
(s.GetAt(0)>='1'&&
s.GetAt(0)<='9')||
s.Find(" ")>=1||
(pDoc->diagram->have(s)==1&&s!=pDoc->diagram->selected->name))
{
MessageBox("error input in the formal dialog",NULL,MB_ICONSTOP);
return;
}
pDoc->diagram->selected->name=s;
this->Invalidate();
}
else if(pDoc->diagram->selected->type==2)
{
CString s11;
CString s21;
CString s31;
MyEntity* e1;
MyEntity* e2;
int flag;
Relation *r=(Relation*)pDoc->diagram->selected;
CDialog3 a=new CDialog3();
a.father=pDoc->diagram->firstElement;
a.m_relationname=r->name;
a.m_entity1name=r->entity1->name;
a.m_entity2name=r->entity2->name;
a.m_relationtype=r->flag;
if(r->flag==5)
{
a.m_relationtype=2;
}
a.DoModal();
s31=a.m_relationname;
s11=a.m_entity1name;
s21=a.m_entity2name;
flag=a.m_relationtype;
if(pDoc->diagram->father(s11,2)!=NULL&&pDoc->diagram->father(s21,2)!=NULL)
{
e1=(MyEntity*)pDoc->diagram->father(s11,2);
e2=(MyEntity*)pDoc->diagram->father(s21,2);
}
if(
s11==""||s21==""||s31==""||
(s31.GetAt(0)>='1'&&
s31.GetAt(0)<='9')||
s31.Find(" ")>=1||
(pDoc->diagram->have(s31)==1&&s31!=pDoc->diagram->selected->name)||
pDoc->diagram->father(s11,2)==NULL||
pDoc->diagram->father(s21,2)==NULL||
a.m_relationtype==0||
(r->flag<=4&&e2->flag==2)||
(r->flag==5&&e2->flag==1)
)
{
MessageBox(s11+s21+"error input in the formal dialog",NULL,MB_ICONSTOP);
}
else
{
r->name=s31;
r->entity1=e1;
r->entity2=e2;
if(r->flag<=4)
{
r->flag=a.m_relationtype;
}
this->Invalidate();
}
}
else if(pDoc->diagram->selected->type==3)
{
Attribute* att=(Attribute*)pDoc->diagram->selected;
CDialog2 a=new CDialog2();
a.m_attributename=att->name;
a.m_attributefather=att->father->name;
a.m_nametype=att->nametype;
a.canempty=att->canempty;
a.mainkey=att->mainkey;
if(a.m_nametype.GetAt(0)=='c')
{
a.m_nametype="char";
a.m_datalength.Format("%d",att->datelength);
}
else if(a.m_nametype.GetAt(0)=='v')
{
a.m_nametype="varchar";
a.m_datalength.Format("%d",att->datelength);
}
else a.m_datalength="4";
a.father=pDoc->diagram->firstElement;
a.DoModal();
CString s1=a.m_attributename;
CString s2=a.m_attributefather;
CString s3=a.m_datalength;
CString s4=a.m_nametype;
int i1=a.mainkey;
int i2=a.canempty;
if(
s1==""||s2==""||s4==""||
(s1.GetAt(0)>1&&s1.GetAt(0)<9)||
(pDoc->diagram->have(s1)==1&&s1!=att->name)||
s1.Find(" ")>=1||
pDoc->diagram->father(s2,1)==NULL||
s4==""||
s3.Find(" ")>=1||((i1==0||i2==0))
)
{
MessageBox("error input in the formal dialog",NULL,MB_ICONSTOP);
}
else
{
if((s4=="char"||s4=="varchar")&&s3=="")
{
MessageBox("error input in the formal dialog",NULL,MB_ICONSTOP);
start=0;
flag=0;
this->Invalidate(true);
return;
}
att->name=s1;
att->nametype=s4;
att->father=pDoc->diagram->father(s2,1);
att->datelength=atoi(s3);
att->canempty=i2;
att->mainkey=i1;
}
this->Invalidate();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -