コード例 #1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public KeyWordModel GetModel(string KeyWord)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select KeyWord, OrderNo, KeyWordType  ");
            strSql.Append("  from CORE.dbo.KeyWord ");
            strSql.Append(" where KeyWord=@KeyWord ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@KeyWord", SqlDbType.VarChar, 30)
            };
            parameters[0].Value = KeyWord;


            KeyWordModel model = new KeyWordModel();
            DataSet      ds    = helper.ExecSqlReDs(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                model.KeyWord = ds.Tables[0].Rows[0]["KeyWord"].ToString();
                if (ds.Tables[0].Rows[0]["OrderNo"].ToString() != "")
                {
                    model.OrderNo = int.Parse(ds.Tables[0].Rows[0]["OrderNo"].ToString());
                }
                model.KeyWordType = ds.Tables[0].Rows[0]["KeyWordType"].ToString();

                return(model);
            }
            else
            {
                return(model);
            }
        }
コード例 #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(KeyWordModel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into CORE.dbo.KeyWord (");
            strSql.Append("KeyWord,OrderNo,KeyWordType");
            strSql.Append(") values (");
            strSql.Append("@KeyWord,@OrderNo,@KeyWordType");
            strSql.Append(") ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@KeyWord",     SqlDbType.VarChar, 30),
                new SqlParameter("@OrderNo",     SqlDbType.Int,      4),
                new SqlParameter("@KeyWordType", SqlDbType.VarChar, 10)
            };

            parameters[0].Value = model.KeyWord;
            parameters[1].Value = model.OrderNo;
            parameters[2].Value = model.KeyWordType;

            bool result = false;

            try
            {
                helper.ExecSqlReInt(strSql.ToString(), parameters);
                result = true;
            }
            catch (Exception ex)
            {
                this.helper.Close();
                throw ex;
            }
            finally
            {
            }
            return(result);
        }
コード例 #3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(KeyWordModel model)
        {
            bool          reValue = true;
            int           reCount = 0;
            StringBuilder strSql  = new StringBuilder();

            strSql.Append("update CORE.dbo.KeyWord set ");

            strSql.Append(" KeyWord = @KeyWord , ");
            strSql.Append(" OrderNo = @OrderNo , ");
            strSql.Append(" KeyWordType = @KeyWordType  ");
            strSql.Append(" where KeyWord=@KeyWord  ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@KeyWord",     SqlDbType.VarChar, 30),
                new SqlParameter("@OrderNo",     SqlDbType.Int,      4),
                new SqlParameter("@KeyWordType", SqlDbType.VarChar, 10)
            };

            parameters[0].Value = model.KeyWord;
            parameters[1].Value = model.OrderNo;
            parameters[2].Value = model.KeyWordType; try
            {//异常处理
                reCount = this.helper.ExecSqlReInt(strSql.ToString(), parameters);
            }
            catch (Exception ex)
            {
                this.helper.Close();
                throw ex;
            }
            if (reCount <= 0)
            {
                reValue = false;
            }
            return(reValue);
        }
コード例 #4
0
ファイル: KeyWordRepository.cs プロジェクト: dhtweb/dht
        public async Task <bool> InsertOrUpdateAsync(KeyWordModel model, IDbTransaction transaction)
        {
            var sql = "INSERT INTO t_keyword AS t (word, num, isdanger) VALUES (@word,@num,@danger) ON CONFLICT(word) DO UPDATE SET num=t.num + excluded.num ,isdanger=excluded.isdanger;";

            return(await SqlMapper.ExecuteAsync(Connection, sql, new { word = model.Word, num = model.Num, danger = model.IsDanger }, transaction) > 0);
        }