Esempio n. 1
0
    protected void Button2_Click(object sender, EventArgs e)
    {
        articles = (Article[])Session["articles"];

        Button2.Visible = false;

        int  length = articles.Length;
        bool result = true;

        Label1.Visible = true;
        for (int i = 0; i < length; i++)
        {
            List <int> ids = dealGroupID(Request.Form["ctl00$MainContent$hf" + i]);
            //Label1.Text = Request.Form["ctl00$MainContent$hf" + i];
            result &= ManagerAssist.changeGroupRelation(articles[i], ids);
        }

        if (result)
        {
            Label1.Text = "保存成功!将在3秒之后返回...";
        }
        else
        {
            Label1.Text = "保存失败,请重试!";
        }
        Label1.Visible = true;

        Response.AddHeader("Refresh", "3");
    }
Esempio n. 2
0
    private static void getPrimaryGroupNamesByPrimaryGroupIds()
    {
        output += "getPrimaryGroupNamesByPrimaryGroupIds\n";

        List <string[]> list   = PrimaryGroupMananger.getAllGroups();
        List <int>      idList = new List <int>();

        foreach (string[] item in list)
        {
            idList.Add(int.Parse(item[0]));
        }
        List <string> nameList = ManagerAssist.getPrimaryGroupNamesByPrimaryGroupIds(idList);

        if (nameList == null)
        {
            output += "Error! getPrimaryGroupNamesByPrimaryGroupIds失败,返回null。\n";
            errorCount++;
            return;
        }
        if (nameList.Count < 3)
        {
            output += "Error! 返回列表长度(=" + nameList.Count + ")小于测试用例数量!\n";
            errorCount++;
        }
        else
        {
            output += "Ok! 返回列表长度(=" + nameList.Count + ")不少于测试用例数量!\n";
        }
    }
Esempio n. 3
0
 protected void Button2_Click(object sender, EventArgs e)
 {
     if (TextBox2.Text.Trim() == "" || TextBox3.Text.Trim() == "")
     {
         ClientScript.RegisterStartupScript(GetType(), "message", @"<script>alert('不能输入空内容!');</script>");
         return;
     }
     ManagerAssist.addSecondaryGroup(Int32.Parse(DropDownList1.SelectedItem.Value), TextBox2.Text.Trim(), TextBox3.Text);
 }
Esempio n. 4
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox0.Text.Trim() == "" || TextBox1.Text.Trim() == "")
        {
            ClientScript.RegisterStartupScript(GetType(), "message", @"<script>alert('不能输入空内容!');</script>");
            return;
        }
        List <Article> articles = ManagerAssist.addPrimaryGroup(TextBox0.Text.Trim(), TextBox1.Text.Trim());

        foreach (Article a in articles)
        {
            TableRow  tr    = new TableRow();
            TableCell tc    = new TableCell();
            Label     label = new Label();
            label.Text = a.Title;
            tc.Controls.Add(label);
            tr.Controls.Add(tc);
            HolderTable.Rows.Add(tr);
        }
    }
Esempio n. 5
0
    private static void changeGroupRelation()
    {
        output += "changeGroupRelation\n";

        List <int> list0_pre = Article2GroupManager.getArticleIdsByGroup(primaryGroup[0]);
        List <int> list1_pre = Article2GroupManager.getArticleIdsByGroup(primaryGroup[1]);

        int list1_pre_len = 0;

        if (list1_pre != null)
        {
            list1_pre_len = list1_pre.Count;
        }

        output += "调用changeGroupRelation前,primaryGroup[0]下有" + list0_pre.Count + "篇文章,primaryGroup[1]下有" + list1_pre_len + "篇文章。\n";
        List <int> groupIds = new List <int>();

        groupIds.Add(primaryGroup[0].GroupId);
        groupIds.Add(primaryGroup[1].GroupId);
        for (int i = 0; i < count; i++)
        {
            Article a = new Article();
            a.ArticleId = ids[i];
            ManagerAssist.changeGroupRelation(a, groupIds);
        }
        List <int> list0_post = Article2GroupManager.getArticleIdsByGroup(primaryGroup[0]);
        List <int> list1_post = Article2GroupManager.getArticleIdsByGroup(primaryGroup[1]);

        output += "调用changeGroupRelation前,primaryGroup[0]下有" + list0_post.Count + "篇文章,primaryGroup[1]下有" + list1_post.Count + "篇文章。\n";

        if (list0_pre.Count - list1_pre_len > list0_post.Count - list1_post.Count)
        {
            output += "Ok! changeGroupRelation执行成功!\n";
        }
        else
        {
            output += "Ok! changeGroupRelation执行失败!\n";
            errorCount++;
        }
    }
Esempio n. 6
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        //先清除所有的内容
        HolderTable.Visible = false;
        Button1.Visible     = false;
        Button2.Visible     = true;
        DirectoryInfo rawdi = new DirectoryInfo(Server.MapPath(PATH));

        FileInfo[] rawfis = rawdi.GetFiles();
        foreach (FileInfo fi in rawfis)
        {
            File.Delete(fi.FullName);
        }


        foreach (FileUpload fu in fus)
        {
            string filename = fu.FileName;
            if (filename != "")
            {
                fu.PostedFile.SaveAs(Server.MapPath(PATH + filename));
            }
        }

        DirectoryInfo di = new DirectoryInfo(Server.MapPath(PATH));

        FileInfo[] fis = di.GetFiles();

        hfs      = new List <HiddenField>();
        tbs      = new TextBox[fis.Length];
        articles = new Article[fis.Length];

        //Session.Add("hfs", hfs);
        //Session.Add("articles", articles);

        var count = 0;

        foreach (FileInfo fi in fis)
        {
            FileStream fs     = new FileStream(fi.FullName, FileMode.Open);
            string     title  = fi.Name.Split('.')[0];
            int        length = (int)fs.Length;
            byte[]     bytes  = new byte[length];
            fs.Read(bytes, 0, length);
            fs.Close();

            string content = Encoding.UTF8.GetString(bytes);

            //需要替换
            //int articleID = testAddArticle(title, content);
            int     articleID = ManagerAssist.addArticle(title, content);
            Article art       = new Article();
            art.ArticleId = articleID;
            List <int> ids = ManagerAssist.getGroupIdsByArticleWrapper(art);
            //List<int> ids = testGetGroupIdsByArticleWrapper(art);

            List <string> idstrs = ManagerAssist.getPrimaryGroupNamesByPrimaryGroupIds(ids);
            //List<string> idstrs = testGetPrimaryGroupNamesByPrimaryGroupIds(ids);

            articles[count] = art;

            var groupstrs = "";

            foreach (string str in idstrs)
            {
                groupstrs += str + ' ';
            }

            TableRow tr = new TableRow();
            OutputTable.Rows.Add(tr);
            TableCell tc    = new TableCell();
            Label     label = new Label();
            label.Text = "我们为《" + title + "》选择的默认分类为:" + groupstrs;


            tc.Controls.Add(label);
            tr.Controls.Add(tc);

            TableRow tr2 = new TableRow();
            OutputTable.Rows.Add(tr2);
            TableCell tc2 = new TableCell();

            Label label2 = new Label();
            label2.Text = "如果您对此分类不满意,请您选择分类:";

            Button bt = new Button();

            bt.Text = "选择分类";
            bt.UseSubmitBehavior = true;
            bt.OnClientClick     = "return popup(" + count + ")";

            tc2.Controls.Add(label2);
            tc2.Controls.Add(bt);
            tr2.Controls.Add(tc2);

            Label label3 = new Label();
            label3.Text = "您新选择的分类为:";

            TableRow tr3 = new TableRow();
            OutputTable.Rows.Add(tr3);
            TableCell tc3 = new TableCell();
            tr3.Controls.Add(tc3);
            tc3.Controls.Add(label3);

            TextBox tb = new TextBox();
            tb.ReadOnly = true;
            tb.ID       = "tb" + count;
            tc3.Controls.Add(tb);

            HiddenField hf = new HiddenField();
            hf.ID = "hf" + count;
            hfs.Add(hf);
            tbs[count] = tb;
            tc3.Controls.Add(hf);



            count++;
        }

        Session.Add("articles", articles);
    }
Esempio n. 7
0
    private static void addPrimaryGroup()
    {
        output += "addPrimaryGroup\n";

        // add
        string name     = "sample123";
        string keywords = "qawsed rftgyh";

        ManagerAssist.addPrimaryGroup(name, keywords);

        // check
        List <string[]> list    = PrimaryGroupMananger.getAllGroups();
        bool            found   = false;
        int             groupId = -1;

        foreach (string[] item in list)
        {
            if (item[1].Equals("sample123"))
            {
                found   = true;
                groupId = int.Parse(item[0]);
                break;
            }
        }
        if (!found)
        {
            output += "Error! addPrimaryGroup执行失败!主分类未加入数据库中。\n";
            errorCount++;
        }
        else
        {
            output += "Ok! addPrimaryGroup执行成功!主分类已加入数据库中。\n";
        }

        PrimaryGroups pg    = new PrimaryGroups(groupId, name);
        List <string> list2 = PrimaryGroupKeyWordsManager.getKeyWordsOfCertainPrimaryGroup(pg);

        if (list2.Count != 2)
        {
            output += "Error! PrimaryGroupKeyWords数目不对!应为2\n";
        }
        else
        {
            output += "Ok! PrimaryGroupKeyWords数目正确!应为2\n";
        }

        if (list2.First().Equals("qawsed") || list2.First().Equals("rftgyh"))
        {
            output += "Ok! PrimaryGroupKeyWords中对应的第一个关键词通过验证!\n";
        }
        else
        {
            output += "Error! PrimaryGroupKeyWords中对应的第一个关键词未通过验证!\n";
            errorCount++;
        }

        List <Tag> tagL = TagManager.getAllTagsByCertainGroupId(groupId);

        if (tagL == null || tagL.Count != 1)
        {
            output += "Error! addPrimaryGroup调用后没有将“其他”子分类插入tag表!\n";
            errorCount++;
        }
        else
        {
            output += "Ok! addPrimaryGroup调用后成功将“其他”子分类插入tag表!\n";
        }

        // delete
        foreach (string item in list2)
        {
            if (!PrimaryGroupKeyWordsManager.deleteRecord(new PrimaryGroupKeyWords(groupId, item)))
            {
                output += "Error! 删除测试关键词失败!\n";
                errorCount++;
            }
        }
        Tag t = new Tag();

        t.TagId = tagL.First().TagId;
        if (!TagManager.deleteTag(t))
        {
            output += "Error! 删除测试主分类下“其他”子分类失败!\n";
            errorCount++;
        }
        PrimaryGroups temp = new PrimaryGroups();

        temp.GroupId = groupId;
        if (!PrimaryGroupMananger.deleteRecord(temp))
        {
            output += "Error! 删除测试主分类失败!\n";
            errorCount++;
        }
    }