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

📄 mainform.pas

📁 基于SQL数据库,实现所有图书馆基本功能 可以按图书类别系别班别等信息自动生成书号或学号
💻 PAS
📖 第 1 页 / 共 4 页
字号:
ED_Find.Text:='';
if Radio_BName.Checked=True then
Lab_find.Caption:='书名';

if Radio_BID.Checked=True then
Lab_find.Caption:='书号';

if Radio_BType.Checked=True then
Lab_find.Caption:='类别';

if Radio_LendBool.Checked=True then
Lab_find.Caption:='是否借出';

if Radio_StuID.Checked=True then
Lab_find.Caption:='学号';

if Radio_StuName.Checked=True then
Lab_find.Caption:='姓名';

if Radio_BDays.Checked=True then
Lab_find.Caption:='剩余日期';

if Radio_LendDay.Checked=True then
Lab_find.Caption:='借出日期';

if Radio_BODay.Checked=True then
Lab_find.Caption:='过期日期';

if Radio_BWriter.Checked=True then
Lab_find.Caption:='作者';
end;

procedure TForm_main.BitBtn2Click(Sender: TObject);
begin

if Radio_BName.Checked=True then
ED_Find.Text:=Lab_BName.Caption;

if Radio_BID.Checked=True then
ED_Find.Text:=Lab_BID.Caption;

if Radio_BType.Checked=True then
ED_Find.Text:=Lab_BType.Caption;

if Radio_LendBool.Checked=True then
ED_Find.Text:=Lab_Bool.Caption;

if Radio_StuID.Checked=True then
ED_Find.Text:=Lab_BStuID.Caption;

if Radio_StuName.Checked=True then
ED_Find.Text:=Lab_BStu.Caption;

if Radio_BDays.Checked=True then
ED_Find.Text:=Lab_BDays.Caption;

if Radio_LendDay.Checked=True then
ED_Find.Text:=Lab_BLendDate.Caption;

if Radio_BODay.Checked=True then
ED_Find.Text:=Lab_BODay.Caption;

if Radio_BWriter.Checked=True then
ED_Find.Text:=Lab_BWriter.Caption;

if Radio_BMoney.Checked=True then
ED_Find.Text:=Lab_BMoney.Caption;

end;

procedure TForm_main.Bit_ShowAllClick(Sender: TObject);
begin
DM.ADOQuery1.SQL.Clear;
DM.ADOQuery1.SQL.Add('select * from BookInfo order by BID,BType');
DM.ADOQuery1.Open;
 DBGridLenght;
end;

procedure TForm_main.BTN_insertClick(Sender: TObject);
var
  IsRight_BType:Boolean;
  IsExist_BID:Boolean;
begin
  DM.ADOQuery2.SQL.Clear;
  DM.ADOQuery2.SQL.Add('select * from BookType where BookType='+QuotedStr(LeftStr(ED_BID.Text,3)));
  DM.ADOQuery2.Open;
  IsRight_BType:=DM.ADOQuery2.IsEmpty;



  DM.ADOQuery2.SQL.Clear;
  DM.ADOQuery2.SQL.Add('select * from BookInfo where BID='+QuotedStr(ED_BID.Text));
  DM.ADOQuery2.Open;
  IsExist_BID:=not DM.ADOQuery2.IsEmpty;

  if (IsRight_BType) or (IsExist_BID) then
  begin
  ShowMessage('书本已经存在或书号输入错误!');
  end
  else
  begin
  try
  DM.ADOConnection1.BeginTrans;
   DM.ADOQuery2.SQL.Clear;
  DM.ADOQuery2.SQL.Add('insert into Book (BName,BNum,BType,BDate,BPrice,BPress,BWriter,BBool,BLendTimes)');
  DM.ADOQuery2.SQL.Add(' values (:BName,:BNum,:BType,:BDate,:BPrice,:BPress,:BWriter,:BBool,:BLendTimes)');
  DM.ADOQuery2.Parameters.ParamByName('BName').Value:=ED_BName.Text;
  DM.ADOQuery2.Parameters.ParamByName('BType').Value:=LeftStr(ED_BID.Text,3);
  DM.ADOQuery2.Parameters.ParamByName('BNum').Value:=RightStr(ED_BID.Text,5);
  DM.ADOQuery2.Parameters.ParamByName('BDate').Value:=StrToDate(ED_BDate.Text); 
  DM.ADOQuery2.Parameters.ParamByName('BPrice').Value:=StrToFloat(ED_BPrice.Text);
  DM.ADOQuery2.Parameters.ParamByName('BPress').Value:=ED_BPress.Text;
  DM.ADOQuery2.Parameters.ParamByName('BWriter').Value:=ED_BWriter.Text;
  DM.ADOQuery2.Parameters.ParamByName('BBool').Value:=0;
  DM.ADOQuery2.Parameters.ParamByName('BLendTimes').Value:=0;
  DM.ADOQuery2.ExecSQL;
  DM.ADOQuery2.Close;
  DM.ADOConnection1.CommitTrans;
    except
    Application.MessageBox('插入失败!','失败',MB_OK+MB_ICONWARNING);
    DM.ADOConnection1.RollbackTrans;
    end;

  end;



  DM.ADOQuery1.SQL.Clear;
  DM.ADOQuery1.SQL.Add('select * from BookInfo order by BID,BType');
  DM.ADOQuery1.Open;
  DBGridLenght;
end;

procedure TForm_main.Bit_lendClick(Sender: TObject);

   var
    substr:TStrings;
   // i:Integer;
    temp_StuBook:string;
    int_max_num_book:Integer;
    BLendTimes:integer;
    str_bookname:string;
     str_bookID:string;
     str_stuname:string;
     str_strID:string;
  begin
  Form_main.ED_lend_BID.OnChange(ED_lend_BID);
Form_main.ED_lend_StuID.OnChange(ED_lend_StuID);
if (bool_lend_bookid) and(bool_lend_stuid) then
begin
DM.ADOQuery2.SQL.Clear;
DM.ADOQuery2.SQL.Add('select * from StuInfo where StuID='+QuotedStr(ED_lend_stuID.Text));
DM.ADOQuery2.Open;


str_bookID:=ED_lend_stuID.text;
str_strID:=ED_lend_BID.text;
str_stuname:=DM.ADOQuery2.FieldByName('StuName').AsString;

substr:=TStringList.Create;
substr.Delimiter:='|';
substr.DelimitedText:=DM.ADOQuery2.fieldbyname('StuBook').AsString;

temp_StuBook:=DM.ADOQuery2.FieldByName('StuBook').AsString;

DM.ADOQuery2.SQL.Clear;
DM.ADOQuery2.SQL.Add('select top 1 * from setup');
DM.ADOQuery2.Open;
   int_max_num_book:=strtoint(DM.ADOQuery2.FieldByName('Max_Num_Book').asstring);
//ShowMessage(DM.ADOQuery2.fieldbyname('StuBook').AsString+inttostr(substr.Count));
if substr.Count-1<int_max_num_book then
begin
DM.ADOQuery2.SQL.Clear;
DM.ADOQuery2.SQL.Add('select * from BookInfo where BID='+QuotedStr(ED_lend_BID.Text));
DM.ADOQuery2.Open;

if DM.ADOQuery2.FieldByName('BBool').AsString='False' then
begin

str_bookname:=DM.ADOQuery2.FieldByName('BName').AsString;

DM.ADOQuery2.SQL.Clear;
DM.ADOQuery2.SQL.Add('update stuinfo set stubook='+
QuotedStr(temp_StuBook+'|'+ED_lend_BID.Text)+'where StuID='+QuotedStr(ED_lend_stuID.Text));
DM.ADOQuery2.ExecSQL;


DM.ADOQuery2.SQL.Clear;
DM.ADOQuery2.SQL.Add('select BLendTimes from Book where BType+BNum='+QuotedStr(ED_lend_BID.Text));
DM.ADOQuery2.open;
BLendTimes:=DM.ADOQuery2.fieldbyname('BLendTimes').AsInteger+1;


DM.ADOQuery2.SQL.Clear;
DM.ADOQuery2.SQL.Add('update Book'
+' set BBool=1 ,BStuID='
+QuotedStr(ED_lend_stuID.Text)
+' ,BLendDate='
+QuotedStr( DateToStr(Date()))
+' ,BLendTimes='
+inttostr(BLendTimes)
+' where BType+BNum='
+QuotedStr(ED_lend_BID.text));
DM.ADOQuery2.ExecSQL;
//Memo_lend.Lines.Add('借书  '+str_memo_bookID+str_memo_bookname+str_memo_strID+str_memo_stuname+format('%25s',[DateToStr(date)])+'  '+TimeToStr(now));
//ShowMessage('借书成功!');
  DM.ADOQuery2.SQL.Clear;
  DM.ADOQuery2.SQL.Add('insert into lend_log(type,bookid,bookname,stuid,stuname,logtime)');
  DM.ADOQuery2.SQL.Add(' values (:type,:bookid,:bookname,:stuid,:stuname,:logtime)');
  DM.ADOQuery2.Parameters.ParamByName('type').Value:='借书';
  DM.ADOQuery2.Parameters.ParamByName('bookid').Value:=str_bookID;
  DM.ADOQuery2.Parameters.ParamByName('bookname').Value:=str_bookname;
  DM.ADOQuery2.Parameters.ParamByName('stuid').Value:=str_strID;
  DM.ADOQuery2.Parameters.ParamByName('stuname').Value:=str_stuname;
  DM.ADOQuery2.Parameters.ParamByName('logtime').Value:=DateToStr(date)+'  '+TimeToStr(now);
  DM.ADOQuery2.ExecSQL;
  Application.MessageBox('借书成功!','成功',MB_OK+MB_ICONASTERISK);

end
else
begin
showMessage('书本已借出!');
end;

end
else
begin
showMessage('借书额超出上限!');
end;
end
else
begin
 Application.MessageBox('信息有错或未完整','错误',MB_OK+MB_ICONWARNING);
end;
  bool_lend_bookid:=False;
  bool_lend_stuid:=False;
end;

procedure TForm_main.DBGridLenght();
begin
DBGrid2.Columns[0].Title.Caption:='书名';
DBGrid2.Columns[1].Title.Caption:='类别';
DBGrid2.Columns[2].Title.Caption:='书号';
DBGrid2.Columns[3].Title.Caption:='作者';
DBGrid2.Columns[4].Title.Caption:='价格';
DBGrid2.Columns[5].Title.Caption:='出版社';
DBGrid2.Columns[6].Title.Caption:='入库日期';
DBGrid2.Columns[7].Title.Caption:='是否借出';
DBGrid2.Columns[8].Title.Caption:='学号';
DBGrid2.Columns[9].Title.Caption:='姓名';
DBGrid2.Columns[10].Title.Caption:='班级信息';
DBGrid2.Columns[11].Title.Caption:='借书日期';
DBGrid2.Columns[12].Title.Caption:='到期日期';
DBGrid2.Columns[13].Title.Caption:='赔偿额';
DBGrid2.Columns[14].Title.Caption:='超期天数';
DBGrid2.Columns[0].Width:=80;
DBGrid2.Columns[1].Width:=50;
DBGrid2.Columns[2].Width:=60;
DBGrid2.Columns[3].Width:=40;
DBGrid2.Columns[4].Width:=30;
DBGrid2.Columns[5].Width:=80;
DBGrid2.Columns[6].Width:=55;
DBGrid2.Columns[7].Width:=50;
DBGrid2.Columns[8].Width:=70;
DBGrid2.Columns[9].Width:=50;
DBGrid2.Columns[10].Width:=110;
DBGrid2.Columns[11].Width:=55;
DBGrid2.Columns[12].Width:=55;
DBGrid2.Columns[13].Width:=50;
DBGrid2.Columns[14].Width:=50;

end;
procedure TForm_main.menu_setupClick(Sender: TObject);
begin
Form_Setup:=TForm_Setup.Create(self);
Form_Setup.ShowModal;

DM.ADOQuery1.SQL.Clear;
DM.ADOQuery1.SQL.Add('select * from BookInfo order by BID,BType');
DM.ADOQuery1.Open;
DBGridLenght;
Form_Setup.Free;
end;

procedure TForm_main.TabSheet8Show(Sender: TObject);
var

         i:Integer;
begin
i:=0;
DM.ADOQuery2.SQL.Clear;
DM.ADOQuery2.SQL.Add('select * from BookType');
DM.ADOQuery2.Open;

CB_BType.Items.Clear;
          while not DM.ADOQuery2.Eof  do
              begin
                CB_BType.Items.add(DM.ADOQuery2.fieldbyname('BType').asstring);
                 BTypeList[i]:=DM.ADOQuery2.fieldbyname('BType').asstring;
                 i:=i+1;
                DM.ADOQuery2.Next;
              end;

ED_BDate.Text:=DateToStr(date);

end;

procedure TForm_main.CB_BTypeChange(Sender: TObject);
var
 strtemp:string;
 str:string;

begin
 strtemp:= Format('%.3d',[CB_BType.ItemIndex+1]);

 str:=strtemp;


 DM.ADOQuery2.SQL.Clear;
 DM.ADOQuery2.SQL.Add('select max(BNum) from Book where BType='+QuotedStr(str));
 DM.ADOQuery2.Open;


 strtemp:=dm.ADOQuery2.Fields[0].AsString;
 if strtemp<>'' then
  begin
 strtemp:= Format('%.5d',[strtoint(strtemp)+1]);
 end
  else
  begin
 strtemp:='';
 end;
 str:=str+strtemp;
 ED_BID.Text:=str;

end;



procedure TForm_main.DBGrid1CellClick(Column: TColumn);
var
i:Integer;
 s:TStrings;
 str:String;
 strBook:string;
begin
Lab_StuName.Caption:=DM.ADOQuery1.FieldByName('StuName').AsString;
Lab_StuID.Caption:=DM.ADOQuery1.FieldByName('StuID').AsString;
Lab_StuClass.Caption:=DM.ADOQuery1.FieldByName('class').AsString;
Lab_Series.Caption:=DM.ADOQuery1.FieldByName('Stype').AsString;

Lab_SType.Caption:=DM.ADOQuery1.FieldByName('BRtype').AsString;
Lab_Grade.Caption:=DM.ADOQuery1.FieldByName('StuGrade').AsString;
Lab_ClassInfo.Caption:=DM.ADOQuery1.FieldByName('ClassInfo').AsString;
Lab_class.Caption:=DM.ADOQuery1.FieldByName('class').AsString;
Lab_Num.Caption:=DM.ADOQuery1.FieldByName('num').AsString;

Lab_Sex.Caption:=DM.ADOQuery1.FieldByName('StuSex').AsString;
if DM.ADOQuery1.FieldByName('StuSex').AsString='True' then
begin
Lab_Sex.Caption:='男';
end
else
begin
Lab_Sex.Caption:='女';
end;


str:=DM.ADOQuery1.FieldByName('StuBook').AsString;

if str<>'' then
begin
s:=TStringList.Create;
s.Delimiter:='|';
s.DelimitedText:=str;

memo1.Lines.Clear;
i:=1;

repeat

DM.ADOQuery2.SQL.Clear;
DM.ADOQuery2.SQL.Add('select BName from BookInfo where BID='+QuotedStr(s[i]));
Dm.ADOQuery2.Open;

strBook:=DM.ADOQuery2.FieldByName('BName').AsString;
memo1.Lines.Add(s[i]+'     '+strBook);
i:=i+1;
until i=s.Count;
Lab_booknum.Caption:=inttostr(s.Count-1)+'本';
DM.ADOQuery2.SQL.Clear;
DM.ADOQuery2.SQL.Add('select * from StuInfo');
Dm.ADOQuery2.Open;


end
else
begin
memo1.Lines.Clear;
end;




end;

procedure TForm_main.DBGrid1Lenght();
begin
DBGrid1.Columns[0].Title.Caption:='学号';
DBGrid1.Columns[1].Title.Caption:='姓名';
DBGrid1.Columns[2].Title.Caption:='性别';
DBGrid1.Columns[3].Title.Caption:='年级';
DBGrid1.Columns[4].Title.Caption:='类别';
DBGrid1.Columns[5].Title.Caption:='系别';
DBGrid1.Columns[6].Title.Caption:='班别';
DBGrid1.Columns[7].Title.Caption:='班内学号';
DBGrid1.Columns[8].Title.Caption:='班级信息';
DBGrid1.Columns[9].Title.Caption:='借阅的书本';
DBGrid1.Columns[0].Width:=80;
DBGrid1.Columns[1].Width:=50;
DBGrid1.Columns[2].Width:=30;
DBGrid1.Columns[3].Width:=30;
DBGrid1.Columns[4].Width:=60;
DBGrid1.Columns[5].Width:=60;
DBGrid1.Columns[6].Width:=30;
DBGrid1.Columns[7].Width:=60;
DBGrid1.Columns[8].Width:=120;
DBGrid1.Columns[9].Width:=200;

end;
   procedure TForm_main.TabSheet10Show(Sender: TObject);
begin
str_Grade:=CB_Grade.Items.Strings[CB_Grade.ItemIndex];
str_class:='1';
int_Sex:=1;



   DM.ADOQuery2.SQL.Clear;
   DM.ADOQuery2.SQL.Add('select * from SeriesType');
   DM.ADOQuery2.Open;
   CB_SeriesType.Items.Clear;
   while not Dm.ADOQuery2.Eof do
   begin
   CB_SeriesType.Items.Add(DM.ADOQuery2.fieldbyname('SType').AsString);
   DM.ADOQuery2.Next;
   end;
   CB_SeriesType.ItemIndex:=0;
   str_SType:='001';

   DM.ADOQuery2.SQL.Clear;
   DM.ADOQuery2.SQL.Add('select BRType from BranchType where SeriesType='+QuotedStr(str_SType));
   DM.ADOQuery2.Open;
   CB_BranchType.Items.Clear;
   while not Dm.ADOQuery2.Eof do
   begin
   CB_BranchType.Items.Add(DM.ADOQuery2.fieldbyname('BRType').AsString);
   DM.ADOQuery2.Next;
   end;
   CB_BranchType.ItemIndex:=0;
   str_BRtype:='01';

   Lab_Insert_StuID.Caption:=str_Grade+str_SType+str_BRtype+str_class+str_Num;

end;




procedure TForm_main.CB_GradeChange(Sender: TObject);
begin
str_Grade:=CB_Grade.Items.Strings[CB_Grade.ItemIndex];
Lab_Insert_StuID.Caption:=str_Grade+str_SType+str_BRtype+str_class+str_Num;
end;

procedure TForm_main.CB_SeriesTypeChange(Sender: TObject);
begin
DM.ADOQuery2.SQL.Clear;
   DM.ADOQuery2.SQL.Add('select SeriesType from SeriesType where SType='+QuotedStr(CB_SeriesType.Items.Strings[CB_SeriesType.Itemindex]));
   DM.ADOQuery2.Open;
   str_SType:=DM.ADOQuery2.fieldbyname('SeriesType').AsString;

   DM.ADOQuery2.SQL.Clear;
   DM.ADOQuery2.SQL.Add('select BRType from BranchType where SeriesType='+QuotedStr(str_SType));
   DM.ADOQuery2.Open;
   CB_BranchType.Items.Clear;
   while not Dm.ADOQuery2.Eof do
   begin
   CB_BranchType.Items.Add(DM.ADOQuery2.fieldbyname('BRType').AsString);
   DM.ADOQuery2.Next;
   end;
   CB_BranchType.ItemIndex:=0;
   Lab_Insert_StuID.Caption:=str_Grade+str_SType+str_BRtype+str_class+str_Num;
end;

procedure TForm_main.CB_BranchTypeChange(Sender: TObject);
begin
   DM.ADOQuery2.SQL.Clear;
   DM.ADOQuery2.SQL.Add('select * from BranchType where BRType='+QuotedStr(CB_BranchType.Items.Strings[CB_BranchType.Itemindex]));
   DM.ADOQuery2.Open;
   str_BRtype:=DM.ADOQuery2.fieldbyname('BranchType').AsString;
   Lab_Insert_StuID.Caption:=str_Grade+str_SType+str_BRtype+str_class+str_Num;
end;

procedure TForm_main.ED_NumKeyPress(Sender: TObject; var Key: Char);
begin
if not (key  in ['1','2','3','4','5','6','7','8','9','0',#8]) then
begin
key:=#0;

⌨️ 快捷键说明

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