SlideShare ist ein Scribd-Unternehmen logo
1 von 10
Downloaden Sie, um offline zu lesen
8

Programming in C++.NET
Programmer’s Guide for .NET

Chapter 8 – Programming in C++.NET

Chapter 8 - Programming in C++ .NET
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:
•
•
•
•
•
•

Introduction
Generating DLL file
Creating C++ Project
Adding Referenced Project
Working with the Generating Code and Persistent Library
Running the Application

Introduction
C++ is an Object-Oriented Programming (OOP) language that is viewed by many as the best language for creating large-scale
applications. The .NET Framework contains a virtual machine called Common Intermediate Language (CIL). Simply put,
programs are compiled to produce CIL and the CIL is distributed to user to run on a virtual machine. C++, VB.NET, C#
compilers are available from Microsoft for creating CIL. In DB-VA you can generate C# persistent source code and DLL file,
so you can reference the DLL file and persistent library in Visual Studio .NET 2003 and develop the C++ application.
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.

Generating DLL File
1.

From the menu bar, select Tools > Object-Relational Mapping (ORM) > Generate Database… to open the
Database Code Generate dialog box.

2.

Check the Compile to DLL option to generate the DLL file.
• Compile to DLL
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.

8-2
Programmer’s Guide for .NET

Chapter 8 – Programming in C++.NET

Creating C++ Project
1.
2.

Open Microsoft Visual Studio .NET 2003.
Select File > New > Project … from the menu.

3.

Select Project Types as Visual C++ Projects and Templates as Windows Form Application (.NET) and Location for
the new application.

4.

The School System Project is created.

5.

Right click Standalone School System cpp Project, select Add > Add New Item… from the popup menu.

8-3
Programmer’s Guide for .NET

Chapter 8 – Programming in C++.NET

6.

Select Category as Visual C++, Template Windows Form (.NET) and enter the name for the form called
“SchoolSystemForm”. This is the start point for the application.

7.

Append the following content to the SchoolSystemForm.cpp file (Source files/SchoolSystemForm.cpp). This is the
main method for C++ Application to execute.
#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;
}

8.

Remove the Form1.cpp and Form1.h files.

Adding Referenced Project
1.

8-4

Right click References under the Standalone School System C++ project and select Add Reference…. Reference the
C# example DDL file and persistent libraries for developing the C++ application.
Programmer’s Guide for .NET

2.

Chapter 8 – Programming in C++.NET

Click Browse… on the Add Reference dialog box to select the folder of the downloaded C# standalone application
sample. Select C# sample folder/bin/SchoolSystem.dll and all libraries in C# sample folder/lib.

Working with the Generating Code and Persistent Library
C# and C++ are both languages that built on the .NET framework and they both accomplish the same thing, just using different
language syntax. In this section, you will learn how to work with Generate Code and Persistent Library with C++ language.
•

Creating Object and Save to Database
1. From the menu bar, select File > Register Student to open the Add Student dialog box.

2.

Fill in the student information. Click OK to create the new Student record in School System.

8-5
Programmer’s Guide for .NET

3.

Chapter 8 – Programming in C++.NET

After that, the system creates the new Student Persistent object.
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

4.

Set the student information from the text fields value to the Student Object
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

5.

Call Save() method of Student Persistent Object and Commit() method of PersistentTransaction, then the
new Student object will be saved in database. If there are any errors occurred during the transaction, you can
call the Rollback() method to cancels the proposed changes in a pending database transaction
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

8-6
Programmer’s Guide for .NET

•

Chapter 8 – Programming in C++.NET

Querying Object from Database
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:

1.

Query the course objects when user login. When Student login, the system will call ListCourseByQuery()
method in CourseFactory to get all available courses. When Teacher login, the system will call courses
collection variable in Teacher object.
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

•

Updating Object and Saving to Database
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.

8-7
Programmer’s Guide for .NET

Chapter 8 – Programming in C++.NET

1.

From the menu bar, select User > Modify User Information to open the Modify User Information dialog
box.

2.

Enter new user information and click OK to update the User record.

3.

Update the information for the User object includes password, name and email address.
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 cppModifyUserDialog.h

8-8
Programmer’s Guide for .NET

•

Chapter 8 – Programming in C++.NET

Deleting Object in Database
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.
1.

Teacher can create the course by clicking the Add Course button, fill in Course name and Description.

2.

Student can register the course by clicking the Register button.

3.

The teacher can view how many students registered his course, and he can delete the course in the system.

4.

Click Delete of a Course then it will trigger the deleteButton_Click() method.
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 cppSchoolSystemform.h

8-9
Programmer’s Guide for .NET

5.

Chapter 8 – Programming in C++.NET

Call deleteAndDissociate() method to delete the course object and remove the relationships of student and
teacher with it.
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 cppSchoolSystemForm.h

Running the Application
To execute the C++ application, select Debug > Start (F5) on the menu bar Visual Studio .NET 2003.

8-10

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming conceptsGanesh Karthik
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5Mahmoud Ouf
 
chap 8 : The java.lang and java.util Packages (scjp/ocjp)
chap 8 : The java.lang and java.util Packages (scjp/ocjp)chap 8 : The java.lang and java.util Packages (scjp/ocjp)
chap 8 : The java.lang and java.util Packages (scjp/ocjp)It Academy
 
Object Oriented Programming With C++
Object Oriented Programming With C++Object Oriented Programming With C++
Object Oriented Programming With C++Vishnu Shaji
 
Wiesław Kałkus: C# functional programming
Wiesław Kałkus: C# functional programmingWiesław Kałkus: C# functional programming
Wiesław Kałkus: C# functional programmingAnalyticsConf
 
ASP.NET Session 3
ASP.NET Session 3ASP.NET Session 3
ASP.NET Session 3Sisir Ghosh
 
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org)  (usef...Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org)  (usef...
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...Make Mannan
 
C# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slidesC# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slidesSami Mut
 

Was ist angesagt? (11)

Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming concepts
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5
 
chap 8 : The java.lang and java.util Packages (scjp/ocjp)
chap 8 : The java.lang and java.util Packages (scjp/ocjp)chap 8 : The java.lang and java.util Packages (scjp/ocjp)
chap 8 : The java.lang and java.util Packages (scjp/ocjp)
 
Intro.net
Intro.netIntro.net
Intro.net
 
Working in Visual Studio.Net
Working in Visual Studio.NetWorking in Visual Studio.Net
Working in Visual Studio.Net
 
Intake 38 4
Intake 38 4Intake 38 4
Intake 38 4
 
Object Oriented Programming With C++
Object Oriented Programming With C++Object Oriented Programming With C++
Object Oriented Programming With C++
 
Wiesław Kałkus: C# functional programming
Wiesław Kałkus: C# functional programmingWiesław Kałkus: C# functional programming
Wiesław Kałkus: C# functional programming
 
ASP.NET Session 3
ASP.NET Session 3ASP.NET Session 3
ASP.NET Session 3
 
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org)  (usef...Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org)  (usef...
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
 
C# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slidesC# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slides
 

Andere mochten auch

Andere mochten auch (9)

Meeting minutes 9
Meeting minutes 9Meeting minutes 9
Meeting minutes 9
 
Seerat e rasoolearabipbuhpart1noorbushkhtawakali
Seerat e rasoolearabipbuhpart1noorbushkhtawakaliSeerat e rasoolearabipbuhpart1noorbushkhtawakali
Seerat e rasoolearabipbuhpart1noorbushkhtawakali
 
P.a
P.aP.a
P.a
 
Chapter 3f
Chapter 3fChapter 3f
Chapter 3f
 
Chapter 8f
Chapter 8fChapter 8f
Chapter 8f
 
Ahsan danish
Ahsan danishAhsan danish
Ahsan danish
 
Akhtarul iman
Akhtarul imanAkhtarul iman
Akhtarul iman
 
Cambridge english grammar_in_u
Cambridge english grammar_in_uCambridge english grammar_in_u
Cambridge english grammar_in_u
 
Akhtar shirani
Akhtar shiraniAkhtar shirani
Akhtar shirani
 

Ähnlich wie Dbva dotnet programmer_guide_chapter8

Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxNEHARAJPUT239591
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJmeharikiros2
 
Creating simple component
Creating simple componentCreating simple component
Creating simple componentpriya Nithya
 
C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...bhargavi804095
 
Bt0082 visual basic
Bt0082 visual basicBt0082 visual basic
Bt0082 visual basicTechglyphs
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docMayurWagh46
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfoliomwillmer
 
Dot net guide for beginner
Dot net guide for beginner Dot net guide for beginner
Dot net guide for beginner jayc8586
 
Understanding C# in .NET
Understanding C# in .NETUnderstanding C# in .NET
Understanding C# in .NETmentorrbuddy
 
Object-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesObject-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesDurgesh Singh
 
The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84Mahmoud Samir Fayed
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfAnassElHousni
 
Aae oop xp_02
Aae oop xp_02Aae oop xp_02
Aae oop xp_02Niit Care
 
PT1420 File Access and Visual Basic .docx
PT1420 File Access and Visual Basic                      .docxPT1420 File Access and Visual Basic                      .docx
PT1420 File Access and Visual Basic .docxamrit47
 

Ähnlich wie Dbva dotnet programmer_guide_chapter8 (20)

C++Basics2022.pptx
C++Basics2022.pptxC++Basics2022.pptx
C++Basics2022.pptx
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptx
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
 
Creating simple component
Creating simple componentCreating simple component
Creating simple component
 
C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...
 
Bt0082 visual basic
Bt0082 visual basicBt0082 visual basic
Bt0082 visual basic
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).doc
 
2310 b 03
2310 b 032310 b 03
2310 b 03
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
Dot net guide for beginner
Dot net guide for beginner Dot net guide for beginner
Dot net guide for beginner
 
Understanding C# in .NET
Understanding C# in .NETUnderstanding C# in .NET
Understanding C# in .NET
 
Object-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesObject-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modules
 
T2
T2T2
T2
 
The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdf
 
Visual programming
Visual programmingVisual programming
Visual programming
 
Aae oop xp_02
Aae oop xp_02Aae oop xp_02
Aae oop xp_02
 
PT1420 File Access and Visual Basic .docx
PT1420 File Access and Visual Basic                      .docxPT1420 File Access and Visual Basic                      .docx
PT1420 File Access and Visual Basic .docx
 
Csharp
CsharpCsharp
Csharp
 
C# p3
C# p3C# p3
C# p3
 

Mehr von Shakeel Mujahid (20)

Ch 16 Al-Quran +923074302552
Ch 16                    Al-Quran +923074302552Ch 16                    Al-Quran +923074302552
Ch 16 Al-Quran +923074302552
 
Ch 2 Al-Quran +923074302552
Ch 2                   Al-Quran +923074302552Ch 2                   Al-Quran +923074302552
Ch 2 Al-Quran +923074302552
 
Ch 11 Al-Quran +923074302552
Ch 11               Al-Quran +923074302552Ch 11               Al-Quran +923074302552
Ch 11 Al-Quran +923074302552
 
Ch 5 Al-Quran +923074302552
Ch 5               Al-Quran +923074302552Ch 5               Al-Quran +923074302552
Ch 5 Al-Quran +923074302552
 
Ch 3 Al-Quran +923074302552
Ch 3               Al-Quran +923074302552Ch 3               Al-Quran +923074302552
Ch 3 Al-Quran +923074302552
 
The mouse-that-knew
The mouse-that-knewThe mouse-that-knew
The mouse-that-knew
 
Seasons and months pictionary poster worksheet
Seasons and months pictionary poster worksheetSeasons and months pictionary poster worksheet
Seasons and months pictionary poster worksheet
 
Tot
TotTot
Tot
 
Unit 1
Unit 1Unit 1
Unit 1
 
Salam machli shahri
Salam machli shahriSalam machli shahri
Salam machli shahri
 
Ibtidai deeni nisab 2013
Ibtidai deeni nisab 2013Ibtidai deeni nisab 2013
Ibtidai deeni nisab 2013
 
Sameer
SameerSameer
Sameer
 
Proverbs123456
Proverbs123456Proverbs123456
Proverbs123456
 
Proverbs123
Proverbs123Proverbs123
Proverbs123
 
Proverbs
ProverbsProverbs
Proverbs
 
Shazaib
ShazaibShazaib
Shazaib
 
Unit 1
Unit 1Unit 1
Unit 1
 
Seerat e rasoolearabipbuhpart1noorbushkhtawakali
Seerat e rasoolearabipbuhpart1noorbushkhtawakaliSeerat e rasoolearabipbuhpart1noorbushkhtawakali
Seerat e rasoolearabipbuhpart1noorbushkhtawakali
 
Salam machli shahri
Salam machli shahriSalam machli shahri
Salam machli shahri
 
Cambridge english grammar_in_u
Cambridge english grammar_in_uCambridge english grammar_in_u
Cambridge english grammar_in_u
 

Kürzlich hochgeladen

Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Kürzlich hochgeladen (20)

Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

Dbva dotnet programmer_guide_chapter8

  • 2. Programmer’s Guide for .NET Chapter 8 – Programming in C++.NET Chapter 8 - Programming in C++ .NET 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: • • • • • • Introduction Generating DLL file Creating C++ Project Adding Referenced Project Working with the Generating Code and Persistent Library Running the Application Introduction C++ is an Object-Oriented Programming (OOP) language that is viewed by many as the best language for creating large-scale applications. The .NET Framework contains a virtual machine called Common Intermediate Language (CIL). Simply put, programs are compiled to produce CIL and the CIL is distributed to user to run on a virtual machine. C++, VB.NET, C# compilers are available from Microsoft for creating CIL. In DB-VA you can generate C# persistent source code and DLL file, so you can reference the DLL file and persistent library in Visual Studio .NET 2003 and develop the C++ application. 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. Generating DLL File 1. From the menu bar, select Tools > Object-Relational Mapping (ORM) > Generate Database… to open the Database Code Generate dialog box. 2. Check the Compile to DLL option to generate the DLL file. • Compile to DLL 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. 8-2
  • 3. Programmer’s Guide for .NET Chapter 8 – Programming in C++.NET Creating C++ Project 1. 2. Open Microsoft Visual Studio .NET 2003. Select File > New > Project … from the menu. 3. Select Project Types as Visual C++ Projects and Templates as Windows Form Application (.NET) and Location for the new application. 4. The School System Project is created. 5. Right click Standalone School System cpp Project, select Add > Add New Item… from the popup menu. 8-3
  • 4. Programmer’s Guide for .NET Chapter 8 – Programming in C++.NET 6. Select Category as Visual C++, Template Windows Form (.NET) and enter the name for the form called “SchoolSystemForm”. This is the start point for the application. 7. Append the following content to the SchoolSystemForm.cpp file (Source files/SchoolSystemForm.cpp). This is the main method for C++ Application to execute. #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; } 8. Remove the Form1.cpp and Form1.h files. Adding Referenced Project 1. 8-4 Right click References under the Standalone School System C++ project and select Add Reference…. Reference the C# example DDL file and persistent libraries for developing the C++ application.
  • 5. Programmer’s Guide for .NET 2. Chapter 8 – Programming in C++.NET Click Browse… on the Add Reference dialog box to select the folder of the downloaded C# standalone application sample. Select C# sample folder/bin/SchoolSystem.dll and all libraries in C# sample folder/lib. Working with the Generating Code and Persistent Library C# and C++ are both languages that built on the .NET framework and they both accomplish the same thing, just using different language syntax. In this section, you will learn how to work with Generate Code and Persistent Library with C++ language. • Creating Object and Save to Database 1. From the menu bar, select File > Register Student to open the Add Student dialog box. 2. Fill in the student information. Click OK to create the new Student record in School System. 8-5
  • 6. Programmer’s Guide for .NET 3. Chapter 8 – Programming in C++.NET After that, the system creates the new Student Persistent object. 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 4. Set the student information from the text fields value to the Student Object 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 5. Call Save() method of Student Persistent Object and Commit() method of PersistentTransaction, then the new Student object will be saved in database. If there are any errors occurred during the transaction, you can call the Rollback() method to cancels the proposed changes in a pending database transaction 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 8-6
  • 7. Programmer’s Guide for .NET • Chapter 8 – Programming in C++.NET Querying Object from Database 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: 1. Query the course objects when user login. When Student login, the system will call ListCourseByQuery() method in CourseFactory to get all available courses. When Teacher login, the system will call courses collection variable in Teacher object. 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 • Updating Object and Saving to Database 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. 8-7
  • 8. Programmer’s Guide for .NET Chapter 8 – Programming in C++.NET 1. From the menu bar, select User > Modify User Information to open the Modify User Information dialog box. 2. Enter new user information and click OK to update the User record. 3. Update the information for the User object includes password, name and email address. 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 cppModifyUserDialog.h 8-8
  • 9. Programmer’s Guide for .NET • Chapter 8 – Programming in C++.NET Deleting Object in Database 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. 1. Teacher can create the course by clicking the Add Course button, fill in Course name and Description. 2. Student can register the course by clicking the Register button. 3. The teacher can view how many students registered his course, and he can delete the course in the system. 4. Click Delete of a Course then it will trigger the deleteButton_Click() method. 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 cppSchoolSystemform.h 8-9
  • 10. Programmer’s Guide for .NET 5. Chapter 8 – Programming in C++.NET Call deleteAndDissociate() method to delete the course object and remove the relationships of student and teacher with it. 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 cppSchoolSystemForm.h Running the Application To execute the C++ application, select Debug > Start (F5) on the menu bar Visual Studio .NET 2003. 8-10