|
The
Form design, agenda_appoint.cs
Create Visual C# 2010 Forn -
agenda_appoint.cs
Classes used in this
Form: Label, TextBox, Button,
ComboBox, Panel, ImageList
Create the Form
agenda_appoint.cs
Add New Item -
agenda_appoint.cs Form to work_VCNet10
Project
- On the Projet
menu , click Add New Item ...,
Add New Item - work_VCNet10 dialog box appears, Select
Windows form Icon,
in the Name box type
agenda_appoint.cs 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.cs created, appears the empty window Form
design |
|
The codes file, created
... |
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
namespace
work_VCNet10
{
public
partial
class
agenda_appoint :
Form
{
public
agenda_appoint()
{
InitializeComponent();
}
private
void
agenda_appoint_Load(object
sender,
EventArgs
e)
{
}
}
}
|
|
|
|
|
1. |
Picture files... |
|
- The folder
c:\work_VCNet10\work_VCNet10\pic stored the
bmp files oclock.bmp, btn_ok.bmp,
btn_cancel.bmp
|
2. |
The
agenda_appoint.cs
design |
|
 |
The Properties of
the Form -
agenda_appoint.cs... |
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_VCNet10\work_VCNet10\pic
stored the bmp file
btn_calculator.bmp
- ImageList2
ImageSize:
56,
36
The folder
c:\work_VCNet10\work_VCNet10\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.cs file, the codes after modification
...
Note: Logical Classe-
DbConnection1-
Data Source=C:\work_VCnet10\work_VCnet10\data\work_VCnet.mdb |
|
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using System.Data;
using
System.Drawing;
using System.Linq;
using System.Text;
using
System.Windows.Forms;
namespace
work_VCnet10
{
public
partial
class
agenda_appoint :
Form
{
//variable
//connection
System.Data.OleDb. OleDbConnection
DbConnection1 =
new
System.Data.OleDb.OleDbConnection();
//Select command
System.Data.OleDb. OleDbCommand
vselect;
//Dataadapter
System.Data.OleDb. OleDbDataAdapter
vda;
System.Data. DataSet
vdset;
// public variables
public
class
agenda_appoint_cl
{
public
static
bool
appoint_flag;
public
static
string
appoint_bookid;
public
static
int
appoint_left;
public
static
int
appointtxttime_Left;
public
static
int
appoint_Top;
public
static
int
appointtxttime_Top;
public
static
int
appointtxttime_Height;
}
public
agenda_appoint()
{
InitializeComponent();
}
private
void
agenda_appoint_Load(object
sender,
EventArgs
e)
{
this.DbConnection1.ConnectionString
=
@"Provider=""Microsoft.Jet.OLEDB.4.0"";Data
Source=""C:\work_VCnet10\work_VCnet10\data\work_VCnet.mdb"";Persist
Security Info=False;User ID=Admin;Mode=Share Deny None;Jet
OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet
OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk
Transactions=1;Jet OLEDB:Create System Database=False;Jet
OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale
on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet
OLEDB:SFP=False";
//size ...
agenda_appoint_cl.appoint_left
=
this.Left;
agenda_appoint_cl.appointtxttime_Left
=
this.txttime.Left;
agenda_appoint_cl.appoint_Top
=
this.Top;
agenda_appoint_cl.appointtxttime_Top
=
this.txttime.Top;
agenda_appoint_cl.appointtxttime_Height
=
this.txttime.Height;
this.Btntime.Top =
this.txttime.Top
+ (this.txttime.Height
-
this.Btntime.Height)
/ 2;
this.Width =
this.txtdescription.Left
+
this.txtdescription.Width
+ 7 *
this.Panelinter.Width
/ 4;
this.Paneldata.BackColor
=
this.BackColor;
this.Panelinter.BackColor
=
this.BackColor;
this.Btn_cancel.Left
= (this.txtdescription.Left
+
this.txtdescription.Width)
-
this.Btn_cancel.Width;
this.Btndetail.Left
= (this.cmbfirst_father.Left
+
this.cmbfirst_father.Width)
-
this.Btndetail.Width;
this.Btndetail.Text
=
"detail";
agenda_appoint_cl.appoint_flag
=
false;
//new appointment & edit appointment
switch
(work_VCnet10.agenda.agenda_cl.appoint_type)
{
case
"edit":
this.Text =
"edit
appointment";
this.txtdescription.Text
= work_VCnet10.agenda.agenda_cl.agenda_desc;
this.DateTimePicker1.Value
= work_VCnet10.agenda.agenda_cl.appoint_date;
this.txttime.Text =
work_VCnet10.agenda_time.agenda_time_cl.appoint_time;
this.Btn_ok.Enabled
=
false;
sub_info( false);
break;
case
"task_appoint":
//fagenda_task.Close();
this.Text =
"new
appointment - task moved ...";
this.txtdescription.Text
= work_VCnet10.agenda.agenda_cl.agenda_desc;
this.DateTimePicker1.Value
= work_VCnet10.agenda.agenda_cl.appoint_date;
sub_nullovalue();
break;
case
"new":
this.Text =
"new
appointment";
this.DateTimePicker1.Value
= work_VCnet10.agenda.agenda_cl.appoint_date;
this.txtdescription.Text
= "";
sub_nullovalue();
if (work_VCnet10.agenda.agenda_cl.appoint_full
==
true)
{
//with this current date, add new appointmement not
available
MessageBox.Show("note:
to add new appointment, change the current date - "
+ System.Convert.ToString(work_VCnet10.agenda.agenda_cl.appoint_date.Month)
+
"/" + System.Convert.ToString(work_VCnet10.agenda.agenda_cl.appoint_date.Day)
+
"/" + System.Convert.ToString(work_VCnet10.agenda.agenda_cl.appoint_date.Year)
+ "
", work_VCnet10.mainform.mainform_cl.Title,
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
break;
}
}
private
void
sub_nullovalue()
{
this.cmbname.Items.Clear();
this.cmbfirst_father.Items.Clear();
this.cmbname.Text =
"";
this.cmbfirst_father.Text
= "";
this.txttime.Text =
"";
work_VCnet10. agenda_time.agenda_time_cl.appoint_time
= "";
this.txtname.Text =
"";
this.txtfirst_father.Text
= "";
this.Btn_ok.Enabled
=
false;
sub_info( true);
this.Btndetail.Enabled
=
false;
}
private
void
sub_info(bool
bval)
{
this.cmbname.Visible
= bval;
this.cmbfirst_father.Visible
= bval;
this.txtname.Visible
= !bval;
this.txtfirst_father.Visible
= !bval;
this.txtname.Width =
this.cmbname.Width;
this.txtfirst_father.Width
=
this.cmbfirst_father.Width;
switch
(work_VCnet10.agenda.agenda_cl.appoint_type)
{
case
"task_appoint":
sub_load( "name",
"");
this.cmbfirst_father.Enabled
=
false;
break;
case
"new":
sub_load( "name",
"");
this.cmbfirst_father.Enabled
=
false;
break;
case
"edit":
this.txtbookid.Text
=
agenda_appoint_cl.appoint_bookid;
//load value corresponding to editbookid.Text
sub_load( "detail",
this.txtbookid.Text.Trim());
if (agenda_appoint_cl.appoint_bookid.Trim().Length
> 0)
this.Btndetail.Enabled
=
true;
break;
}
}
//book table, add data to comboboxes and detail
information
private
void
sub_load(string
v_field,
string
v_fieldname)
{
int i;
int val_fieldname;
switch (v_field)
{
case
"name":
vselect =
new
System.Data.OleDb.OleDbCommand("SELECT
DISTINCT Trim(name) AS vname FROM book WHERE (Trim(name)
<> '') ORDER BY Trim(name)");
break;
case
"first":
vselect =
new
System.Data.OleDb.OleDbCommand("SELECT
bookid, name, first_name, father_name FROM book WHERE
(name = '" +
v_fieldname +
"') ORDER
BY first_name, father_name");
break;
case
"detail":
val_fieldname = System. Convert.ToInt32(v_fieldname);
vselect =
new
System.Data.OleDb.OleDbCommand("SELECT
bookid, city, civil_status, country, email, father_name,
first_name, homephone, mobilephone, name, sex, web,
workphone FROM book WHERE (bookid = "
+ val_fieldname +
")");
break;
}
vda =
new
System.Data.OleDb.OleDbDataAdapter(vselect);
vdset =
new
System.Data.DataSet();
vselect.Connection = DbConnection1;
vdset.EnforceConstraints =
false;
try
{
DbConnection1.Open();
vda.Fill(vdset,
"book");
}
catch (System.Exception
fillException)
{
System.Windows.Forms. MessageBox.Show(fillException.Message);
}
vdset.EnforceConstraints =
true;
DbConnection1.Close();
if (vdset.Tables["book"].Rows.Count
== 0)
{
if (work_VCnet10.agenda.agenda_cl.appoint_type
==
"edit")
{
this.txtname.Text =
"?????";
this.txtfirst_father.Text
=
"?????";
return;
}
}
if (vdset.Tables["book"].Rows.Count
> 0)
{
for (i = 0; i <= (vdset.Tables["book"].Rows.Count
- 1); i++)
{
switch (v_field)
{
case
"name":
this.cmbname.Items.Add(vdset.Tables["book"].Rows[i]["vname"].ToString().Trim());
break;
case
"first":
this.cmbfirst_father.Items.Add(vdset.Tables["book"].Rows[i]["first_name"].ToString().Trim()
+ "
" + vdset.Tables["book"].Rows[i]["father_name"].ToString().Trim());
this.cmbbookid.Items.Add(System.Convert.ToString(vdset.Tables["book"].Rows[i]["bookid"]));
break;
case
"detail":
this.l_name.Text =
vdset.Tables["book"].Rows[i]["name"].ToString().Trim();
if (vdset.Tables["book"].Rows[i]["first_name"].ToString().Trim().Length
== 0)
{
this.l_first.Text =
"
... ";
}
else
this.l_first.Text =
vdset.Tables["book"].Rows[i]["first_name"].ToString().Trim();
if (vdset.Tables["book"].Rows[i]["father_name"].ToString().Trim().Length
== 0)
{
this.l_father.Text =
"
... ";
}
else
this.l_father.Text =
vdset.Tables["book"].Rows[i]["father_name"].ToString().Trim();
if (vdset.Tables["book"].Rows[i]["city"].ToString().Trim().Length
== 0)
{
this.l_city.Text =
"
... ";
}
else
this.l_city.Text =
vdset.Tables["book"].Rows[i]["city"].ToString().Trim();
if (vdset.Tables["book"].Rows[i]["homephone"].ToString().Trim().Length
== 0)
{
this.l_phone.Text =
"
... ";
}
else
this.l_phone.Text =
vdset.Tables["book"].Rows[i]["homephone"].ToString().Trim();
if (vdset.Tables["book"].Rows[i]["mobilephone"].ToString().Trim().Length
== 0)
{
this.l_mobile.Text =
"
... ";
}
else
this.l_mobile.Text =
vdset.Tables["book"].Rows[i]["mobilephone"].ToString().Trim();
if (vdset.Tables["book"].Rows[i]["email"].ToString().Trim().Length
== 0)
{
this.l_email.Text =
"
... ";
}
else
this.l_email.Text =
vdset.Tables["book"].Rows[i]["email"].ToString().Trim();
break;
}
if (work_VCnet10.agenda.agenda_cl.appoint_type
==
"edit")
{
this.txtname.Text =
this.l_name.Text;
this.txtfirst_father.Text
=
this.l_first.Text +
" "
+
this.l_father.Text;
}
}
}
}
private
void
cmbname_SelectedIndexChanged(object
sender,
EventArgs
e)
{
sub_load( "first",
this.cmbname.Text);
this.cmbfirst_father.Enabled
=
true;
}
private
void
cmbfirst_father_SelectedIndexChanged(object
sender,
EventArgs
e)
{
this.txtname.Text =
this.cmbname.Text;
this.txtfirst_father.Text
=
this.cmbfirst_father.Text;
this.cmbbookid.SelectedIndex
=
this.cmbfirst_father.SelectedIndex;
this.txtbookid.Text
=
this.cmbbookid.Text;
sub_load( "detail",
this.txtbookid.Text.Trim());
this.Btndetail.Enabled
=
true;
}
//from book table, detail information
private
void
Btndetail_Click(object
sender,
EventArgs
e)
{
if (this.Btndetail.Text
==
"detail")
{
this.Width = 2 *
this.txtdescription.Left
+
this.txtdescription.Width
+
this.Paneldetail.Width
+ 7 *
this.Panelinter.Width
/ 4;
this.Paneldata.BackColor
=
this.Paneldetail.BackColor;
this.Panelinter.BackColor
=
this.Paneldetail.BackColor;
this.Btndetail.Text
=
"hide";
return;
}
if (this.Btndetail.Text
==
"hide")
{
this.Width =
this.txtdescription.Left
+
this.txtdescription.Width
+ 7 *
this.Panelinter.Width
/ 4;
this.Paneldata.BackColor
=
this.BackColor;
this.Panelinter.BackColor
=
this.BackColor;
this.Btndetail.Text
=
"detail";
}
}
private
void
Btntime_Click(object
sender,
EventArgs
e)
{
agenda_time
Fagenda_time =
new
agenda_time();
Fagenda_time.Show();
}
//agenda_time form, response
private
void
agenda_appoint_Activated(object
sender,
EventArgs
e)
{
sub_timeok();
}
private
void
sub_timeok()
{
if (work_VCnet10.agenda_time.agenda_time_cl.time_flag
==
true)
{
this.txttime.Text =
work_VCnet10.agenda_time.agenda_time_cl.appoint_time;
this.Btn_ok.Enabled
=
true;
}
}
private
void
txtdescription_KeyPress(object
sender, System.Windows.Forms.KeyPressEventArgs
e)
{
this.Btn_ok.Enabled
=
true;
}
private
void
Btn_ok_Click(object
sender,
EventArgs
e)
{
if ((this.txtdescription.Text.Trim().Length
> 0) && (this.txttime.Text.Trim().Length
> 0))
{
if ((this.txtname.Text.Trim().Length
> 0) && (this.txtfirst_father.Text.Trim().Length
> 0))
{
sub_Btn_ok();
return;
}
else
{
MessageBox.Show("name
value or first and father value, empty ... not available",
work_VCnet10.mainform.mainform_cl.Title,
MessageBoxButtons.OK,
MessageBoxIcon.Information);
return;
}
}
else
{
MessageBox.Show("description
value or time value, empty ... not available",
work_VCnet10.mainform.mainform_cl.Title,
MessageBoxButtons.OK,
MessageBoxIcon.Information);
return;
}
}
private
void
sub_Btn_ok()
{
System.Windows.Forms. DialogResult
response;
switch
(work_VCnet10.agenda.agenda_cl.appoint_type)
{
case
"task_appoint":
sub_Full( "A",
this.DateTimePicker1.Value);
if ((vdset.Tables["agenda"].Rows.Count
- 1) >= 24)
{
response =
MessageBox.Show("to
save the current appointment ..., change the current date
- " + System.Convert.ToString(work_VCnet10.agenda.agenda_cl.appoint_date.Month)
+
"/" + System.Convert.ToString(work_VCnet10.agenda.agenda_cl.appoint_date.Day)
+
"/" + System.Convert.ToString(work_VCnet10.agenda.agenda_cl.appoint_date.Year)
+ "
", work_VCnet10.mainform.mainform_cl.Title,
MessageBoxButtons.YesNo,
MessageBoxIcon.Information);
if (response ==
DialogResult.Yes)
return;
if (response ==
DialogResult.No)
{
sub_cancel();
return;
}
}
else
{
agenda_appoint_cl.appoint_flag
=
true;
work_VCnet10. agenda.agenda_cl.appoint_date
=
this.DateTimePicker1.Value;
work_VCnet10. agenda.agenda_cl.agenda_desc
=
this.txtdescription.Text;
agenda_appoint_cl.appoint_bookid
=
this.txtbookid.Text;
this.Close();
//work_VCnet10.book_note.ActiveForm.Refresh();
//work_VCnet10.book_note.ActiveForm.Activate();
}
break;
case
"new":
sub_Full( "A",
this.DateTimePicker1.Value);
if ((vdset.Tables["agenda"].Rows.Count
- 1) >= 24)
{
//with this current date, add new appointmement not
available
response =
MessageBox.Show("to
save this appointment, change the current date - "
+ System.Convert.ToString(work_VCnet10.agenda.agenda_cl.appoint_date.Month)
+
"/" + System.Convert.ToString(work_VCnet10.agenda.agenda_cl.appoint_date.Day)
+
"/" + System.Convert.ToString(work_VCnet10.agenda.agenda_cl.appoint_date.Year)
+ "
", work_VCnet10.mainform.mainform_cl.Title,
MessageBoxButtons.YesNo,
MessageBoxIcon.Information);
if (response ==
DialogResult.Yes)
return;
if (response ==
DialogResult.No)
{
sub_cancel();
return;
}
}
else
{
agenda_appoint_cl.appoint_flag
=
true;
work_VCnet10. agenda.agenda_cl.agenda_desc
=
this.txtdescription.Text;
work_VCnet10. agenda.agenda_cl.appoint_date
=
this.DateTimePicker1.Value;
agenda_appoint_cl.appoint_bookid
=
this.txtbookid.Text;
this.Close();
//work_VCnet10.book_note.ActiveForm.Refresh();
//work_VCnet10.book_note.ActiveForm.Activate();
}
break;
case
"edit":
agenda_appoint_cl.appoint_flag
=
true;
work_VCnet10. agenda.agenda_cl.agenda_desc
=
this.txtdescription.Text;
work_VCnet10. agenda.agenda_cl.appoint_date
=
this.DateTimePicker1.Value;
this.Close();
//work_VCnet10.book_note.ActiveForm.Refresh();
//work_VCnet10.book_note.ActiveForm.Activate();
break;
}
}
private
void
sub_Full(string
v_entry_type, System.DateTime
v_date)
{
string strdate_d;
string strdate_m;
string strdate_y;
strdate_d = System. Convert.ToString(v_date.Day);
strdate_m = System. Convert.ToString(v_date.Month);
strdate_y = System. Convert.ToString(v_date.Year);
vselect =
new
System.Data.OleDb.OleDbCommand("SELECT
entry_type, ondate, ondate_d, ondate_m, ondate_y FROM
agenda WHERE (entry_type = '"
+ v_entry_type +
"') AND (ondate_d
= '" + strdate_d +
"')
AND (ondate_m = '" +
strdate_m +
"') AND (ondate_y
= '" + strdate_y +
"')
ORDER BY serialno");
vda =
new
System.Data.OleDb.OleDbDataAdapter(vselect);
vdset =
new
System.Data.DataSet();
vselect.Connection = DbConnection1;
vdset.EnforceConstraints =
false;
try
{
DbConnection1.Open();
vda.Fill(vdset,
"agenda");
}
catch (System.Exception
fillException)
{
System.Windows.Forms. MessageBox.Show(fillException.Message);
}
vdset.EnforceConstraints =
true;
DbConnection1.Close();
}
private
void
Btn_cancel_Click(object
sender,
EventArgs
e)
{
sub_cancel();
}
private
void
sub_cancel()
{
agenda_appoint_cl.appoint_flag
=
false;
work_VCnet10. agenda.agenda_cl.agenda_desc
= "";
this.Close();
//work_VCnet10.book_note.ActiveForm.Refresh();
//work_VCnet10.book_note.ActiveForm.Activate();
}
}
}
| | |
|
|