/// <summary> /// 借阅图书 /// </summary> /// <param name="log"></param> /// <returns></returns> public bool AddBorrowLog(BookBorrowLog log) { string sqlStr = "AddBookBorrowLog"; //储存Datatable MySqlParameter[] para = new MySqlParameter[]//存储相应参数的容器 { new MySqlParameter("@returnValue", MySqlDbType.Int32, 1), new MySqlParameter("@readerId", log.ReaderId), new MySqlParameter("@bookId", log.BookId), new MySqlParameter("@borrowTime", log.BorrowTime), }; para[0].Direction = ParameterDirection.Output;//将第一个变量设为输出变量 int count = helper.ExecuteNonQuery(sqlStr, para, CommandType.StoredProcedure); if (para[0].Value.ToString() == "-2") { throw new Exception("存在未处理违约"); } if (para[0].Value.ToString() == "-3") { throw new Exception("用户可借阅数量不足"); } return(para[0].Value.ToString() == "1"); }
/// <summary> /// 增加记录 /// </summary> private void AddLog_Click(object sender, EventArgs e) { try { List <string> errorList = new List <string>();//创建一个错误列表 //获取根据当前页面内容生成的订单(若有错误会被添加到错误列表中) BookBorrowLog log = GetBookBorrowLog(ref errorList); //判断是否添加订单成功 if (circulationBll.AddBorrowLog(log, ref errorList)) { MessageBox.Show("添加成功"); } else { MessageBox.Show("添加失败"); foreach (var i in errorList) { MessageBox.Show(i);//逐条显示错误信息 } } } catch (Exception ex) { MessageBox.Show(ex.Message); } DataBind(); }
private BookBorrowLog GetBookBorrowLog(ref List <string> error) { List <string> errorList = new List <string>();//错误列表 Match matchBorrowCardNum = Regex.Match(borrowCardNumTextBox.Text, @"(^\d{11}$)"); if (!matchBorrowCardNum.Success) { errorList.Add("BorrowCardNum Error"); } //通过借书证号获取id int readerId = circulationBll.GetReaderIdByNum(borrowCardNumTextBox.Text); if (readerId == -1) { errorList.Add("ReaderId Error"); } string bookId = bookCodeTextBox.Text; if (string.IsNullOrEmpty(bookId)) { errorList.Add("BookId Error"); } BookBorrowLog bookBorrowLog = new BookBorrowLog() { BookId = int.Parse(bookId), ReaderId = readerId, BorrowTime = borrowDatePicker.Value, State = "有效" }; error = errorList; return(bookBorrowLog); }
private void btn_addCase_Click(object sender, EventArgs e) { try { List <string> errorList = new List <string>();//创建一个错误列表 //获取根据当前页面内容生成的订单(若有错误会被添加到错误列表中) var list = new BookBorrowLog[] { GetBookBorrowLog(ref errorList) }; if (errorList.Count == 0) { if (userCaseHandle.AddUserCases(list.ToList())) { MessageBox.Show("添加成功"); } } else { MessageBox.Show("添加失败"); foreach (var i in errorList) { MessageBox.Show(i);//逐条显示错误信息 } } } catch (Exception ex) { MessageBox.Show(ex.Message); } DataBind(); }
private BookBorrowLog GetBookBorrowLog(ref List <string> error) { List <string> errorList = new List <string>();//错误列表 string bookId = bookCodeTextBox.Text; if (string.IsNullOrEmpty(bookId)) { errorList.Add("BookId Error"); } string readerId = readerIdTextBox.Text; if (string.IsNullOrEmpty(readerId)) { errorList.Add("ReaderId Error"); } BookBorrowLog bookBorrowLog = new BookBorrowLog() { BookId = int.Parse(bookId), ReaderId = int.Parse(readerId), BorrowTime = borrowDatePicker.Value, State = "有效" }; error = errorList; return(bookBorrowLog); }
public void AddBorrowLogTest() { Tools.UserCaseHandle userCaseHandle = new Tools.UserCaseHandle(@"C:\Users\96464\Desktop\软件工程\测试用例\Add_BookBorrowLog.xls"); IEnumerable bookBorrowLogs = userCaseHandle.GetUserCases(); List <string> errorList = new List <string>(); foreach (var i in bookBorrowLogs) { Assert.AreEqual(false, circulationBll.AddBorrowLog((BookBorrowLog)i, ref errorList)); } int maxId = -1; foreach (Book i in circulationBll.GetAllBooksArray()) { if (i.Id > maxId) { maxId = i.Id; } } BookBorrowLog log = new BookBorrowLog() { Id = 1, BookId = maxId, ReaderId = utilBll.GetUserIdFormNumber("201709001013"), State = "有效", BorrowTime = DateTime.Now, }; Assert.AreEqual(true, circulationBll.AddBorrowLog(log, ref errorList)); maxId = -1; foreach (Book i in circulationBll.GetAllBooksArray()) { if (i.Id > maxId) { maxId = i.Id; } } log = new BookBorrowLog() { Id = 1, BookId = maxId, ReaderId = utilBll.GetUserIdFormNumber("201709001013"), State = "有效", BorrowTime = DateTime.Now, }; Assert.AreEqual(true, circulationBll.AddBorrowLog(log, ref errorList)); }
/// <summary> /// 借阅图书 /// </summary> /// <param name="log"></param> /// <param name="errorMsg">错误</param> /// <returns>增加成功与否</returns> public bool AddBorrowLog(BookBorrowLog log, ref List <string> errorMsg) { bool result = false; try { if (!BookBorrowLog.isNull(log)) //是否有空项 { if (BookBorrowLog.isNormative(log, ref errorMsg)) //是否符合规范 { result = circulationDal.AddBorrowLog(log); } } } catch (Exception ex) { Console.WriteLine(ex.Message); throw ex; } return(result); }
/// <summary> /// 获取某人全部借阅记录列表 /// </summary> /// <param name="readerId">读者编号</param> /// <param name="bookId">书籍编号</param> /// <returns>某人全部借阅记录列表</returns> public IEnumerable GetBorrowLogByReaderArray(int readerId, string bookId) { List <BookBorrowLog> result = new List <BookBorrowLog>(); try { DataTable datatable = circulationDal.GetBorrowLogByReader(readerId, bookId); foreach (DataRow dr in datatable.Rows) { BookBorrowLog log = new BookBorrowLog() { Id = (int)dr["编号"], BorrowTime = (DateTime)dr["借阅时间"], }; result.Add(log); } return(result); } catch (Exception e) { Console.WriteLine(e.Message); throw e; } }