📄 unit.cpp
字号:
// Unit.cpp: implementation of the Unit class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Unit.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//##ModelId=40A481F0030E
Unit::Unit():ID(0),Title(_T("")),SuperiorID(0)
{
//ID = GetNewID();
}
//##ModelId=40A481F002FE
Unit::Unit(long ID)
{
this->ID = ID;
}
//##ModelId=40A481F0030F
Unit::~Unit()
{
}
//##ModelId=40A481F0029F
bool Unit::Update(CDaoRecordset *RS)
{
RS->SetCurrentIndex("ID");
if(RS->Seek("=", &COleVariant((long)ID)))
{
RS->Edit();
RS->SetFieldValue("unit", LPCTSTR(Title));
RS->SetFieldValue("superior_id", COleVariant((long)SuperiorID));
RS->Update();
return true;
}
return false;
}
//##ModelId=40A481F00292
bool Unit::Delete(CDaoRecordset *RS)
{
if(ID==1)
{
AfxMessageBox("不能删除学校名称");
return false;
}
RS->SetCurrentIndex("ID");
if(RS->Seek("=", &COleVariant((long)ID)))
{
RS->Delete();
return true;
}
return false;
}
//##ModelId=40A481F002B3
void Unit::Set(long ID, CString unit, long superior)
{
this->ID = ID;
Title = unit;
SuperiorID = superior;
}
//##ModelId=40A481F002AF
Unit::Unit(long ID, CString title, long superior)
{
Set(ID, title, superior);
}
//##ModelId=40A481F002F4
void Unit::LoadCur(CDaoRecordset *RS)
{
Set(RS->GetFieldValue("ID").lVal,
V_BSTRT(&RS->GetFieldValue("Unit")),
RS->GetFieldValue("Superior_id").lVal
);
}
//##ModelId=40A481F00300
void Unit::UpdateCur(CDaoRecordset *RS)
{
RS->Edit();
RS->SetFieldValue("unit", LPCTSTR(Title));
RS->SetFieldValue("superior_id", COleVariant((long)SuperiorID));
RS->Update();
}
//##ModelId=40A481F002A1
void Unit::AddNew(CDaoRecordset *RS)
{
RS->AddNew();
RS->SetFieldValue("unit", LPCTSTR(Title));
RS->SetFieldValue("superior_id", COleVariant((long)SuperiorID));
RS->Update();
RS->MoveLast();
ID = RS->GetFieldValue("ID").lVal;
}
//##ModelId=40A481F00290
bool Unit::Load(CDaoRecordset *RS)
{
RS->SetCurrentIndex("ID");
if(RS->Seek("=", &COleVariant((long)ID)))
{
Set((long)RS->GetFieldValue("ID").lVal,
V_BSTRT(&RS->GetFieldValue("Unit")),
(long)RS->GetFieldValue("Superior_id").lVal
);
return true;
}
return false;
}
//##ModelId=40A481F00282
void Unit::DeleteAssociate(CDaoRecordset *RS)
{
COleVariant var(ID);
IDBuf.clear();
GetChildBuf(RS, ID);
if(!IDBuf.size())
return;
sort(IDBuf.begin(), IDBuf.end());
int i = 0;
RS->SetCurrentIndex("ID");
do
{
var.lVal = IDBuf[i];
if(RS->Seek("=", &var))
RS->Delete();
}while(++i<IDBuf.size());
}
//##ModelId=40A481F00272
void Unit::GetChildBuf(CDaoRecordset *RS, long id)
{
vector<int> id_buf;
COleVariant var(id);
RS->SetCurrentIndex("Superior_ID");
if(RS->Seek("=", &var))
{
while(!RS->IsEOF() && RS->GetFieldValue("Superior_ID").lVal==id)
{
id_buf.push_back(RS->GetFieldValue("ID").lVal);
RS->MoveNext();
}
for(int i=0; i<id_buf.size(); i++)
{
IDBuf.push_back(id_buf[i]);
}
for(int j=0; j<id_buf.size(); j++)
{
GetChildBuf(RS, id_buf[j]);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -