public static void WarehouseExistentBook(string order_id) { using (IDbConnection connection = new SqlConnection(Tools.GetConnectionStringValue())) { string sql = @"UPDATE dbo.SupplierOrders SET status_id = 2 WHERE id = @OrderId"; connection.Execute(sql, new { OrderId = order_id }); } var order = GetOrderOfExistentBookByOrderId(order_id); string book_isbn = order.Book_ISBN; int amount = order.Supplier_Order.Amount; if (BookDataAccess.IsBookExisted(book_isbn)) { throw new MyException("入库失败 图书不存在"); } int quantity = BookDataAccess.GetBookQuantityByISBN(book_isbn); int nQuantity = quantity + amount; try { BookDataAccess.UpdateBookQuantity(book_isbn, nQuantity); } catch (Exception ex) { throw new MyException("更新图书数量失败\n" + ex.Message); } }
public static void WarehouseNewBook(string order_id, bool is_on_sale) { using (IDbConnection connection = new SqlConnection(Tools.GetConnectionStringValue())) { string sql = @"UPDATE dbo.SupplierOrders SET status_id = 2 WHERE id = @OrderId"; connection.Execute(sql, new { OrderId = order_id }); } var order = GetOrderOfNewBookByOrderId(order_id); bool isAuthorNull = order.Book_Author.Equals(null); bool isPublisherNull = order.Book_Publisher.Equals(null); bool isPublicationDateNull = !order.Publication_Date.HasValue; bool isIntroductonNull = order.Introduction.Equals(null); if (BookDataAccess.IsBookExisted(order.Book_ISBN)) { int quantity = BookDataAccess.GetBookQuantityByISBN(order.Book_ISBN); int nQuantity = quantity + order.Supplier_Order.Amount; try { BookDataAccess.UpdateBookQuantity(order.Book_ISBN, nQuantity); } catch (Exception ex) { throw new MyException("添加图书失败\n" + ex.Message); } } else { try { BookDataAccess.InsertBook(order.Book_ISBN, order.Book_Title, order.Book_Price, order.Book_Author, order.Book_Publisher, order.Genre, order.Supplier_Order.Amount, order.Publication_Date, order.Introduction, is_on_sale, isAuthorNull, isPublisherNull, isPublicationDateNull, isIntroductonNull); } catch (Exception ex) { throw new MyException("添加图书失败\n" + ex.Message); } } }