Пример #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Shop.Model.BookType model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update BookType set ");
            strSql.Append("TypeTitle=@TypeTitle,");
            strSql.Append("TypeParentId=@TypeParentId");
            strSql.Append(" where TypeId=@TypeId");
            SqlParameter[] parameters =
            {
                new SqlParameter("@TypeTitle",    SqlDbType.NVarChar, 50),
                new SqlParameter("@TypeParentId", SqlDbType.Int,       4),
                new SqlParameter("@TypeId",       SqlDbType.Int, 4)
            };
            parameters[0].Value = model.TypeTitle;
            parameters[1].Value = model.TypeParentId;
            parameters[2].Value = model.TypeId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtTypeTitle.Text.Trim().Length == 0)
            {
                strErr += "TypeTitle不能为空!\\n";
            }
            if (!PageValidate.IsNumber(txtTypeParentId.Text))
            {
                strErr += "TypeParentId格式错误!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string TypeTitle    = this.txtTypeTitle.Text;
            int    TypeParentId = int.Parse(this.txtTypeParentId.Text);

            Shop.Model.BookType model = new Shop.Model.BookType();
            model.TypeTitle    = TypeTitle;
            model.TypeParentId = TypeParentId;

            Shop.BLL.BookType bll = new Shop.BLL.BookType();
            bll.Add(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx");
        }
Пример #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Shop.BLL.BookType btBll = new Shop.BLL.BookType();
            if (!IsPostBack)//初次加载请求
            {
                int id = int.Parse(Request["id"]);

                BtModel = btBll.GetModel(id);
            }
            else
            {
                //回传,进行修改处理
                BtModel = new Shop.Model.BookType()
                {
                    TypeId       = int.Parse(Request["tid"]),
                    TypeTitle    = Request["tTitle"],
                    TypeParentId = int.Parse(Request["tPid"])
                };

                if (btBll.Update(BtModel))
                {
                    Response.Redirect("BookTypeList.aspx");
                }
                else
                {
                    Response.Write("修改失败,请稍候重试");
                }
            }
        }
Пример #4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Shop.Model.BookType model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into BookType(");
            strSql.Append("TypeTitle,TypeParentId)");
            strSql.Append(" values (");
            strSql.Append("@TypeTitle,@TypeParentId)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@TypeTitle",    SqlDbType.NVarChar, 50),
                new SqlParameter("@TypeParentId", SqlDbType.Int, 4)
            };
            parameters[0].Value = model.TypeTitle;
            parameters[1].Value = model.TypeParentId;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Пример #5
0
 private void ShowInfo(int TypeId)
 {
     Shop.BLL.BookType   bll   = new Shop.BLL.BookType();
     Shop.Model.BookType model = bll.GetModel(TypeId);
     this.lblTypeId.Text       = model.TypeId.ToString();
     this.lblTypeTitle.Text    = model.TypeTitle;
     this.lblTypeParentId.Text = model.TypeParentId.ToString();
 }
Пример #6
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Shop.Model.BookType DataRowToModel(DataRow row)
 {
     Shop.Model.BookType model = new Shop.Model.BookType();
     if (row != null)
     {
         if (row["TypeId"] != null && row["TypeId"].ToString() != "")
         {
             model.TypeId = int.Parse(row["TypeId"].ToString());
         }
         if (row["TypeTitle"] != null)
         {
             model.TypeTitle = row["TypeTitle"].ToString();
         }
         if (row["TypeParentId"] != null && row["TypeParentId"].ToString() != "")
         {
             model.TypeParentId = int.Parse(row["TypeParentId"].ToString());
         }
     }
     return(model);
 }
Пример #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                Shop.Model.BookType btModel = new Shop.Model.BookType()
                {
                    TypeTitle    = Request["title"],
                    TypeParentId = int.Parse(Request["pid"])
                };

                Shop.BLL.BookType btBll = new Shop.BLL.BookType();
                if (btBll.Add(btModel) > 0)
                {
                    Response.Redirect("BookTypeList.aspx");
                }
                else
                {
                    Response.Write("添加失败,请稍候重试");
                }
            }
        }
Пример #8
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Shop.Model.BookType GetModel(int TypeId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 TypeId,TypeTitle,TypeParentId from BookType ");
            strSql.Append(" where TypeId=@TypeId");
            SqlParameter[] parameters =
            {
                new SqlParameter("@TypeId", SqlDbType.Int, 4)
            };
            parameters[0].Value = TypeId;

            Shop.Model.BookType model = new Shop.Model.BookType();
            DataSet             ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Пример #9
0
 public bool Delete(Shop.Model.BookType bookType)
 {
     return(Delete(bookType.TypeId));
 }