public void TestMethod1() { BBook bll = new BBook(); MBook model = new MBook(); model.Name = "操作系统"; model.Author = "不知道了"; model.Press = 2; model.PressDateTime = new DateTime(1990, 10, 1); model.IsRead = 1; bool ret = bll.AddBook(model); Assert.AreEqual(ret, true); }
private void BTN_AddBook_Click(object sender, EventArgs e) { BBook bll = new BBook(); MBook model = new MBook(); Random random = new Random(); int a = random.Next(10000, 100000); model.KeyID = DateTime.Now.ToString("yyyyMMddHHmmss") + "0" + a; model.Name = this.TXT_BookName.Text.ToString(); model.Author = this.TXT_BookAuthor.Text.ToString(); bool ret = bll.AddBook(model); if (ret == true) { MessageBox.Show("添加成功"); } else { MessageBox.Show("添加不成功"); } }
public bool UpdateBook(System.Data.IDbTransaction trans, System.Data.IDbConnection conn, MBook model) { throw new NotImplementedException(); }
public bool AddBook(MBook model) { BAddBookTrans bll = new BAddBookTrans(model); bll.Execute(); return bll.IsSuccess; }
public bool AddBook(System.Data.IDbTransaction trans, System.Data.IDbConnection conn, MBook model) { StringBuilder sql = new StringBuilder(); sql.Append(" INSERT INTO Book(KeyID, Name, Author, Press, PressDateTime, IsRead)"); sql.Append(" SELECT @KeyID, @Name, @Author, @Press, @PressDateTime, @IsRead"); sql.Append(" FROM DUAL"); sql.Append(" WHERE NOT EXISTS("); sql.Append(" SELECT *"); sql.Append(" FROM Book"); sql.Append(" WHERE Name = @Name"); sql.Append(" AND Author = @Author"); sql.Append(" AND Press = @Press"); sql.Append(" )"); MySqlParameter[] para = new MySqlParameter[] { new MySqlParameter("@KeyID", model.KeyID), new MySqlParameter("@Name", MySqlDbType.VarChar){ Value = model.Name }, new MySqlParameter("@Author", model.Author), new MySqlParameter("@Press", model.Press), new MySqlParameter("@PressDateTime", model.PressDateTime), new MySqlParameter("@IsRead", model.IsRead) }; return MysqlHelper.ExecuteSql(trans, conn, sql.ToString(), para) >= 1 ? true : false; }