Moss中调查问卷多选题目 单独统计

  Moss中做过调查问卷统计多选的人都知道,再查看答案的时候 总是有不方便的时候,比如组织去旅游,选择地点,一个人可以选择多个,但是最后只能去一个地方,那就要看最后哪个选择的人多,调查自带的统计就办不到了,根据这个需求,我做了一个小页面,大家希望扩展也可以做成部件,代码如下:

 

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.SharePoint;
using System.Collections.Generic;

namespace SearchResoprt
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
             //获取到列表名称
            string ListName= Request.QueryString["list"];
           // string ListName = "";
            //找到对应网站,并取出列表数据
             SPSite site = SPContext.Current.Site;
             SPWeb web = SPContext.Current.Web; 
             SPList list = web.Lists[ListName];
             SPListItemCollection ListItemC = list.Items;
             int itemCount = list.ItemCount;//答题总数
             SPFieldCollection fieldC = ListItemC[0].Fields;//取出栏目
             string[] fieldAnswer = new string[fieldC.Count]; //每题每个人的答案集合
             int count = 1; //题目数累加                  

             //第一题 A,B
             // Dictionary> dic = new Dictionary>();
             Dictionary dic = null;
             //查询调查列表答案
             foreach (SPField field in fieldC)
             {
                 dic = new Dictionary();

                 if (!field.FromBaseType)
                 {
                     string title = field.Title.ToString().Substring(2);
                     this.lbltitle.Text += title+"
";
                     for (int i = 0; i < itemCount; i++)
                     {
                         //有间隔符号的答案,处理字符串
                         string answerL = ListItemC[i][field.InternalName].ToString();
                         //string an = answerL.Replace(';', ' ');
                         //string answer = an.Replace('#', ' ');
                         char[] zf = new char[] { ';', '#', '.' };
                         string[] danswer = answerL.Split(zf);
                         foreach (string daan in danswer)
                         {
                             if (daan.ToString() != "" && daan != null && daan.Length == 1)
                             {
                                 if (dic.ContainsKey(daan))
                                 {
                                     //判断是否已经选择过这个选项,选择过的话给value加一
                                     dic[daan] = count + 1;
                                 }
                                 else
                                 {
                                     dic.Add(daan, count);
                                 }
                             }

                         }
                     }
                     var diclist = dic.OrderBy(f => f.Key);
                     foreach (var item in diclist)
                     {
                         double prc = Convert.ToDouble(item.Value) / Convert.ToDouble(itemCount) * 100;
                         string prcent = prc.ToString().Substring(0, 4);
                         this.lbltitle.Text += item.Key + ":" + prcent + "%"+"
";

                     }


                 }

             }
        }
    }
}

页面前台只放了一个Lable控件用于展示答案,我这是用百分比的形式展示的结果:如下

北京一日游选择地点?
A:50%
B:50%
C:25%
D:50%
济南一日游选择地点?
A:50%
B:50%
C:50%
D:50%
上海一日游选择地点?
A:50%
B:50%
C:50%
D:25%

使用方法需要在对应网站里面部署,第一步:给程序加个签名,找到自己程序的路径

第二步:把程序bin下面的dll文件复制到c:\Windows\assembly这个下面

第三步:把对应的应用程序“页面”复制到Layout下面,可以新建个文件夹

第四步:把程序的dll文件再复制到网站对应的端口下面

进行访问,在IE地址栏中输入:网站地址_Layouts/页面名称?list=/Lists/ChooseSearch 其中list是访问参数你可以改,后面是你调查问卷的地址路径按照我写的案例来。

如果访问报找不到程序集,则把应用程序池回购一下,可以重启IIS,也可以使用WSPBuilderExtensions.msi 这个工具

你可能感兴趣的:(C#,SharePoint)