|
DB Visual ARCHITECT (DB-VA) can generate C#.NET source code so you can implement your application by C# programming language directly but you can also choose another language (VB.NET or C++) based on your taste in the .NET Framework. DB-VA generates DLL file and persistent libraries that can be referenced by .NET projects of language other than C#.
In this chapter:
In the following section, you will develop a C++ application. The application is exactly same as the one in Chapter 4 – Developing Standalone .NET Application sample, but this time you use C++ instead of C# for development. You need to download the Chapter 4 sample application because it contains DLL file and persistent libraries for your C++ project.

By checking this option, DB-VA will generate DLL files which can be referenced by .NET projects of language other than C#. DB-VA generates batch file for the DLL file at the same time. You can modify the configuration file (hibernate.cfg.xml) manually and use the batch file to recompile and build an up-to-date DLL file for referenced project.
![]()





|
#include <windows.h>
using namespace StandaloneSchoolSystemcpp;
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA; Application::Run(new SchoolSystemForm()); return 0; } |





|
private: System::Void okButton_Click(System::Object *sender, System::EventArgs *e) if(loginIDTextBox->Text->Length == 0 || passwordTextBox->Text->Length == 0){ MessageBox::Show("Login id or password missing"); return; } PersistentTransaction *t = SchoolSystemPersistentManager::Instance()->GetSession()->BeginTransaction(); try{ if(userType == CREATE_TEACHER){ createdUser = TeacherFactory::CreateTeacher(); }else{ createdUser = StudentFactory::CreateStudent(); } |
|
|
Source File : Standalone School System cpp \RegisterDialog.h |
|
|
createdUser->set_Name(userNameTextBox->Text); createdUser->set_Password(passwordTextBox->Text); createdUser->set_LoginID(loginIDTextBox->Text); if(dynamic_cast<Teacher*>(createdUser)){ dynamic_cast<Teacher*>(createdUser)->set_Email(emailTextBox->Text); } |
|
Source File : Standalone School System cpp \RegisterDialog.h |
|
createdUser->Save(); this->set_CreatedUser(createdUser); DialogResult = DialogResult::OK; t->Commit(); Close(); }catch(Exception *ex){ Console::WriteLine(ex->InnerException->Message); DialogResult = DialogResult::Cancel; t->RollBack(); } |
|
Source File : Standalone School System cpp \RegisterDialog.h |
After the user login the School System, the system queries different Course objects from the database according to user role. If the user is a student, the system shows all the available courses. The student can select and register the course. If the user is teacher, the system shows the courses that are created by that teacher. The teacher can update or delete the course information in system.
Student Login:

Teacher Login:

|
void updateTreeView(void){ Course *courses[]; if(dynamic_cast<Student*>(currentUser)){ courses = CourseFactory::ListCourseByQuery(NULL, NULL); }else{ courses = dynamic_cast<Teacher*>(currentUser)->courses->ToArray(); } ... } |
|
Source File : Standalone School System cpp \SchoolSystemForm.h |
You can modify the user information and update the record in database. After the user login, the User object is stored in the application, so you can set new information in the user object and update the database record.


|
private: System::Void okButton_Click(System::Object *sender, System::EventArgs *e) { if(nameTextBox->Text->Length == 0 || passwordTextBox->Text->Length == 0){ MessageBox::Show("Missing name or password"); return; }else{ PersistentTransaction *t = SchoolSystemPersistentManager::Instance()->GetSession()->BeginTransaction(); try{ user->set_Name(nameTextBox->Text); user->set_Password(passwordTextBox->Text); if(dynamic_cast<Teacher*>(user)){ (dynamic_cast<Teacher*>(user))->set_Email(emailTextBox->Text); } user->Save(); DialogResult = DialogResult::OK; t->Commit(); }catch(Exception *ex){ DialogResult = DialogResult::Cancel; t->RollBack(); } } } |
|
Source File : Standalone School System cpp\ModifyUserDialog.h |
Teacher can create courses for students to register and they can cancel the course in the system. They only need to click delete button of the course then the course information will be deleted in the database and all its relationships with register students will be removed.



|
private: System::Void deleteButton_Click(System::Object *sender, System::EventArgs *e) { if(MessageBox::Show("Delete", "Delete", MessageBoxButtons::OKCancel) == DialogResult::OK){ |
|
Source File : Standalone School System cpp\SchoolSystemform.h |
|
PersistentTransaction *t = SchoolSystemPersistentManager::Instance()->GetSession()->BeginTransaction(); try{ selectedNode->get_Course()->DeleteAndDissociate(); selectedNode->Remove(); t->Commit(); }catch(Exception *ex){ Console::WriteLine(ex->InnerException->Message); t->RollBack(); } } } |
|
Source File : Standalone School System cpp\SchoolSystemForm.h |
To execute the C++ application, select Debug > Start (F5) on the menu bar Visual Studio .NET 2003.


|
|
|||||||