Example #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(LFL.Favorite.Model.FavCategory model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.CategoryName != null)
            {
                strSql1.Append("CategoryName,");
                strSql2.Append("'" + model.CategoryName + "',");
            }
            if (model.ParentID != null)
            {
                strSql1.Append("ParentID,");
                strSql2.Append("" + model.ParentID + ",");
            }
            strSql.Append("insert into T_FavCategory(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            strSql.Append(";SELECT SCOPE_IDENTITY() AS [ID]");
            return(db.RunSqlReturnInt(strSql.ToString()));
        }
Example #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public LFL.Favorite.Model.FavCategory GetModel(int FavCategoryID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1  ");
            strSql.Append(" FavCategoryID,CategoryName,ParentID ");
            strSql.Append(" from T_FavCategory ");
            strSql.Append(" where FavCategoryID=" + FavCategoryID + " ");
            LFL.Favorite.Model.FavCategory model = new LFL.Favorite.Model.FavCategory();
            DataSet ds = db.GetDs(strSql.ToString());

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["FavCategoryID"].ToString() != "")
                {
                    model.FavCategoryID = int.Parse(ds.Tables[0].Rows[0]["FavCategoryID"].ToString());
                }
                model.CategoryName = ds.Tables[0].Rows[0]["CategoryName"].ToString();
                if (ds.Tables[0].Rows[0]["ParentID"].ToString() != "")
                {
                    model.ParentID = int.Parse(ds.Tables[0].Rows[0]["ParentID"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(LFL.Favorite.Model.FavCategory model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update T_FavCategory set ");
            if (model.CategoryName != null)
            {
                strSql.Append("CategoryName='" + model.CategoryName + "',");
            }
            if (model.ParentID != null)
            {
                strSql.Append("ParentID=" + model.ParentID + ",");
            }
            int n = strSql.ToString().LastIndexOf(",");

            strSql.Remove(n, 1);
            strSql.Append(" where FavCategoryID=" + model.FavCategoryID + " ");
            db.RunSql(strSql.ToString());
        }