Example #1
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            ArticleClass myArticleClass = new ArticleClass();
            myArticleClass.ac_name = this.tbxAcname.Text.Trim();
            myArticleClass.parent_id = Convert.ToInt32(this.DropDownListTree.SelectedValue);

            if(ArticleClassManage.Insert(myArticleClass))
            {
                ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "click",
                    "alert('添加文章分类成功!!!')", true);
                LoadTree();
            }
            else
            {
                this.lblError.Visible = true;
            }
        }
Example #2
0
        /// <summary>条件查询文章分类 </summary>
        /// <param name="ac_id">文章分类ID</param>
        /// <returns>ArticleClass模型 包含一条文章分类记录.</returns>
        public static ArticleClass GetItem(int ac_id)
        {
            ArticleClass myArticleClass = new ArticleClass();
            string sql = "SELECT * FROM t_articleclass WHERE ac_id = ?ac_id";
            MySqlParameter[] parms = { new MySqlParameter("?ac_id", MySqlDbType.Int32) };
            parms[0].Value = ac_id;

            MySqlDataReader myReader = DbHelper.ExecuteDataReader(sql, parms);

            if (myReader.HasRows)
            {
                if (myReader.Read())
                {
                    myArticleClass = FillDataRecord(myReader);
                }
            }

            myReader.Close();

            return myArticleClass;
        }
Example #3
0
 public static bool Insert(ArticleClass myArticleClass)
 {
     if (!string.IsNullOrEmpty(myArticleClass.ac_name))
     {
         return ArticleClassService.Insert(myArticleClass);
     }
     else
     {
         return false;
     }
 }
Example #4
0
 public static bool Update(int ac_id, string ac_name)
 {
     ArticleClass myArticleClass = new ArticleClass();
     if (ac_id > 0 && !string.IsNullOrEmpty(ac_name))
     {
         myArticleClass.ac_id = ac_id;
         myArticleClass.ac_name = ac_name;
         return ArticleClassService.Update(myArticleClass);
     }
     else
     {
         return false;
     }
 }
Example #5
0
        /// <summary>
        /// 初始化一个ArticleClass类实体,并填充数据。
        /// </summary>
        private static ArticleClass FillDataRecord(IDataRecord myDataRecord)
        {
            ArticleClass myArticleClass = new ArticleClass();

            myArticleClass.ac_id = myDataRecord.GetInt32(myDataRecord.GetOrdinal("ac_id"));
            myArticleClass.ac_name = myDataRecord.GetString(myDataRecord.GetOrdinal("ac_name"));
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("parent_id")))
            {
                myArticleClass.parent_id = myDataRecord.GetInt32(myDataRecord.GetOrdinal("parent_id"));
            }

            myArticleClass.ac_order = myDataRecord.GetInt32(myDataRecord.GetOrdinal("ac_order"));

            return myArticleClass;
        }
Example #6
0
        /// <summary>修改文章分类记录</summary>
        /// <param name="myArticleClass">myArticleClass 模型</param>
        /// <returns>返回 <c>true</c> 修改成功, 或 <c>false</c> 修改失败.</returns>
        public static bool Update(ArticleClass myArticleClass)
        {
            int result = 0;
            string sql = "	UPDATE t_articleclass SET ac_name = ?ac_name WHERE ac_id = ?ac_id";
            MySqlParameter[] parms = {
                                        new MySqlParameter("?ac_name", MySqlDbType.VarChar),
                                        new MySqlParameter("?ac_id", MySqlDbType.Int32)
                                     };

            parms[0].Value = myArticleClass.ac_name;
            parms[1].Value = myArticleClass.ac_id;

            result = DbHelper.ExecuteNonQuery(sql, parms);

            return result > 0;
        }
Example #7
0
        /// <summary>插入文章分类记录</summary>
        /// <param name="myArticleClass">myArticleClass 模型</param>
        /// <returns>返回 <c>true</c> 插入成功, 或 <c>false</c> 插入失败.</returns>
        public static bool Insert(ArticleClass myArticleClass)
        {
            int result = 0;
            int? parent_id = null;
            int ac_order;
            string sql1, sql2;

            if (myArticleClass.parent_id > 0)
            {
                parent_id = myArticleClass.parent_id;
            }

            MySqlParameter[] parms = null;
            if (parent_id == null)
            {
                sql1 = "select count(*) from T_ArticleClass where parent_id is null";
            }
            else
            {
                sql1 = "select count(*) from T_ArticleClass where parent_id = ?Parent_id";
                parms = new MySqlParameter[] {
                    new MySqlParameter("?Parent_id",MySqlDbType.Int32),
                };
                parms[0].Value = parent_id;
            }

            ac_order = Convert.ToInt32(DbHelper.ExecuteScalar(sql1, parms));

            MySqlParameter[] params2 = null;
            if (parent_id == null)
            {
                sql2 = "insert into T_ArticleClass(ac_name,ac_order) values (?ac_name,?ac_order)";
                params2 = new MySqlParameter[]{
                                          new MySqlParameter("?ac_name",MySqlDbType.VarChar),
                                          new MySqlParameter("?ac_order",MySqlDbType.Int32)
                                       };
                params2[0].Value = myArticleClass.ac_name;
                params2[1].Value = ac_order + 1;
            }
            else
            {
                sql2 = "insert into T_ArticleClass(ac_name,parent_id,ac_order) values (?ac_name,?parent_id,?ac_order)";
                params2 = new MySqlParameter[]{
                                          new MySqlParameter("?ac_name",MySqlDbType.VarChar),
                                          new MySqlParameter("?parent_id",MySqlDbType.Int32),
                                          new MySqlParameter("?ac_order",MySqlDbType.Int32)
                                       };
                params2[0].Value = myArticleClass.ac_name;
                params2[1].Value = parent_id;
                params2[2].Value = ac_order + 1;

            }

            result = DbHelper.ExecuteNonQuery(sql2, params2);

            return result > 0;
        }