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

📄 frmloanu.pas

📁 图书借阅管理系统含源代码
💻 PAS
📖 第 1 页 / 共 2 页
字号:
    //if Dm.adoLoan.FieldByName('BagMonth').AsString='1' then//预付型用户
      if StrToFloat(Dm.adoLoan.FieldByName('Balance').AsString)<MaxArrearage then//余额不足
      begin
        MessageBox(0,Pchar('借出失败!'+Chr(13)+'借书证为:“'+edLeaseNo.Text+'的用户余额少于最少余额限制'+FloatToStr(MaxArrearage)+'元的规定,本次借书行动被终止。'+chr(13)+'该读者现在余额只有:'+Dm.adoLoan.FieldByName('Balance').AsString+'元'),'提示',MB_OK+MB_ICONSTOP+MB_TASKMODAL);
        Dm.adoLoan.Close;
        exit;
      end;
//----------------------------------------
    Dm.adoLoan.Close;
    Dm.adoLoan.SQL.Clear;
    Dm.adoLoan.SQL.Text:='Select * from Loan';
    Dm.adoLoan.Open;

    Dm.adoTemp.Close;
    Dm.adoTemp.SQL.Clear;
    Dm.adoTemp.SQL.Text:='select * from Book where BookNo='+QuotedStr(edBookNo.Text);
    Dm.adoTemp.Open;

    //------Loan表写入-----
    DM.adoLoan.Append;
    DM.adoLoan.FieldByName('LeaseNo').AsString:=Trim(edLeaseNo.Text);
    Dm.adoLoan.FieldByName('BookNo').AsString:=Trim(edBookNo.Text);
    Dm.adoLoan.FieldByName('LoanDate').AsString:=DateToStr(Date);
    Dm.adoLoan.FieldByName('ReturnDate').AsString:=DateToStr(Date+Dm.adoTemp.FieldByName('Term').AsInteger);
    Dm.adoLoan.Post;
    //-----book修改-------
    Dm.adoTemp.Edit;
    Dm.adoTemp.FieldByName('Loan').AsString:='1';
    Dm.adoTemp.FieldByName('LoanDate').AsString:=DateToStr(Date);
    Dm.adoTemp.FieldByName('LeaseNo').AsString:=edLeaseNo.Text;
    Dm.adoTemp.FieldByName('WBTN').AsInteger:=Dm.adoTemp.FieldByName('WBTN').AsInteger+1;
    Dm.adoTemp.Post;
    //-------------------
    Dm.adoLoan.Close;
    Dm.adoTemp.Close;
    MessageBox(0,'借出成功!','提示',MB_OK+MB_ICONEXCLAMATION+MB_TASKMODAL);
  end
  else
  begin//还书
    Dm.adoLoan.Close;
    Dm.adoLoan.SQL.Clear;
    Dm.adoLoan.SQL.Text:='select * from Loan where BookNo='+QuotedStr(edBookNo.Text);
    Dm.adoLoan.Open;

    Dm.adoTemp.Close;
    Dm.adoTemp.SQL.Clear;
    DM.adoTemp.SQL.Text:='select * from Book where BookNo='+QuotedStr(edBookNo.Text);
    Dm.adoTemp.Open;

    Dm.adoTemp2.Close;
    Dm.adoTemp2.SQL.Clear;
    Dm.adoTemp2.SQL.Text:='select * from Reader where LeaseNo='+QuotedStr(edLeaseNo.Text);
    Dm.adoTemp2.Open;

    //------修改Book表----------
    Dm.adoTemp.Edit;
    Dm.adoTemp.FieldByName('LoanDate').AsString:='';
    Dm.adoTemp.FieldByName('Loan').AsString:='0';
    DM.adoTemp.FieldByName('LeaseNo').AsString:='';
    Dm.adoTemp.Post;

    //-----修改Reader表---------
    myDate1:=0;//限期内借阅天数
    myDate2:=0;//超出归还限期天数
    myDate3:=0;//借书后才开始包月之前的天数
    myDate4:=0;//包月时间内超出归还限期天数
    myDate5:=0;//非包月时间内超出归还限期天数
    Money1:=0.00;
    Money2:=0.00;
    Money3:=0.00;
    Money4:=0.00;
    Money5:=0.00;
    //计算出图书借出天数
    myDate1:=trunc(Date)-trunc(Dm.adoLoan.FieldByName('LoanDate').AsDateTime);//计算出一共借阅了的时间
    if myDate1=0 then//如果图书当天借当天还则按一天计算
      myDate1:=1;

    if Dm.adoTemp2.FieldByName('BagMoStTim').AsDateTime>Dm.adoLoan.FieldByName('LoanDate').AsDateTime then
      myDate3:=Trunc(Dm.adoTemp2.FieldByName('BagMoStTim').AsDateTime)-Trunc(Dm.adoLoan.FieldByName('LoanDate').AsDateTime);
    if Date>Dm.adoLoan.FieldByName('ReturnDate').AsDateTime then
    begin
      if Dm.adoTemp2.FieldByName('BagMoTim').AsDateTime<Date then
        myDate4:=Trunc(Dm.adoTemp2.FieldByName('BagMoTim').AsDateTime)-Trunc(Dm.adoLoan.FieldByName('ReturnDate').AsDateTime);
      myDate2:=Trunc(Date)-Trunc(Dm.adoLoan.FieldByName('ReturnDate').AsDateTime);//超出归还限期天数
      myDate1:=myDate1-myDate2;//没超出归还限期天数
      myDate5:=myDate2-myDate4;
    end;

    str:='还书成功!';
    //----------------------
    if Dm.adoTemp2.FieldByName('BagMoTim').AsDateTime<Dm.adoLoan.FieldByName('LoanDate').AsDateTime then
    begin//非包月读者处理
      Money1:=RoundTo(myDate1*Loancost,-2);
      Money2:=RoundTo(myDate2*OverstepTermHire,-2);
      str:=Str+Chr(13)+'预存式归还限期内借阅'+IntToStr(myDate1)+'天,共扣费'+FloatToStr(RoundTo(Money1,-2))+'元'
           +Chr(13)+'预存式超出归还限期'+IntToStr(myDate2)+'天,共扣费'+FloatToStr(RoundTo(Money2,-2))+'元';
    end
    else
    begin//包月读者处理
      Money3:=RoundTo(myDate3*LoanCost,-2);
      Money4:=RoundTo(myDate4*OverstepTermHire2,-2);
      Money5:=RoundTo(myDate5*OverstepTermHire,-2);
      Str:=Str+Chr(13)+'包月式归还限期内借阅'+IntToStr(myDate1)+'天,共扣费0元'
           +Chr(13)+'预存式归还限期内借阅'+IntToStr(myDate3)+'天,共扣费'+FloatToStr(RoundTo(Money3,-2))+'元'
           +Chr(13)+'包月式超出归还限期'+IntToStr(myDate4)+'天,共扣费'+FloatToStr(RoundTo(Money4,-2))+'元'
           +CHr(13)+'预存式超出归还限期'+IntToStr(myDate5)+'天,共扣费'+FloatToStr(RoundTo(Money5,-2))+'元';
    end;
    Money:=RoundTo(Money1+Money2+Money3+Money4+Money5,-2);
    Str:=Str+Chr(13)+'借阅'+IntToStr(myDate1+myDate2)+'天共扣费:'+FloatToStr(RoundTo(Money,-2))+'元人民币'+Chr(13)+'<系统自动扣费完成。>';
    Dm.adoTemp2.Edit;
    Dm.adoTemp2.FieldByName('Balance').AsString:=FloatToStr(RoundTo(DM.adoTemp2.FieldByName('Balance').AsFloat-Money,-2));
    Dm.adoTemp2.Post;
    //---------删除Loan表中数据--------
    Dm.adoLoan.Delete;
    MessageBox(0,Pchar(str),'提示',MB_OK+MB_ICONEXCLAMATION+MB_TASKMODAL);
  end;

//================
  Dm.adoLoan.Close;
  Dm.adoLoan.SQL.Clear;
  Dm.adoLoan.SQL.Text:='select * from Reader where LeaseNo='+QuotedStr(edLeaseNo.Text);
  Dm.adoLoan.Open;

  Dm.adoTemp.Close;
  Dm.adoTemp.SQL.Clear;
  Dm.adoTemp.SQL.Text:='select * from Loan where LeaseNo='+QuotedStr(edLeaseNo.Text);
  Dm.adoTemp.Open;


  if DM.adoTemp.RecordCount=0 then
    if Dm.adoLoan.FieldByName('BagMonth').AsString='0' then//是否包月用户
      if StrToDate(DM.adoLoan.FieldByName('BagMoTim').AsString)<Date then//其包月时间已过
      begin
        Dm.adoLoan.Edit;
        Dm.adoLoan.FieldByName('BagMonth').AsString:='1';//将该读者的借阅计费改为预存方式
        Dm.adoLoan.FieldByName('BagMoTim').AsString:='';
        Dm.adoLoan.FieldByName('BagMoStTim').AsString:='';
        Dm.adoLoan.Post;
      end;
  DM.adoLoan.Close;
  Dm.adoTemp.Close;
  clsText();
end;

procedure TfrmLoan.edLeaseNOExit(Sender: TObject);
begin
  if edLeaseNo.Text<>''then
    btnLeaseNo.Click;
end;

procedure TfrmLoan.btnBookNoClick(Sender: TObject);
var
  f:file of Byte;
  TempPic:String;
begin
  Dm.adoTemp.Close;
  Dm.adoTemp.SQL.Clear;
  Dm.adoTemp.SQL.Text:='select * from book where BookNo='+QuotedStr(edBookNo.Text);
  Dm.adoTemp.Open;

  if Dm.adoTemp.RecordCount=0 then
  begin
    MessageBox(0,Pchar('找不到图书号为:“'+edBookNo.Text+'”的图书。'),'提示',MB_OK+MB_ICONEXCLAMATION+MB_TASKMODAL);
    edBookNo.SetFocus;
    edBookNo.Clear;
    exit;
  end;

  Dm.adoTemp.Close;
  Dm.adoTemp.SQL.Clear;
  Dm.adoTemp.SQL.Text:='select * from book where BookNo='+QuotedStr(edBookNo.Text);
  Dm.adoTemp.Open;

  if not LoanBoo then
    if Dm.adoTemp.FieldByName('Loan').AsString='0' then
    begin
      MessageBox(0,Pchar('图书号为:“'+edBookNo.Text+'”的图书尚未被借出。'),'提示',MB_OK+MB_ICONEXCLAMATION+MB_TASKMODAL);
      edBookNo.SetFocus;
      edBookNo.Clear;
      Dm.adoTemp.Close;
      exit;
    end
    else
      edLeaseNo.Text:=Dm.adoTemp.FieldByName('LeaseNo').AsString;
  btnLeaseNo.Click;
  Dm.adoTemp.Close;
  Dm.adoTemp.SQL.Clear;
  Dm.adoTemp.SQL.Text:='select * from book where BookNo='+QuotedStr(edBookNo.Text);
  Dm.adoTemp.Open;

  edTitle.Text:=Dm.adoTemp.FieldByName('Title').AsString;
  edAuthor.Text:=Dm.adoTemp.FieldByName('author').AsString;
  edBoConName.Text:=Dm.adoTemp.FieldByName('BoConName').AsString;
  if Dm.adoTemp.FieldByName('Loan').AsString='0'then
  begin
    Label10.Visible:=False;
    edLoanDate.Visible:=False;
    edLoan.Text:='未借出';
  end
  else
  begin
    Label10.Visible:=True;
    edLoanDate.Visible:=True;
    edLoanDate.Text:=Dm.adoTemp.FieldByName('LoanDate').AsString;
    edLoan.Text:='已借出';
  end;
//===============读取相片===========
  TempPic:=ExtractFilePath(Application.ExeName)+'temp.jpg';
  DeleteFile(TempPic);
  TblobField(DM.adoTemp.FieldByName('Pic')).SaveToFile(TempPic);
  AssignFile(f,TempPic);
  Reset(f);
  if FileSize(f)=0 then
  begin
    imgPic.Picture.LoadFromFile(ExtractFilePath(Application.ExeName)+'\noPic.jpg');
    CloseFile(f);
  end
  else
  begin
    CloseFile(f);
    imgPic.Picture.LoadFromFile(TempPic);
  end;
  DeleteFile(TempPic);
  imgPic.Visible:=True;
//===========================
  Dm.adoTemp.Close;
end;

procedure TfrmLoan.edBookNoExit(Sender: TObject);
begin
  if edBookNo.Text<>''then
    btnBookNo.Click;
end;

end.

⌨️ 快捷键说明

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