/*具体实现时发现为无法使用的服务层
     * 借书的逻辑在查询书籍之后,BID可确定
    //借书
    //传入参数为ID(辅助函数将name转为PSID)
    //返回是否借阅成功
    //之后配套函数需要执行,返回employee可借数量
    //前置条件:PSID存在,Title可以不存在
    public bool Borrow(string PSID, string Title)
    {
        DBConnectionLayer db = new DBConnectionLayer();
        db.OpenConnection();

        //查Title,如果没书,return false;有书返回第一本BID(不能在tb_borrowed中)
        string sqlSearchBook = "select BID from tb_book where Title=@title except (select BID from tb_borrowed))";
        SqlCeParameter[] pmsBook = new SqlCeParameter[]{
            new SqlCeParameter("@title",Title)
        };
        DataTable dtBook = db.GetDataTable(sqlSearchBook, pmsBook);
        if (dtBook.Rows.Count == 0)
        {
            return false;
        }
        string bid = dtBook.Rows[0][1].ToString();

        //查Employee,如果达到最大借阅,return false
        if (CanBorrowNum(PSID) == 0)
        {
            return false;
        }

        //满足可借条件
        string sql = "insert into tb_borrowed(PSID,BID) values(PSID=@psid,BID=@bid)";
        SqlCeParameter[] pms = new SqlCeParameter[]{
            new SqlCeParameter("@psid",PSID),
            new SqlCeParameter("@title",Title)
        };
        db.ExecuteCommand(sql, pms);
        db.CloseConnection();
        return true;
    }
    */
    //在查询书籍逻辑之后,故书籍一定存在,不能借阅只能是达到了最大借阅量
    //BID可确定,之后search employee,PSID也可确定
    public bool Borrow(string PSID, string BID)
    {
        DBConnectionLayer db = new DBConnectionLayer();
        db.OpenConnection();

        //检查是否达到最大借阅量
        if (CanBorrowNum(PSID) == 0)
        {
            return false;
        }

        //满足可借条件
        string sql = "insert into tb_borrowed(PSID,BID) values(@psid,@bid)";
        SqlCeParameter[] pms = new SqlCeParameter[]{
            new SqlCeParameter("@psid",PSID),
            new SqlCeParameter("@bid",BID)
        };
        db.ExecuteCommand(sql, pms);
        db.CloseConnection();
        return true;
    }
 //还书
 //仅需要知道BID便可归还
 //同借书后三条
 //前置条件:无
 public void Return(string BID)
 {
     //建立打开数据库连接
     DBConnectionLayer db = new DBConnectionLayer();
     db.OpenConnection();
     string sql = "delete from tb_borrowed where BID=@bid";
     SqlCeParameter[] pms = new SqlCeParameter[]{
         new SqlCeParameter("@bid",BID)
     };
     db.ExecuteCommand(sql, pms);
     db.CloseConnection();
 }