programador de eventos
Publicado por playme (1 intervención) el 10/01/2010 17:21:25
alguien me podria darme una mano, con la aplicacion de programador de eventos, el code source lo encontré el la red; funciona exelente para programar eventos en el dia, lo que quisiera es que se pueda programar eventos para toda la semana o mes, gracias ante todo. este es el code source:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ExtCtrls, StdCtrls, Spin, ShellApi, IniFiles, Mask,
JvExMask, JvSpin, ComCtrls, dateutils;
type
TTask = Record
path : String;
description : String;
formato : string;
horaev : string;
time : TDateTime;
date : tdate;
end;
TForm1 = class(TForm)
HoursSpinEdit: TSpinEdit;
MinutesSpinEdit: TSpinEdit;
ListBox1: TListBox;
ScheduleFileButton: TButton;
OpenDialog1: TOpenDialog;
Timer1: TTimer;
PopupMenu1: TPopupMenu;
TestSelected: TMenuItem;
DeleteSelected: TMenuItem;
Memo1: TMemo;
Label3: TLabel;
ListBox2: TListBox;
hora: TJvTimeEdit;
Button1: TButton;
fecha: TDateTimePicker;
anio: TSpinEdit;
mes: TSpinEdit;
dia: TSpinEdit;
Lunes: TCheckBox;
Martes: TCheckBox;
Miercoles: TCheckBox;
Jueves: TCheckBox;
Viernes: TCheckBox;
Sabado: TCheckBox;
Domingo: TCheckBox;
Button2: TButton;
mResultado: TMemo;
txtFechaInicio: TDateTimePicker;
txtFechaFin: TDateTimePicker;
Button3: TButton;
Label1: TLabel;
procedure ScheduleFileButtonClick(Sender: TObject);
procedure HoursSpinEditChange(Sender: TObject);
procedure MinutesSpinEditChange(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure AddTask(APath, ADescription, Aformato, Ahoraev : String);
procedure SaveToFile;
procedure LoadFromFile;
procedure EnableControls(enable : boolean);
procedure ClearControls;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure horaChange(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure anioChange(Sender: TObject);
procedure diaChange(Sender: TObject);
procedure mesChange(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure LunesClick(Sender: TObject);
procedure MartesClick(Sender: TObject);
procedure MiercolesClick(Sender: TObject);
procedure JuevesClick(Sender: TObject);
procedure ViernesClick(Sender: TObject);
procedure SabadoClick(Sender: TObject);
procedure DomingoClick(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
Tasks : array of TTask;
NumTasks : integer;
Selected : integer;
IgnoreChange : boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ScheduleFileButtonClick(Sender: TObject);
begin
if OpenDialog1.Execute then AddTask(OpenDialog1.FileName, 'Open File', '1', '0');
end;
procedure TForm1.HoursSpinEditChange(Sender: TObject);
begin
if IgnoreChange then Exit;
Tasks[Selected].time := EncodeTime(HoursSpinEdit.Value, MinutesSpinEdit.Value, 0, 0);
end;
procedure TForm1.MinutesSpinEditChange(Sender: TObject);
begin
if IgnoreChange then Exit;
Tasks[Selected].time := EncodeTime(HoursSpinEdit.Value, MinutesSpinEdit.Value, 0, 0);
end;
procedure TForm1.ListBox1Click(Sender: TObject);
Var
i : integer;
h, m, s, u : word;
an, me, di : word;
begin
if ListBox1.SelCount = 0 then Exit;
Selected := 0;
for i := 0 to ListBox1.Items.Count - 1 do
if ListBox1.Selected[i] then Selected := i;
Memo1.Clear;
IgnoreChange := True;
with Tasks[Selected] do begin
Memo1.Lines.Add(description);
DecodeTime(time, h, m, s, u);
HoursSpinEdit.Value := h;
MinutesSpinEdit.Value := m;
decodedate(date, an, me, di);
dia.Value := di;
mes.Value := me;
anio.Value := an;
end;
IgnoreChange := False;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
Var
a, i : integer;
current, previous : TDateTime;
begin
current := Time;
previous := Time - 1 / 1400;
for i := 0 to NumTasks - 1 do begin
if (current > Tasks[i].time) and (previous < Tasks[i].time) then begin
label3.Caption := (Tasks[i].path);
listbox2.Items.LoadFromFile(label3.Caption);
// end;
end;
end;
end;
procedure TForm1.AddTask(APath, ADescription, Aformato, Ahoraev: String);
begin
ListBox1.Items.Append(APath);
Selected := ListBox1.Items.Count - 1;
ListBox1.Selected[Selected] := True;
Inc(NumTasks);
SetLength(Tasks, NumTasks);
Tasks[Selected].path := APath;
Tasks[Selected].description := ADescription;
Tasks[Selected].formato := Aformato;
Tasks[Selected].horaev := Ahoraev;
EnableControls(True);
ClearControls; ////procedure
ListBox1Click(Self);
end;
procedure TForm1.LoadFromFile;
Var
stream : TMemoryStream;
i, len, fos : integer;
path : string;
begin
path := ExtractFilePath(ParamStr(0)) + 'ScheduleData.sch';
if not FileExists(path) then Exit;
stream := TMemoryStream.Create;
stream.LoadFromFile(path);
stream.Seek(0, 0);
stream.Read(NumTasks, SizeOf(integer));
SetLength(Tasks, NumTasks);
if NumTasks = 0 then Exit;
for i := 0 to NumTasks - 1 do begin
stream.read(len, SizeOf(integer));
SetLength(Tasks[i].path, len);
stream.read(Tasks[i].path[1], len);
ListBox1.Items.Append(Tasks[i].path);
stream.read(len, SizeOf(integer));
SetLength(Tasks[i].description, len);
stream.read(Tasks[i].description[1], len);
stream.read(Tasks[i].date, SizeOf(date));
stream.read(Tasks[i].time, SizeOf(TDateTime));
end;
Selected := NumTasks - 1;
ListBox1.Selected[Selected] := True;
ListBox1Click(Self);
EnableControls(True);
end;
procedure TForm1.SaveToFile;
Var
stream : TMemoryStream;
i, len, fos : integer;
begin
stream := TMemoryStream.Create;
stream.Seek(0, 0);
stream.Write(NumTasks, SizeOf(integer));
for i := 0 to NumTasks - 1 do begin
len := length(Tasks[i].path);
stream.Write(len, SizeOf(integer));
stream.Write(Tasks[i].path[1], len);
len := length(Tasks[i].description);
//fos := length(Tasks[i].formato);
stream.Write(len, SizeOf(integer));
//stream.Write(fos, SizeOf(integer));
stream.Write(Tasks[i].description[1], len);
stream.Write(Tasks[i].date, sizeof(date));
stream.Write(Tasks[i].time, SizeOf(TDateTime));
end;
stream.SaveToFile(ExtractFilePath(ParamStr(0)) + 'ScheduleData.sch');
end;
procedure TForm1.ClearControls;
begin
IgnoreChange := True;
Memo1.Clear;
HoursSpinEdit.Value := 0;
MinutesSpinEdit.Value := 0;
IgnoreChange := False;
end;
procedure TForm1.EnableControls(enable: boolean);
begin
Memo1.Enabled := enable;
// memo2.Enabled := enable;
HoursSpinEdit.Enabled := enable;
MinutesSpinEdit.Enabled := enable;
TestSelected.Enabled := enable;
DeleteSelected.Enabled := enable;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SetLength(Tasks, 0);
NumTasks := 0;
Selected := 0;
IgnoreChange := False;
LoadFromFile;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
SaveToFile;
end;
procedure TForm1.horaChange(Sender: TObject);
begin
if IgnoreChange then Exit;
// Tasks[Selected].horaev := fecha.DateTime;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SaveToFile;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ExtCtrls, StdCtrls, Spin, ShellApi, IniFiles, Mask,
JvExMask, JvSpin, ComCtrls, dateutils;
type
TTask = Record
path : String;
description : String;
formato : string;
horaev : string;
time : TDateTime;
date : tdate;
end;
TForm1 = class(TForm)
HoursSpinEdit: TSpinEdit;
MinutesSpinEdit: TSpinEdit;
ListBox1: TListBox;
ScheduleFileButton: TButton;
OpenDialog1: TOpenDialog;
Timer1: TTimer;
PopupMenu1: TPopupMenu;
TestSelected: TMenuItem;
DeleteSelected: TMenuItem;
Memo1: TMemo;
Label3: TLabel;
ListBox2: TListBox;
hora: TJvTimeEdit;
Button1: TButton;
fecha: TDateTimePicker;
anio: TSpinEdit;
mes: TSpinEdit;
dia: TSpinEdit;
Lunes: TCheckBox;
Martes: TCheckBox;
Miercoles: TCheckBox;
Jueves: TCheckBox;
Viernes: TCheckBox;
Sabado: TCheckBox;
Domingo: TCheckBox;
Button2: TButton;
mResultado: TMemo;
txtFechaInicio: TDateTimePicker;
txtFechaFin: TDateTimePicker;
Button3: TButton;
Label1: TLabel;
procedure ScheduleFileButtonClick(Sender: TObject);
procedure HoursSpinEditChange(Sender: TObject);
procedure MinutesSpinEditChange(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure AddTask(APath, ADescription, Aformato, Ahoraev : String);
procedure SaveToFile;
procedure LoadFromFile;
procedure EnableControls(enable : boolean);
procedure ClearControls;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure horaChange(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure anioChange(Sender: TObject);
procedure diaChange(Sender: TObject);
procedure mesChange(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure LunesClick(Sender: TObject);
procedure MartesClick(Sender: TObject);
procedure MiercolesClick(Sender: TObject);
procedure JuevesClick(Sender: TObject);
procedure ViernesClick(Sender: TObject);
procedure SabadoClick(Sender: TObject);
procedure DomingoClick(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
Tasks : array of TTask;
NumTasks : integer;
Selected : integer;
IgnoreChange : boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ScheduleFileButtonClick(Sender: TObject);
begin
if OpenDialog1.Execute then AddTask(OpenDialog1.FileName, 'Open File', '1', '0');
end;
procedure TForm1.HoursSpinEditChange(Sender: TObject);
begin
if IgnoreChange then Exit;
Tasks[Selected].time := EncodeTime(HoursSpinEdit.Value, MinutesSpinEdit.Value, 0, 0);
end;
procedure TForm1.MinutesSpinEditChange(Sender: TObject);
begin
if IgnoreChange then Exit;
Tasks[Selected].time := EncodeTime(HoursSpinEdit.Value, MinutesSpinEdit.Value, 0, 0);
end;
procedure TForm1.ListBox1Click(Sender: TObject);
Var
i : integer;
h, m, s, u : word;
an, me, di : word;
begin
if ListBox1.SelCount = 0 then Exit;
Selected := 0;
for i := 0 to ListBox1.Items.Count - 1 do
if ListBox1.Selected[i] then Selected := i;
Memo1.Clear;
IgnoreChange := True;
with Tasks[Selected] do begin
Memo1.Lines.Add(description);
DecodeTime(time, h, m, s, u);
HoursSpinEdit.Value := h;
MinutesSpinEdit.Value := m;
decodedate(date, an, me, di);
dia.Value := di;
mes.Value := me;
anio.Value := an;
end;
IgnoreChange := False;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
Var
a, i : integer;
current, previous : TDateTime;
begin
current := Time;
previous := Time - 1 / 1400;
for i := 0 to NumTasks - 1 do begin
if (current > Tasks[i].time) and (previous < Tasks[i].time) then begin
label3.Caption := (Tasks[i].path);
listbox2.Items.LoadFromFile(label3.Caption);
// end;
end;
end;
end;
procedure TForm1.AddTask(APath, ADescription, Aformato, Ahoraev: String);
begin
ListBox1.Items.Append(APath);
Selected := ListBox1.Items.Count - 1;
ListBox1.Selected[Selected] := True;
Inc(NumTasks);
SetLength(Tasks, NumTasks);
Tasks[Selected].path := APath;
Tasks[Selected].description := ADescription;
Tasks[Selected].formato := Aformato;
Tasks[Selected].horaev := Ahoraev;
EnableControls(True);
ClearControls; ////procedure
ListBox1Click(Self);
end;
procedure TForm1.LoadFromFile;
Var
stream : TMemoryStream;
i, len, fos : integer;
path : string;
begin
path := ExtractFilePath(ParamStr(0)) + 'ScheduleData.sch';
if not FileExists(path) then Exit;
stream := TMemoryStream.Create;
stream.LoadFromFile(path);
stream.Seek(0, 0);
stream.Read(NumTasks, SizeOf(integer));
SetLength(Tasks, NumTasks);
if NumTasks = 0 then Exit;
for i := 0 to NumTasks - 1 do begin
stream.read(len, SizeOf(integer));
SetLength(Tasks[i].path, len);
stream.read(Tasks[i].path[1], len);
ListBox1.Items.Append(Tasks[i].path);
stream.read(len, SizeOf(integer));
SetLength(Tasks[i].description, len);
stream.read(Tasks[i].description[1], len);
stream.read(Tasks[i].date, SizeOf(date));
stream.read(Tasks[i].time, SizeOf(TDateTime));
end;
Selected := NumTasks - 1;
ListBox1.Selected[Selected] := True;
ListBox1Click(Self);
EnableControls(True);
end;
procedure TForm1.SaveToFile;
Var
stream : TMemoryStream;
i, len, fos : integer;
begin
stream := TMemoryStream.Create;
stream.Seek(0, 0);
stream.Write(NumTasks, SizeOf(integer));
for i := 0 to NumTasks - 1 do begin
len := length(Tasks[i].path);
stream.Write(len, SizeOf(integer));
stream.Write(Tasks[i].path[1], len);
len := length(Tasks[i].description);
//fos := length(Tasks[i].formato);
stream.Write(len, SizeOf(integer));
//stream.Write(fos, SizeOf(integer));
stream.Write(Tasks[i].description[1], len);
stream.Write(Tasks[i].date, sizeof(date));
stream.Write(Tasks[i].time, SizeOf(TDateTime));
end;
stream.SaveToFile(ExtractFilePath(ParamStr(0)) + 'ScheduleData.sch');
end;
procedure TForm1.ClearControls;
begin
IgnoreChange := True;
Memo1.Clear;
HoursSpinEdit.Value := 0;
MinutesSpinEdit.Value := 0;
IgnoreChange := False;
end;
procedure TForm1.EnableControls(enable: boolean);
begin
Memo1.Enabled := enable;
// memo2.Enabled := enable;
HoursSpinEdit.Enabled := enable;
MinutesSpinEdit.Enabled := enable;
TestSelected.Enabled := enable;
DeleteSelected.Enabled := enable;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SetLength(Tasks, 0);
NumTasks := 0;
Selected := 0;
IgnoreChange := False;
LoadFromFile;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
SaveToFile;
end;
procedure TForm1.horaChange(Sender: TObject);
begin
if IgnoreChange then Exit;
// Tasks[Selected].horaev := fecha.DateTime;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SaveToFile;
end;
end.
Valora esta pregunta
0