Example #1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.Tao.Modules GetModel(int ModuleID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ModuleID,ModuleName,Description,TimeDuration,Status,Tags,ImageUrl,Type,VideoContent,CreatedDate,CreatedUserID,Price,PV,Sequence,Attachment,UpdatedDate from Tao_Modules ");
            strSql.Append(" where ModuleID=@ModuleID");
            SqlParameter[] parameters = {
                    new SqlParameter("@ModuleID", SqlDbType.Int,4)
            };
            parameters[0].Value = ModuleID;

            Maticsoft.Model.Tao.Modules model = new Maticsoft.Model.Tao.Modules();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ModuleID"] != null && ds.Tables[0].Rows[0]["ModuleID"].ToString() != "")
                {
                    model.ModuleID = int.Parse(ds.Tables[0].Rows[0]["ModuleID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ModuleName"] != null && ds.Tables[0].Rows[0]["ModuleName"].ToString() != "")
                {
                    model.ModuleName = ds.Tables[0].Rows[0]["ModuleName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Description"] != null && ds.Tables[0].Rows[0]["Description"].ToString() != "")
                {
                    model.Description = ds.Tables[0].Rows[0]["Description"].ToString();
                }
                if (ds.Tables[0].Rows[0]["TimeDuration"] != null && ds.Tables[0].Rows[0]["TimeDuration"].ToString() != "")
                {
                    model.TimeDuration = int.Parse(ds.Tables[0].Rows[0]["TimeDuration"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Status"] != null && ds.Tables[0].Rows[0]["Status"].ToString() != "")
                {
                    model.Status = int.Parse(ds.Tables[0].Rows[0]["Status"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Tags"] != null && ds.Tables[0].Rows[0]["Tags"].ToString() != "")
                {
                    model.Tags = ds.Tables[0].Rows[0]["Tags"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ImageUrl"] != null && ds.Tables[0].Rows[0]["ImageUrl"].ToString() != "")
                {
                    model.ImageUrl = ds.Tables[0].Rows[0]["ImageUrl"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Type"] != null && ds.Tables[0].Rows[0]["Type"].ToString() != "")
                {
                    model.Type = int.Parse(ds.Tables[0].Rows[0]["Type"].ToString());
                }
                if (ds.Tables[0].Rows[0]["VideoContent"] != null && ds.Tables[0].Rows[0]["VideoContent"].ToString() != "")
                {
                    model.VideoContent = ds.Tables[0].Rows[0]["VideoContent"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CreatedDate"] != null && ds.Tables[0].Rows[0]["CreatedDate"].ToString() != "")
                {
                    model.CreatedDate = DateTime.Parse(ds.Tables[0].Rows[0]["CreatedDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CreatedUserID"] != null && ds.Tables[0].Rows[0]["CreatedUserID"].ToString() != "")
                {
                    model.CreatedUserID = int.Parse(ds.Tables[0].Rows[0]["CreatedUserID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Price"] != null && ds.Tables[0].Rows[0]["Price"].ToString() != "")
                {
                    model.Price = decimal.Parse(ds.Tables[0].Rows[0]["Price"].ToString());
                }
                if (ds.Tables[0].Rows[0]["PV"] != null && ds.Tables[0].Rows[0]["PV"].ToString() != "")
                {
                    model.PV = int.Parse(ds.Tables[0].Rows[0]["PV"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Sequence"] != null && ds.Tables[0].Rows[0]["Sequence"].ToString() != "")
                {
                    model.Sequence = int.Parse(ds.Tables[0].Rows[0]["Sequence"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Attachment"] != null && ds.Tables[0].Rows[0]["Attachment"].ToString() != "")
                {
                    model.Attachment = ds.Tables[0].Rows[0]["Attachment"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UpdatedDate"] != null && ds.Tables[0].Rows[0]["UpdatedDate"].ToString() != "")
                {
                    model.UpdatedDate = DateTime.Parse(ds.Tables[0].Rows[0]["UpdatedDate"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }
        protected void btnSava_Click(object sender, EventArgs e)
        {
            int iCourseId = 0;
            if (Request.QueryString["CourseId"] != null)
            {
                iCourseId = int.Parse(Request.QueryString["CourseId"]);
                cid = iCourseId;
            }
            if (string.IsNullOrEmpty(this.txtModuleName.Text.Trim()))
            {
                this.ErrorMsg.Visible = true;
                this.ErrorMsg.Text = "小节名称不能为空";
                return;
            }
            if (string.IsNullOrEmpty(this.btnSava.CommandArgument))
            {
                module = new Model.Tao.Modules();
            }
            else
            {
                int mId = int.Parse(this.btnSava.CommandArgument);
                module = modulesBll.GetModel(mId);
            }
            //Maticsoft.Model.Tao.Modules module = new Maticsoft.Model.Tao.Modules();
            module.ModuleName = this.txtModuleName.Text.Trim();
            module.Description = this.txtDescription.Text.Trim();

            int iResult = 0;
            //判断是否为新增小节,当this.btnSava.CommandArgument有值,则为”新增“,否则为”修改“
            if (string.IsNullOrEmpty(this.btnSava.CommandArgument))
            {
                //添加课程小节
                module.CreatedDate = DateTime.Now;
                iResult = modulesBll.Add(module);

                if (iResult > 0)
                {
                    Maticsoft.Model.Tao.CourseModule courseModule = new Maticsoft.Model.Tao.CourseModule();
                    courseModule.CourseID = iCourseId;
                    courseModule.ModuleID = iResult;
                    courseModule.ModuleIndex = courseModuleBll.GetMaxModuleIndex(iCourseId);

                    if (courseModuleBll.Add(courseModule) > 0)
                    {
                        this.ErrorMsg.Text = "新增课程成功!";
                    }
                }
                else
                {
                    modulesBll.Delete(iResult);
                    this.ErrorMsg.Text = "新增课程小节失败,请重试!";
                }
            }
            else
            {
                module.ModuleID = int.Parse(this.btnSava.CommandArgument);
                this.btnSava.CommandArgument = null;
                module.UpdatedDate = DateTime.Now;
                modulesBll.Update(module);
            }

            this.txtDescription.Text = string.Empty;
            this.txtModuleName.Text = string.Empty;
            this.ErrorMsg.Visible = false;

            BindData(iCourseId);
        }