Public
Class
agenda_appoint
Inherits System.Windows.Forms.Form
Dim vselect As
System.Data.OleDb.OleDbCommand ' Select command
Dim vda As
System.Data.OleDb.OleDbDataAdapter ' Dataadapter
Dim vdset As
System.Data.DataSet
Windows Form Designer
generated code |
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"
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() =
fagenda.OleDbConnection1
' Select command
vselect.CommandTimeout = 30
vdset.EnforceConstraints =
False
Try
fagenda.OleDbConnection1.Open()
vda.Fill(vdset, "book")
Catch
fillException As
System.Exception
System.Windows.Forms.MessageBox.Show(fillException.Message)
End
Try
vdset.EnforceConstraints =
True
fagenda.OleDbConnection1.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
Dim
i As
Integer
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")
vda =
New
OleDb.OleDbDataAdapter(vselect)
vdset =
New
DataSet
vselect.Connection() =
fagenda.OleDbConnection1
' Select command
vselect.CommandTimeout = 30
vdset.EnforceConstraints =
False
Try
fagenda.OleDbConnection1.Open()
vda.Fill(vdset, "agenda")
Catch
fillException As
System.Exception
System.Windows.Forms.MessageBox.Show(fillException.Message)
End
Try
vdset.EnforceConstraints =
True
fagenda.OleDbConnection1.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
|