看看怎样把我这段代码改一下,让它在DrawGrid里自动根据数据库中的房间号来排序,1行不超过10列,多的自动换行排列 ( 积分: 50 )

  • 主题发起人 主题发起人 motorola168
  • 开始时间 开始时间
M

motorola168

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit4;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, Db, DBTables, Grids, ImgList, ComCtrls,
DBCtrls;

type
Tfrmkfzt = class(TForm)
Query1: TQuery;
Panel1: TPanel;
Panel2: TPanel;
GroupBox1: TGroupBox;
StatusBar1: TStatusBar;
Panel3: TPanel;
Panel4: TPanel;
Image1: TImage;
Image2: TImage;
Image3: TImage;
Image4: TImage;
Image5: TImage;
Image6: TImage;
BitBtn1: TBitBtn;
ImageList1: TImageList;
Splitter1: TSplitter;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Panel5: TPanel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Query2: TQuery;
DataSource1: TDataSource;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
ComboBox3: TComboBox;
ComboBox4: TComboBox;
Label1: TLabel;
DrawGrid1: TDrawGrid;
procedure BitBtn1Click(Sender: TObject);
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);


procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure StringGrid1EndDock(Sender, Target: TObject; X, Y: Integer);
procedure DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState); private
{ Private declarations }
public
{ Public declarations }
preorder:string;
procedure seticon(index:integer;cellcol:integer;cellrow:integer);
procedure textout(number:string;cellcol:integer;cellrow:integer);
procedure showstatus();

end;

var
frmkfzt: Tfrmkfzt;
roomnum:integer;
ischosen:bool;
chosenindex:integer;
chosenstatus:string;

implementation

{$R *.DFM}



procedure Tfrmkfzt.BitBtn1Click(Sender: TObject);
begin
close();
end;

procedure Tfrmkfzt.seticon(index,cellcol,cellrow:integer);
var bitmap:Tbitmap;
rt:Trect;
begin
rt:=DrawGrid1.cellrect(cellcol,cellrow);
bitmap:=TBitmap.Create;
ImageList1.getbitmap(index,bitmap);
DrawGrid1.canvas.draw(rt.left+5,rt.top,bitmap);
bitmap.free;
end;
//在stringgrid单元格里显示房间编号
procedure Tfrmkfzt.textout(number:string;cellcol,cellrow:integer);
var
rt:Trect;

begin
rt:=DrawGrid1.cellrect(cellcol,cellrow);
DrawGrid1.canvas.brush.style:=bsclear;
DrawGrid1.canvas.textout(rt.left+5,rt.top+5,number);
//DrawGrid1.Canvas.textout(name.left+3,name.top+8,aa);

end;

Procedure Tfrmkfzt.showstatus;
var
floor,room,num,index:integer;
aa,roomnum,status:string;
begin
query1.Close;
query1.sql.Clear;
query1.sql.Add('select kfno,stat,kfms kfms from kfzl order by kfno');
query1.Open;

while not query1.Eof do
begin
aa:=query1.fieldbyname('kfms').asstring;
roomnum:=query1.fieldbyname('kfno').asstring;
num:=strtoint(roomnum);
status:=query1.fieldbyname('stat').asstring;
floor:=round(num/100);
room:=num mod(100*floor);
if status='空房' then index:=0;
if status='住房' then index:=1;
if status='自用' then index:=2;
if status='维修' then index:=3;
if status='预定' then index:=4;
if status='打扫' then index:=5;
seticon(index,room-1,floor-1);
Textout(roomnum+aa,room-1,floor-1);
query1.next;

end;
end;









procedure Tfrmkfzt.FormShow(Sender: TObject);
var
a,b,c,d,e,f:integer;
begin
with query1 do
begin
close;
sql.Clear;
sql.Add('select count(*) as stat from kfzl where stat="空房"');
open;
a:=query1.fieldbyname('stat').asinteger;
StatusBar1.Panels[1].text:=inttostr(a)+' 间';
end;
with query1 do
begin
close;
sql.Clear;
sql.Add('select count(*) as stat from kfzl where stat="住房"');
open;
b:=query1.fieldbyname('stat').asinteger;
StatusBar1.Panels[3].text:=inttostr(b)+' 间';
end;
with query1 doAAA
begin
close;
sql.Clear;
sql.Add('select count(*) as stat from kfzl where stat="预定"');
open;
c:=query1.fieldbyname('stat').asinteger;
StatusBar1.Panels[5].text:=inttostr(c)+' 间';
end;
with query1 do
begin
close;
sql.Clear;
sql.Add('select count(*) as stat from kfzl where stat="维修"');
open;
d:=query1.fieldbyname('stat').asinteger;
StatusBar1.Panels[7].text:=inttostr(d)+' 间';
end;
with query1 do
begin
close;
sql.Clear;
sql.Add('select count(*) as stat from kfzl where stat="自用"');
open;
e:=query1.fieldbyname('stat').asinteger;
StatusBar1.Panels[9].text:=inttostr(e)+' 间';
end;
with query1 do
begin
close;
sql.Clear;
sql.Add('select count(*) as stat from kfzl where stat="打扫"');
open;
f:=query1.fieldbyname('stat').asinteger;
StatusBar1.Panels[11].text:=inttostr(f)+' 间';
end;
with query2 do
begin
close;
sql.Clear;
sql.add('select kfno from kfzl order by kfno');
open;
end;
query2.first;
while not query2.Eof do
begin
combobox1.Items.Add(query2.fieldbyname('kfno').asstring);
combobox2.Items.Add(query2.fieldbyname('kfno').asstring);
combobox3.Items.Add(query2.fieldbyname('kfno').asstring);
combobox4.Items.Add(query2.fieldbyname('kfno').asstring);
query2.next;
end;



{ with Query1 do
begin
close;
sql.clear;
sql.add('select lcno,count(*) as sum from kfzl group by lcno ');
open;
end;
StringGrid1.RowCount:=Query1.RecordCount;
Query1.First;
i:=Query1.fieldbyname('sum').asinteger;
while not(Query1.eof) do
begin
if i<Query1.fieldbyname('sum').asinteger then
i:=Query1.fieldbyname('sum').asinteger;
Query1.Next;
end;
StringGrid1.ColCount:=i;
if i<11 then
StringGrid1.DefaultColWidth:=trunc((StringGrid1.Width-5)/i);
end; }
end;

procedure Tfrmkfzt.StringGrid1DrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
// showstatus();
end;





procedure Tfrmkfzt.Button1Click(Sender: TObject);
begin
with query1 do
begin
close;
sql.Clear;
sql.Add('update kfzl set stat=&quot;空房&quot; where kfno='''+combobox1.text+'''');
execsql;
showstatus();
end;
end;

procedure Tfrmkfzt.Button3Click(Sender: TObject);
begin
with query1 do
begin
close;
sql.Clear;
sql.add('update kfzl set stat=&quot;自用&quot; where kfno='''+combobox2.text+'''');
execsql;
showstatus();
end;
end;

procedure Tfrmkfzt.Button2Click(Sender: TObject);
begin
with query1 do
begin
close;
sql.Clear;
sql.add('update kfzl set stat=&quot;维修&quot; where kfno='''+combobox3.Text+'''');
execsql;
showstatus();
end;

end;

procedure Tfrmkfzt.Button4Click(Sender: TObject);
begin
with query1 do
begin
close;
sql.Clear;
sql.add('update kfzl set stat=&quot;打扫&quot; where kfno='''+combobox4.text+'''');
ExecSQL;
showstatus();
end;
end;

procedure Tfrmkfzt.StringGrid1EndDock(Sender, Target: TObject; X,
Y: Integer);
begin
showstatus();
end;

procedure Tfrmkfzt.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
showstatus();
end;

end.
 
unit Unit4;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, Db, DBTables, Grids, ImgList, ComCtrls,
DBCtrls;

type
Tfrmkfzt = class(TForm)
Query1: TQuery;
Panel1: TPanel;
Panel2: TPanel;
GroupBox1: TGroupBox;
StatusBar1: TStatusBar;
Panel3: TPanel;
Panel4: TPanel;
Image1: TImage;
Image2: TImage;
Image3: TImage;
Image4: TImage;
Image5: TImage;
Image6: TImage;
BitBtn1: TBitBtn;
ImageList1: TImageList;
Splitter1: TSplitter;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Panel5: TPanel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Query2: TQuery;
DataSource1: TDataSource;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
ComboBox3: TComboBox;
ComboBox4: TComboBox;
Label1: TLabel;
DrawGrid1: TDrawGrid;
procedure BitBtn1Click(Sender: TObject);
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);


procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure StringGrid1EndDock(Sender, Target: TObject; X, Y: Integer);
procedure DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState); private
{ Private declarations }
public
{ Public declarations }
preorder:string;
procedure seticon(index:integer;cellcol:integer;cellrow:integer);
procedure textout(number:string;cellcol:integer;cellrow:integer);
procedure showstatus();

end;

var
frmkfzt: Tfrmkfzt;
roomnum:integer;
ischosen:bool;
chosenindex:integer;
chosenstatus:string;

implementation

{$R *.DFM}



procedure Tfrmkfzt.BitBtn1Click(Sender: TObject);
begin
close();
end;

procedure Tfrmkfzt.seticon(index,cellcol,cellrow:integer);
var bitmap:Tbitmap;
rt:Trect;
begin
rt:=DrawGrid1.cellrect(cellcol,cellrow);
bitmap:=TBitmap.Create;
ImageList1.getbitmap(index,bitmap);
DrawGrid1.canvas.draw(rt.left+5,rt.top,bitmap);
bitmap.free;
end;
//在stringgrid单元格里显示房间编号
procedure Tfrmkfzt.textout(number:string;cellcol,cellrow:integer);
var
rt:Trect;

begin
rt:=DrawGrid1.cellrect(cellcol,cellrow);
DrawGrid1.canvas.brush.style:=bsclear;
DrawGrid1.canvas.textout(rt.left+5,rt.top+5,number);
//DrawGrid1.Canvas.textout(name.left+3,name.top+8,aa);

end;

Procedure Tfrmkfzt.showstatus;
var
floor,room,num,index:integer;
aa,roomnum,status:string;
begin
query1.Close;
query1.sql.Clear;
query1.sql.Add('select kfno,stat,kfms kfms from kfzl order by kfno');
query1.Open;

while not query1.Eof do
begin
aa:=query1.fieldbyname('kfms').asstring;
roomnum:=query1.fieldbyname('kfno').asstring;
num:=strtoint(roomnum);
status:=query1.fieldbyname('stat').asstring;
floor:=round(num/100);
room:=num mod(100*floor);
if status='空房' then index:=0;
if status='住房' then index:=1;
if status='自用' then index:=2;
if status='维修' then index:=3;
if status='预定' then index:=4;
if status='打扫' then index:=5;
seticon(index,room-1,floor-1);
Textout(roomnum+aa,room-1,floor-1);
query1.next;

end;
end;









procedure Tfrmkfzt.FormShow(Sender: TObject);
var
a,b,c,d,e,f:integer;
begin
with query1 do
begin
close;
sql.Clear;
sql.Add('select count(*) as stat from kfzl where stat=&quot;空房&quot;');
open;
a:=query1.fieldbyname('stat').asinteger;
StatusBar1.Panels[1].text:=inttostr(a)+' 间';
end;
with query1 do
begin
close;
sql.Clear;
sql.Add('select count(*) as stat from kfzl where stat=&quot;住房&quot;');
open;
b:=query1.fieldbyname('stat').asinteger;
StatusBar1.Panels[3].text:=inttostr(b)+' 间';
end;
with query1 doAAA
begin
close;
sql.Clear;
sql.Add('select count(*) as stat from kfzl where stat=&quot;预定&quot;');
open;
c:=query1.fieldbyname('stat').asinteger;
StatusBar1.Panels[5].text:=inttostr(c)+' 间';
end;
with query1 do
begin
close;
sql.Clear;
sql.Add('select count(*) as stat from kfzl where stat=&quot;维修&quot;');
open;
d:=query1.fieldbyname('stat').asinteger;
StatusBar1.Panels[7].text:=inttostr(d)+' 间';
end;
with query1 do
begin
close;
sql.Clear;
sql.Add('select count(*) as stat from kfzl where stat=&quot;自用&quot;');
open;
e:=query1.fieldbyname('stat').asinteger;
StatusBar1.Panels[9].text:=inttostr(e)+' 间';
end;
with query1 do
begin
close;
sql.Clear;
sql.Add('select count(*) as stat from kfzl where stat=&quot;打扫&quot;');
open;
f:=query1.fieldbyname('stat').asinteger;
StatusBar1.Panels[11].text:=inttostr(f)+' 间';
end;
with query2 do
begin
close;
sql.Clear;
sql.add('select kfno from kfzl order by kfno');
open;
end;
query2.first;
while not query2.Eof do
begin
combobox1.Items.Add(query2.fieldbyname('kfno').asstring);
combobox2.Items.Add(query2.fieldbyname('kfno').asstring);
combobox3.Items.Add(query2.fieldbyname('kfno').asstring);
combobox4.Items.Add(query2.fieldbyname('kfno').asstring);
query2.next;
end;



{ with Query1 do
begin
close;
sql.clear;
sql.add('select lcno,count(*) as sum from kfzl group by lcno ');
open;
end;
StringGrid1.RowCount:=Query1.RecordCount;
Query1.First;
i:=Query1.fieldbyname('sum').asinteger;
while not(Query1.eof) do
begin
if i<Query1.fieldbyname('sum').asinteger then
i:=Query1.fieldbyname('sum').asinteger;
Query1.Next;
end;
StringGrid1.ColCount:=i;
if i<11 then
StringGrid1.DefaultColWidth:=trunc((StringGrid1.Width-5)/i);
end; }
end;

procedure Tfrmkfzt.StringGrid1DrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
// showstatus();
end;





procedure Tfrmkfzt.Button1Click(Sender: TObject);
begin
with query1 do
begin
close;
sql.Clear;
sql.Add('update kfzl set stat=&quot;空房&quot; where kfno='''+combobox1.text+'''');
execsql;
showstatus();
end;
end;

procedure Tfrmkfzt.Button3Click(Sender: TObject);
begin
with query1 do
begin
close;
sql.Clear;
sql.add('update kfzl set stat=&quot;自用&quot; where kfno='''+combobox2.text+'''');
execsql;
showstatus();
end;
end;

procedure Tfrmkfzt.Button2Click(Sender: TObject);
begin
with query1 do
begin
close;
sql.Clear;
sql.add('update kfzl set stat=&quot;维修&quot; where kfno='''+combobox3.Text+'''');
execsql;
showstatus();
end;

end;

procedure Tfrmkfzt.Button4Click(Sender: TObject);
begin
with query1 do
begin
close;
sql.Clear;
sql.add('update kfzl set stat=&quot;打扫&quot; where kfno='''+combobox4.text+'''');
ExecSQL;
showstatus();
end;
end;

procedure Tfrmkfzt.StringGrid1EndDock(Sender, Target: TObject; X,
Y: Integer);
begin
showstatus();
end;

procedure Tfrmkfzt.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
showstatus();
end;

end.
 
后退
顶部