⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unitschoolmanager.pas.~5~

📁 初中成绩录入系统网络版(firebird) firebird下的网络编程
💻 ~5~
字号:
unit UnitSchoolManager;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls,
  Forms, Dialogs,IBQuery,IBDatabase,unitDataModule,UnitStudent,ComCtrls,grids;

type
  TSchoolManager = class(TObject)
  private
    IBTrans1: TIBTransaction;
    Query1: TIBQuery;
  public
    constructor Create;
    destructor Destroy; override;
    function AddSchool(schoolname,schOrder:string): Boolean;
    function ModifySchoolname(OldName,NewName,schOrder:String): Boolean;
    function postschoolgrid(grid1:TStringGrid):boolean;
    procedure DelSchool(schoolname:string);
    procedure readTree(Tree1:TTreeView);
    procedure SchoolList(list1:Tstrings);
    procedure schoolGrid(grid1:TStringGrid);
  end;
  

implementation

{
******************************** TSchoolManager ********************************
}
constructor TSchoolManager.Create;
begin
  Query1:=TIBQuery.Create(nil);
  IBTrans1:=TIBTransaction.Create(nil);
  Query1.Transaction:=IBTrans1;
  IBTrans1.DefaultDatabase:=dm.IBDB;
  Query1.Database:=dm.IBDB;
end;

destructor TSchoolManager.Destroy;
begin
  Query1.Free;
  IBTrans1.Free;
end;

function TSchoolManager.AddSchool(schoolname,schOrder:string): Boolean;
begin
  Query1.Close;
  Query1.SQL.Text:='insert into school(schname,schorder) values('''+schoolname+''','''+schOrder+''')';
  try
    Query1.ExecSQL;
    IBTrans1.Commit;
    result:=true;
  except
    IBTrans1.Rollback;
    result:=false;
  end;
end;

procedure TSchoolManager.DelSchool(schoolname:string);
begin
  Query1.Close;
  Query1.SQL.Text:='delete from school where schname='''+schoolname+'''';
  try
    Query1.ExecSQL;
    IBTrans1.Commit;
  except
    IBTrans1.Rollback;
  end;
end;

function TSchoolManager.ModifySchoolname(OldName,NewName,schOrder:String): Boolean;
begin
  Query1.Close;
  Query1.SQL.Text:='update school set schname='''+newname+''','+
    'schorder='''+schorder+''' where schname='''+oldname+'''';
  try
    Query1.ExecSQL;
    IBTrans1.Commit;
    result:=true;
  except
    IBTrans1.Rollback;
    result:=false;
  end;
end;

procedure TSchoolManager.readTree(Tree1:TTreeView);
var
  Query2:TIBQuery;
  item:TTreeNode;
begin
  Tree1.Items.Clear;
  Query2:=TIBQuery.Create(nil);
  Query2.Database:=dm.IBDB;
  IBTrans1.Active:=false;
  Query1.Close;
  Query1.SQL.Text:='select schname from school order by schorder';
  Query1.Open;
  Query1.First;
  while not Query1.Eof do
  begin
    Item:=Tree1.Items.Add(nil,Query1.FieldByName('schname').AsString);
    Query2.Close;
    Query2.SQL.Text:='select distinct classroom from student where school='''+Item.Text+''' group by classroom order by classroom';
    Query2.Open;
    Query2.First;
    while not Query2.Eof do
    begin
      Tree1.Items.AddChild(Item,Inttostr(Query2.FieldByName('classRoom').asInteger));
      Query2.Next;
    end;
    Query1.Next;
  end;
end;


procedure TSchoolManager.SchoolList(list1:TStrings);
begin
  IBTrans1.Active:=false;
  Query1.Close;
  query1.SQL.Text:='select schname from school order by schorder';
  Query1.Open;
  Query1.First;
  while not Query1.Eof do
  begin
    list1.Add(Query1.FieldByName('schname').AsString);
    Query1.Next;
  end;
end;

procedure TSchoolManager.schoolGrid(grid1: TStringGrid);
var
  i:Integer;
begin
  Query1.Close;
  Query1.SQL.Text:='select * from school order by schorder';
  Query1.Open;
  Query1.Last;
  Grid1.RowCount:=Query1.RecordCount+1;

  Grid1.ColCount:=2;
  Grid1.Fixedcols:=0;
  Grid1.Cells[0,0]:='学校名称';
  Grid1.Cells[1,0]:='排序';
  Query1.First;
  i:=1;
  while not query1.Eof do
  begin
    Grid1.Cells[0,i]:=Query1.FieldByName('schname').AsString;
    Grid1.Cells[1,i]:=Query1.FieldByName('schorder').AsString;
    Query1.Next;
    i:=i+1;
  end;
end;

function TSchoolManager.postschoolgrid(grid1: TStringGrid):Boolean;
var
  i,j:Integer;
begin
  for i:=1 to Grid1.RowCount-1 do
  begin
    if not trystrtoint(grid1.Cells[1,i],j) then
    begin
      Application.MessageBox('排序栏必需填数字!','提示',MB_OK);
      result:=false;
      exit;
    end;
    if trim(grid1.Cells[0,i])='' then
    begin
      Application.MessageBox('学校名称不能为空!','提示',MB_OK);
      result:=false;
      exit;
    end;
  end;
  Query1.Close;
  Query1.SQL.Text:='delete from school';
  Query1.ExecSQL;
  IBTrans1.Commit;
  for i:=1 to Grid1.RowCount-1 do
  begin
    if not AddSchool(Grid1.Cells[0,i],Grid1.cells[1,i]) then
      Application.MessageBox(pchar(Grid1.cells[0,i]+'学校信息有误,可能是有重名!'),'提示',MB_OK);
  end;
  result:=true;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -