Esempio n. 1
0
    private static bool clean()
    {
        for (int i = 0; i < count; i++)
        {
            if (i < count / 2)
            {
                Article2Group a2g = new Article2Group(ids[i], primaryGroupId);
                if (!Article2GroupManager.deleteRecord(a2g))
                {
                    output += "Error! 将id为" + ids[i] + "的文章取消与id为" + primaryGroupId + "的主分类的关联时失败!测试无法继续进行。请先解决Article2GroupManager中的错误。\n";
                    errorCount++;
                    return(false);
                }
            }
            else
            {
                Article2Group a2g = new Article2Group(ids[i], OtherGroupId);
                if (!Article2GroupManager.deleteRecord(a2g))
                {
                    output += "Error! 将id为" + ids[i] + "的文章取消与id为" + OtherGroupId + "的主分类的关联时失败!测试无法继续进行。请先解决Article2GroupManager中的错误。\n";
                    errorCount++;
                    return(false);
                }
            }
            Article a = new Article(ids[i], titles[i], titles[i], "", DateTime.Now, 0, 0);
            if (!ArticleManager.deleteRecord(a))
            {
                output += "Error! 删除测试文章\"" + titles[i] + "\"失败!测试无法继续进行。请先解决ArticleManager中的错误。\n";
                errorCount++;
                return(false);
            }
        }

        return(true);
    }
Esempio n. 2
0
    private static string deleteRecord()
    {
        string output = "deleteRecord\n";

        for (int i = 0; i < count; i++)
        {
            Article2Group a2g = new Article2Group(ids[i], primaryGroupId);
            if (!Article2GroupManager.deleteRecord(a2g))
            {
                output += "Error! 删除关联(文章id为" + ids[i] + ",主分类id为" + primaryGroupId + ")失败!\n";
                errorCount++;
            }
            else
            {
                output += "Ok! 删除关联(文章id为" + ids[i] + ",主分类id为" + primaryGroupId + ")成功!\n";
            }

            Article a = new Article();
            a.ArticleId = ids[i];
            if (!ArticleManager.deleteRecord(a))
            {
                output += "Error! 删除文章\"" + titles[i] + "\"失败!\n";
                errorCount++;
            }
            else
            {
                output += "Ok! 删除文章\"" + titles[i] + "\"成功!\n";
            }
        }

        return(output);
    }
Esempio n. 3
0
    private static bool clean()
    {
        for (int i = 0; i < count; i++)
        {
            Article2Group a2g = new Article2Group(ids[i], primaryGroup[1].GroupId);
            if (!Article2GroupManager.deleteRecord(a2g))
            {
                output += "Error! 删除关联(文章id为" + ids[i] + ",主分类id为" + primaryGroup[1].GroupId + ")失败!\n";
                errorCount++;
            }

            Article a = new Article();
            a.ArticleId = ids[i];
            if (!ArticleManager.deleteRecord(a))
            {
                output += "Error! 删除文章\"" + titles[i] + "\"失败!\n";
                errorCount++;
            }
        }

        if (!PrimaryGroupMananger.deleteRecord(primaryGroup[0]))
        {
            output += "Error! 删除测试辅助主分类失败!\n";
            errorCount++;
            return(false);
        }
        if (!PrimaryGroupMananger.deleteRecord(primaryGroup[1]))
        {
            output += "Error! 删除测试辅助主分类失败!\n";
            errorCount++;
            return(false);
        }

        return(true);
    }
Esempio n. 4
0
    /*
     * 输入:一个文章的Article实例,以及一个文章所属的groupId的列表
     * 输出:成功返回true,失败返回false
     * 功能:对指定文章进行分类,将其分到groupIds所包含的所有组别中去(即一篇文章可以被分到多个类别中)。
     * 用途说明:管理员新增一篇文章到数据库中去以后,系统会自动将文章分类,并将结果显示在页面上,管理员若对自动
     *           分类的结果不满意,可以手动调整,调整完毕后调用本函数修改文章的分类结果
     */
    public static bool changeGroupRelation(Article a, List <int> groupIds)
    {
        bool result = true;

        // 先删除旧的 groupIds
        List <int> old_gids = Article2GroupManager.getGroupIdsByArticle(a);  // 这里我认为这个传入的 Article 的 id 是已经赋值了的

        foreach (int old_gid in old_gids)
        {
            Article2GroupManager.deleteRecord(new Article2Group(a.ArticleId, old_gid));
        }
        // 再插入新的 groupIds
        foreach (int gid in groupIds)
        {
            if (Article2GroupManager.addRecord(new Article2Group(a.ArticleId, gid)) == false)
            {
                result = false; // 只要有一条记录插入不成功,则返回 false
            }
        }

        return(result);
    }