📄 jvtfmanager.pas
字号:
procedure TJvTFCustomImageMap.Add(const ImageName: string; ImageIndex: Integer);
begin
if FMap.IndexOf(ImageName) = -1 then
begin
FMap.AddObject(ImageName, TObject(ImageIndex));
Change;
end;
end;
procedure TJvTFCustomImageMap.Delete(MapIndex: Integer);
begin
FMap.Delete(MapIndex);
Change;
end;
procedure TJvTFCustomImageMap.Move(SrcMapIndex, DestMapIndex: Integer);
begin
FMap.Move(SrcMapIndex, DestMapIndex);
end;
function TJvTFCustomImageMap.FindMapIndex(const ImageName: string): Integer;
begin
Result := FMap.IndexOf(ImageName);
end;
function TJvTFCustomImageMap.FindImageIndex(const ImageName: string): Integer;
begin
Result := FindMapIndex(ImageName);
if Result > -1 then
Result := GetImage(Result);
end;
procedure TJvTFCustomImageMap.Clear;
begin
while FMap.Count > 0 do
FMap.Delete(0);
Change;
end;
procedure TJvTFCustomImageMap.Assign(Source: TPersistent);
var
I: Integer;
begin
if Source is TJvTFCustomImageMap then
begin
while FMap.Count > 0 do
FMap.Delete(0);
for I := 0 to TJvTFCustomImageMap(Source).Count - 1 do
Add(TJvTFCustomImageMap(Source).ImageNames[I],
TJvTFCustomImageMap(Source).Images[I]);
Change;
end
else
inherited Assign(Source);
end;
//=== { TJvTFStateImageMap } =================================================
constructor TJvTFStateImageMap.Create(Serv: TJvTFScheduleManager);
var
I: TJvTFStatePic;
begin
inherited Create;
for I := Low(TJvTFStatePic) to High(TJvTFStatePic) do
FPics[I] := -1;
FUpdating := False;
end;
procedure TJvTFStateImageMap.SetImage(StatePicID: TJvTFStatePic; Value: Integer);
begin
if Value < -1 then
Value := -1;
if FPics[StatePicID] <> Value then
begin
FPics[StatePicID] := Value;
Change;
end;
end;
function TJvTFStateImageMap.GetImage(StatePicID: TJvTFStatePic): Integer;
begin
Result := FPics[StatePicID];
end;
function TJvTFStateImageMap.GetAlarmDisabled: Integer;
begin
Result := GetImage(spAlarmDisabled);
end;
function TJvTFStateImageMap.GetAlarmEnabled: Integer;
begin
Result := GetImage(spAlarmEnabled);
end;
function TJvTFStateImageMap.GetModified: Integer;
begin
Result := GetImage(spModified);
end;
function TJvTFStateImageMap.GetRecurring: Integer;
begin
Result := GetImage(spRecurring);
end;
function TJvTFStateImageMap.GetShared: Integer;
begin
Result := GetImage(spShared);
end;
procedure TJvTFStateImageMap.SetAlarmDisabled(const Value: Integer);
begin
SetImage(spAlarmDisabled, Value);
end;
procedure TJvTFStateImageMap.SetAlarmEnabled(const Value: Integer);
begin
SetImage(spAlarmEnabled, Value);
end;
procedure TJvTFStateImageMap.SetModified(const Value: Integer);
begin
SetImage(spModified, Value);
end;
procedure TJvTFStateImageMap.SetRecurring(const Value: Integer);
begin
SetImage(spRecurring, Value);
end;
procedure TJvTFStateImageMap.SetShared(const Value: Integer);
begin
SetImage(spShared, Value);
end;
procedure TJvTFStateImageMap.Change;
begin
if Assigned(FScheduleManager) and not (csLoading in FScheduleManager.ComponentState) and
not (csDesigning in FScheduleManager.ComponentState) and not FUpdating then
FScheduleManager.RefreshConnections(nil);
end;
procedure TJvTFStateImageMap.BeginUpdate;
begin
FUpdating := True;
end;
procedure TJvTFStateImageMap.EndUpdate;
begin
if FUpdating then
begin
FUpdating := False;
Change;
end;
end;
procedure TJvTFStateImageMap.Clear;
var
I: TJvTFStatePic;
begin
for I := Low(TJvTFStatePic) to High(TJvTFStatePic) do
FPics[I] := -1;
Change;
end;
procedure TJvTFStateImageMap.Assign(Source: TPersistent);
var
Pic: TJvTFStatePic;
begin
if Source is TJvTFStateImageMap then
begin
for Pic := Low(TJvTFStatePic) to High(TJvTFStatePic) do
FPics[Pic] := TJvTFStateImageMap(Source).Pics[Pic];
Change;
end
else
inherited Assign(Source);
end;
//=== { TJvTFAppt } ==========================================================
constructor TJvTFAppt.Create(Serv: TJvTFScheduleManager; const ApptID: string);
begin
if not Assigned(Serv) then
raise EJvTFScheduleManagerError.CreateRes(@RsECouldNotCreateAppointmentObject);
inherited Create;
FSchedules := TStringList.Create;
FConnections := TStringList.Create;
FStartDate := Date;
FStartTime := Time;
FEndDate := Date;
FEndTime := FStartTime + EncodeTime(0, 1, 0, 0);
FScheduleManager := Serv;
if ApptID <> '' then
FID := ApptID
else
FID := FScheduleManager.GenerateApptID;
FModified := False;
FColor := clDefault;
FBarColor := clDefault;
FImageMap := TJvTFCustomImageMap.Create(Self);
ScheduleManager.Notify(Self, sncLoadAppt);
Serv.DoCreateApptEvent(Self);
end;
destructor TJvTFAppt.Destroy;
begin
if Assigned(ScheduleManager) then
ScheduleManager.DoDestroyApptEvent(Self);
ScheduleManager.Notify(Self, sncDestroyAppt);
FSchedules.Free;
FConnections.Free;
FImageMap.Free;
inherited Destroy;
end;
function TJvTFAppt.GetDescription: string;
begin
Result := FDescription;
ScheduleManager.GetApptDescription(Self, Result);
end;
procedure TJvTFAppt.SetDescription(Value: string);
begin
ScheduleManager.SetApptDescription(Self, Value);
if Value <> FDescription then
begin
FDescription := Value;
if not ScheduleManager.LoadingAppts and not ScheduleManager.Refreshing then
begin
FModified := True;
Change;
end;
end;
end;
procedure TJvTFAppt.SetAlarmEnabled(Value: Boolean);
begin
if Value <> FAlarmEnabled then
begin
FAlarmEnabled := Value;
if not ScheduleManager.LoadingAppts and not ScheduleManager.Refreshing then
begin
FModified := True;
Change;
end;
end;
end;
procedure TJvTFAppt.SetAlarmAdvance(Value: Integer);
begin
if Value < 0 then
Value := 0;
if Value <> FAlarmAdvance then
begin
FAlarmAdvance := Value;
if not ScheduleManager.LoadingAppts and not ScheduleManager.Refreshing then
begin
FModified := True;
Change;
end;
end;
end;
procedure TJvTFAppt.SetColor(Value: TColor);
begin
if Value <> FColor then
begin
FColor := Value;
if not ScheduleManager.LoadingAppts and not ScheduleManager.Refreshing then
begin
FModified := True;
Change;
end;
end;
end;
procedure TJvTFAppt.SetBarColor(Value: TColor);
begin
if Value <> FBarColor then
begin
FBarColor := Value;
if not ScheduleManager.LoadingAppts and not ScheduleManager.Refreshing then
begin
FModified := True;
Change;
end;
end;
end;
procedure TJvTFAppt.Notify(Sender: TObject; Code: TJvTFServNotifyCode);
begin
case Code of
sncConnectAppt:
Connect(TJvTFSched(Sender));
sncDisconnectAppt:
Disconnect(TJvTFSched(Sender));
// implicit post fix
//sncPostAppt : FModified := False;
sncPostAppt:
PostApptNotification;
sncDeleteAppt:
InternalClearSchedules;
sncRefresh:
FModified := False;
end;
end;
procedure TJvTFAppt.NotifyManager(Serv: TJvTFScheduleManager; Sender: TObject;
Code: TJvTFServNotifyCode);
begin
if Assigned(Serv) then
Serv.Notify(Sender, Code)
else
raise EJvTFScheduleManagerError.CreateRes(@RsEScheduleManagerNotificationFailedSc);
end;
procedure TJvTFAppt.NotifySchedule(Sched: TJvTFSched; Sender: TObject;
Code: TJvTFServNotifyCode);
begin
if Assigned(Sched) then
Sched.Notify(Sender, Code)
else
raise EJvTFScheduleManagerError.CreateRes(@RsEScheduleNotificationFailed);
end;
function TJvTFAppt.GetConnection(Index: Integer): TJvTFSched;
begin
Result := TJvTFSched(FConnections.Objects[Index]);
end;
function TJvTFAppt.GetSchedule(Index: Integer): string;
begin
Result := FSchedules[Index];
end;
procedure TJvTFAppt.CheckConnections;
var
Schedule: TJvTFSched;
I: Integer;
ADate: TDate;
Temp: TStringList;
begin
// Schedules --> Connections
for I := 0 to ScheduleCount - 1 do
begin
ADate := StartDate;
while Trunc(ADate) <= Trunc(EndDate) do
begin
Schedule := ScheduleManager.FindSchedule(Schedules[I], ADate);
if Assigned(Schedule) and (FConnections.IndexOfObject(Schedule) = -1) then
Connect(Schedule);
ADate := ADate + 1;
end;
end;
// Connections --> Schedules
Temp := TStringList.Create;
try
Temp.Assign(FConnections);
for I := 0 to Temp.Count - 1 do
begin
Schedule := TJvTFSched(Temp.Objects[I]);
if (FSchedules.IndexOf(Schedule.SchedName) = -1) or
((Trunc(Schedule.SchedDate) < Trunc(StartDate)) or
(Trunc(Schedule.SchedDate) > Trunc(EndDate))) then
Disconnect(Schedule);
end;
finally
Temp.Free;
end;
{ implicit post fix
If not FDeleting and not ScheduleManager.LoadingAppts and not ScheduleManager.Refreshing Then
// To avoid display anomolies we need to post the appt here.
Post;
}
end;
procedure TJvTFAppt.Connect(Schedule: TJvTFSched);
var
SchedID: string;
I: Integer;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -