📄 unit1.pas
字号:
for j := 1 to 7 do begin
if CheckBox2[j].Checked then begin
TimePicker1[j][k].Enabled := true;
if CheckBox2[1].Checked then
TimePicker1[1][k].SetFocus;
end;
end;
end else begin
if k < 7 then
TimePicker2[k].Enabled := false;
TimePicker2[k].Time := strtodatetime('00:00:00');
for j := 1 to 7 do begin
TimePicker1[j][k].Enabled := False;
TimePicker1[j][k].Time := strtodatetime('00:00:00');
end;
end;
end;
procedure TForm1.Check2click(Sender: TObject); //星期
var
i,j,k,count: integer;
begin
count := 0;
k := 0;
for i := 1 to 7 do begin
if CheckBox2[i] = Sender then
k := i;
end;
if CheckBox2[k].Checked then begin
if k < 7 then
TimePicker2[k].Enabled := true;
for j := 1 to 6 do begin
if CheckBox1[j].Checked then begin
TimePicker1[k][j].Enabled := true;
end;
end;
end else begin
if k < 7 then
TimePicker2[k].Enabled := false;
for j := 1 to 7 do begin
if j<7 then begin
TimePicker1[k][j].Enabled := false;
TimePicker1[k][j].Time := strtodatetime('00:00:00');
end;
if CheckBox2[j].Checked then
inc(count);
end;
if count = 0 then begin
for i := 1 to 6 do begin
TimePicker2[i].Enabled := False;
TimePicker2[i].Time := strtodatetime('00:00:00');
end;
end;
end;
end;
function TForm1.datetimesort(str: string; week: string): string;
var
i,j: integer;
tmpstr,tmpdt: string;
list1: TStrings;
begin
str := copy(str, 1, length(str) - 1);
list1 := Tstringlist.Create;
list1.CommaText := str;
for i := 0 to list1.Count - 1 do begin
for j := i + 1 to List1.Count - 1 do begin
if strtodatetime(list1[i]) > strtodatetime(list1[j]) then begin
tmpdt := list1[i];
list1[i] := list1[j];
list1[j] := tmpdt;
end;
end;
end;
for i := 0 to list1.Count - 1 do begin
tmpstr := tmpstr + list1[i] + ',';
end;
result := copy(tmpstr,1,length(tmpstr)-1);
end;
procedure TForm1.FormActivate(Sender: TObject);
var
i,j: integer;
tmpstr1,tmpstr2,tmpstr3,tmpstr4,tmpstr5,tmpstr6,tmpstr7,tmpstr8,tmpstr9,tmpstr10: string;
Tlist1,Tlist2,Tlist3,Tlist4,Tlist5,Tlist6,Tlist7,Tlist8,Tlist9,Tlist10: TStrings;
begin
tmpstr1 := inifile.ReadString('day1', 'value', '');
tmpstr2 := inifile.ReadString('day2', 'value', '');
tmpstr3 := inifile.ReadString('day3', 'value', '');
tmpstr4 := inifile.ReadString('day4', 'value', '');
tmpstr5 := inifile.ReadString('day5', 'value', '');
tmpstr6 := inifile.ReadString('day6', 'value', '');
tmpstr7 := inifile.ReadString('day7', 'value', '');
tmpstr8 := inifile.ReadString('Picker2', 'value', '');
tmpstr9 := inifile.ReadString('check1', 'value', '');
tmpstr10 := inifile.ReadString('check2', 'value', '');
try
Tlist1 := Tstringlist.Create;
Tlist1.CommaText := tmpstr1;
Tlist2 := Tstringlist.Create;
Tlist2.CommaText := tmpstr2;
Tlist3 := Tstringlist.Create;
Tlist3.CommaText := tmpstr3;
Tlist4 := Tstringlist.Create;
Tlist4.CommaText := tmpstr4;
Tlist5 := Tstringlist.Create;
Tlist5.CommaText := tmpstr5;
Tlist6 := Tstringlist.Create;
Tlist6.CommaText := tmpstr6;
Tlist7 := Tstringlist.Create;
Tlist7.CommaText := tmpstr7;
Tlist8 := Tstringlist.Create;
Tlist8.CommaText := tmpstr8;
Tlist9 := Tstringlist.Create;
Tlist9.CommaText := tmpstr9;
Tlist10 := Tstringlist.Create;
Tlist10.CommaText := tmpstr10;
for i := 0 to Tlist9.Count - 1 do begin
CheckBox1[strtoint(Tlist9[i])].Checked := true;
end;
for i := 0 to Tlist10.Count - 1 do begin
CheckBox2[strtoint(Tlist10[i])].Checked := true;
end;
for i := 0 to Tlist1.Count - 1 do begin
TimePicker2[i+1].Time := StrToTime(Tlist8[i]);
for j := 1 to 7 do begin
case j of
1: TimePicker1[1][i+1].Time := StrToTime(Tlist1[i]);
2: TimePicker1[2][i+1].Time := StrToTime(Tlist2[i]);
3: TimePicker1[3][i+1].Time := StrToTime(Tlist3[i]);
4: TimePicker1[4][i+1].Time := StrToTime(Tlist4[i]);
5: TimePicker1[5][i+1].Time := StrToTime(Tlist5[i]);
6: TimePicker1[6][i+1].Time := StrToTime(Tlist6[i]);
7: TimePicker1[7][i+1].Time := StrToTime(Tlist7[i]);
end;
end;
end;
finally
freeandnil(Tlist1);
freeandnil(Tlist2);
freeandnil(Tlist3);
freeandnil(Tlist4);
freeandnil(Tlist5);
freeandnil(Tlist6);
freeandnil(Tlist7);
freeandnil(Tlist8);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i,j:integer;
begin
for i:=1 to 6 do begin
TimePicker2[i] := TDateTimePicker.Create(GroupBox2);
with TimePicker2[i] do begin
Parent :=self;
case i of
1: begin
Left :=65;
Top :=225;
end;
2: begin
Left :=73 + 150*(i-1);
Top :=225;
end;
3: begin
Left :=65;
Top :=250;
end;
4: begin
Left :=73 + 150*(i-3);
Top :=250;
end;
5: begin
Left :=92 + 150*(i-3);
Top :=225;
end;
6: begin
Left :=92 + 150*(i-4);
Top :=250;
end;
end;
Width := 51;
Visible :=true;
Time := strtodatetime('00:00:00');
Kind := dtkTime;
Enabled := false;
end;
end;
for i := 1 to 7 do begin
CheckBox2[i] := TCheckBox.Create(GroupBox1);
with CheckBox2[i] do begin
Parent :=self;
Left :=20+60*i;
Top :=10;
Width := 51;
Visible :=true;
caption :='星期'+inttostr(i);
OnClick := Check2click;
end;
if i < 7 then
begin
CheckBox1[i] := TCheckBox.Create(GroupBox1);
with CheckBox1[i] do begin
Parent :=self;
Left :=10;
Top :=30*i;
Width := 65;
Visible :=true;
OnClick := Check1click;
case i of
1: caption :='上午进校';
2: caption :='上午出校';
3: caption :='下午进校';
4: caption :='下午出校';
5: caption :='晚上进校';
6: caption :='晚上出校';
end;
end;
end;
for j:=1 to 6 do begin
TimePicker1[i][j] := TDateTimePicker.Create(GroupBox1);
with TimePicker1[i][j] do begin
Parent := self;
Left := 20 + 60*i;
Top := 30*j;
Width := 51;
Visible := true;
Time := strtodatetime('00:00:00');
Enabled := false;
Kind := dtkTime;
OnChange := TimePicker1Change;
OnClick:= TimePicker1Focused;
end;
end;
end;
SetWindowLong(self.Handle, GWL_STYLE, WS_CAPTION);
end;
function TForm1.removedo(str, dostr: string): string;
begin
if RightStr(str,1) = dostr then
result := copy(str, 1, length(str)-1)
else
result := str;
end;
procedure TForm1.TimePicker1Change(Sender: TObject);
var
i,j,m: integer;
begin
for i := 1 to 7 do begin
for j := 1 to 6 do begin
if TimePicker1[1][j] = Sender then begin
for m := 2 to 7 do begin
if CheckBox2[m].Checked then
TimePicker1[m][j].Time := TimePicker1[1][j].Time;
end;
end;
end;
end;
end;
procedure TForm1.TimePicker1Focused(Sender: TObject);
var
i,j: integer;
begin
for i := 1 to 7 do begin
for j := 1 to 6 do begin
if TimePicker1[i][j] = Sender then begin
CheckBox1[j].font.Color := clRed;//$000000FF; //为什么不起作用?
CheckBox2[i].font.Color := clRed;//$000000FF;
end;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -