📄 coursemanage.pas
字号:
unit CourseManage;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, StdCtrls, ExtCtrls, ComCtrls, DB, ADODB,login;
type
TForm4 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
ADOQuery_Course: TADOQuery;
Edit_Course: TEdit;
Edit_Kp: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label_Course: TLabel;
Label_Kp: TLabel;
TreeView1: TTreeView;
ADOQuery_Kp: TADOQuery;
procedure FormShow(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure ssssMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure TreeView1Change(Sender: TObject; Node: TTreeNode);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form4: TForm4;
MyHitTest:ThitTests;
X1,Y1:INTEGER;
AnItem: TTreeNode;
implementation
uses ServerMain;
{$R *.dfm}
procedure TForm4.FormShow(Sender: TObject);
var i :integer ;
begin
TreeView1.Items.Clear;
{增加科目节点}
ADOQuery_Course.Close;
ADOQuery_Course.SQL.Clear;
// ADOQuery_Course.SQL.Add('select cr_name,kp_des from tb_course,tb_knowledge_point');
//ADOQuery_Course.SQL.Add('where cr_id=kp_cr_id');
ADOQuery_Course.SQL.Add(' select distinct cr_name from tb_course');
ADOQuery_Course.Open;
ADOQuery_Course.First;
while ( not ( ADOQuery_Course.Eof ) ) do
begin
TreeView1.Items.Add(nil,ADOQuery_Course.FieldValues['cr_name'] );
ADOQuery_Course.Next;
end;
{增加kpoint节点}
adoquery_Kp.Close;
ADOQuery_Kp.SQL.Clear;
ADOQuery_Kp.SQL.Add('select cr_name,kp_des from tb_course,tb_knowledge_point');
ADOQuery_Kp.SQL.Add('where cr_id=kp_cr_id');
ADOQuery_Kp.Open;
ADOQuery_Kp.First;
while ( not ( ADOQuery_Kp.Eof ) ) do
begin
for i := 0 to TreeView1.Items.Count-1 do
begin
if (( TreeView1.Items.Item[i].Parent =nil ) and ( TreeView1.Items.Item[i].Text = ADOQuery_Kp.FieldValues['cr_name']) ) then
TreeView1.Items.Addchild( TreeView1.Items.Item[i] ,ADOQuery_Kp.FieldValues['kp_des']);
end;
ADOQuery_Kp.Next;
end;
TreeView1.FullExpand;
Label_Course.Caption:='';
Label_Kp.Caption:='';
Edit_Course.Text:='';
Edit_Kp.Text:='';
end;
procedure TForm4.SpeedButton4Click(Sender: TObject);
begin
close();
end;
procedure TForm4.ssssMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
AnItem := TreeView1.GetNodeAt(X, Y)
end;
procedure TForm4.TreeView1Change(Sender: TObject; Node: TTreeNode);
begin
if ( node.Parent <> nil ) then
begin
Label_Course.Caption := node.Parent.Text ;
Edit_Course.Text := node.Parent.Text ;
Label_Kp.Caption := node.Text ;
end
else
begin
Label_Course.Caption := node.Text ;
Edit_Course.Text:= node.Text ;
label_Kp.Caption := '' ;
end;
end;
procedure TForm4.SpeedButton2Click(Sender: TObject);
var course , kp :string ;
begin
course := Label_Course.Caption;
kp := Label_Kp.Caption ;
if ( ( comparetext (kp , 'All') <> 0 )and (comparetext (kp , '') <> 0 ) )then
begin
showmessage('如果你点击删除,所有相关题目都会被删除 !! ');
if (application.MessageBox('操作不可逆,确认删除?','confirm_delete',mb_okcancel) = idok ) then
begin
ADOquery_Course.Close;
ADOquery_Course.SQL.Clear;
ADOquery_Course.SQL.Add('delete from tb_knowledge_point where kp_des = :kp');
ADOquery_Course.Parameters.ParamByName('kp').Value := kp;
ADOquery_Course.ExecSQL();
TreeView1.Selected.Delete;
Label_Course.Caption := '';
Label_KP.Caption := '';
end
else
begin
ADOquery_Course.Close;
ADOquery_Course.SQL.Clear;
ADOquery_Course.SQL.Add('UPDATE tb_knowledge_point SET kp_des = ''All''');
ADOquery_Course.SQL.Add(' where kp_cr_id =(select cr_id from tb_course where cr_name =:course');
ADOquery_Course.Parameters.ParamByName('course').Value := course;
ADOquery_Course.ExecSQL();
showmessage('所有相关题目的知识点信息已经修改为All(未指定) !! ');
Label_Course.Caption := '';
Label_Kp.Caption := '';
end;
end
else
begin
if (Label_Kp.Caption = 'All') then showmessage('知识点 All 代表未指定,不能被删除 !! ');
if (Label_Kp.Caption = '') then
begin
showmessage('没有选择知识点 !! ');
ADOquery_Course.Close;
ADOquery_Course.SQL.Clear;
ADOquery_Course.SQL.Add('delete from tb_course where cr_name = :course');
ADOquery_Course.Parameters.ParamByName('course').Value := course;
ADOquery_Course.ExecSQL();
TreeView1.Selected.Delete;
Label_Course.Caption := '';
Label_KP.Caption := '';
end;
end;
end;
procedure TForm4.SpeedButton1Click(Sender: TObject);
var valid :boolean;
begin
valid := true ;
if ( ( comparetext (Edit_Course.Text , '') = 0 ) or ( comparetext (Edit_Kp.Text , '') = 0 ) )then
begin
showmessage('科目\知识点怎么能空呢? ');
valid := false ;
end;
if ( valid ) then
begin
adoquery_Course.Close;
adoquery_Course.SQL.Clear;
adoquery_Course.SQL.Add('select * from tb_course,tb_knowledge_point where cr_id=kp_cr_id and cr_name = :course and kp_des = :kp');
adoquery_Course.Parameters.ParamByName('course').Value :=Edit_Course.Text;
adoquery_Course.Parameters.ParamByName('kp').Value := Edit_Kp.Text;
adoquery_Course.open();
if ( ADOQuery_Course.RecordCount <> 0 ) then
begin
valid := false ;
showmessage (' 已经有相同的知识点了 ') ;
end;
end;
if(valid) then
begin
adoquery_Course.Close;
adoquery_Course.SQL.Clear;
adoquery_Course.SQL.Add('select * from tb_course where cr_name = :course ');
adoquery_Course.Parameters.ParamByName('course').Value :=Edit_Course.Text;
adoquery_Course.open();
if ( ADOQuery_Course.RecordCount = 0 ) then
begin
adoquery_Course.Close;
adoquery_Course.SQL.Clear;
adoquery_Course.SQL.Add('INSERT INTO tb_course (cr_name) VALUES ( :course );');
adoquery_Course.SQL.Add('INSERT INTO tb_knowledge_point (kp_des , kp_cr_id) VALUES ( :kp,@@identity )');
adoquery_Course.Parameters.ParamByName('course').Value := Edit_Course.Text;
adoquery_Course.Parameters.ParamByName('kp').Value := Edit_Kp.Text;
adoquery_Course.ExecSQL();
showmessage (' 操作成功完成 ! ') ;
FormShow(self);
Edit_Course.Text := '';
Edit_Kp.Text:= '' ;
end
else
begin
adoquery_Course.Close;
adoquery_Course.SQL.Clear;
adoquery_Course.SQL.Add('declare @Var_course smallint;') ;
adoquery_Course.SQL.Add('select @Var_course = cr_id from tb_course where cr_name = :course ;');
adoquery_Course.SQL.Add('INSERT INTO tb_knowledge_point (kp_des , kp_cr_id) VALUES ( :kp,@Var_course)');
adoquery_Course.Parameters.ParamByName('course').Value :=Edit_Course.Text;
adoquery_Course.Parameters.ParamByName('kp').Value := Edit_Kp.Text;
adoquery_Course.ExecSQL();
showmessage (' 操作成功完成 ! ') ;
FormShow(self);
Edit_Course.Text := '';
Edit_Kp.Text:= '' ;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -