public Order(Order order) { this.o_id = order.O_id; this.order_id = order.Order_id; this.order_course = order.Order_course; this.order_user = order.Order_user; this.order_date = order.Order_date; this.order_price = order.Order_price; this.order_isPaid = order.Order_isPaid; this.order_isDeleted = order.Order_isDeleted; }
/// <summary> /// 在数据库中创建订单 /// </summary> /// <param name="order">包含完整信息的Order实例</param> /// <returns>成功返回true,失败返回false</returns> public Boolean CreateOrder(Order order) { Boolean result = false; if (isLegalOrder(order)) { IOrderDAL orderDAL = DALFactory.CreateInstance<IOrderDAL>("OrderDAL"); result = orderDAL.CreateOrder(order); } else { result = false; } return result; }
/// <summary> /// 判断Order类的实例中数据类型是否合法 /// </summary> /// <param name="order">要判断的Order类实例</param> /// <returns>成功返回true,失败返回false</returns> public Boolean isLegalOrder(Order order) { Boolean result = true; if (order.Order_id == null) result = false; if (order.Order_date == null) result = false; if (order.Order_course == null) result = false; if (order.Order_user == null) result = false; if (order.Order_price < 0.0 || order.Order_price == null) result = false; return result; }
/// <summary> /// 根据用户和课程创建订单,注意,所有要这么干的地方,必须调用该函数而不是new一个出来! /// </summary> /// <param name="course">用户购买的课程</param> /// <param name="user">登录的用户</param> /// <returns>一个Order类的Instance</returns> public Order CreateOrderByUserAndCourse(Course course, User user) { Order result = null; IUserBLL userBLL = BLLFactory.CreateInstance<IUserBLL>("UserBLL"); ICourseBLL courseBLL = BLLFactory.CreateInstance<ICourseBLL>("CourseBLL"); if (userBLL.isLegalNewUser(user) && courseBLL.isLegalCourse(course)) { result = new Order(); result.Order_course = course.Course_id; result.Order_user = user.User_id; } else { result = null; } return result; }
/// <summary> /// 在数据库中创建订单,调用的是数据库中的CreateNewOrder存储过程。这个函数有事务保护 /// </summary> /// <param name="order">包含订单信息的完整order类</param> /// <returns>成功返回true,否则返回false</returns> public Boolean CreateOrder(Order order) { Boolean result = false; avfunEntities DataEntity = DataEntityManager.GetDataEntity(); try { DataEntity.CreateNewOrder (order.Order_price, order.Order_user, order.Order_course, BitConverter.GetBytes(order.Order_isPaid)); result = true; } catch { result = false; } return result; }