예제 #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtKeyword.Text.Trim().Length == 0)
            {
                strErr += "Keyword不能为空!\\n";
            }
            if (!PageValidate.IsNumber(txtSearchCount.Text))
            {
                strErr += "SearchCount格式错误!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string Keyword     = this.txtKeyword.Text;
            int    SearchCount = int.Parse(this.txtSearchCount.Text);

            OLBookstore.Model.SearchKeywords model = new OLBookstore.Model.SearchKeywords();
            model.Keyword     = Keyword;
            model.SearchCount = SearchCount;

            OLBookstore.BLL.SearchKeywordsManager bll = new OLBookstore.BLL.SearchKeywordsManager();
            bll.Add(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx");
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(OLBookstore.Model.SearchKeywords model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update SearchKeywords set ");
            strSql.Append("Keyword=@Keyword,");
            strSql.Append("SearchCount=@SearchCount");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Keyword",     SqlDbType.NVarChar, 50),
                new SqlParameter("@SearchCount", SqlDbType.Int,       4),
                new SqlParameter("@Id",          SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Keyword;
            parameters[1].Value = model.SearchCount;
            parameters[2].Value = model.Id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(OLBookstore.Model.SearchKeywords model)
        {
            StringBuilder strSql = new StringBuilder();

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

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
예제 #4
0
 private void ShowInfo(int Id)
 {
     OLBookstore.BLL.SearchKeywordsManager bll   = new OLBookstore.BLL.SearchKeywordsManager();
     OLBookstore.Model.SearchKeywords      model = bll.GetModel(Id);
     this.lblId.Text          = model.Id.ToString();
     this.lblKeyword.Text     = model.Keyword;
     this.lblSearchCount.Text = model.SearchCount.ToString();
 }
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public OLBookstore.Model.SearchKeywords DataRowToModel(DataRow row)
 {
     OLBookstore.Model.SearchKeywords model = new OLBookstore.Model.SearchKeywords();
     if (row != null)
     {
         if (row["Id"] != null && row["Id"].ToString() != "")
         {
             model.Id = int.Parse(row["Id"].ToString());
         }
         if (row["Keyword"] != null)
         {
             model.Keyword = row["Keyword"].ToString();
         }
         if (row["SearchCount"] != null && row["SearchCount"].ToString() != "")
         {
             model.SearchCount = int.Parse(row["SearchCount"].ToString());
         }
     }
     return(model);
 }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public OLBookstore.Model.SearchKeywords GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

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

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

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