|
The Form design,
agenda_appoint
Create Delphi 8 Windows Forn -
agenda_appoint
Classes used in this Form: System.Drawing,
System.Collections, System.ComponentModel, System.Windows.Forms,
System.Data, System.Resources;
Type of Controls
used in this Form: Label, TextBox, Button,
ComboBox, Panel, ImageList
Create the Form
agenda_tappoint
- On the File menu ,
click New. and then click Windows Form
- New File
name WinForm.pas appears. (Form name - TWinForm)
- On the View menu ,
click Object Inspector. In Object Inspector
modify the following .
|
|
1. |
WinForm.pas - the File name created
|
|
|
Old |
New |
File
Name: |
WinForm.pas |
agenda_appoint.,pas |
|
|
|
|
2. |
TWinForm- Form name created
|
|
|
Old |
New |
Caption:
Name:
Icon:
Menu:
Maximizebox:
StartPosition:
Size:
Text: |
WinForm
TWinForm
(Icon)
(none)
True
WindowsDefaultLocation
300,300
WinForm |
agenda_appoint
Tagenda_appoint
(Icon)
(none)
False
CenterScreen
640,225
agenda appointment ... |
|
|
|
|
3. |
Save this
file ... On the
File menu , click Save |
|
|
|
1. |
Picture files... |
|
- The folder
c:\work_Delphinet\pic stored the bmp files
oclock.bmp, btn_ok.bmp, btn_cancel.bmp
|
2. |
The
agenda_appoint design |
|
|
3. |
From the Tool palette add these
controls ...
(From the View menu, click Tool
palette)
. 20 Label controls,
5 TextBox controls, 4 Button
controls, 3 ComboBox controls, 3 Panel
controls, 2 ImageList controls |
|
- Add 20 Label
controls
- ldate, Object inspector
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, Object inspector
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, Object inspector
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, Object inspector
Name: Size: |
cmbname 120,
21 | |
- cmbfirst_father
Size: 120,
21
- cmbbookid
Size: 32,
21
|
- Add 3 Panel
controls
-
Paneldetail, Object inspector
Name: Size: |
Paneldetail 200,
184 | |
- Panelinter
Size:
8, 40
- Paneldata
Size:
224,
74
|
- Add 2 ImageList
controls
- ImageList1, Object inspector
Name: Images: ImageSize: |
ImageList1 (Collection)
- of 1 Bitmap
image 15,
15 | |
The
folder c:\work_Delphinet\pic
stored the bmp file
btn_calculator.bmp
- ImageList2
ImageSize:
56,
36
The folder
c:\work_Delphinet\pic stored the 2 bmp
files btn_cancel.bmp,
btn_ok.bmp |
- Add the DateTimePicker control
- DateTimePicker1, Object inspector
Name: Size: |
Paneldetail 200,
184 | |
| | |
|
agenda_appoint file, the codes after modification
...
The
text
Code is
red
color, the codes added
manuel |
|
unit agenda_appoint;
interface
uses
System.Drawing, System.Collections,
System.ComponentModel,
System.Windows.Forms, System.Data, System.Data.OleDb,
System.Resources;
type
Tagenda_appoint = class(System.Windows.Forms.Form)
strict protected
/// <summary>
/// Clean up any resources being used.
/// </summary>
procedure Dispose(Disposing: Boolean); override;
private
{ Private Declarations }
procedure sub_nullovalue;
procedure sub_info(bval: Boolean);
procedure sub_load(v_field: string; v_fieldname:
string);
procedure sub_timeok;
procedure sub_Btn_ok;
procedure sub_Full(v_entry_type: string ; v_date:
System.DateTime);
procedure sub_cancel;
public
constructor Create;
class function Showagenda_appoint:
System.Windows.Forms.DialogResult;
class function appoint_flag: Boolean;
class function appoint_agenda_desc: string;
class function appoint_agenda_time: string;
class function appoint_agenda_date: System.DateTime;
class function appoint_agenda_bookid: string;
class function appoint_left: Integer;
class function appointtxttime_Left: Integer;
class function appoint_Top: Integer;
class function appointtxttime_Top: Integer;
class function appointtxttime_Height: Integer;
end;
[assembly:
RuntimeRequiredAttribute(TypeOf(Tagenda_appoint))]
implementation
uses
mainform, agenda, agenda_time;
var
vselect: System.Data.OleDb.OleDbCommand;
vda: System.Data.OleDb.OleDbDataAdapter;
vdset: System.Data.DataSet;
time_flag: Boolean;
v_appoint_flag: Boolean;
v_appoint_agenda_desc: string;
v_appoint_agenda_time: string;
v_appoint_agenda_date: System.DateTime;
v_appoint_agenda_bookid: string;
v_appoint_left: Integer;
v_appoint_txttimeLeft: Integer;
v_appoint_Top: Integer;
v_appoint_txttimeTop: Integer;
v_appoint_txttimeHeight: Integer;
Windows Form Designer
generated code |
procedure
Tagenda_appoint.Dispose(Disposing: Boolean);
begin
if Disposing then
begin
if Components <> nil then
Components.Dispose();
end;
inherited Dispose(Disposing);
end;
constructor Tagenda_appoint.Create;
begin
inherited Create;
//
// Required for Windows Form Designer support
//
InitializeComponent;
//
// TODO: Add any constructor code after
InitializeComponent call
//
Self.Btntime.Top :=
Self.txttime.Top + ((Self.txttime.Height -
Self.Btntime.Height) div 2);
Self.Width := Self.txtdescription.Left +
Self.txtdescription.Width + (7 * Self.Panelinter.Width
div 4);
Self.Paneldata.BackColor := Self.BackColor;
Self.Panelinter.BackColor := Self.BackColor;
Self.Btn_cancel.Left := (Self.txtdescription.Left +
Self.txtdescription.Width) - Self.Btn_cancel.Width;
Self.Btndetail.Left := (Self.cmbfirst_father.Left +
Self.cmbfirst_father.Width) - Self.Btndetail.Width;
v_appoint_left := Self.Width;
v_appoint_Top := Self.Height;
v_appoint_txttimeLeft := Self.txttime.Left;
v_appoint_txttimeTop := Self.txttime.Top;
v_appoint_txttimeHeight := Self.txttime.Height;
end;
class function
Tagenda_appoint.appoint_flag: Boolean;
begin
result := v_appoint_flag;
end;
class function Tagenda_appoint.appoint_agenda_desc:
string;
begin
result := v_appoint_agenda_desc;
end;
class function Tagenda_appoint.appoint_agenda_time:
string;
begin
result := v_appoint_agenda_time;
end;
class function Tagenda_appoint.appoint_agenda_date:
System.DateTime;
begin
result := v_appoint_agenda_date;
end;
class function Tagenda_appoint.appoint_agenda_bookid:
string;
begin
result := v_appoint_agenda_bookid;
end;
class function Tagenda_appoint.appoint_left: Integer;
begin
result := v_appoint_left;
end;
class function Tagenda_appoint.appoint_Top: Integer;
begin
result := v_appoint_Top;
end;
class function Tagenda_appoint.appointtxttime_Left:
Integer;
begin
result := v_appoint_txttimeLeft;
end;
class function Tagenda_appoint.appointtxttime_Top:
Integer;
begin
result := v_appoint_txttimeTop;
end;
class function Tagenda_appoint.appointtxttime_Height:
Integer;
begin
result := v_appoint_txttimeHeight;
end;
class function Tagenda_appoint.Showagenda_appoint:
System.Windows.Forms.DialogResult;
begin
with Tagenda_appoint.Create do
Result := ShowDialog;
end;
procedure Tagenda_appoint.Tagenda_appoint_Load(sender:
System.Object; e: System.EventArgs);
begin
Self.Btndetail.Text := 'detail';
v_appoint_flag := False;
time_flag := False;
//new appointment & edit appointment
if (agenda.Tagenda.agenda_appoint_type = 'edit') then
begin
Self.Text := 'edit appointment';
Self.txtdescription.Text := agenda.Tagenda.agenda_desc;
Self.DateTimePicker1.Value :=
agenda.Tagenda.agenda_appoint_date;
Self.txttime.Text := agenda.Tagenda.agenda_appoint_time;
Self.Btn_ok.Enabled := False;
sub_info(False);
end;
if (agenda.Tagenda.agenda_appoint_type = 'task_appoint')
then
begin
//fagenda_task.Close();
Self.Text := 'new appointment - task moved ...';
Self.txtdescription.Text := agenda.Tagenda.agenda_desc;
Self.DateTimePicker1.Value :=
agenda.Tagenda.agenda_appoint_date;
sub_nullovalue();
end;
if (agenda.Tagenda.agenda_appoint_type = 'new') then
begin
Self.Text := 'new appointment';
Self.DateTimePicker1.Value :=
agenda.Tagenda.agenda_appoint_date;
Self.txtdescription.Text := '';
sub_nullovalue();
if (agenda.Tagenda.appoint_full = True) then
begin
//with this current date, add new appointmement not
available
MessageBox.Show('note: to add new appointment, change
the current date - ' +
System.Convert.ToString(agenda.Tagenda.agenda_appoint_date.Month)
+ '/' +
System.Convert.ToString(agenda.Tagenda.agenda_appoint_date.Day)
+ '/' +
System.Convert.ToString(agenda.Tagenda.agenda_appoint_date.Year)
+ ' ', mainform.Tmainform.Title, MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information);
end;
end;
end;
procedure Tagenda_appoint.sub_nullovalue;
begin
Self.cmbname.Items.Clear();
Self.cmbfirst_father.Items.Clear();
Self.cmbname.Text := '';
Self.cmbfirst_father.Text := '';
Self.txttime.Text := '';
v_appoint_agenda_time := '';
Self.txtname.Text := '';
Self.txtfirst_father.Text := '';
Self.Btn_ok.Enabled := False;
sub_info(True);
Self.Btndetail.Enabled := False;
end;
procedure Tagenda_appoint.sub_info(bval: Boolean);
begin
Self.cmbname.Visible := bval;
Self.cmbfirst_father.Visible := bval;
Self.txtname.Visible := not bval;
Self.txtfirst_father.Visible := not bval;
Self.txtname.Width := Self.cmbname.Width;
Self.txtfirst_father.Width := Self.cmbfirst_father.Width;
if (agenda.Tagenda.agenda_appoint_type = 'task_appoint')
then
begin
sub_load('name', '');
Self.cmbfirst_father.Enabled := False;
exit
end;
if (agenda.Tagenda.agenda_appoint_type = 'new') then
begin
sub_load('name', '');
Self.cmbfirst_father.Enabled := False;
exit
end;
if (agenda.Tagenda.agenda_appoint_type = 'edit') then
begin
Self.txtbookid.Text :=
agenda.Tagenda.agenda_appoint_bookid;
//load value corresponding to editbookid.Text
sub_load('detail', Self.txtbookid.Text.Trim());
if (agenda.Tagenda.agenda_appoint_bookid.Trim().Length >
0 ) then
Self.Btndetail.Enabled := True;
exit
end;
end;
//book table, add data to comboboxes and detail
information
procedure Tagenda_appoint.sub_load(v_field: string;
v_fieldname: string);
var
i: Integer;
begin
vselect := System.Data.OleDb.OleDbCommand.Create;
vda := System.Data.OleDb.OleDbDataAdapter.Create;
vdset := System.Data.DataSet.Create;
if (v_field = 'name') then
vselect.CommandText := 'SELECT DISTINCT Trim(name) AS
vname FROM book WHERE (Trim(name) <> "") ORDER BY
Trim(name)';
if (v_field = 'first') then
vselect.CommandText := 'SELECT bookid, name, first_name,
father_name FROM book WHERE (name = "' + v_fieldname +
'") ORDER BY first_name, father_name';
if (v_field = 'detail') then
vselect.CommandText := 'SELECT bookid, city,
civil_status, country, email, father_name, first_name,
homephone, mobilephone, name, sex, web, workphone FROM
book WHERE (bookid = '+ v_fieldname + ')';
vselect.Connection := Self.OleDbConnection1;
vda.SelectCommand := vselect;
vdset.EnforceConstraints := False;
Try
//Open the connection.
Self.OleDbConnection1.Open();
vda.Fill(vdset, 'book');
finally
//Turn constraint checking back on.
vdset.EnforceConstraints := True;
//Close the connection
Self.OleDbConnection1.Close();
end;
if (vdset.Tables['book'].Rows.Count > 0) then
begin
for i := 0 to (vdset.Tables['book'].Rows.Count - 1) do
begin
if ( v_field = 'name') then
begin
Self.cmbname.Items.Add(vdset.Tables['book'].Rows[i].Item['vname'].ToString().Trim());
end;
if ( v_field = 'first') then
begin
Self.cmbfirst_father.Items.Add(vdset.Tables['book'].Rows[i].Item['first_name'].ToString().Trim()
+ ' ' +
vdset.Tables['book'].Rows[i].Item['father_name'].ToString().Trim());
Self.cmbbookid.Items.Add(System.Convert.ToString(vdset.Tables['book'].Rows[i].Item['bookid']));
end;
if ( v_field = 'detail') then
begin
Self.l_name.Text :=
vdset.Tables['book'].Rows[i].Item['name'].ToString().Trim();
if (vdset.Tables['book'].Rows[i].Item['first_name'].ToString().Trim().Length
= 0) then
Self.l_first.Text := ' ... '
else
Self.l_first.Text :=
vdset.Tables['book'].Rows[i].Item['first_name'].ToString().Trim();
if (vdset.Tables['book'].Rows[i].Item['father_name'].ToString().Trim().Length
= 0) then
Self.l_father.Text := ' ... '
else
Self.l_father.Text :=
vdset.Tables['book'].Rows[i].Item['father_name'].ToString().Trim();
if (vdset.Tables['book'].Rows[i].Item['city'].ToString().Trim().Length
= 0) then
Self.l_city.Text := ' ... '
else
Self.l_city.Text :=
vdset.Tables['book'].Rows[i].Item['city'].ToString().Trim();
if (vdset.Tables['book'].Rows[i].Item['homephone'].ToString().Trim().Length
= 0) then
Self.l_phone.Text := ' ... '
else
Self.l_phone.Text :=
vdset.Tables['book'].Rows[i].Item['homephone'].ToString().Trim();
if (vdset.Tables['book'].Rows[i].Item['mobilephone'].ToString().Trim().Length
= 0) then
Self.l_mobile.Text := ' ... '
else
Self.l_mobile.Text :=
vdset.Tables['book'].Rows[i].Item['mobilephone'].ToString().Trim();
if (vdset.Tables['book'].Rows[i].Item['email'].ToString().Trim().Length
= 0) then
Self.l_email.Text := ' ... '
else
Self.l_email.Text :=
vdset.Tables['book'].Rows[i].Item['email'].ToString().Trim();
end;
if (agenda.Tagenda.agenda_appoint_type = 'edit') then
begin
Self.txtname.Text := Self.l_name.Text;
Self.txtfirst_father.Text := Self.l_first.Text + ' ' +
Self.l_father.Text;
exit;
end;
end;
end;
end;
procedure
Tagenda_appoint.cmbname_SelectedIndexChanged(sender:
System.Object;
e: System.EventArgs);
begin
sub_load('first', Self.cmbname.Text);
Self.cmbfirst_father.Enabled := True;
end;
procedure
Tagenda_appoint.cmbfirst_father_SelectedIndexChanged(sender:
System.Object;
e: System.EventArgs);
begin
Self.txtname.Text := Self.cmbname.Text;
Self.txtfirst_father.Text := Self.cmbfirst_father.Text;
Self.cmbbookid.SelectedIndex :=
Self.cmbfirst_father.SelectedIndex;
Self.txtbookid.Text := Self.cmbbookid.Text;
sub_load('detail', Self.txtbookid.Text.Trim());
Self.Btndetail.Enabled := True;
end;
//from book table, detail information
procedure Tagenda_appoint.Btndetail_Click(sender:
System.Object; e: System.EventArgs);
begin
if (Self.Btndetail.Text = 'detail') then
begin
Self.Width := 2 * Self.txtdescription.Left +
Self.txtdescription.Width + Self.Paneldetail.Width + 7 *
Self.Panelinter.Width div 4;
Self.Paneldata.BackColor := Self.Paneldetail.BackColor;
Self.Panelinter.BackColor := Self.Paneldetail.BackColor;
Self.Btndetail.Text := 'hide';
exit;
end;
if (Self.Btndetail.Text = 'hide') then
begin
Self.Width := Self.txtdescription.Left +
Self.txtdescription.Width + 7 * Self.Panelinter.Width
div 4;
Self.Paneldata.BackColor := Self.BackColor;
Self.Panelinter.BackColor := Self.BackColor;
Self.Btndetail.Text := 'detail';
end;
end;
//agenda_time form, show
procedure Tagenda_appoint.Btntime_Click(sender:
System.Object; e: System.EventArgs);
begin
time_flag := true;
agenda_time.Tagenda_time.Showagenda_time;
end;
procedure Tagenda_appoint.txtdescription_KeyPress(sender:
System.Object; e: System.Windows.Forms.KeyPressEventArgs);
begin
Self.Btn_ok.Enabled := true;
end;
procedure
Tagenda_appoint.Tagenda_appoint_Activated(sender:
System.Object; e: System.EventArgs);
begin
if ((agenda_time.Tagenda_time.time_flag = true) And (time_flag
= true)) then
sub_timeok();
end;
procedure Tagenda_appoint.sub_timeok;
begin
if (agenda_time.Tagenda_time.time_flag = True) then
begin
Self.txttime.Text :=
agenda_time.Tagenda_time.appoint_time;
Self.Btn_ok.Enabled := True;
end;
end;
procedure Tagenda_appoint.btn_ok_Click(sender:
System.Object; e: System.EventArgs);
begin
if ((Self.txtdescription.Text.Trim().Length > 0) And (Self.txttime.Text.Trim().Length
> 0)) then
begin
if ((Self.txtname.Text.Trim().Length > 0) And (Self.txtfirst_father.Text.Trim().Length
> 0)) then
begin
sub_Btn_ok();
exit;
end
else
begin
MessageBox.Show('name value or first and father value,
empty ... not available', mainform.Tmainform.Title,
MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information);
exit;
end;
end
else
begin
MessageBox.Show('description value or time value, empty
... not available', mainform.Tmainform.Title,
MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information);
exit;
end;
end;
procedure Tagenda_appoint.sub_Btn_ok;
var
response: System.Windows.Forms.DialogResult;
begin
if (agenda.Tagenda.agenda_appoint_type = 'task_appoint')
then
begin
sub_Full('A', Self.DateTimePicker1.Value);
if ((vdset.Tables['agenda'].Rows.Count - 1) >= 24) then
begin
response := MessageBox.Show('to save the current
appointment ..., change the current date - ' +
System.Convert.ToString(agenda.Tagenda.agenda_appoint_date.Month)
+ '/' +
System.Convert.ToString(agenda.Tagenda.agenda_appoint_date.Day)
+ '/' +
System.Convert.ToString(agenda.Tagenda.agenda_appoint_date.Year)
+ ' ', mainform.Tmainform.Title, MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Information);
if (response = System.Windows.Forms.DialogResult.Yes)
then
exit;
if (response = System.Windows.Forms.DialogResult.No)
then
begin
sub_cancel();
exit;
end;
end
else
begin
v_appoint_flag := true;
v_appoint_agenda_desc := Self.txtdescription.Text;
v_appoint_agenda_date := Self.DateTimePicker1.Value;
v_appoint_agenda_time := Self.txttime.Text;
v_appoint_agenda_bookid := Self.txtbookid.Text;
Self.Close();
agenda.Tagenda.ActiveForm.Refresh();
agenda.Tagenda.ActiveForm.Activate();
end;
end;
if (agenda.Tagenda.agenda_appoint_type = 'new') then
begin
sub_Full('A', Self.DateTimePicker1.Value);
if ((vdset.Tables['agenda'].Rows.Count - 1) >= 24) then
begin
//with this current date, add new appointmement not
available
response := MessageBox.Show('to save this appointment,
change the current date - ' +
System.Convert.ToString(agenda.Tagenda.agenda_appoint_date.Month)
+ '/' +
System.Convert.ToString(agenda.Tagenda.agenda_appoint_date.Day)
+ '/' +
System.Convert.ToString(agenda.Tagenda.agenda_appoint_date.Year)
+ ' ', mainform.Tmainform.Title, MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Information);
if (response = System.Windows.Forms.DialogResult.Yes)
then
exit;
if (response = System.Windows.Forms.DialogResult.No)
then
begin
sub_cancel();
exit;
end;
end
else
begin
v_appoint_flag := True;
v_appoint_agenda_desc := Self.txtdescription.Text;
v_appoint_agenda_date := Self.DateTimePicker1.Value;
v_appoint_agenda_time := Self.txttime.Text;
v_appoint_agenda_bookid := Self.txtbookid.Text;
Self.Close();
agenda.Tagenda.ActiveForm.Refresh();
agenda.Tagenda.ActiveForm.Activate();
end;
end;
if (agenda.Tagenda.agenda_appoint_type = 'edit') then
begin
v_appoint_flag := True;
v_appoint_agenda_desc := Self.txtdescription.Text;
v_appoint_agenda_date := Self.DateTimePicker1.Value;
v_appoint_agenda_time := Self.txttime.Text;
Self.Close();
agenda.Tagenda.ActiveForm.Refresh();
agenda.Tagenda.ActiveForm.Activate();
end;
end;
procedure Tagenda_appoint.sub_Full(v_entry_type: string
; v_date: System.DateTime);
var
strdate_d: string;
strdate_m: string;
strdate_y: string;
begin
vselect := System.Data.OleDb.OleDbCommand.Create;
vda := System.Data.OleDb.OleDbDataAdapter.Create;
vdset := System.Data.DataSet.Create;
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.CommandText := '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';
vselect.Connection := Self.OleDbConnection1;
vda.SelectCommand := vselect;
vdset.EnforceConstraints := False;
Try
//Open the connection.
Self.OleDbConnection1.Open();
vda.Fill(vdset, 'agenda');
finally
//Turn constraint checking back on.
vdset.EnforceConstraints := True;
//Close the connection
Self.OleDbConnection1.Close();
end;
end;
procedure Tagenda_appoint.btn_cancel_Click(sender:
System.Object; e: System.EventArgs);
begin
sub_cancel();
end;
procedure Tagenda_appoint.sub_cancel;
begin
v_appoint_flag := False;
v_appoint_agenda_desc := '';
v_appoint_agenda_time := '';
Self.Close();
agenda.Tagenda.ActiveForm.Refresh();
agenda.Tagenda.ActiveForm.Activate();
end;
end. | | |
|
|