|
The Form design,
agenda_appoint.cs
Create Visual C# .Net Forn -
agenda_appoint.cs
Classes used in this Form: Label, TextBox, Button,
ComboBox, Panel, ImageList
- On the View menu ,
click Solution Explorer
- In Solution
Explorer
In Solution Explorer, right click the
work_VCnet, select Add on the shortcut menu to
open other shortcut menu, click Add New Item,
the Add New Item - work_VCnet dialog box
appears. |

|
- In the Add New
Item -work_VCnet dialog box:
- In the
Categories pane, select Local Project
Items
- In the Templates
pane, select Windows form . A message
appears - (a form for Windows Applications).
- In the Name
box, type agenda_appoint.cs
- Click
Open
|

|
- In the windows
Forms Designer appears the empty window Form
design
|
1. |
Picture files... |
|
- The folder
c:\work_VCnet\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_VCnet\pic
stored the bmp file
btn_calculator.bmp
- ImageList2
ImageSize:
56,
36
The folder
c:\work_VCnet\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
...
The
text
Code
is red color, the codes added manuel |
|
using
System;
using
System.Drawing;
using
System.Collections;
using
System.ComponentModel;
using
System.Windows.Forms;
namespace
work_VCnet
{
///
<summary>
///
Summary description for agenda_appoint.
///
</summary>
public
class
agenda_appoint : System.Windows.Forms.Form
{
internal
System.Windows.Forms.Button Btn_cancel;
internal
System.Windows.Forms.ImageList ImageList2;
internal
System.Windows.Forms.Label ldate;
internal
System.Windows.Forms.ImageList ImageList1;
internal
System.Windows.Forms.Label ltime;
private
System.Data.OleDb.OleDbConnection oleDbConnection1;
internal
System.Windows.Forms.TextBox txtdescription;
internal
System.Windows.Forms.Panel Paneldata;
internal
System.Windows.Forms.Button Btndetail;
internal
System.Windows.Forms.ComboBox cmbbookid;
internal
System.Windows.Forms.TextBox txtbookid;
internal
System.Windows.Forms.TextBox txtfirst_father;
internal
System.Windows.Forms.TextBox txtname;
internal
System.Windows.Forms.ComboBox cmbfirst_father;
internal
System.Windows.Forms.ComboBox cmbname;
internal
System.Windows.Forms.Label lblfirst_name;
internal
System.Windows.Forms.Label lblname;
internal
System.Windows.Forms.Label ldescription;
internal
System.Windows.Forms.Panel Paneldetail;
internal
System.Windows.Forms.Label Label9;
internal
System.Windows.Forms.Label Label8;
internal
System.Windows.Forms.Label Label7;
internal
System.Windows.Forms.Label Label6;
internal
System.Windows.Forms.Label Label4;
internal
System.Windows.Forms.Label Label3;
internal
System.Windows.Forms.Label Label2;
internal
System.Windows.Forms.Label l_email;
internal
System.Windows.Forms.Label Label5;
internal
System.Windows.Forms.Label l_mobile;
internal
System.Windows.Forms.Label l_phone;
internal
System.Windows.Forms.Label l_city;
internal
System.Windows.Forms.Label l_father;
internal
System.Windows.Forms.Label l_first;
internal
System.Windows.Forms.Label l_name;
internal
System.Windows.Forms.DateTimePicker DateTimePicker1;
internal
System.Windows.Forms.Button Btn_ok;
internal
System.Windows.Forms.Button Btntime;
internal
System.Windows.Forms.Panel Panelinter;
internal
System.Windows.Forms.TextBox txttime;
private
System.ComponentModel.IContainer components;
/// Variables
//Select command
System.Data.OleDb.OleDbCommand
vselect;
//Dataadapter
System.Data.OleDb.OleDbDataAdapter vda;
System.Data.DataSet vdset;
public
agenda_appoint()
{
//
// Required for
Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any
constructor code after InitializeComponent call
//
}
///
<summary>
///
Clean up any resources being used.
///
</summary>
protected
override
void
Dispose( bool
disposing )
{
if(
disposing )
{
if(components
!= null)
{
components.Dispose();
}
}
base.Dispose(
disposing );
}
Windows Form Designer
generated code |
// 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;
}
private void
agenda_appoint_Load(object
sender, System.EventArgs e)
{
//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_VCnet.agenda.agenda_cl.appoint_type)
{
case
"edit":
this.Text
= "edit appointment";
this.txtdescription.Text
= work_VCnet.agenda.agenda_cl.agenda_desc;
this.DateTimePicker1.Value
= work_VCnet.agenda.agenda_cl.appoint_date;
this.txttime.Text
= work_VCnet.aganda_time.aganda_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_VCnet.agenda.agenda_cl.agenda_desc;
this.DateTimePicker1.Value
= work_VCnet.agenda.agenda_cl.appoint_date;
sub_nullovalue();
break;
case
"new":
this.Text
= "new appointment";
this.DateTimePicker1.Value
= work_VCnet.agenda.agenda_cl.appoint_date;
this.txtdescription.Text
= "";
sub_nullovalue();
if (work_VCnet.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_VCnet.agenda.agenda_cl.appoint_date.Month)
+ "/" +
System.Convert.ToString(work_VCnet.agenda.agenda_cl.appoint_date.Day)
+ "/" +
System.Convert.ToString(work_VCnet.agenda.agenda_cl.appoint_date.Year)
+ " ", work_VCnet.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_VCnet.aganda_time.aganda_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_VCnet.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 =
this.oleDbConnection1;
vdset.EnforceConstraints =
false;
try
{
this.oleDbConnection1.Open();
vda.Fill(vdset, "book");
}
catch
(System.Exception fillException)
{
System.Windows.Forms.MessageBox.Show(fillException.Message);
}
vdset.EnforceConstraints =
true;
this.oleDbConnection1.Close();
if
(vdset.Tables["book"].Rows.Count == 0)
{
if
(work_VCnet.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_VCnet.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, System.EventArgs e)
{
sub_load("first",
this.cmbname.Text);
this.cmbfirst_father.Enabled = true;
}
private void
cmbfirst_father_SelectedIndexChanged(object
sender, System.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, System.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, System.EventArgs e)
{
aganda_time Faganda_time =
new
aganda_time();
Faganda_time.Show();
}
//aganda_time
form, response
private void
agenda_appoint_Activated(object
sender, System.EventArgs e)
{
sub_timeok();
}
private void
sub_timeok()
{
if (work_VCnet.aganda_time.aganda_time_cl.time_flag
== true)
{
this.txttime.Text
= work_VCnet.aganda_time.aganda_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, System.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_VCnet.mainform.mainform_cl.Title,
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
else
{
MessageBox.Show("description
value or time value, empty ... not available",
work_VCnet.mainform.mainform_cl.Title,
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
private void
sub_Btn_ok()
{
System.Windows.Forms.DialogResult
response;
switch(work_VCnet.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_VCnet.agenda.agenda_cl.appoint_date.Month)
+ "/" +
System.Convert.ToString(work_VCnet.agenda.agenda_cl.appoint_date.Day)
+ "/" +
System.Convert.ToString(work_VCnet.agenda.agenda_cl.appoint_date.Year)
+ " ", work_VCnet.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_VCnet.agenda.agenda_cl.appoint_date =
this.DateTimePicker1.Value;
work_VCnet.agenda.agenda_cl.agenda_desc =
this.txtdescription.Text;
agenda_appoint_cl.appoint_bookid
= this.txtbookid.Text;
this.Close();
//work_VCnet.book_note.ActiveForm.Refresh();
//work_VCnet.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_VCnet.agenda.agenda_cl.appoint_date.Month)
+ "/" +
System.Convert.ToString(work_VCnet.agenda.agenda_cl.appoint_date.Day)
+ "/" +
System.Convert.ToString(work_VCnet.agenda.agenda_cl.appoint_date.Year)
+ " ", work_VCnet.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_VCnet.agenda.agenda_cl.agenda_desc =
this.txtdescription.Text;
work_VCnet.agenda.agenda_cl.appoint_date =
this.DateTimePicker1.Value;
agenda_appoint_cl.appoint_bookid
= this.txtbookid.Text;
this.Close();
//work_VCnet.book_note.ActiveForm.Refresh();
//work_VCnet.book_note.ActiveForm.Activate();
}
break;
case
"edit":
agenda_appoint_cl.appoint_flag =
true;
work_VCnet.agenda.agenda_cl.agenda_desc =
this.txtdescription.Text;
work_VCnet.agenda.agenda_cl.appoint_date =
this.DateTimePicker1.Value;
this.Close();
//work_VCnet.book_note.ActiveForm.Refresh();
//work_VCnet.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 =
this.oleDbConnection1;
vdset.EnforceConstraints =
false;
try
{
this.oleDbConnection1.Open();
vda.Fill(vdset, "agenda");
}
catch
(System.Exception fillException)
{
System.Windows.Forms.MessageBox.Show(fillException.Message);
}
vdset.EnforceConstraints =
true;
this.oleDbConnection1.Close();
}
private void
Btn_cancel_Click(object
sender, System.EventArgs e)
{
sub_cancel();
}
private void
sub_cancel()
{
agenda_appoint_cl.appoint_flag =
false;
work_VCnet.agenda.agenda_cl.agenda_desc = "";
this.Close();
//work_VCnet.book_note.ActiveForm.Refresh();
//work_VCnet.book_note.ActiveForm.Activate();
}
}
}
| | |
|
|