unit bddg1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, DB, DBTables, StdCtrls, Grids, DBGrids, ExtCtrls;
type
Tbddg1_Form = class(TForm)
GroupBox1: TGroupBox;
xm_LEdit: TLabeledEdit;
DBGrid1: TDBGrid;
Button1: TButton;
Button2: TButton;
PopupMenu1: TPopupMenu;
Query1: TQuery;
DataSource1: TDataSource;
N1: TMenuItem;
procedure Button1Click(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
bddg1_Form: Tbddg1_Form;
implementation
uses main;
{$R *.dfm}
procedure Tbddg1_Form.Button1Click(Sender: TObject);
var xm,sqlstr:string;
begin
xm:=Trim(xm_LEdit.Text);
if Length(xm)<1 then
begin
sqlstr:='select a.*,b.ZYMC as ZYMC,c.XBMC as XBMC from xsb a';
sqlstr:=sqlstr+'INNER JOIN zydm b ON a.ZYDM=b.ZYDM';
sqlstr:=sqlstr+'INNER JOIN xbdm c ON a.XBDM=c.XBDM';
end
else
begin
xm:='%'+xm+'%';
sqlstr:='select a.*,b.ZYMC as ZYMC,c.XBMC as XBMC from xsb a';
sqlstr:=sqlstr+'INNER JOIN zydm b ON a.ZYDM=b.ZYDM';
sqlstr:=sqlstr+'INNER JOIN xbdm c ON a.XBDM=b.XBDM';
sqlstr:=sqlstr+'where (a.XM like '''+xm+''')';
end;
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add(sqlstr);
Query1.Open;
if Query1.RecordCount>0 then
N1.Enabled:=true
else
N1.Enabled:=False;
end;
procedure Tbddg1_Form.N1Click(Sender: TObject);
var xh,sqlstr:string;
begin
if Query1.FieldByName('ZT').AsInteger=0 then
begin
xh:=Query1.FieldByName('xh').AsString;
sqlstr:='update xsb set ZT=1 where (XH='''+xh+''')';
with TQuery.Create(nil) do
begin
try
SessionName:=Main_Form.Database1.SessionName;
DataBaseName:=Main_Form.Database1.DatabaseName;
sql.Clear;
sql.Add(sqlstr);
ExecSQL;
finally
Free;
end;
end;
end
else
begin
ShowMessage('该同学已经报道!');
exit;
end;
end;
procedure Tbddg1_Form.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
if gdSelected in State then Exit;
case Query1.FieldByName('ZT').AsInteger of
0:(Sender as TDBGrid).Canvas.Brush.Color:=clWindow;
1:(Sender as TDBGrid).Canvas.Brush.Color:=clYellow;
2:(Sender as TDBGrid).Canvas.Brush.Color:=clBlue;
3:(Sender as TDBGrid).Canvas.Brush.Color:=clRed;
end;
DbGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;
procedure Tbddg1_Form.FormCreate(Sender: TObject);
begin
Query1.SessionName:=Main_Form.Database1.SessionName;
Query1.DatabaseName:=Main_Form.Database1.DatabaseName;
end;
procedure Tbddg1_Form.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Main_Form.N12.Enabled:=True;
Action:=caFree;
end;
end.