예제 #1
0
파일: Course.cs 프로젝트: 0daydigger/Avfun
 public Course(Course course)
 {
     this.c_id = course.C_id;
     this.course_id = course.Course_id;
     this.course_name = course.Course_name;
     this.course_intro = course.Course_intro;
     this.course_price = course.Course_price;
     this.course_robot_link = course.Course_robot_link;
     this.course_begin_date = course.Course_begin_date;
     this.course_isDeleted = course.Course_isDeleted;
 }
예제 #2
0
 /// <summary>
 /// 将Course类转换为COURSE类
 /// </summary>
 /// <param name="course">要转换的Course类</param>
 /// <returns>转换后对应的COURSE类实例</returns>
 public COURSE ConvertCourseToCOURSE(Course course)
 {
     COURSE ResultCOURSE = new COURSE();
     ResultCOURSE.course_id = course.Course_id;
     ResultCOURSE.course_intro = course.Course_intro;
     ResultCOURSE.course_name = course.Course_name;
     ResultCOURSE.course_price = course.Course_price;
     ResultCOURSE.course_robot_link = course.Course_robot_link;
     ResultCOURSE.course_begin_date = course.Course_begin_date;
     ResultCOURSE.course_isDeleted = course.Course_isDeleted;
     return ResultCOURSE;
 }
예제 #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     Admin loggedAdmin = AdminOpr.isLogged(Request);
     if (loggedAdmin == null)
     {
         lblLoginStatus.Text = "您未登录或已登录过期,请重新登录。3秒后转向登录页面";
         lblLoginStatus.Visible = true;
         //重定向
         HtmlMeta RedirectMeta = new HtmlMeta(); //重定向用Meta标签
         RedirectMeta.HttpEquiv = "refresh"; //指定行为为跳转
         RedirectMeta.Content = "3;url=admin_login.aspx"; //时间为三秒,跳转到首页
         this.Page.Header.Controls.Add(RedirectMeta);
     }
     else
     {
         //已登录
         if (Request.QueryString["course_id"] == null)
         {
             //id没有
             lblLoginStatus.Text = "试图删除的课程不存在";
             lblLoginStatus.Visible = true;
         }
         else
         {
             //有了id
             String course_id = Request.QueryString["course_id"];
             Course toDelCourse = new Course();
             toDelCourse.Course_id = new Guid(course_id);
             Course entireCourse = CourseOpr.GetCourseByID(toDelCourse);
             if (entireCourse != null)
             {
                 //获取到了course信息
                 entireCourse.Course_isDeleted = true;
                 if (CourseOpr.UpdateCourseInfo(entireCourse))
                 {
                     lblLoginStatus.Text = "删除课程成功";
                     lblLoginStatus.Visible = true;
                 }
                 else
                 {
                     lblLoginStatus.Text = "删除课程失败";
                     lblLoginStatus.Visible = true;
                 }
             }
             else
             {
                 lblLoginStatus.Text = "试图删除的课程不存在";
                 lblLoginStatus.Visible = true;
             }
         }
     }
 }
예제 #4
0
 /// <summary>
 /// 将从数据库中获取的COURSE类转换为Course类
 /// </summary>
 /// <param name="course">要转换的COURSE类实例</param>
 /// <returns>转换完毕的对应Course类实例</returns>
 public Course ConvertCOURSEToCourse(COURSE course)
 {
     Course result = new Course();
     result.Course_id = course.course_id;
     result.Course_intro = course.course_intro;
     result.Course_name = course.course_name;
     result.Course_price = course.course_price;
     result.Course_robot_link = course.course_robot_link;
     result.Course_begin_date = course.course_begin_date;
     result.Course_isDeleted = course.course_isDeleted;
     result.Course_timestamp = course.course_timestamp;
     return result;
 }
예제 #5
0
 /// <summary>
 /// 更新课程信息,course是包括完整(更新后)课程信息的Course类实例
 /// </summary>
 /// <param name="course">包含完整课程信息的Course类实例</param>
 /// <returns>成功返回true,否则返回false</returns>
 public static Boolean UpdateCourseInfo(Course course)
 {
     Boolean result = false;
     if (isLegalCourse(course))
     {
         CourseData courseData = CourseData.GetNewInstance();
         result = courseData.UpdateCourseInfo(course);
     }
     else
     {
         result = false;
     }
     return result;
 }
예제 #6
0
 /// <summary>
 /// 根据ID获取课程的详细信息,如果获取到返回对应的Course类实例,否则返回null
 /// </summary>
 /// <param name="course">要查找的Course类实例,其中course_id必填</param>
 /// <returns>查找到返回包含全部信息的Course类实例,否则返回null</returns>
 public static Course GetCourseByID(Course course)
 {
     //数据合法性检查
     Course result = null;
     if (course.Course_id != null)
     {
         CourseData courseData = CourseData.GetNewInstance();
         result = courseData.GetCourseByID(course);
     }
     else
     {
         result = null;
     }
     return result;
 }
예제 #7
0
 /// <summary>
 /// 根据用户和课程创建订单,注意,所有要这么干的地方,必须调用该函数而不是new一个出来!
 /// </summary>
 /// <param name="course">用户购买的课程</param>
 /// <param name="user">登录的用户</param>
 /// <returns>一个Order类的Instance</returns>
 public static Order CreateOrderByUserAndCourse(Course course, User user)
 {
     Order result = null;
     if (UserOpr.isLegalNewUser(user)
         && CourseOpr.isLegalCourse(course))
     {
         result = new Order();
         result.Order_course = course.Course_id;
         result.Order_user = user.User_id;
     }
     else
     {
         result = null;
     }
     return result;
 }
예제 #8
0
 /// <summary>
 /// 新增课程,数据完整性检查在BLL层做。成功返回true,失败返回false
 /// </summary>
 /// <param name="course">包含新增课程信息的Course类实例</param>
 /// <returns>成功返回true,失败返回false</returns>
 public Boolean CreateCourse(Course course)
 {
     avfunEntities DataEntity = DataEntityManager.GetDataEntity();
     COURSE newCOURSE = ConvertCourseToCOURSE(course);
     Boolean result = false ;
     try
     {
         DataEntity.COURSE.AddObject(newCOURSE);
         DataEntity.SaveChanges();
         result = true;
     }
     catch
     {
         result = false;
     }
     return result;
 }
예제 #9
0
 /// <summary>
 /// 判断课程类Course的实例是否合法,合法返回true否则返回false
 /// </summary>
 /// <param name="course">要判断的课程类Course的实例</param>
 /// <returns>合法返回true,否则返回false</returns>
 public static Boolean isLegalCourse(Course course)
 {
     Boolean result = true;
     if (course.Course_id == null)
         result = false;
     if (string.IsNullOrEmpty(course.Course_name)
         || course.Course_name.Length > 256
         )
         result = false;
     if (course.Course_price < 0.0d)
         result = false;
     if (string.IsNullOrEmpty(course.Course_robot_link)
         || course.Course_robot_link.Length > 256)
         result = false;
     if (course.Course_begin_date == null)
         result = false;
     return result;
 }
예제 #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Admin loggedAdmin = AdminOpr.isLogged(Request);
            if (loggedAdmin == null)
            {
                //没登录
                LoginForm.Visible = false;
                lblLoginStatus.Visible = true;
                lblLoginStatus.Text = "您未登录或登录已经过期,请重新登录";
            }
            else
            {
                //已经登录
                if (!Page.IsPostBack)
                {
                    //没提交回来
                    if (Request.QueryString["course_id"] != null)
                    {
                        //修改课程信息
                        Course toFindCourse = new Course();
                        toFindCourse.Course_id = new Guid(Request.QueryString["course_id"].ToString());
                        Course entireCourse = CourseOpr.GetCourseByID(toFindCourse);
                        if (entireCourse != null)
                        {
                            //找到了
                            txtCourseIntro.Text = entireCourse.Course_intro;
                            txtCoursePrice.Text = entireCourse.Course_price.ToString();
                            txtCourseTitle.Text = entireCourse.Course_name;
                            txtCourseRobotLink.Text = entireCourse.Course_robot_link;
                        }
                        else
                        {
                            //没找到
                            lblLoginStatus.Text = "试图修改的课程不存在";
                            lblLoginStatus.Visible = true;
                            LoginForm.Visible = false;
                        }
                    }
                }
                else
                {
                    //被提交回来惹!
                    if (Request.QueryString["course_id"] == null)
                    {
                        //填充新课程信息
                        Guid course_id = System.Guid.NewGuid();
                        String course_name = Request.Form[txtCourseTitle.ID];
                        DateTime course_begin_date = DateTime.Now;
                        Double course_price = Convert.ToDouble(Request.Form[txtCoursePrice.ID]);
                        String course_robot_link = Request.Form[txtCourseRobotLink.ID];
                        Boolean course_is_deleted = false;
                        String course_intro = Request.Form[txtCourseIntro.ID];
                        //OK,开始赋值
                        Course newCourse = new Course();
                        newCourse.Course_id = course_id;
                        newCourse.Course_name = course_name;
                        newCourse.Course_begin_date = course_begin_date;
                        newCourse.Course_price = course_price;
                        newCourse.Course_robot_link = course_robot_link;
                        newCourse.Course_intro = course_intro;
                        newCourse.Course_isDeleted = course_is_deleted;
                        if (CourseOpr.CreateCourse(newCourse))
                        {
                            lblLoginStatus.Text = "发布课程成功";
                            lblLoginStatus.Visible = true;
                        }
                        else
                        {
                            lblLoginStatus.Text = "发布课程失败";
                            lblLoginStatus.Visible = true;
                        }
                    }
                    else
                    {
                        //修改课程信息
                        Course toFindCourse = new Course();
                        toFindCourse.Course_id = new Guid(Request.QueryString["course_id"].ToString());
                        Course entireCourse = CourseOpr.GetCourseByID(toFindCourse);
                        if (entireCourse != null)
                        {
                            //找到了
                            String course_name = Request.Form[txtCourseTitle.ID];
                            Double course_price = Convert.ToDouble(Request.Form[txtCoursePrice.ID]);
                            String course_robot_link = Request.Form[txtCourseRobotLink.ID].Trim();
                            String course_intro = Request.Form[txtCourseIntro.ID];
                            //赋值
                            entireCourse.Course_name = course_name;
                            entireCourse.Course_price = course_price;
                            entireCourse.Course_robot_link = course_robot_link;
                            entireCourse.Course_intro = course_intro;
                            if (CourseOpr.UpdateCourseInfo(entireCourse))
                            {
                                lblLoginStatus.Text = "修改课程信息成功";
                                lblLoginStatus.Visible = true;
                            }
                            else
                            {
                                lblLoginStatus.Text = "修改课程信息失败";
                                lblLoginStatus.Visible = true;
                            }
                        }
                        else
                        {
                            //没找到
                            lblLoginStatus.Text = "试图修改的课程不存在";
                            lblLoginStatus.Visible = true;
                            LoginForm.Visible = false;
                        }
                    }

                }
            }
        }
예제 #11
0
 /// <summary>
 /// 根据ID获取包含完整信息的Course类实例
 /// </summary>
 /// <param name="course">包含id字段的Course类实例</param>
 /// <returns>包含完整信息的Course类实例</returns>
 public Course GetCourseByID(Course course)
 {
     avfunEntities DataEntity = DataEntityManager.GetDataEntity();
     Course result = null;
     try
     {
         COURSE toFindCourse = (from c in DataEntity.COURSE
                               where
                               c.course_id == course.Course_id
                               select c).Single();
         result = ConvertCOURSEToCourse(toFindCourse);
     }
     catch
     {
         result = null;
     }
     return result;
 }
예제 #12
0
 /// <summary>
 /// 更新课程信息,course为包含完整的要更新的课程信息的Course类实例
 /// </summary>
 /// <param name="course">包含完整要更新的课程信息的Course类实例</param>
 /// <returns></returns>
 public Boolean UpdateCourseInfo(Course course)
 {
     avfunEntities DataEntity = DataEntityManager.GetDataEntity();
     Boolean result = false;
     try
     {
         COURSE toUpdateCourse = ( from c in DataEntity.COURSE
                                   where
                                   c.course_id == course.Course_id
                                   &&
                                   c.course_timestamp == course.Course_timestamp
                                   select c
                                   ).Single();
         toUpdateCourse.course_intro = course.Course_intro;
         toUpdateCourse.course_name = course.Course_name;
         toUpdateCourse.course_price = course.Course_price;
         toUpdateCourse.course_robot_link = course.Course_robot_link;
         toUpdateCourse.course_begin_date = course.Course_begin_date;
         toUpdateCourse.course_isDeleted = course.Course_isDeleted;
         DataEntity.SaveChanges();
         result = true;
     }
     catch
     {
         result = false;
     }
     return result;
 }
예제 #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            User loggedUser = UserOpr.isLogged(Request);
            if (loggedUser == null) //如果未登录
            {
                BuyCourseForm.Visible = false;
                lblLoginStatus.Text = "您未登录或已登录过期,请登录后再进行召唤。3秒后跳转到用户登录界面";
                //重定向
                HtmlMeta RedirectMeta = new HtmlMeta(); //重定向用Meta标签
                RedirectMeta.HttpEquiv = "refresh"; //指定行为为跳转
                RedirectMeta.Content = "3;url=" + ReadWebConfig.GetAppSettingValue("LoginPageURL"); //时间为三秒,跳转到首页
                this.Page.Header.Controls.Add(RedirectMeta);
            }
            else
            {
                if (loggedUser.User_isChecked == false
                    || loggedUser.User_isDeleted == true
                    )
                {
                    BuyCourseForm.Visible = false;
                    lblLoginStatus.Text = "您的账户未激活或已被删除,无法购买";
                }
                else
                {
                    //已经登录
                    if (!Page.IsPostBack)
                    {
                        //如果页面不是提交回来的
                        try
                        {
                            //这句可能有错
                            Guid courseID = new Guid(Request.QueryString["course_id"]);
                            Course toBuyCourse = new Course();
                            toBuyCourse.Course_id = courseID;
                            Course entireCourse = CourseOpr.GetCourseByID(toBuyCourse);
                            if (entireCourse != null)
                            {
                                //如果找到了课程
                                lblCourseName.Text = "要购买的课程为:" + entireCourse.Course_name;
                                lblCoursePrice.Text = "单价为:" + entireCourse.Course_price.ToString() + "令咒每日";
                                lblUserMoney.Text = "您当前余额为:" + loggedUser.User_money + "令咒";

                            }
                            else
                            {
                                lblCourseStateus.Text = "课程不存在";
                                lblCourseStateus.Visible = true;
                                BuyCourseForm.Visible = false;
                            }
                        }
                        catch
                        {
                            lblCourseStateus.Text = "课程ID错误";
                            lblCourseStateus.Visible = true;
                            BuyCourseForm.Visible = false;
                        }
                    }
                    else
                    {
                        //用户选择进行购买
                        try
                        {
                            Guid courseID = new Guid(Request.QueryString["course_id"]);
                            Course toBuyCourse = new Course();
                            toBuyCourse.Course_id = courseID;
                            Course entireCourse = CourseOpr.GetCourseByID(toBuyCourse);
                            if (entireCourse != null)
                            {
                                //找到了课程
                                //好,这里Course和User全有了,我们就要Create一个Order了!
                                Order newOrder = OrderOpr.CreateOrderByUserAndCourse(entireCourse, loggedUser);
                                //这句话转换可能出错
                                int toBuyDays = Convert.ToInt32(Request.Form[txtCourseTime.ID]);
                                if (toBuyDays < 0)
                                {
                                    lblCourseStateus.Text = "购买天数不能小于0";
                                    lblCourseStateus.Visible = true;
                                }
                                else
                                {

                                    if (newOrder != null)
                                    {
                                        //这个newOrder里面只包含了course_id和user_id因此我们需要手动填充
                                        newOrder.Order_price = toBuyDays * entireCourse.Course_price;
                                        newOrder.Order_isDeleted = false;
                                        //因为存储过程里是直接扣钱的,所以这里默认付款
                                        newOrder.Order_isPaid = true;
                                        newOrder.Order_date = DateTime.Now;
                                        if (newOrder.Order_price <= loggedUser.User_money
                                            && OrderOpr.CreateOrder(newOrder)
                                            )
                                        {
                                            lblCourseStateus.Text = "恭喜!召唤女友成功,快去后宫里面转转吧~";
                                            lblCourseStateus.Visible = true;
                                        }
                                        else
                                        {
                                            lblCourseStateus.Text = "创建订单出错,可能是您余额不足导致的,请确保令咒充足后重试";
                                            lblCourseStateus.Visible = true;
                                        }
                                    }
                                    else
                                    {
                                        lblCourseStateus.Text = "创建订单出错,请稍后再试";
                                        lblCourseStateus.Visible = true;
                                    }
                                }
                            }
                            else
                            {
                                lblCourseStateus.Text = "所购买的课程不存在";
                                lblCourseStateus.Visible = true;
                            }
                        }
                        catch
                        {
                            BuyCourseForm.Visible = false;
                            lblCourseStateus.Text = "课程ID不正确";
                            lblCourseStateus.Visible = true;
                        }
                    }
                }
            }
        }