Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Курсовик по разработке ПО1.DOC
Скачиваний:
29
Добавлен:
01.05.2014
Размер:
1.97 Mб
Скачать

Текст разработанной программы.

// Family.h : main header file for the FAMILY application

CObList *LST=NULL;

// Person.h: interface for the CPerson class.

class CPerson : public CObject

{

private:

BOOL IsMan;

CString name;

CPerson *father;

CPerson *marriage;

CPerson *child1;

CPerson *child2;

CPerson *child3;

public:

CPerson::CPerson(CString &nm,BOOL sex)

{

father = NULL;

marriage = NULL;

child1 = NULL;

child2 = NULL;

child3 = NULL;

name=nm;

IsMan=sex;

}

virtual ~CPerson() {};

BOOL GetIsMan() {return IsMan;}

CString GetName() {return name;}

CPerson* GetFather() {return father;}

CPerson* GetMarriage() {return marriage;}

CPerson* GetChild1() {return child1;}

CPerson* GetChild2() {return child2;}

CPerson* GetChild3() {return child3;}

void SetFather(CPerson* p) {father=p;}

void SetMarriage(CPerson* p) {marriage=p;}

void SetChild1(CPerson* p) {child1=p;}

void SetChild2(CPerson* p) {child2=p;}

void SetChild3(CPerson* p) {child3=p;}

CPerson* FindRoute(CString n,CPerson *back,int *p_route)

{

CPerson *p;

if (name==n) return this;

if ((father!=NULL) && (father!=back))

{

*p_route=1; //father

p_route++;

p=father->FindRoute(n,this,p_route);

if (p!=NULL)

return p;

*p_route=0;

p_route--;

}

if ((marriage!=NULL) && (marriage!=back))

{

if (!(marriage->GetIsMan())) *p_route=5; //жена

else *p_route=4; //муж

p_route++;

p=marriage->FindRoute(n,this,p_route);

if (p!=NULL)

return p;

*p_route=0;

p_route--;

}

if ((child1!=NULL) && (child1!=back))

{

if (!(child1->GetIsMan())) *p_route=3; //дочь

else *p_route=2; //сын

p_route++;

p=child1->FindRoute(n,this,p_route);

if (p!=NULL)

return p;

*p_route=0;

p_route--;

}

if ((child2!=NULL) && (child2!=back))

{

if (!(child2->GetIsMan())) *p_route=3; //дочь

else *p_route=2; //сын

p_route++;

p=child2->FindRoute(n,this,p_route);

if (p!=NULL)

return p;

*p_route=0;

p_route--;

}

if ((child3!=NULL) && (child3!=back))

{

if (!(child3->GetIsMan())) *p_route=3; //дочь

else *p_route=2; //сын

p_route++;

p=child1->FindRoute(n,this,p_route);

if (p!=NULL)

return p;

*p_route=0;

p_route--;

}

return NULL;

}

};

// FamilyDlg.h : header file

class CFamilyDlg : public CDialog

{

// Construction

public:

BOOL m_helpON;

CFamilyDlg(CWnd* pParent = NULL); // standard constructor

CPerson* FindPerson(CString search_name);

// CPerson* GetFather() {return father;}

// Dialog Data

CStatic m_st1;

CEdit m_ctrl_edit;

CButton m_potv;

CString m_head;

CString m_fname;

int m_kol;

public:

virtual void Serialize(CArchive& ar);

virtual void WinHelp(DWORD dwData, UINT nCmd = HELP_CONTEXT);

protected:

virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

protected:

HICON m_hIcon;

CObList *FamLst;

};

// FamilyDlg.cpp : implementation file

extern CObList *LST;

class CAboutDlg : public CDialog

{public: CAboutDlg(); };

void CAboutDlg::DoDataExchange(CDataExchange* pDX)

{ CDialog::DoDataExchange(pDX); }

CFamilyDlg::CFamilyDlg(CWnd* pParent /*=NULL*/)

: CDialog(CFamilyDlg::IDD, pParent)

{

m_head = _T("");

m_fname = _T("");

m_kol = 0;

FamLst = new CObList();

m_helpON=false;

}

void CFamilyDlg::DoDataExchange(CDataExchange* pDX)

{

CDialog::DoDataExchange(pDX);

DDX_Control(pDX, IDC_ST1, m_st1);

DDX_Control(pDX, IDC_KOL, m_ctrl_edit);

DDX_Control(pDX, IDC_BUTTON1, m_potv);

DDX_Text(pDX, IDC_EDIT1, m_head);

DDX_Text(pDX, IDC_EDIT2, m_fname);

DDX_Text(pDX, IDC_KOL, m_kol);

}

// CFamilyDlg message handlers

BOOL CFamilyDlg::OnInitDialog()

{

CDialog::OnInitDialog();

return TRUE; // return TRUE unless you set the focus to a control

}

void CFamilyDlg::OnButAdd()

{

m_st1.ShowWindow(SW_HIDE);

m_ctrl_edit.ShowWindow(SW_HIDE);

if (LST!=NULL)

if(!LST->IsEmpty())

{CPersonDlg a;

a.DoModal();

}

}

void CFamilyDlg::OnButton1()

{

m_st1.ShowWindow(SW_HIDE);

m_ctrl_edit.ShowWindow(SW_HIDE);

UpdateData(true);

CPerson *p = NULL;

BOOL sex=true;

m_head.TrimLeft();

m_head.TrimRight();

if (!m_head.IsEmpty())

{ if (LST==NULL)

{ p = new CPerson(m_head,sex);

FamLst->AddTail(p);

LST = FamLst;

}

else

{ p = (CPerson*)LST->GetHead();

m_head=p->GetName();

}

}

if (LST!=NULL)

{ p=(CPerson*)LST->GetHead();

m_head=p->GetName();

}

UpdateData(false);

}

void CFamilyDlg::OnClose()

{

if (LST!=NULL)

if(!LST->IsEmpty())

{ CPerson *ptr=NULL;

POSITION tail=0, head=0;

tail=LST->GetTailPosition();

head=LST->GetHeadPosition();

while (head!=tail)

{

ptr= (CPerson*)LST->GetNext(head);

delete ptr;

}

ptr= (CPerson*)LST->GetTail();

delete ptr;

LST->RemoveAll();

}

CDialog::OnClose();

}

void CFamilyDlg::OnDel()

{

m_st1.ShowWindow(SW_HIDE);

m_ctrl_edit.ShowWindow(SW_HIDE);

if (LST!=NULL)

if(!LST->IsEmpty())

{CDelDlg a; a.DoModal();}

}

void CFamilyDlg::Ontree()

{

m_st1.ShowWindow(SW_HIDE);

m_ctrl_edit.ShowWindow(SW_HIDE);

if (LST!=NULL)

if(!LST->IsEmpty())

{CTreeDlg a;

a.DoModal();

}

}

void CFamilyDlg::OnSave()

{

m_st1.ShowWindow(SW_HIDE);

m_ctrl_edit.ShowWindow(SW_HIDE);

UpdateData(true);

m_fname.TrimLeft();

m_fname.TrimRight();

if (m_fname!="")

if (LST!=NULL)

if(!LST->IsEmpty())

{ m_fname+=".fam";

CFile OutFile(m_fname,CFile::modeCreate | CFile::modeWrite);

CPerson *ptr=NULL;

CString add_name="";

POSITION tail=0, head=0;

tail=LST->GetTailPosition();

head=LST->GetHeadPosition();

while (head!=tail)

{ ptr= (CPerson*)LST->GetNext(head);

add_name="";

if (ptr->GetIsMan())

add_name+="1";

else add_name+="0";

add_name+=ptr->GetName();

add_name+="\n";

if (ptr->GetFather()==NULL)

add_name+="-\n";

else

{ add_name+="~";

if (ptr->GetFather()->GetIsMan())

add_name+="1";

else add_name+="0";

add_name+=ptr->GetFather()->GetName();

add_name+="\n";

}

if (ptr->GetMarriage()==NULL)

add_name+="-\n";

else

{ add_name+="~";

if (ptr->GetMarriage()->GetIsMan())

add_name+="1";

else add_name+="0";

add_name+=ptr->GetMarriage()->GetName();

add_name+="\n";

}

if (ptr->GetChild1()==NULL)

add_name+="-\n";

else

{ add_name+="~";

if (ptr->GetChild1()->GetIsMan())

add_name+="1";

else add_name+="0";

add_name+=ptr->GetChild1()->GetName();

add_name+="\n";

}

if (ptr->GetChild2()==NULL)

add_name+="-\n";

else

{ add_name+="~";

if (ptr->GetChild2()->GetIsMan())

add_name+="1";

else add_name+="0";

add_name+=ptr->GetChild2()->GetName();

add_name+="\n";

}

if (ptr->GetChild3()==NULL)

add_name+="-\n";

else

{ add_name+="~";

if (ptr->GetChild3()->GetIsMan())

add_name+="1";

else add_name+="0";

add_name+=ptr->GetChild3()->GetName();

add_name+="\n";

}

OutFile.Write(add_name,add_name.GetLength());

}

ptr= (CPerson*)LST->GetTail();

add_name="";

if (ptr->GetIsMan())

add_name+="1";

else add_name+="0";

add_name+=ptr->GetName();

add_name+="\n";

if (ptr->GetFather()==NULL)

add_name+="-\n";

else

{ add_name+="~";

if (ptr->GetFather()->GetIsMan())

add_name+="1";

else add_name+="0";

add_name+=ptr->GetFather()->GetName();

add_name+="\n";

}

if (ptr->GetMarriage()==NULL)

add_name+="-\n";

else

{ add_name+="~";

if (ptr->GetMarriage()->GetIsMan())

add_name+="1";

else add_name+="0";

add_name+=ptr->GetMarriage()->GetName();

add_name+="\n";

}

if (ptr->GetChild1()==NULL)

add_name+="-\n";

else

{ add_name+="~";

if (ptr->GetChild1()->GetIsMan())

add_name+="1";

else add_name+="0";

add_name+=ptr->GetChild1()->GetName();

add_name+="\n";

}

if (ptr->GetChild2()==NULL)

add_name+="-\n";

else

{ add_name+="~";

if (ptr->GetChild2()->GetIsMan())

add_name+="1";

else add_name+="0";

add_name+=ptr->GetChild2()->GetName();

add_name+="\n";

}

if (ptr->GetChild3()==NULL)

add_name+="-\n";

else

{ add_name+="~";

if (ptr->GetChild3()->GetIsMan())

add_name+="1";

else add_name+="0";

add_name+=ptr->GetChild3()->GetName();

add_name+="\n";

}

OutFile.Write(add_name,add_name.GetLength());

CSucsesDlg e(5);

e.DoModal();

OutFile.Close();

m_fname="";

UpdateData(false);

}

}

void CFamilyDlg::OnLoad()

{ m_st1.ShowWindow(SW_HIDE);

m_ctrl_edit.ShowWindow(SW_HIDE);

UpdateData(true);

m_fname.TrimLeft();

m_fname.TrimRight();

if (m_fname!="")

{ m_fname+=".fam";

CFile InFile(m_fname,CFile::modeRead);

CString inStr;

for(UINT i =0; i*10<InFile.GetLength();i++)

{ char in_arr[11]=" ";

InFile.Seek(10*i,CFile::begin);

int ch_read=InFile.Read(in_arr,10);

for (int j=0; j<ch_read; j++)

inStr+=in_arr[j];

}

CString str="";

int find=0;

BOOL s=true;

CPerson* found=NULL;

CPerson* found_ch=NULL;

if (LST!=NULL)

if(!LST->IsEmpty())

{ CPerson *ptr=NULL;

POSITION tail=0, head=0;

tail=LST->GetTailPosition();

head=LST->GetHeadPosition();

while (head!=tail)

{ ptr= (CPerson*)LST->GetNext(head);

delete ptr;

}

ptr= (CPerson*)LST->GetTail();

delete ptr;

LST->RemoveAll();

}

while (inStr!="")

{ find = inStr.Find("\n"); //1 строка - имя

str=inStr.Left(find);

if (str[0]=='1') s=true; else s=false;

inStr=inStr.Mid(find+1);

found=FindPerson(str.Mid(1));

if (found==NULL)

{ found = new CPerson(str.Mid(1),s);

FamLst->AddTail(found);

LST = FamLst;}

find = inStr.Find("\n"); //2 строкаs - отец

str=inStr.Left(find);

inStr=inStr.Mid(find+1);

if (str[0]=='~')

{ str=str.Mid(1);

if (str[0]=='1') s=true; else s=false;

found_ch=FindPerson(str.Mid(1));

if (found_ch==NULL)

{ found_ch= new CPerson(str.Mid(1),s);

FamLst->AddTail(found_ch);

LST=FamLst;

}

else

{ found->SetFather(found_ch);

if (found_ch->GetChild1()==NULL)

found_ch->SetChild1(found);

else if (found_ch->GetChild2()==NULL)

found_ch->SetChild2(found);

else if (found_ch->GetChild3()==NULL)

found_ch->SetChild3(found);

else

{

CSucsesDlg b(3);

b.DoModal();

}

}

}

find = inStr.Find("\n"); //3 строкаs - муж/жена

str=inStr.Left(find);

inStr=inStr.Mid(find+1);

if (str[0]=='~')

{ str=str.Mid(1);

if (str[0]=='1') s=true; else s=false;

found_ch=FindPerson(str.Mid(1));

if (found_ch==NULL)

{ found_ch= new CPerson(str.Mid(1),s);

FamLst->AddTail(found_ch);

LST=FamLst;

}

else

{ found->SetMarriage(found_ch);

found_ch->SetMarriage(found);

}

}

find = inStr.Find("\n"); //4 строкаs - первый ребенок

str=inStr.Left(find);

inStr=inStr.Mid(find+1);

if (str[0]=='~')

{ str=str.Mid(1);

if (str[0]=='1') s=true; else s=false;

found_ch=FindPerson(str.Mid(1));

if (found_ch==NULL)

{ found_ch= new CPerson(str.Mid(1),s);

FamLst->AddTail(found_ch);

LST=FamLst;

}

else

{ found->SetChild1(found_ch);

found_ch->SetFather(found);

}

}

find = inStr.Find("\n"); //5 строкаs - второй ребенок

str=inStr.Left(find);

inStr=inStr.Mid(find+1);

if (str[0]=='~')

{ str=str.Mid(1);

if (str[0]=='1') s=true; else s=false;

found_ch=FindPerson(str.Mid(1));

if (found_ch==NULL)

{ found_ch= new CPerson(str.Mid(1),s);

FamLst->AddTail(found_ch);

LST=FamLst;

}

else

{ found->SetChild2(found_ch);

found_ch->SetFather(found);

}

}

find = inStr.Find("\n"); //6 строкаs - третий ребенок

str=inStr.Left(find);

inStr=inStr.Mid(find+1);

if (str[0]=='~')

{ str=str.Mid(1);

if (str[0]=='1') s=true; else s=false;

found_ch=FindPerson(str.Mid(1));

if (found_ch==NULL)

{ found_ch= new CPerson(str.Mid(1),s);

FamLst->AddTail(found_ch);

LST=FamLst;

}

else

{ found->SetChild3(found_ch);

found_ch->SetFather(found);

}

}

}

InFile.Close();

m_kol=LST->GetCount();

m_fname="";

UpdateData(false);

m_st1.ShowWindow(SW_NORMAL);

m_ctrl_edit.ShowWindow(SW_NORMAL);

}

}

CPerson* CFamilyDlg::FindPerson(CString search_name)

{ CPerson *found=NULL;

if (LST!=NULL)

if(!LST->IsEmpty())

{ CPerson *ptr=NULL;

CSucsesDlg a(1);

POSITION tail=0, head=0;

tail=LST->GetTailPosition();

head=LST->GetHeadPosition();

CString add_name = "";

while (head!=tail)

{ ptr= (CPerson*)LST->GetNext(head);

add_name=ptr->GetName();

if (add_name==search_name) found=ptr;

}

ptr= (CPerson*)LST->GetTail();

add_name=ptr->GetName();

if (add_name==search_name) found=ptr;

ptr=NULL;

}

return found;

}

void CFamilyDlg::OnAnalyze()

{ if (LST!=NULL)

if(LST->GetCount()>2)

{ CLinkDlg a;

a.DoModal();

}

}

void CFamilyDlg::WinHelp(DWORD dwData, UINT nCmd)

{ if (!m_helpON)

{ m_helpON=TRUE;

CAboutDlg help;

help.DoModal();

m_helpON=FALSE;

}

}

// PersonDlg.h : header file

class CPersonDlg : public CDialog

{

// Construction

public:

CPersonDlg(CWnd* pParent = NULL); // standard constructor

// Dialog Data

CComboBox m_sex;

CButton m_wife;

CButton m_son;

CButton m_husb;

CButton m_father;

CButton m_doch;

CComboBox m_box;

CString m_name;

BOOL sex;

CString box_name;

CString sex_name;

virtual BOOL OnInitDialog();

afx_msg void OnSelchangeCombo1();

afx_msg void OnRFather();

afx_msg void OnRHusb();

afx_msg void OnRSon();

afx_msg void OnRWife();

afx_msg void OnRDoch();

afx_msg void OnAdd();

afx_msg void OnSelchangeCombNm();

afx_msg void OnKillfocusEdName();

};

// PersonDlg.cpp : implementation file

CPersonDlg::CPersonDlg(CWnd* pParent /*=NULL*/)

: CDialog(CPersonDlg::IDD, pParent)

{ //{{AFX_DATA_INIT(CPersonDlg)

m_name = _T("");

//}}AFX_DATA_INIT

sex = true;

box_name ="";

sex_name ="";

}

void CPersonDlg::DoDataExchange(CDataExchange* pDX)

{ CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP(CPersonDlg)

DDX_Control(pDX, IDC_COMBO1, m_sex);

DDX_Control(pDX, IDC_R_WIFE, m_wife);

DDX_Control(pDX, IDC_R_SON, m_son);

DDX_Control(pDX, IDC_R_HUSB, m_husb);

DDX_Control(pDX, IDC_R_FATHER, m_father);

DDX_Control(pDX, IDC_R_DOCH, m_doch);

DDX_Control(pDX, IDC_COMB_NM, m_box);

DDX_Text(pDX, IDC_ED_NAME, m_name);

//}}AFX_DATA_MAP}

BOOL CPersonDlg::OnInitDialog()

{ CDialog::OnInitDialog();

m_sex.AddString("M");

m_sex.AddString("Ж");

return TRUE; // return TRUE unless you set the focus to a control

// EXCEPTION: OCX Property Pages should return FALSE

}

void CPersonDlg::OnSelchangeCombo1()

{

m_box.ResetContent();

m_father.ShowWindow(SW_HIDE);

m_husb.ShowWindow(SW_HIDE);

m_doch.ShowWindow(SW_HIDE);

m_wife.ShowWindow(SW_HIDE);

m_son.ShowWindow(SW_HIDE);

m_sex.GetLBText(m_sex.GetCurSel(),sex_name);

if (sex_name=="M")

{ m_father.SetCheck(0);

m_husb.SetCheck(0);

m_son.SetCheck(0);

m_wife.SetCheck(0);

m_doch.SetCheck(0);

sex=true;

m_father.ShowWindow(SW_NORMAL);

m_husb.ShowWindow(SW_NORMAL);

m_son.ShowWindow(SW_NORMAL);

}

else

{ m_father.SetCheck(0);

m_husb.SetCheck(0);

m_son.SetCheck(0);

m_wife.SetCheck(0);

m_doch.SetCheck(0);

sex=false;

m_doch.ShowWindow(SW_NORMAL);

m_wife.ShowWindow(SW_NORMAL);

}

}

void CPersonDlg::OnRFather()

{ m_box.ResetContent();

m_father.SetCheck(1);

m_husb.SetCheck(0);

m_son.SetCheck(0);

m_wife.SetCheck(0);

m_doch.SetCheck(0);

CPerson *ptr=NULL;

POSITION tail=0, head=0;

tail=LST->GetTailPosition();

head=LST->GetHeadPosition();

CString add_name = "bad";

while (head!=tail)

{

ptr= (CPerson*)LST->GetNext(head);

add_name=ptr->GetName();

if(ptr->GetFather()==NULL)

m_box.AddString(add_name);

}

ptr= (CPerson*)LST->GetTail();

add_name=ptr->GetName();

if(ptr->GetFather()==NULL)

m_box.AddString(add_name);

}

void CPersonDlg::OnRHusb()

{

m_father.SetCheck(0);

m_husb.SetCheck(1);

m_son.SetCheck(0);

m_wife.SetCheck(0);

m_doch.SetCheck(0);

m_box.ResetContent();

CPerson *ptr=NULL;

POSITION tail=0, head=0;

tail=LST->GetTailPosition();

head=LST->GetHeadPosition();

CString add_name = "bad";

while (head!=tail)

{

ptr= (CPerson*)LST->GetNext(head);

add_name=ptr->GetName();

if(ptr->GetMarriage()==NULL && (!ptr->GetIsMan()))

m_box.AddString(add_name);

}

ptr= (CPerson*)LST->GetTail();

add_name=ptr->GetName();

if(ptr->GetMarriage()==NULL && (!ptr->GetIsMan()))

m_box.AddString(add_name);

}

void CPersonDlg::OnRSon()

{

m_father.SetCheck(0);

m_husb.SetCheck(0);

m_son.SetCheck(1);

m_wife.SetCheck(0);

m_doch.SetCheck(0);

m_box.ResetContent();

CPerson *ptr=NULL;

POSITION tail=0, head=0;

tail=LST->GetTailPosition();

head=LST->GetHeadPosition();

CString add_name = "bad";

while (head!=tail)

{

ptr= (CPerson*)LST->GetNext(head);

add_name=ptr->GetName();

if( ( (ptr->GetChild1()==NULL)

|| (ptr->GetChild2()==NULL)

|| (ptr->GetChild3()==NULL)

)

&& (ptr->GetIsMan())

)

m_box.AddString(add_name);

}

ptr= (CPerson*)LST->GetTail();

add_name=ptr->GetName();

if( ( (ptr->GetChild1()==NULL)

|| (ptr->GetChild2()==NULL)

|| (ptr->GetChild3()==NULL)

)

&& (ptr->GetIsMan())

)

m_box.AddString(add_name);

}

void CPersonDlg::OnRWife()

{

m_father.SetCheck(0);

m_husb.SetCheck(0);

m_son.SetCheck(0);

m_wife.SetCheck(1);

m_doch.SetCheck(0);

m_box.ResetContent();

CPerson *ptr=NULL;

POSITION tail=0, head=0;

tail=LST->GetTailPosition();

head=LST->GetHeadPosition();

CString add_name = "bad";

while (head!=tail)

{

ptr= (CPerson*)LST->GetNext(head);

add_name=ptr->GetName();

if((ptr->GetMarriage()==NULL) && (ptr->GetIsMan()))

m_box.AddString(add_name);

}

ptr= (CPerson*)LST->GetTail();

add_name=ptr->GetName();

if(ptr->GetMarriage()==NULL && (ptr->GetIsMan()))

m_box.AddString(add_name);

}

void CPersonDlg::OnRDoch()

{

m_father.SetCheck(0);

m_husb.SetCheck(0);

m_son.SetCheck(0);

m_wife.SetCheck(0);

m_doch.SetCheck(1);

m_box.ResetContent();

CPerson *ptr=NULL;

POSITION tail=0, head=0;

tail=LST->GetTailPosition();

head=LST->GetHeadPosition();

CString add_name = "bad";

while (head!=tail)

{

ptr= (CPerson*)LST->GetNext(head);

add_name=ptr->GetName();

if( ( (ptr->GetChild1()==NULL)

|| (ptr->GetChild2()==NULL)

|| (ptr->GetChild3()==NULL)

)

&& (ptr->GetIsMan())

)

m_box.AddString(add_name);

}

ptr= (CPerson*)LST->GetTail();

add_name=ptr->GetName();

if( ( (ptr->GetChild1()==NULL)

|| (ptr->GetChild2()==NULL)

|| (ptr->GetChild3()==NULL)

)

&& (ptr->GetIsMan())

)

m_box.AddString(add_name);

}

void CPersonDlg::OnAdd()

{

UpdateData(true);

m_name.TrimLeft();

m_name.TrimRight();

if (m_name!="")

if (sex_name!="")

if (box_name!="")

{

CPerson *ptr=NULL;

CPerson *found=NULL;

CSucsesDlg a(1);

POSITION tail=0, head=0;

tail=LST->GetTailPosition();

head=LST->GetHeadPosition();

CString add_name = "";

while (head!=tail)

{

ptr= (CPerson*)LST->GetNext(head);

add_name=ptr->GetName();

if (add_name==box_name) found=ptr;

}

ptr= (CPerson*)LST->GetTail();

add_name=ptr->GetName();

if (add_name==box_name) found=ptr;

ptr=NULL;

ptr = new CPerson(m_name,sex);

LST->AddTail(ptr);

if (m_father.GetCheck())

{

found->SetFather(ptr);

ptr->SetChild1(found);

a.DoModal();

}

if (m_husb.GetCheck())

{

found->SetMarriage(ptr);

ptr->SetMarriage(found);

a.DoModal();

}

if ( (m_son.GetCheck()) || (m_doch.GetCheck()) )

{

ptr->SetFather(found);

if (found->GetChild1()==NULL)

{

found->SetChild1(ptr);

a.DoModal();

}

else if (found->GetChild2()==NULL)

{

found->SetChild2(ptr);

a.DoModal();

}

else if (found->GetChild3()==NULL)

{

found->SetChild3(ptr);

a.DoModal();

}

else

{

CSucsesDlg b(3);

b.DoModal();

}

}

if (m_wife.GetCheck())

{

found->SetMarriage(ptr);

ptr->SetMarriage(found);

a.DoModal();

}

m_box.ResetContent();

m_father.SetCheck(0);

m_husb.SetCheck(0);

m_son.SetCheck(0);

m_wife.SetCheck(0);

m_doch.SetCheck(0);

m_name="";

UpdateData(false);

}

}

void CPersonDlg::OnSelchangeCombNm()

{ m_box.GetLBText(m_box.GetCurSel(),box_name); }

void CPersonDlg::OnKillfocusEdName()

{ UpdateData(true);

BOOL chek=false;

m_name.TrimLeft();

m_name.TrimRight();

CPerson *ptr=NULL;

POSITION tail=0, head=0;

tail=LST->GetTailPosition();

head=LST->GetHeadPosition();

CString add_name = "bad";

while (head!=tail)

{

ptr= (CPerson*)LST->GetNext(head);

add_name=ptr->GetName();

if (add_name==m_name) chek=true;

}

ptr= (CPerson*)LST->GetTail();

add_name=ptr->GetName();

if (add_name==m_name) chek=true;

if (chek)

{

CSucsesDlg a(2);

a.DoModal();

m_name="";

}

UpdateData(false);

}

// LinkDlg.h : header file

class CLinkDlg : public CDialog

{

public:

BOOL m_helpON;

void EraseRoute();

CString last_per;

CString first_per;

int route[40];

CLinkDlg(CWnd* pParent = NULL); // standard constructor

CComboBox m_last;

CComboBox m_first;

CButton m_go;

CString m_result;

protected:

virtual BOOL OnInitDialog();

afx_msg void OnSelchangeFirst();

afx_msg void OnSelchangeSecond();

afx_msg void OnGo();

};

// LinkDlg.cpp : implementation file

char *rods[31]={"Отец","Сын","Дочь","Муж","Жена",

"Мать","Брат","Сестра","Дед","Бабка",

"Кузен","Кузина","Деверь","Дядя",

"Золовка","Зять","Невестка","Племянник",

"Племянница","Свояченица","Сват",

"Сватья","Свекор","Свекровь",

"Свояк","Тесть","Тетя",

"Теща","Шурин","Внук","Внучка"};

int tabl[32][6] = {0,1,2,3,4,5, //matr is row,col

1,9,7,8,0,6,

2,0,30,31,0,17,

3,0,0,0,16,0,

4,23,2,3,0,0,

5,26,0,0,0,0,

6,9,0,0,0,0,

7,0,18,19,0,17,

8,0,0,0,16,0,

9,0,14,27,0,10,

10,0,0,0,0,0,

11,0,0,0,0,0,

12,0,0,0,0,0,

13,0,18,19,0,17,

14,0,11,12,0,27,

15,0,0,0,16,0,

16,21,18,19,0,0,

17,21,0,0,0,0,

18,0,0,0,0,0,

19,0,0,0,0,0,

20,0,0,0,25,0,

21,0,0,0,0,22,

22,0,0,0,0,0,

23,0,13,15,0,24,

24,0,0,0,0,0,

25,0,18,19,0,0,

26,0,29,20,0,28,

27,0,0,0,0,14,

28,0,0,0,0,0,

29,0,18,19,0,17,

30,0,0,0,0,0,

31,0,0,0,0,0};

CLinkDlg::CLinkDlg(CWnd* pParent /*=NULL*/)

: CDialog(CLinkDlg::IDD, pParent)

first_per="";

last_per="";

m_helpON=false;

}

// CLinkDlg message handlers

BOOL CLinkDlg::OnInitDialog()

{ CDialog::OnInitDialog();

CPerson *ptr=NULL;

CString add_name="";

POSITION tail=0, head=0;

tail=LST->GetTailPosition();

head=LST->GetHeadPosition();

// LST->GetNext(head);

while (head!=tail)

{

ptr= (CPerson*)LST->GetNext(head);

add_name=ptr->GetName();

m_first.AddString(add_name);

}

ptr= (CPerson*)LST->GetTail();

add_name=ptr->GetName();

m_first.AddString(add_name);

return TRUE; // return TRUE unless you set the focus to a control

// EXCEPTION: OCX Property Pages should return FALSE

}

void CLinkDlg::OnSelchangeFirst()

{

m_first.GetLBText(m_first.GetCurSel(),last_per);

m_last.EnableWindow(true);

m_last.ResetContent();

CPerson *ptr=NULL;

CString add_name="";

POSITION tail=0, head=0;

tail=LST->GetTailPosition();

head=LST->GetHeadPosition();

// LST->GetNext(head);

while (head!=tail)

{

ptr= (CPerson*)LST->GetNext(head);

add_name=ptr->GetName();

if (add_name!=first_per)

m_last.AddString(add_name);

}

ptr= (CPerson*)LST->GetTail();

add_name=ptr->GetName();

if (add_name!=first_per)

m_last.AddString(add_name);

}

void CLinkDlg::OnSelchangeSecond()

{

m_last.GetLBText(m_last.GetCurSel(),first_per);

m_go.EnableWindow(true);

}

void CLinkDlg::OnGo()

{ EraseRoute();

CPerson *found=NULL;

CPerson *last_found=NULL;

CString search_name=first_per;

if (LST!=NULL)

if(!LST->IsEmpty())

{ CPerson *ptr=NULL;

POSITION tail=0, head=0;

tail=LST->GetTailPosition();

head=LST->GetHeadPosition();

CString add_name = "";

while (head!=tail)

{

ptr= (CPerson*)LST->GetNext(head);

add_name=ptr->GetName();

if (add_name==search_name) found=ptr;

}

ptr= (CPerson*)LST->GetTail();

add_name=ptr->GetName();

if (add_name==search_name) found=ptr;

ptr=NULL;

}

int *p=route;

last_found=found->FindRoute(last_per,NULL,p);

// обpаботка пути

int rez=1;

int i=0;

while(p[i+1]!=0)

{

p[i+1]=tabl[p[i]][p[i+1]];

if (!p[i+1]) rez=0;

i++;

}

// return p[i];

if (rez==0) m_result="Связь не найдена";

else m_result=rods[(p[i])-1];

UpdateData(false);

}

void CLinkDlg::EraseRoute()

{ for(int i=0;i<40;i++)

route[i]=0; }

// DelDlg.h : header file

class CDelDlg : public CDialog

{

public:

CString m_text;

CDelDlg(CWnd* pParent = NULL); // standard constructor

afx_msg void OnDelling();

virtual BOOL OnInitDialog();

afx_msg void OnSelchangeCombo1();

};

// DelDlg.cpp : implementation file

CDelDlg::CDelDlg(CWnd* pParent /*=NULL*/)

: CDialog(CDelDlg::IDD, pParent)

{ //{{AFX_DATA_INIT(CDelDlg)

//}}AFX_DATA_INIT

m_text="";}

void CDelDlg::OnDelling()

{ // TODO: Add your control notification handler code here

if (m_text!="")

{

CPerson *ptr=NULL;

CPerson *found=NULL;

CSucsesDlg a(4);

POSITION tail=0, head=0;

tail=LST->GetTailPosition();

head=LST->GetHeadPosition();

CString add_name = "bad";

while (head!=tail)

{

ptr= (CPerson*)LST->GetNext(head);

add_name=ptr->GetName();

if (add_name==m_text) found=ptr;

}

ptr= (CPerson*)LST->GetTail();

add_name=ptr->GetName();

if (add_name==m_text) found=ptr;

tail=0;

tail=LST->Find(found);

LST->RemoveAt(tail);

if (found->GetFather()!=NULL)

found->GetFather()->SetChild1(NULL);

if (found->GetChild1()!=NULL)

found->GetChild1()->SetFather(NULL);

if (found->GetMarriage()!=NULL)

found->GetMarriage()->SetMarriage(NULL);

delete found;

a.DoModal();

EndModalLoop(IDOK);

}

}

BOOL CDelDlg::OnInitDialog()

{

CDialog::OnInitDialog();

int count=0;

CPerson *ptr=NULL;

CString add_name="";

POSITION tail=0, head=0;

tail=LST->GetTailPosition();

head=LST->GetHeadPosition();

while (head!=tail)

{

ptr= (CPerson*)LST->GetNext(head);

count=0;

add_name=ptr->GetName();

if(ptr->GetFather()!=NULL)

count=count+1;

if(ptr->GetMarriage()!=NULL)

count=count+1;

if(ptr->GetChild1()!=NULL)

count=count+1;

if (count==1)

m_list.AddString(add_name);

}

ptr= (CPerson*)LST->GetTail();

count=0;

add_name=ptr->GetName();

if(ptr->GetFather()!=NULL)

count=count+1;

if(ptr->GetMarriage()!=NULL)

count=count+1;

if(ptr->GetChild1()!=NULL)

count=count+1;

if (count==1)

m_list.AddString(add_name);

return TRUE; // return TRUE unless you set the focus to a control

}

void CDelDlg::OnSelchangeCombo1()

{ m_list.GetLBText(m_list.GetCurSel(),m_text);

UpdateData(false); }

// TreeDlg.h : header file

class CTreeDlg : public CDialog

{

public: CTreeDlg(CWnd* pParent = NULL); // standard constructor

CTreeCtrl m_tree;

virtual BOOL OnInitDialog();

};

// TreeDlg.cpp : implementation file

BOOL CTreeDlg::OnInitDialog()

{

CDialog::OnInitDialog();

CPerson *ptr=NULL;

CString s="";

CString add_name="";

POSITION tail=0, head=0;

tail=LST->GetTailPosition();

head=LST->GetHeadPosition();

while (head!=tail)

{

ptr= (CPerson*)LST->GetNext(head);

add_name=ptr->GetName();

HTREEITEM a = m_tree.InsertItem(add_name);

if (ptr->GetIsMan()) s="Пол: мужской";

else s="Пол: женский";

m_tree.InsertItem(s,a);

if (ptr->GetFather()!=NULL)

{

s="Отец: ";

s+=ptr->GetFather()->GetName();

m_tree.InsertItem(s,a);

}

if (ptr->GetMarriage()!=NULL)

{

if (ptr->GetIsMan()) s="Супруга: ";

else s="Супруг: ";

s+=ptr->GetMarriage()->GetName();

m_tree.InsertItem(s,a);

}

if (ptr->GetChild1()!=NULL)

{

if (ptr->GetChild1()->GetIsMan()) s="Сын: ";

else s="Дочь: ";

s+=ptr->GetChild1()->GetName();

m_tree.InsertItem(s,a);

}

if (ptr->GetChild2()!=NULL)

{

if (ptr->GetChild2()->GetIsMan()) s="Сын: ";

else s="Дочь: ";

s+=ptr->GetChild2()->GetName();

m_tree.InsertItem(s,a);

}

if (ptr->GetChild3()!=NULL)

{

if (ptr->GetChild3()->GetIsMan()) s="Сын: ";

else s="Дочь: ";

s+=ptr->GetChild3()->GetName();

m_tree.InsertItem(s,a);

}

}

ptr= (CPerson*)LST->GetTail();

add_name=ptr->GetName();

HTREEITEM a = m_tree.InsertItem(add_name);

if (ptr->GetIsMan()) s="Пол: мужской";

else s="Пол: женский";

m_tree.InsertItem(s,a);

if (ptr->GetFather()!=NULL)

{

s="Отец: ";

s+=ptr->GetFather()->GetName();

m_tree.InsertItem(s,a);

}

if (ptr->GetMarriage()!=NULL)

{

if (ptr->GetIsMan()) s="Супруга: ";

else s="Супруг: ";

s+=ptr->GetMarriage()->GetName();

m_tree.InsertItem(s,a);

}

if (ptr->GetChild1()!=NULL)

{

if (ptr->GetChild1()->GetIsMan()) s="Сын: ";

else s="Дочь: ";

s+=ptr->GetChild1()->GetName();

m_tree.InsertItem(s,a);

}

if (ptr->GetChild2()!=NULL)

{

if (ptr->GetChild2()->GetIsMan()) s="Сын: ";

else s="Дочь: ";

s+=ptr->GetChild2()->GetName();

m_tree.InsertItem(s,a);

}

if (ptr->GetChild3()!=NULL)

{

if (ptr->GetChild3()->GetIsMan()) s="Сын: ";

else s="Дочь: ";

s+=ptr->GetChild3()->GetName();

m_tree.InsertItem(s,a);

}

return TRUE; // return TRUE unless you set the focus to a control

}

// SucsesDlg.h : header file

class CSucsesDlg : public CDialog

{

public:

CSucsesDlg(int act,CWnd* pParent = NULL); // standard constructor

CStatic m_st5;

CStatic m_st4;

CStatic m_st3;

CStatic m_st2;

CStatic m_st1;

int action;

virtual BOOL OnInitDialog();

};

// SucsesDlg.cpp : implementation file

BOOL CSucsesDlg::OnInitDialog()

{

CDialog::OnInitDialog();

// TODO: Add extra initialization here

if (action==1)

m_st1.ShowWindow(SW_NORMAL);

if (action==2)

m_st2.ShowWindow(SW_NORMAL);

if (action==3)

m_st3.ShowWindow(SW_NORMAL);

if (action==4)

m_st4.ShowWindow(SW_NORMAL);

if (action==5)

m_st5.ShowWindow(SW_NORMAL);

return TRUE; // return TRUE unless you set the focus to a control

}

//{{NO_DEPENDENCIES}}

// Microsoft Developer Studio generated include file.

// Used by Family.rc

//

#define IDM_ABOUTBOX 0x0010

#define IDD_ABOUTBOX 100

#define IDS_ABOUTBOX 101

#define IDD_FAMILY_DIALOG 102

#define IDR_MAINFRAME 128

#define IDD_DLG_PRINT 129

#define IDD_DLG_NEWPERSON 130

#define IDD_D_SUC_NEW 131

#define IDD_Del 132

#define IDD_LINK 133

#define IDC_EDIT1 1000

#define IDC_BUT_ADD 1001

#define IDC_ADD 1002

#define IDC_ED_NAME 1006

#define IDC_R_HUSB 1007

#define IDC_R_FATHER 1008

#define IDC_R_SON 1009

#define IDC_R_WIFE 1010

#define IDC_R_DOCH 1011

#define IDC_COMB_NM 1012

#define IDC_BUTTON1 1015

#define IDC_COMBO1 1018

#define IDC_STATIC1 1021

#define IDC_STATIC2 1022

#define IDC_STATIC3 1023

#define IDC_DEL 1026

#define IDC_STATIC4 1029

#define IDC_TREE1 1030

#define IDC_BUTTON2 1031

#define IDC_SAVE 1032

#define IDC_EDIT2 1033

#define IDC_BUTTON3 1035

#define IDC_KOL 1036

#define IDC_ST1 1037

#define IDC_ST5 1038

#define IDC_BUTTON4 1039

#define IDC_SECOND 1040

#define IDC_GO 1041

#define IDC_FIRST 1042

// Next default values for new objects

//

#ifdef APSTUDIO_INVOKED

#ifndef APSTUDIO_READONLY_SYMBOLS

#define _APS_NEXT_RESOURCE_VALUE 134

#define _APS_NEXT_COMMAND_VALUE 32771

#define _APS_NEXT_CONTROL_VALUE 1043

#define _APS_NEXT_SYMED_VALUE 101

#endif

#endif

41