Вот мой календарь покапайся
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, Grids, StdCtrls;
type
TForm1 = class(TForm)
sg: TStringGrid;
DT: TMonthCalendar;
l1: TStaticText;
l2: TLabel;
CB: TComboBox;
Label1: TLabel;
function findday(d:integer):string;
procedure addmonth;
procedure vis;
procedure FormShow(Sender: TObject);
procedure DTClick(Sender: TObject);
procedure sgDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;
State: TGridDrawState);
procedure DTGetMonthInfo(Sender: TObject; Month: Cardinal;
var MonthBoldInfo: Cardinal);
procedure CBChange(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
dk,dn:tdatetime;
rez,r:integer;
c_row,c_col:integer;
m:array [1..12] of string;
ssg:array [0..6,1..6] of string;
implementation
{$R *.DFM}
function TForm1.findday(d:integer):string;
var j,k:integer;
begin
for j:=1 to sg.RowCount-1 do
for k:=0 to sg.ColCount-1 do
begin
if pos(inttostr(d),ssg[k,j])<>0 then
begin
c_col:=k;
c_row:=j;
result:=sg.Cells[k,j];
exit;
end;
end;
end;
procedure TForm1.addmonth;
begin
m[1]:='Январь';
m[2]:='Февраль';
m[3]:='Март';
m[4]:='Апрель';
m[5]:='Май';
m[6]:='Июнь';
m[7]:='Июль';
m[8]:='Август';
m[9]:='Сентябрь';
m[10]:='Октябрь';
m[11]:='Ноябрь';
m[12]:='Декабрь';
end;
procedure TForm1.vis;
var
yy,mm,dd:word;
dweek:integer;
month,stroka:integer;
j,k:integer;
begin
for j:=1 to sg.RowCount-1 do
begin
sg.Rows[j].Clear;
for k:=0 to sg.ColCount-1 do
ssg[k,j]:='';
end;
dn:=strtodate('05.01.08')+cb.ItemIndex;
dk:=dt.Date;
DecodeDate(dk,yy,mm,dd);
dk:= EncodeDate(yy, mm, 1);
month:=mm;
l1.caption:=m[mm];
dd:=1;
stroka:=1;
while month = mm do
begin
dweek:= (DayOfWeek(dk)+6) mod 7;
if dweek = 0 then dweek:=7;
r:=round(dk-dn);
rez:= r mod 4;
case rez of
0: begin sg.Cells[dweek-1,stroka]:=inttostr(dd)+' день';
ssg[dweek-1,stroka]:=inttostr(dd)+' день';
end;
1: begin sg.Cells[dweek-1,stroka]:=inttostr(dd)+' в ночь';
ssg[dweek-1,stroka]:=inttostr(dd)+' в ночь';
end;
2: begin sg.Cells[dweek-1,stroka]:=inttostr(dd)+' с ночи';
ssg[dweek-1,stroka]:=inttostr(dd)+' с ночи';
end;
3: begin sg.Cells[dweek-1,stroka]:=inttostr(dd)+' выходной';
ssg[dweek-1,stroka]:=inttostr(dd)+' выходной';
end;
end;
dk:= dk+1;
DecodeDate(dk,yy,mm,dd);
dweek:= (DayOfWeek(dk)+6) mod 7;
if dweek = 1 then inc(stroka);
end;
dk:=dt.Date;
DecodeDate(dk,yy,mm,dd);
l2.Caption:=findday(dd);
end;
procedure TForm1.FormShow(Sender: TObject);
begin
sg.Cells[0,0]:='Пон';
sg.Cells[1,0]:='Вт';
sg.Cells[2,0]:='Ср';
sg.Cells[3,0]:='Чет';
sg.Cells[4,0]:='Пят';
sg.Cells[5,0]:='Суб';
sg.Cells[6,0]:='Вос';
cb.ItemIndex:=0;
dt.Date := Now;
addmonth;
vis;
end;
procedure TForm1.DTClick(Sender: TObject);
begin
vis;
end;
procedure TForm1.sgDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if pos('день',sg.Cells[acol,arow])>0 then
sg.Canvas.Brush.Color:=$0080FFFF;
if pos('в ночь',sg.Cells[acol,arow])>0 then
sg.Canvas.Brush.Color:=$00F0C8BF;
if pos('с ночи',sg.Cells[acol,arow])>0 then
sg.Canvas.Brush.Color:=$00FCF1A3;
if pos('выходной',sg.Cells[acol,arow])>0 then
sg.Canvas.Brush.Color:=$00A6F9A6;
if (acol=c_col)and(arow=c_row) then
sg.Canvas.Font.Style:=[fsbold];
sg.Canvas.FillRect( sg.CellRect(acol,arow));
sg.Canvas.Font.Color := clblack;
sg.Canvas.TextOut(Rect.Left + 2, Rect.Top+2, sg.Cells[acol,arow]);
end;
procedure TForm1.DTGetMonthInfo(Sender: TObject; Month: Cardinal;
var MonthBoldInfo: Cardinal);
begin
dt.BoldDays([16,28], MonthBoldInfo);
end;
procedure TForm1.CBChange(Sender: TObject);
begin
vis;
end;
end.