|
 |
1test Database Window Application
developed with Microsoft Visual C#
2019 | |
 |
|
|
|
|
|
|
|
The Microsoft Visual C# 2019 member of the Microsoft
Visual Studio Community 2019 |
|
|
|
|
|
|
|
1test
Database
Window Application.., describe
how to use Microsoft Visual C# 2019 to create game application
1- |
1test Database Application Executable (exe file)
| |
|
-
1test
Database Software,
Developed with
Microsoft Visual
C# 2019 (& used .Net
Framework 4.7.2),
but The Microsoft Access database manage the data.
(The Microsoft
Access database
file -
KJV2002.mdb)
-
Functions: Navigate,
Search, ....
-
Executable
Database Software
(exe file), Developed with
Microsoft Visual C# 2019
|
 | |
|
|
2- |
The
Microsoft Visual C# 2019 member of the Microsoft
Visual Studio Community 2019 |
|
|
3- |
How Create
a C# application project. |
|
-
Open Visual Studio 2019.
-
On the start window, choose Create
a new project.
-
On the Create
a new project window, choose
the Windows
Forms App (.NET Framework) template for
C#.
(If you prefer, you can refine your search to quickly get to
the template you want. For example, enter or type Windows
Forms App in the search box. Next,
choose C# from
the Language list, and then choose Windows from
the Platform list.)
-
In the Configure
your new project window, type or
enter HelloWorld in
the Project
name box. Then,
choose Create.
-
Visual Studio opens your new project.
-
Create the application After you
select your C# project template and name your file, Visual Studio
opens a form for you. A form is a Windows user interface.
We'll create a "Hello World" application by adding controls
to the form, and then we'll run the application.
-
Note:
the Name of the
default Form created - Form1.cs, Before to Add controls,
it is Available to Modify the name and Proprieties of this
Form
-
Add
a "Controls" to this form ...
-
Note: Example, to Create DataSource / Dataset ... - KJV2002.mdb
|
|
|
 |
Note: Example, to Create DataSource / Dataset ... - KJV2002.mdb | |
|
|
1- |
Create a dataset for an .mdb
file - (Ex: KJV2002.mdb) |
|
|
1.1- |
Connect to databases created with Access 2000-2003 by
using the following procedure.
- Open a Windows Forms or WPF application project in Visual Studio.
- On the View menu, select Other
Windows > Data Sources.
- In the Data Sources window, click Add New
Data Source
The Data Source Configuration
Wizard opens.
.
- Select Database on the Choose a Data Source
Type page, and then select Next.
- Select Dataset on the Choose a Database
Model page, and then select
Next.
-
Add & Test
Connection
- On the Choose your Data Connection page, select New Connection to configure a new data connection
-
If the data source is not Microsoft Access Database File
(OLE DB), select Change to open the Change Data Source dialog box and select Microsoft Access Database File, and then select OK.
-
In the Database file name, specify the path and
name of the .mdb file you want to connect to, and then select OK.

-
Select Next on the Choose your Data
Connection page.
-
Select Next on the Save connection string
to the Application Configuration file page.
-
Expand the Tables node on the Choose your
Database Objects page.
-
Select whatever tables or views you want in your dataset
, and then select Finish.
The dataset is added to your project, and the tables and views appear
in the Data Sources window.
|
|
|
2- |
Drag a data source from
the Data Sources window onto a form design surface
|
|
You can drag a data source from the Data
Sources window onto a form design surface or control. This causes
boilerplate code to be generated that displays the data from the data
store.
The following illustration shows a dataset that has been dropped onto a
Windows form. If you select F5 on the application, the
data from the underlying database appears in the form's controls.
|
|
|
|
|
|
| | | |
|
|
|
|
|
|
|
|
4- |
1test Database Proprieties and
Solution
Explorer |
|
- 1test Database
Proprieties:
- the
Assembly/Project name : 1test
-
Assembly Project Folder: C:\Users\...\source\repos\1test\
-
the Target framework: .Net Framework 4.7.2
-
the Output
type: Window Application
-
Startup
object: 1test.Program
|
 |
-
1test Solution Explorer
- 1test project developed
with C# 2019, consist of:
- 2
Form files
Form1.cs,
Form2.cs -
1
Folder - pic
pic folder stores 1 picture file and 1 Micosoft Access database
file - KJV2002.mdb
|
|
 |
|
|
|
5- |
How
to Run this
application
|
|
-
Remove the read-only attribute
of all files in the folder -
C:\Users\...\source\repos\1test
-
Run
the Microsoft Visual Studio
Community 2019.
-
From
File menu, choose
Open then
choose Project/Solution,
the Open Project dialog
box appears, select the
1test project file -Type:
Microsoft Visual Studio Solution
(C:\Users\...\source\repos\1test \1test .sln)
and then click Open.
-
From
Debug menu, choose and
click Start Debugging
|
|
|
6- |
After
running 1test, the following View design
display by order |
|
|
 |
1test Database Application developed with Microsoft
Visual Studio Community 2019, C# - Face Game
| |
1test Database Application
developed with Microsoft
Visual
Studio Community 2019, C# - Face
Game |
1. |
- Database Software,
using Access file
- KJV2002.mdb.
- Functions: Navigation, Search
and Animation.
- Includes
2 Forms, where using 2 methods,
Automatically and Manuel,
- Classes used :
DataSet, Button,
ComboBox, Label,
TabControl,
ListView,
PictureBox, TextBox,
StausBar, TextBox,Timer
- Software Classes:
Connection and DataAdapter
|
2. |
1st Form -
Form1.cs |
|
The designer View
|
 |
Functions
|
Using Automatically (Wizard) Method to
add datasourse functions to Form :
Navigate buttons between the records, add
new record, save record and delete record | |
3. |
2nd Form
- Form2.cs |
|
The designer View
|
 |
Functions
|
- Using Automatically (Wizard) aManuel
Methods to add datasourse functions to Forms :
Navigate buttons between the records, add
new record, save record and delete record
| |
| | | |
|
|
|
|
|
|
7- |
Form1.cs,
1st
Form of 1test project/Application |
|
7.1 |
View Design |
|
 |
|
|
7.2 |
View
Codes |
|
|
 |
the
Code of Form1
Form | |
the Code of Form1
Form of 1test Database Application
developed with
Microsoft Visual
Studio Community 2019, C# - Face
Game |
|
|
|
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
using
System.Windows.Forms;
namespace
_1test
{
public
partial
class
Form1
: Form
{
public
Form1()
{
InitializeComponent();
}
private
void
BibleTableBindingNavigatorSaveItem_Click(object
sender, EventArgs e)
{
this.Validate();
this.BibleTableBindingSource.EndEdit();
this.TableAdapterManager.UpdateAll(this.KJV2002BookDSet);
}
private
void
Form1_Load(object
sender, EventArgs e)
{
// TODO: This line of code
loads data into the
'kJV2002BookDSet.BibleTable'
table. You can move, or
remove it, as needed.
this.BibleTableTableAdapter.Fill(this.KJV2002BookDSet.BibleTable);
}
private
void
Button1_Click(object
sender, EventArgs e)
{
Form2 frm =
new
Form2();
frm.Show();
}
private
void
button2_Click(object
sender, EventArgs e)
{
Application.Exit();
}
}
} |
|
| | | |
|
| |
|
|
8- |
Form2.cs,
2nd
Form of 1test
project/Application |
|
8.1 |
View
Design |
|
|
|
 |
8.2 |
View
Codes |
|
|
 |
the
Code of Form2
Form | |
the Code of Form2.cs Form
of
1test Database Application
developed with
Microsoft Visual
Studio Community 2019, C# - Face
Game |
|
|
|
using System;
using
System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _1test
{
public partial class Form2 :
Form
{
//Variable
int vrow;
int View_Listview = 0;
public Form2()
{
InitializeComponent();
}
private void
BibleTableBindingNavigatorSaveItem_Click(object
sender, EventArgs e)
{
this.Validate();
this.BibleTableBindingSource.EndEdit();
this.TableAdapterManager.UpdateAll(this.KJV2002BookDSet);
}
private void
Form2_Load(object sender,
EventArgs e)
{
// TODO: This line of code
loads data into the
'kJV2002BookDSet.BibleTable'
table. You can move, or
remove it, as needed.
this.BibleTableTableAdapter.Fill(this.KJV2002BookDSet.BibleTable);
//Navigation
this.PItextBox1.Text =
this.BibleTableBindingSource.Position.ToString();
this.CtextBox2.Text = "of " +
this.BibleTableBindingSource.Count.ToString();
//Combobox
this.Cmbbook.Text = "Select";
for (vrow = 2; vrow <=
this.KJV2002BookDSet.BibleTable.Rows.Count
- 1; vrow++)
{
if
((KJV2002BookDSet.BibleTable.Rows[vrow]["Chapter"].ToString()
== "001") &&
(KJV2002BookDSet.BibleTable.Rows[vrow]["Verse"].ToString()
== "001"))
{
//
this.cmbtitle.Items.Add(kJV2002BookDSet.BibleTable.Rows[vrow]["BookTitle"].ToString());
this.Cmbbook.Items.Add(KJV2002BookDSet.BibleTable.Rows[vrow]["Book"].ToString());
}
}
//View is Detail
View_Listview = 1;
this.Btnview.Text = "View
Details";
this.ListView0.View =
View.Details;
}
private void
Fbutton1_Click(object sender,
EventArgs e)
{
this.BibleTableBindingSource.MoveFirst();
PItextBox1.Text =
this.BibleTableBindingSource.Position.ToString();
this.CtextBox2.Text = "of" +
"" +
this.BibleTableBindingSource.Count.ToString();
}
private void
Pbutton2_Click(object sender,
EventArgs e)
{
this.BibleTableBindingSource.MovePrevious();
this.PItextBox1.Text =
this.BibleTableBindingSource.Position.ToString();
this.CtextBox2.Text = "of " +
this.BibleTableBindingSource.Count.ToString();
}
private void
Lbutton4_Click(object sender,
EventArgs e)
{
this.BibleTableBindingSource.MoveLast();
this.PItextBox1.Text =
this.BibleTableBindingSource.Position.ToString();
this.CtextBox2.Text = "of " +
this.BibleTableBindingSource.Count.ToString();
}
private void
Nbutton3_Click(object sender,
EventArgs e)
{
this.BibleTableBindingSource.MoveNext();
this.PItextBox1.Text =
this.BibleTableBindingSource.Position.ToString();
this.CtextBox2.Text = "of " +
this.BibleTableBindingSource.Count.ToString();
}
private void
Cmbbook_SelectedIndexChanged(object
sender, EventArgs e)
{
int vrow1;
//---------------
for (vrow1 = 2; vrow1 <=
KJV2002BookDSet.BibleTable.Rows.Count
- 1; vrow1++)
{
if
((KJV2002BookDSet.BibleTable.Rows[vrow1]["Book"].ToString()
==
this.Cmbbook.SelectedItem.ToString())
&&
(KJV2002BookDSet.BibleTable.Rows[vrow1]["Chapter"].ToString()
== "001") &&
(KJV2002BookDSet.BibleTable.Rows[vrow1]["Verse"].ToString()
== "001"))
{
// VPos = vrow;
//
this.cmbchapter.Items.Add(kJV2002BookDSet.BibleTable.Rows[vrow]["Chapter"].ToString());
//
this.cmbverse.Items.Add(kJV2002BookDSet.BibleTable.Rows[vrow]["Verse"].ToString());
//
// VPos = vrow;
this.BibleTableBindingSource.Position
= vrow1; // VPosition;
this.TesttextBox1.Text =
this.BibleTableBindingSource.Position.ToString();
this.PItextBox1.Text =
this.BibleTableBindingSource.Position.ToString();
this.CtextBox2.Text = "of " +
this.BibleTableBindingSource.Count.ToString();
//
this.bibleTableBindingSource.PositionChanged();
// goto NextA1;
}
}
// NextA1:
//--------------
}
private void
Btnsearch_Click(object
sender, EventArgs e)
{
// Variable
int IFound = 0;
//
// selectCMD = new
System.Data.OleDb.OleDbCommand("SELECT
Book, BookTitle, Chapter,
Verse, TextData FROM
BibleTable ORDER BY Book,
Chapter, Verse",
this.oleDbConnection1);
// selectCMD.Connection =
this.oleDbConnection1;
// bookDA.SelectCommand =
selectCMD;
// KJVDSet = new
System.Data.DataSet();
//
this.oleDbConnection1.Open();
// bookDA.Fill(KJVDSet, "BibleTable");
//
this.oleDbConnection1.Close();
// Clear ...
this.ListView0.Clear();
// Allow the user to edit
item text.
this.ListView0.LabelEdit =
true;
// Allow the user to
rearrange columns.
this.ListView0.AllowColumnReorder
= true;
// Select the item and
subitems when selection is
made.
this.ListView0.FullRowSelect
= true;
// Display grid lines.
this.ListView0.GridLines =
true;
// Column Header
this.ListView0.Columns.Add("Record
#", 60,
HorizontalAlignment.Center);
this.ListView0.Columns.Add("Book",
45, HorizontalAlignment.Left);
this.ListView0.Columns.Add("Book
title", 80,
HorizontalAlignment.Left);
this.ListView0.Columns.Add("Chapter",
55, HorizontalAlignment.Left);
this.ListView0.Columns.Add("Verse",
55, HorizontalAlignment.Left);
for (vrow = 2; vrow <=
KJV2002BookDSet.BibleTable.Rows.Count
- 1; vrow++)
{
// Use RichEdit control to
store TextData field
this.TDWtextBox1.Text =
KJV2002BookDSet.BibleTable.Rows[vrow]["TextData"].ToString().ToLower();
// Search by Word operation,
Use the Find function of
RichText control if the
TxtWord Value exist
if
(this.TDWtextBox1.Find(this.TxtWord.Text.ToLower())
!= -1)
{
// Create item and four sets
of subitems.
ListViewItem item1 = new
ListViewItem(System.Convert.ToString(vrow),
0);
// Place a check mark next to
the item.
item1.SubItems.Add(KJV2002BookDSet.BibleTable.Rows[vrow]["Book"].ToString());
item1.SubItems.Add(KJV2002BookDSet.BibleTable.Rows[vrow]["BookTitle"].ToString());
item1.SubItems.Add(KJV2002BookDSet.BibleTable.Rows[vrow]["Chapter"].ToString());
item1.SubItems.Add(KJV2002BookDSet.BibleTable.Rows[vrow]["Verse"].ToString());
//Add the items to the
ListView.
ListView0.Items.AddRange(new
ListViewItem[] { item1 });
// Number of verse found
IFound = IFound + 1;
if (IFound > 5000)
{
this.lbinfo1.Text = " Search
results for [" +
this.TxtWord.Text + "] - more
then" +
System.Convert.ToString(IFound)
+ " verses found.";
goto ExitPt;
}
}
}
//'Display the number of
items found
if (IFound > 0)
this.lbinfo1.Text = " Search
results for [" +
this.TxtWord.Text + "] - " +
System.Convert.ToString(IFound)
+ " verses found.";
else
{
this.lbinfo1.Text = " Search
results for [" +
this.TxtWord.Text + "] - 0
verse found.";
}
ExitPt:
this.TxtWord.Text = "";
this.TxtWord.Enabled = true;
this.Btnsearch.Enabled =
false;
this.Btnview.Enabled = true;
}
private void
TxtWord_KeyPress(object
sender, KeyPressEventArgs e)
{
// btnSearch is enabled, if
the lenght of the word typed
in the TxtWord control > 1
if (this.TxtWord.Text.Length
>= 1)
{
this.Btnsearch.Enabled =
true;
this.Btnview.Enabled = false;
}
}
private void
Btnview_Click(object sender,
EventArgs e)
{
View_Listview = View_Listview
+ 1;
switch (View_Listview)
{
case 1:
this.ListView0.View =
View.Details;
this.Btnview.Text = "View
Details";
break;
case 2:
this.ListView0.View =
View.LargeIcon;
this.Btnview.Text = "View L
Icon";
break;
case 3:
this.ListView0.View =
View.List;
this.Btnview.Text = "View
List";
break;
case 4:
this.ListView0.View =
View.SmallIcon;
this.Btnview.Text = "View S
Icon";
break;
case 5:
goto case 1;
}
}
private void
ListView0_Click(object
sender, EventArgs e)
{
//
this.BindingContext[KJV2002BookDSet,
"BibleTable"].Position =
System.Convert.ToInt16(this.ListView0.SelectedItems[0].Text);
// convert string to int
this.BibleTableBindingSource.Position
=
System.Convert.ToInt16(this.ListView0.SelectedItems[0].Text);
// convert string to int
//
this.kJV2002BookDSet_PositionChanged();
this.PItextBox1.Text =
this.BibleTableBindingSource.Position.ToString();
this.CtextBox2.Text = "of " +
this.BibleTableBindingSource.Count.ToString();
}
private void
button1_Click(object sender,
EventArgs e)
{
this.Close();
}
}
} |
|
| | | |
|
| |
|
|
|
|
|
| | | |