/// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(OLBookstore.Model.Categories model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Categories(");
            strSql.Append("Name,PId,SortNum)");
            strSql.Append(" values (");
            strSql.Append("@Name,@PId,@SortNum)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Name",    SqlDbType.NVarChar, 200),
                new SqlParameter("@PId",     SqlDbType.Int,        4),
                new SqlParameter("@SortNum", SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Name;
            parameters[1].Value = model.PId;
            parameters[2].Value = model.SortNum;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(OLBookstore.Model.Categories model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Categories set ");
            strSql.Append("PId=@PId,");
            strSql.Append("SortNum=@SortNum");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@PId",     SqlDbType.Int,      4),
                new SqlParameter("@SortNum", SqlDbType.Int,      4),
                new SqlParameter("@Id",      SqlDbType.Int,      4),
                new SqlParameter("@Name",    SqlDbType.NVarChar, 200)
            };
            parameters[0].Value = model.PId;
            parameters[1].Value = model.SortNum;
            parameters[2].Value = model.Id;
            parameters[3].Value = model.Name;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
        public void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (!PageValidate.IsNumber(txtPId.Text))
            {
                strErr += "PId格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtSortNum.Text))
            {
                strErr += "SortNum格式错误!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int    Id      = int.Parse(this.lblId.Text);
            string Name    = this.lblName.Text;
            int    PId     = int.Parse(this.txtPId.Text);
            int    SortNum = int.Parse(this.txtSortNum.Text);


            OLBookstore.Model.Categories model = new OLBookstore.Model.Categories();
            model.Id      = Id;
            model.Name    = Name;
            model.PId     = PId;
            model.SortNum = SortNum;

            OLBookstore.BLL.CategoriesManager bll = new OLBookstore.BLL.CategoriesManager();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx");
        }
Esempio n. 4
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtName.Text.Trim().Length == 0)
            {
                strErr += "Name不能为空!\\n";
            }
            if (!PageValidate.IsNumber(txtPId.Text))
            {
                strErr += "PId格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtSortNum.Text))
            {
                strErr += "SortNum格式错误!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string Name    = this.txtName.Text;
            int    PId     = int.Parse(this.txtPId.Text);
            int    SortNum = int.Parse(this.txtSortNum.Text);

            OLBookstore.Model.Categories model = new OLBookstore.Model.Categories();
            model.Name    = Name;
            model.PId     = PId;
            model.SortNum = SortNum;

            OLBookstore.BLL.CategoriesManager bll = new OLBookstore.BLL.CategoriesManager();
            bll.Add(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx");
        }
Esempio n. 5
0
 private void ShowInfo(int Id)
 {
     OLBookstore.BLL.CategoriesManager bll   = new OLBookstore.BLL.CategoriesManager();
     OLBookstore.Model.Categories      model = bll.GetModel(Id);
     this.lblId.Text      = model.Id.ToString();
     this.lblName.Text    = model.Name;
     this.lblPId.Text     = model.PId.ToString();
     this.lblSortNum.Text = model.SortNum.ToString();
 }
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public OLBookstore.Model.Categories DataRowToModel(DataRow row)
 {
     OLBookstore.Model.Categories model = new OLBookstore.Model.Categories();
     if (row != null)
     {
         if (row["Id"] != null && row["Id"].ToString() != "")
         {
             model.Id = int.Parse(row["Id"].ToString());
         }
         if (row["Name"] != null)
         {
             model.Name = row["Name"].ToString();
         }
         if (row["PId"] != null && row["PId"].ToString() != "")
         {
             model.PId = int.Parse(row["PId"].ToString());
         }
         if (row["SortNum"] != null && row["SortNum"].ToString() != "")
         {
             model.SortNum = int.Parse(row["SortNum"].ToString());
         }
     }
     return(model);
 }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public OLBookstore.Model.Categories GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,Name,PId,SortNum from Categories ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }