|
The
Form design, agenda_appoint.vb
Create Visual Basic 2010 Forn
- agenda_appoint.vb
Classes used in this Form: Label, TextBox, Button,
ComboBox, Panel, ImageList
-
Create the Form
agenda_appoint.vb
Add New Item -
agenda_appoint.vb Form to work_VBNet_10
Project
- On the Projet
menu , click Add New Item ...,
Add New Item - work_VBNet_10 dialog box appears, Select
Windows form Icon,
in the Name box type
agenda_appoint.vb and then click
Add.
|
 |
|
Note:
In the Windows Forms Designer appears the
design form created and in the Properties
Windows displays the corresponding properties
and
The design Form agenda_appoint.vb created, appears the empty window Form
design |
|
|
The codes file, created
... |
Public
Class
agenda_appoint
Private
Sub
agenda_appoint_Load(ByVal
sender
As
System.Object,
ByVal e
As
System.EventArgs)
Handles
MyBase.Load
End
Sub
End
Class
|
|
|
|
1. |
Picture files... |
|
- The folder
c:\work_VBNet_10\work_VBNet_10\pic stored the
bmp files oclock.bmp,
btn_ok.bmp, btn_cancel.bmp
|
2. |
The
agenda_appoint.vb
design |
|
 |
The Properties of
the Form -
agenda_appoint.vb... |
Name: Icon: Maximize: Menu: Size: Start
Position: Text: Window
State: |
agenda_appoint Icon False (none)
640,225 CenterScreen
agenda_appoint
... Normal | | | |
3. |
From the Toolbox/Windows Form add these
controls .... 20 Label controls, 5 TextBox
controls, 4 Button
controls, 3 ComboBox controls, 3 Panel
controls, 2 ImageList controls
|
|
- Add
20 Label
controls
- ldate, Label
Properties:
Name:
Font:
Size:
Text:
TextAlign: |
ldate
Microsoft Sans Serif, 8.25pt
72, 16
Date
:
MiddleRight | |
- Label9
- Label8
- Label7
- Label6
- Label4
- Label3
- Label2
- l_email
- Label5
- l_mobile
- l_phone
- l_city
- l_father
- l_first
- l_name
- ltime
- ldescription
- lblname
- lblfirst_name
|
- Add
5 TextBox
controls
- txtdescription, TextBox
Properties
Name:
Multiline
Size: |
txtdescription
True
408,
84 | |
- txtname
Size: 96,
20
- txtfirst_father
Size: 96, 20
-
txttime
Size: 112, 18
- txtbookid
Size: 48,
16
|
- Add
4 Button
controls
- btndetail,
Button
Properties
Name:
BackColor:
Size:
Text: |
btndetail
ActiveBorder
48,
16
detail | |
- Btntime
Size:
15, 15
- Btn_ok
Size: 65,
20
- Btn_cancel
Size: 65,
20
|
- Add
3 ComboBox controls
- cmbname, ComboBox
Properties
Name:
Size: |
cmbname
120,
21 | |
- cmbfirst_father
Size: 120,
21
-
cmbbookid
Size:
32, 21
|
- Add
3 Panel
controls
- Paneldetail, Panel
Properties
Name:
Size: |
Paneldetail
200,
184 | |
- Panelinter
Size:
8,
40
- Paneldata
Size:
224,
74
|
- Add
2 ImageList controls
- ImageList1,
ImageList Properties
Name:
Images:
ImageSize: |
ImageList1
(Collection) - of 1
Bitmap
image
15,
15 | |
The
folder
c:\work_VBNet_10\work_VBNet_10\pic stored the
bmp file
btn_calculator.bmp
- ImageList2
ImageSize:
56, 36
The folder
c:\work_VBNet_10\work_VBNet_10\pic stored the 2 bmp
files
btn_cancel.bmp,
btn_ok.bmp |
- Add the DateTimePicker control
-
DateTimePicker1, DateTimePicker
Properties
Name:
Size: |
Paneldetail
200,
184 | |
| | |
|
agenda_appoint.vb file, the codes after modification
...
Note: Logical Classe
Controls:
1- dbConnection '
connection
2- vselect & vselecta '
Select command
3- vda & vdaa '
Dataadapter
4- vdset & vdseta '
DataSet
|
|
Imports
System.Data.OleDb
Imports System.Data
Public
Class
agenda_appoint
Inherits
System.Windows.Forms.Form
'
logical Connection = dbConnection
Protected
Const
OleDbConnectionString
As
String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\work_VBNet_10\work_VBNet_10\data\work_VBNet.mdb;Persist
Security Info=True"
Protected
connectionString
As
String =
OleDbConnectionString
Dim dbConnection
As
New
OleDbConnection(connectionString)
Dim vselect
As
System.Data.OleDb.OleDbCommand
'
Select command
Dim vselecta
As
System.Data.OleDb.OleDbCommand
'
Select commad
Dim vda
As
System.Data.OleDb.OleDbDataAdapter
'
Dataadapter
Dim vdaa
As
System.Data.OleDb.OleDbDataAdapter
'
Dataadapter
Dim vdset
As
System.Data.DataSet
Dim vdseta
As
System.Data.DataSet
Private
Sub
agenda_appoint_Load(ByVal
sender
As
System.Object,
ByVal e
As
System.EventArgs)
Handles
MyBase.Load
Me.Btntime.Top =
Me.txttime.Top
+ (Me.txttime.Height
- Me.Btntime.Height)
/ 2
Me.Width =
Me.txtdescription.Left
+ Me.txtdescription.Width
+ 7 *
Me.Panelinter.Width
/ 4
Me.Paneldata.BackColor
= Me.BackColor
Me.Panelinter.BackColor
= Me.BackColor
Me.Btn_cancel.Left =
(Me.txtdescription.Left
+ Me.txtdescription.Width)
- Me.Btn_cancel.Width
Me.Btndetail.Left =
(Me.cmbfirst_father.Left
+ Me.cmbfirst_father.Width)
- Me.Btndetail.Width
Me.Btndetail.Text =
"detail"
'initial book Table
vselect =
New
OleDb.OleDbCommand("SELECT
address1, address2, alternativePhone, birth, birth_d,
birth_m, birth_y, bookid, city, civil_status, country,
email, father_name, fax, first_name, function, homephone,
mobilephone, name, originalfirst_name, Photo, [post-office_box],
sex, web, workphone FROM book")
vda =
New
OleDb.OleDbDataAdapter(vselect)
vdset =
New
DataSet
vselect.Connection() = dbConnection
' Select
command
vselect.CommandTimeout = 30
vdset.EnforceConstraints =
False
Try
dbConnection.Open()
vda.Fill(vdset,
"book")
Catch fillException
As
System.Exception
System.Windows.Forms. MessageBox.Show(fillException.Message)
End
Try
vdset.EnforceConstraints =
True
dbConnection.Close()
'inital
agendo Table
vselecta =
New
OleDb.OleDbCommand("SELECT
bookid, branch, datecreated, description, entry_type,
ondate, ondate_d, ondate_m, ondate_y, ontime, serialno,
taskprirority from agenda")
vdaa =
New
OleDb.OleDbDataAdapter(vselecta)
vdseta =
New
DataSet
vselecta.Connection() = dbConnection
' Select
command
vselecta.CommandTimeout = 30
vdseta.EnforceConstraints =
False
Try
dbConnection.Open()
vdaa.Fill(vdset,
"agenda")
Catch fillException
As
System.Exception
System.Windows.Forms. MessageBox.Show(fillException.Message)
End
Try
vdseta.EnforceConstraints =
True
dbConnection.Close()
appoint_flag =
False
'new appointment & edit appointment
Select
Case
appoint_type
Case
"edit"
Me.Text =
"edit
appointment"
Me.txtdescription.Text
= agenda_desc
Me.DateTimePicker1.Value
= appoint_date
Me.txttime.Text =
appoint_time
Me.Btn_ok.Enabled =
False
sub_info( False)
Case
"task_appoint"
fagenda_task.Close()
Me.Text =
"new
appointment - task moved ..."
sub_nullovalue()
Me.DateTimePicker1.Value
= appoint_date
Me.txtdescription.Text
= agenda_desc
Case
"new"
Me.Text =
"new
appointment"
sub_nullovalue()
Me.DateTimePicker1.Value
= appoint_date
Me.txtdescription.Text
= ""
If appoint_full =
True
Then
'with this current date, add new appointmement not
available
MsgBox( "note:
to add new appointment, change the current date - "
+ Format(appoint_date,
"M/d/yyyy")
+ "
",
MsgBoxStyle.DefaultButton1
Or
MsgBoxStyle.Information
Or
MsgBoxStyle.OkOnly,
Title)
End
If
End
Select
End
Sub
Private
Sub
sub_nullovalue()
Me.cmbname.Items.Clear()
Me.cmbfirst_father.Items.Clear()
Me.cmbname.Text =
""
Me.cmbfirst_father.Text
= ""
Me.DateTimePicker1.Value
= appoint_date
Me.txttime.Text =
""
Me.txtname.Text =
""
Me.txtfirst_father.Text
= ""
Me.Btn_ok.Enabled =
False
sub_info( True)
Me.Btndetail.Enabled
=
False
End
Sub
Private
Sub
sub_info(ByVal
bval
As
Boolean)
Me.cmbname.Visible =
bval
Me.cmbfirst_father.Visible
= bval
Me.txtname.Visible =
Not
bval
Me.txtfirst_father.Visible
=
Not bval
Me.txtname.Width =
Me.cmbname.Width
Me.txtfirst_father.Width
= Me.cmbfirst_father.Width
Select
Case
appoint_type
Case
"task_appoint"
sub_load( "name",
"")
Me.cmbfirst_father.Enabled
=
False
Case
"new"
sub_load( "name",
"")
Me.cmbfirst_father.Enabled
=
False
Case
"edit"
Me.txtbookid.Text =
appoint_bookid
'load value corresponding to editbookid.Text
sub_load( "detail",
Trim(Me.txtbookid.Text))
If appoint_bookid <>
""
Then
Me.Btndetail.Enabled
=
True
End
Select
End
Sub
'book table, add data to comboboxes and detail information
Private
Sub
sub_load(ByVal
v_field
As
String,
ByVal
v_fieldname
As
String)
Dim WhereSearch
As
String =
""
Dim i
As
Integer
Dim val_fieldname
As
Integer
'
Me.cmbname.Items.Clear()
'
Me.cmbfirst_father.Items.Clear()
Me.cmbbookid.Items.Clear()
Select
Case
v_field
Case
"name"
WhereSearch =
" WHERE (Trim(name)
<> '')"
vselect =
New
OleDb.OleDbCommand("SELECT
DISTINCT Trim(name) AS vname FROM book"
& WhereSearch &
" ORDER BY
Trim(name)")
Case
"first"
WhereSearch =
" WHERE
(name = '" &
v_fieldname &
"')"
vselect =
New
OleDb.OleDbCommand("SELECT
bookid, name, first_name, father_name FROM book"
& WhereSearch &
" ORDER BY
first_name, father_name")
Case
"detail"
val_fieldname = Val(v_fieldname)
WhereSearch =
" WHERE (bookid
= " & val_fieldname
&
")"
vselect =
New
OleDb.OleDbCommand("SELECT
bookid, city, civil_status, country, email, father_name,
first_name, homephone, mobilephone, name, sex, web,
workphone FROM book"
& WhereSearch)
End
Select
vda =
New
OleDb.OleDbDataAdapter(vselect)
vdset =
New
DataSet
vselect.Connection() = dbConnection
' Select
command
vselect.CommandTimeout = 30
vdset.EnforceConstraints =
False
Try
dbConnection.Open()
vda.Fill(vdset,
"book")
Catch fillException
As
System.Exception
System.Windows.Forms. MessageBox.Show(fillException.Message)
End
Try
vdset.EnforceConstraints =
True
dbConnection.Close()
If vdset.Tables("book").Rows.Count
= 0
Then
If appoint_type =
"edit"
Then
Me.txtname.Text =
"?????"
Me.txtfirst_father.Text
=
"?????"
Exit Sub
End
If
End
If
If vdset.Tables("book").Rows.Count
> 0
Then
For i = 0
To
vdset.Tables("book").Rows.Count
- 1
Select
Case
v_field
Case
"name"
Me.cmbname.Items.Add(Trim(vdset.Tables("book").Rows(i).Item("vname")))
Case
"first"
Me.cmbfirst_father.Items.Add(Trim(vdset.Tables("book").Rows(i).Item("first_name"))
& "
" &
Trim(vdset.Tables("book").Rows(i).Item("father_name")))
Me.cmbbookid.Items.Add(Str(vdset.Tables("book").Rows(i).Item("bookid")))
Case
"detail"
Me.l_name.Text =
Trim(vdset.Tables("book").Rows(i).Item("name"))
If
IsDBNull(vdset.Tables("book").Rows(i).Item("first_name"))
Then
Me.l_first.Text =
"
... "
Else
Me.l_first.Text =
Trim(vdset.Tables("book").Rows(i).Item("first_name"))
End
If
If
IsDBNull(vdset.Tables("book").Rows(i).Item("father_name"))
Then
Me.l_father.Text =
"
... "
Else
Me.l_father.Text =
Trim(vdset.Tables("book").Rows(i).Item("father_name"))
End
If
If
IsDBNull(vdset.Tables("book").Rows(i).Item("city"))
Then
Me.l_city.Text =
"
... "
Else
Me.l_city.Text =
Trim(vdset.Tables("book").Rows(i).Item("city"))
End
If
If
IsDBNull(vdset.Tables("book").Rows(i).Item("homephone"))
Then
Me.l_phone.Text =
"
... "
Else
Me.l_phone.Text =
Trim(vdset.Tables("book").Rows(i).Item("homephone"))
End
If
If
IsDBNull(vdset.Tables("book").Rows(i).Item("mobilephone"))
Then
Me.l_mobile.Text =
"
... "
Else
Me.l_mobile.Text =
Trim(vdset.Tables("book").Rows(i).Item("mobilephone"))
End
If
If
IsDBNull(vdset.Tables("book").Rows(i).Item("email"))
Then
Me.l_email.Text =
"
... "
Else
Me.l_email.Text =
Trim(vdset.Tables("book").Rows(i).Item("email"))
End
If
End
Select
If appoint_type =
"edit"
Then
Me.txtname.Text =
Me.l_name.Text
Me.txtfirst_father.Text
= Me.l_first.Text
& "
" &
Me.l_father.Text
End
If
Next
End
If
End
Sub
'add data to combobox, cmbfirst_father
Private
Sub
cmbname_SelectedIndexChanged(ByVal
sender
As
System.Object,
ByVal e
As
System.EventArgs)
Handles
cmbname.SelectedIndexChanged
sub_load( "first",
Me.cmbname.Text)
Me.cmbfirst_father.Enabled
=
True
End
Sub
Private
Sub
cmbfirst_father_SelectedIndexChanged(ByVal
sender
As
System.Object,
ByVal e
As
System.EventArgs)
Handles
cmbfirst_father.SelectedIndexChanged
Me.txtname.Text =
Me.cmbname.Text
Me.txtfirst_father.Text
= Me.cmbfirst_father.Text
Me.cmbbookid.SelectedIndex
= Me.cmbfirst_father.SelectedIndex
Me.txtbookid.Text =
Me.cmbbookid.Text
sub_load( "detail",
Trim(Me.txtbookid.Text))
Me.Btndetail.Enabled
=
True
End
Sub
'from book table, detail information
Private
Sub
Btndetail_Click(ByVal
sender
As
System.Object,
ByVal e
As
System.EventArgs)
Handles
Btndetail.Click
If
Me.Btndetail.Text
=
"detail"
Then
Me.Width = 2 *
Me.txtdescription.Left
+ Me.txtdescription.Width
+ Me.Paneldetail.Width
+ +7 *
Me.Panelinter.Width
/ 4
Me.Paneldata.BackColor
= Me.Paneldetail.BackColor
Me.Panelinter.BackColor
= Me.Paneldetail.BackColor
Me.Btndetail.Text =
"hide"
Exit Sub
End
If
If
Me.Btndetail.Text
=
"hide"
Then
Me.Width =
Me.txtdescription.Left
+ Me.txtdescription.Width
+ 7 *
Me.Panelinter.Width
/ 4
Me.Paneldata.BackColor
= Me.BackColor
Me.Panelinter.BackColor
= Me.BackColor
Me.Btndetail.Text =
"detail"
End
If
End
Sub
'aganda_time
form, show
Private
Sub
Btntime_Click(ByVal
sender
As
System.Object,
ByVal e
As
System.EventArgs)
Handles
Btntime.Click
faganda_time.ShowDialog()
End
Sub
'aganda_time
form, response
Public
Sub
sub_timeok()
If time_flag
Then
Me.txttime.Text =
appoint_time
Me.Btn_ok.Enabled =
True
End
If
End
Sub
Private
Sub
txtdescription_KeyPress(ByVal
sender
As
Object,
ByVal
e As
System.Windows.Forms.KeyPressEventArgs)
Handles
txtdescription.KeyPress
Me.Btn_ok.Enabled =
True
End
Sub
Private
Sub
Btn_ok_Click(ByVal
sender
As
System.Object,
ByVal e
As
System.EventArgs)
Handles Btn_ok.Click
Dim response
As
MsgBoxResult
If
Me.txtdescription.Text
<>
""
And
Me.txttime.Text
<>
""
Then
If
Me.txttime.Text
<>
""
And
Me.txtfirst_father.Text
<>
""
Then
Select
Case
appoint_type
Case
"task_appoint"
sub_Full( "A",
Me.DateTimePicker1.Value)
If ((vdset.Tables("agenda").Rows.Count
- 1) >= 24)
Then
response = MsgBox( "to
save this appointment, change the current date - "
+ Format(appoint_date,
"M/d/yyyy")
+ "
",
MsgBoxStyle.DefaultButton2
Or
MsgBoxStyle.Information
Or
MsgBoxStyle.YesNo,
Title)
If (response =
MsgBoxResult.Yes)
Then
Exit
Sub
If (response =
MsgBoxResult.No)
Then
sub_cancel()
Else
appoint_flag =
True
appoint_date =
Me.DateTimePicker1.Value
agenda_desc =
Me.txtdescription.Text
appoint_bookid =
Me.txtbookid.Text
Close()
fagenda.aftermove_taskappoint()
End
If
Case
"new"
sub_Full( "A",
Me.DateTimePicker1.Value)
If ((vdset.Tables("agenda").Rows.Count
- 1) >= 24)
Then
'
'with this current date, add new appointmement not
available
response = MsgBox( "to
save this appointment, change the current date - "
+ Format(appoint_date,
"M/d/yyyy")
+ "
",
MsgBoxStyle.DefaultButton2
Or
MsgBoxStyle.Information
Or
MsgBoxStyle.YesNo,
Title)
If (response =
MsgBoxResult.Yes)
Then
Exit
Sub
If (response =
MsgBoxResult.No)
Then
sub_cancel()
Else
appoint_flag =
True
agenda_desc =
Me.txtdescription.Text
appoint_date =
Me.DateTimePicker1.Value
appoint_bookid =
Me.txtbookid.Text
Close()
fagenda.afternew_appoint()
End
If
End
Select
Else
MsgBox( "name
value or first and father value, empty ... not available",
MsgBoxStyle.DefaultButton1
Or
MsgBoxStyle.Information
Or
MsgBoxStyle.OkOnly,
Title)
End
If
Select
Case
appoint_type
Case
"edit"
appoint_flag =
True
agenda_desc =
Me.txtdescription.Text
appoint_date =
Me.DateTimePicker1.Value
Close()
fagenda.afteredit_appoint()
End
Select
Else
MsgBox( "description
value or time value, empty ... not available",
MsgBoxStyle.DefaultButton1
Or
MsgBoxStyle.Information
Or
MsgBoxStyle.OkOnly,
Title)
End
If
End
Sub
Private
Sub
sub_Full(ByVal
v_entry_type
As
String,
ByVal
v_date
As
DateTime)
Dim WhereSearch
As
String =
""
Dim strdate_d
As
String, strdate_m
As
String, strdate_y
As
String
strdate_d = Str(v_date.Day)
strdate_m = Str(v_date.Month)
strdate_y = Str(v_date.Year)
WhereSearch =
" WHERE (entry_type
= '" &
Trim(v_entry_type) &
"') AND (ondate_d
= '" & strdate_d &
"')
AND (ondate_m = '" &
strdate_m &
"') AND (ondate_y
= '" & strdate_y &
"')"
vselect =
New
OleDb.OleDbCommand("SELECT
entry_type, ondate, ondate_d, ondate_m, ondate_y FROM
agenda" &
WhereSearch &
" ORDER BY
serialno")
vdaa =
New
OleDb.OleDbDataAdapter(vselect)
vdset =
New
DataSet
vselect.Connection() = dbConnection
' Select
command
vselect.CommandTimeout = 30
vdset.EnforceConstraints =
False
Try
dbConnection.Open()
vdaa.Fill(vdset,
"agenda")
Catch fillException
As
System.Exception
System.Windows.Forms. MessageBox.Show(fillException.Message)
End
Try
vdset.EnforceConstraints =
True
dbConnection.Close()
End
Sub
Private
Sub
Btn_cancel_Click(ByVal
sender
As
System.Object,
ByVal e
As
System.EventArgs)
Handles
Btn_cancel.Click
sub_cancel()
End
Sub
Private
Sub
sub_cancel()
appoint_flag =
False
agenda_desc =
""
If appoint_type =
"task_appoint"
Then
fagenda.ChkA_Checked(False)
Close()
End
Sub
End
Class
| | |
|
|