예제 #1
0
        /// <summary>
        /// 根据ID删除帖子
        /// </summary>
        static void DeletePost()
        {
            Console.WriteLine("请输入将要删除的帖子ID");
            //获取输入并检测输入的帖子ID是否为正整数
            string idStr = PositiveWholeNumberDetection();
            int    id    = int.Parse(idStr);

            //检测帖子ID是否存在
            id = PostIdDetection(idStr, id);
            PostBusinessLayer pbl = new BusinessLayer.PostBusinessLayer();
            Post post             = pbl.QueryPost(id);

            pbl.Delete(post);
        }
예제 #2
0
        /// <summary>
        /// 检测帖子ID是否存在
        /// </summary>
        /// <param name="idStr"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        static int PostIdDetection(string idStr, int id)
        {
            PostBusinessLayer pbl = new BusinessLayer.PostBusinessLayer();
            bool idDetection      = true;

            while (idDetection)
            {
                if (pbl.QueryPost(id) == null)
                {
                    Console.WriteLine("没有该帖子ID,请重新输入!");
                    idStr = PositiveWholeNumberDetection();
                    id    = int.Parse(idStr);
                }
                else
                {
                    idDetection = false;
                }
            }
            return(id);
        }