📄 stu.~pas
字号:
unit stu;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DBTables, DB, ExtCtrls, StdCtrls, Mask, DBCtrls, Grids, DBGrids,
Buttons;
type
TForm2 = class(TForm)
DataSource1: TDataSource;
DataSource2: TDataSource;
Query1: TQuery;
Query2: TQuery;
Query3: TQuery;
Query4: TQuery;
Query5: TQuery;
Table1: TTable;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Edit1: TEdit;
DBEdit3: TDBEdit;
DBEdit4: TDBEdit;
que: TBitBtn;
BitBtn2: TBitBtn;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
xuan: TBitBtn;
tui: TBitBtn;
Label6: TLabel;
stringGrid1: TStringGrid;
procedure Edit1Enter(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure xuanClick(Sender: TObject);
procedure cSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure tuiClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure queClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
i,j :integer ;
sacol,sarow :integer;
acno :array[1..5,1..4] of string ;
snum : string ;
implementation
{$R *.dfm}
procedure TForm2.Edit1Enter(Sender: TObject);
begin
edit1.text:='';
dbedit1.text:='';
dbedit2.text:='';
for i:=1 to 5 do
for j:=1 to 4 do
begin
stringGrid1.Cells[i,j]:= '' ;
acno[i,j]:='';
end;
query5.close;
xuan.enabled:=false;
tui.enabled:=false;
end;
procedure TForm2.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if (key=#13) and (Edit1.Text<>'') then
que.Click;
end;
procedure TForm2.xuanClick(Sender: TObject);
begin
if table1cquato.value:=table1cnum.value then
begin
showmessage('没有名额');
exit;
end ;
sacol:=table1ctime.value div 10;
sarow:=table1ctime.value- sacol*10 ;
if stringGrid1.Cells[sacol,sarow]<>'' then
begin
showmessage('时间冲突');
exit;
end;
try
query3.close;
query3.parambyname('sno').value:=snum ;
query3.parambyname('cno').value:=table1cno.value;
query3.execsql;
except
showmessage('该课程已修');
exit;
end;
stringGrid1.Cells[sacol,sarow]:=table1cname.value;
acno[sacol,sarow]:=table1cno.value;
Table1.Edit ;
Table1cnum.value:=table1cnum.value+1;
Table1.Post ;
query5.close;
query5.open;
end;
procedure TForm2.StringGrid1SelectCell(Sender: TObject; aCol,
aRow: Integer; var CanSelect: Boolean);
begin
sacol:=acol;
sarow:=arow;
procedure TForm2.FormShow(Sender: TObject);
begin
stringGrid1.Cells[0,1]:= '第一节' ;}
stringGrid1.Cells[0,2]:= '第二节' ;
stringGrid1.Cells[0,3]:= '第三节' ;
stringGrid1.Cells[0,4]:= '第四节' ;
stringGrid1.Cells[0,5]:= '第五节' ;
stringGrid1.Cells[0,6]:= '第六节' ;
stringGrid1.Cells[0,7]:= '第七节' ;
stringGrid1.Cells[1,0]:= '星期一' ;
stringGrid1.Cells[2,0]:= '星期二' ;
stringGrid1.Cells[3,0]:= '星期三' ;
stringGrid1.Cells[4,0]:= '星期四' ;
stringGrid1.Cells[5,0]:= '星期五' ;
edit1.SetFocus;
end;
procedure TForm2.queClick(Sender: TObject);
begin
snum:=edit1.text;
query1.close;
query1.sql.Clear;
query1.sql.add('select sname from student');
query1.sql.add('where sno='''+edit1.text+'''');
query1.open;
if query1.fieldbyname('sname').asstring='' then
showmessage('学号有误')
else
begin
dbEdit1.text:=query1.fieldbyname('sname').value;
query1.close;
query1.sql.Clear;
query1.sql.add('select sum(credit) from sc,course');
query1.sql.add('where sno=''' + edit1.text+'''');
query1.sql.add('and sc.cno=course.cno and grade>=60');
query1.open;
dbedit2.text:=query1.Fields[0].asstring;
query5.close;
query5.ParamByName('sno').value:=snum;
query5.open;
query2.close;
query2.ParamByName('sno').value:=snum;
query2.open;
While not query2.EOF do
begin
sacol:=query2ctime.value div 10 ;
sarow:=query2ctime.value - sacol*10 ;
stringGrid1.Cells[sacol,sarow]:=query2cname.value ;
acno[sacol,sarow]:=query2cno.value;
query2.Next;
end;
xuan.enabled:=true;{打开选课,退课按钮}
tui.enabled:=true;
end;
end;
procedure TForm2.cSelectCell(Sender: TObject; ACol,ARow: Integer; var CanSelect: Boolean);
begin
sacol:=acol;
sarow:=arow;
end;
procedureTForm2.tuiClick(Sender: TObject);
begin
if stringGrid1.Cells[sacol,sarow]='' then
begin
showmessage('请选择退选课程');
exit;
end ;
query4.close;
query4.parambyname('sno').value:=snum;
query4.parambyname('cno').value:=acno[sacol,sarow];
query4.execsql;{打开query4}
table1.locate('cno',acno[sacol,sarow],[]);
Table1.Edit ;
Table1cnum.value:=table1cnum.value-1;
Table1.Post ;
stringGrid1.Cells[sacol,sarow]:='' ;
acno[sacol,sarow]:='' ;
query5.close;
query5.open
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -