示例#1
0
    protected void BindKechengInfo()
    {
        string kechengid = Session["kechengid"].ToString();

        TextBoxkcname.Text = KechengInfo.getKechengname(kechengid);
        SqlConnection conn = new SqlConnection();

        conn.ConnectionString = ConfigurationManager.ConnectionStrings["kecheng2012ConnectionString"].ConnectionString;
        SqlCommand comm = conn.CreateCommand();

        comm.CommandText = "select instruction,image,guanliyuan from tb_kecheng where kechengid=" + kechengid;
        conn.Open();
        SqlDataReader sdr = comm.ExecuteReader();

        if (sdr.Read())
        {
            if (!sdr.IsDBNull(0))
            {
                TextBox1.Text = sdr.GetString(0);
            }
            if (!sdr.IsDBNull(1))
            {
                Image1.ImageUrl = sdr.GetString(1);
            }
            DropDownList2.SelectedValue = sdr.GetString(2);
        }
        sdr.Close();
        conn.Close();
    }
    protected void BindKecheng()
    {
        DataSet ds = KechengInfo.GetKecheng();

        ddl_kecheng.DataSource     = ds.Tables[0].DefaultView;
        ddl_kecheng.DataTextField  = "kechengname";
        ddl_kecheng.DataValueField = "kechengid";
        ddl_kecheng.DataBind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        string kechengid = Session["kechengid"].ToString();
        string banjiid   = Request.QueryString["banjiid"];
        string stuun     = Request.QueryString["studentusername"];

        Labelkc.Text = KechengInfo.getKechengname(kechengid);
        Labelbj.Text = BanjiInfo.GetBanjiName(int.Parse(banjiid));
        Labelxm.Text = StudentInfo.GetStuXingming(stuun);
        Labelun.Text = stuun;
        BindDianMingStu();
    }
    protected void Page_Init(object sender, EventArgs e)
    {
        string username = ((FormsIdentity)HttpContext.Current.User.Identity).Ticket.Name;

        if (Session["kechengid"] == null)
        {
            int minkechengid = TeacherInfo.GetTeacherRenke_min_kechengid(username);
            if (minkechengid > 0)
            {
                Session["kechengid"] = minkechengid;
            }
            else if (KechengInfo.GetKechengCount() > 0)
            {
                Session["kechengid"] = KechengInfo.MinKechengid();
            }
            else
            {
                List <string> noneKechengPage = new List <string>();//不需要课程的页面
                noneKechengPage.Add("createcourse.aspx");
                noneKechengPage.Add("help.aspx");
                noneKechengPage.Add("addbanji.aspx");
                noneKechengPage.Add("default.aspx");
                noneKechengPage.Add("studentdaoru.aspx");
                noneKechengPage.Add("wanshanxinxi.aspx");
                noneKechengPage.Add("addstudent.aspx");
                noneKechengPage.Add("editstudent.aspx");
                noneKechengPage.Add("editstudentinfo.aspx");
                noneKechengPage.Add("gerenxinxi.aspx");
                noneKechengPage.Add("kcxianyou.aspx");
                string url     = HttpContext.Current.Request.Url.AbsolutePath;
                string pageurl = url.Substring(url.LastIndexOf("/") + 1).ToLower();
                if (!noneKechengPage.Contains(pageurl))
                {
                    Response.Redirect("createcourse.aspx");
                }
            }
        }
        if (!IsPostBack)
        {
            Literal2.Text = TeacherInfo.TeacherXingMing(username) + "老师.";
            if (Session["kechengid"] != null)
            {
                lbl_kecheng.Text = KechengInfo.getKechengname(DropDownList1.SelectedValue = Session["kechengid"].ToString());
            }
            else
            {
                lbl_kecheng.Text = "未知";
            }
            lbtn_qiehuan.Visible = TeacherInfo.IsManager(username);//是否显示身份切换链接
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        BindKechengTreeView();
        string kechengid = Session["kechengid"].ToString();
        string username  = ((FormsIdentity)HttpContext.Current.User.Identity).Ticket.Name;

        if (!KechengInfo.IsTeacherManageKecheng(username, kechengid))
        {
            BtnAddzhishidian.Enabled = false;
            Lbl_fankui.Text          = "您不是本课程的管理员,无权对其知识结构进行编辑修改。";
        }
        else
        {
            BtnAddzhishidian.Enabled = true;
        }
    }
示例#6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string kechengid = Session["kechengid"].ToString();
        string tusername = ((FormsIdentity)HttpContext.Current.User.Identity).Ticket.Name;

        if (!KechengInfo.IsTeacherManageKecheng(tusername, kechengid))
        {
            Button1.Enabled = false;
            Label1.Text     = "您不是本课程的管理员,无权更新课程信息。";
        }
        else
        {
            Button1.Enabled = true;
        }
        if (!IsPostBack)
        {
            BindKechengInfo();
        }
    }
 protected void Page_Init(object sender, EventArgs e)
 {
     if (Session["kechengid"] == null)
     {
         if (KechengInfo.GetKechengCount() > 0)
         {
             Session["kechengid"] = KechengInfo.MinKechengid().ToString();
         }
         else
         {
             Response.Redirect("default.aspx");
         }
     }
     if (!IsPostBack)
     {
         string stuusername = ((FormsIdentity)HttpContext.Current.User.Identity).Ticket.Name;
         Literalxingming.Text = StudentInfo.GetStuXingming(stuusername);
     }
     lbl_kecheng.Text = KechengInfo.getKechengname(Session["kechengid"].ToString());
     CheckCeshi();//判断学生有无未完成的测试,如果有,不允许进行其他学习活动,只能进行测试
 }
示例#8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string kechengid = Session["kechengid"].ToString();

        if (!IsPostBack)
        {
            UpdateKechengTreeview(kechengid);
        }
        string username = ((FormsIdentity)HttpContext.Current.User.Identity).Ticket.Name;

        if (!KechengInfo.IsTeacherManageKecheng(username, kechengid))
        {
            Button_shanchu.Enabled = false;
            Label1.Text            = "您不是本课程的管理员,无权对其知识结构进行编辑修改。";
            DetailsView1.Enabled   = false;
        }
        else
        {
            Button_shanchu.Enabled = true;
            DetailsView1.Enabled   = true;
        }
    }
示例#9
0
 protected void Page_Init(object sender, EventArgs e)
 {
     if (Request.QueryString["kechengid"] != null)
     {
         Session["kechengid"] = Request.QueryString["kechengid"].Trim();
     }
     else
     {
         if (Session["kechengid"] == null)
         {
             if (KechengInfo.GetKechengCount() > 0)
             {
                 Session["kechengid"] = KechengInfo.MinKechengid().ToString();
             }
             else
             {
                 Response.Redirect("../default.aspx");
             }
         }
     }
     literal_kecheng.Text = KechengInfo.getKechengname(Session["kechengid"].ToString());;
 }
    protected void Page_Init(object sender, EventArgs e)
    {
        if (Session["kechengid"] == null)
        {
            if (KechengInfo.GetKechengCount() > 0)
            {
                Session["kechengid"] = KechengInfo.MinKechengid().ToString();
            }
            else
            {
                Response.Redirect("../default.aspx");
            }
        }
        label_kecheng.Text = KechengInfo.getKechengname(Session["kechengid"].ToString());
        string username    = string.Empty;
        string usershenfen = string.Empty;

        try
        {
            username    = ((FormsIdentity)HttpContext.Current.User.Identity).Ticket.Name;
            usershenfen = ((FormsIdentity)HttpContext.Current.User.Identity).Ticket.UserData;
        }
        catch
        {
        }
        if (username != string.Empty && usershenfen != string.Empty)
        {
            Literal2.Text       = username;
            user_login.Visible  = false;
            user_logout.Visible = true;
        }
        else
        {
            Literal2.Text       = "游客.";
            user_login.Visible  = true;
            user_logout.Visible = false;
        }
    }
示例#11
0
    //显示初始课程结构
    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {
        string username  = ((FormsIdentity)HttpContext.Current.User.Identity).Ticket.Name;
        string kechengid = Session["kechengid"].ToString();

        Lbl_zhishiname.Text = TreeView1.SelectedNode.Text;
        Lbl_zhishiid.Text   = TreeView1.SelectedNode.Value;
        TreeNode node = TreeView1.SelectedNode;

        if (node.ChildNodes.Count > 0 || node.Depth <= 0)
        {
            Button_shanchu.Enabled = false;
        }
        else
        {
            if (KechengInfo.IsTeacherManageKecheng(username, kechengid))
            {
                Button_shanchu.Enabled = true;
            }
            else
            {
                Button_shanchu.Enabled = false;
            }
        }
        int nodedepth = node.Depth;//求结点深度

        //回溯该知识点的上位知识点
        Lbl_dangqianweizhi.Text = "";
        StringBuilder sb = new StringBuilder();

        sb.Append(TreeView1.SelectedNode.Text);
        while (node.Parent != null)
        {
            node = node.Parent;
            sb.Insert(0, node.Text + "&gt;");
        }
        Lbl_dangqianweizhi.Text = sb.ToString();
    }
    protected void FinishButton_Click(object sender, EventArgs e)//开始选题,手工组卷和半自动组卷
    {
        //收集用户选择的信息
        string kechengid   = Session["kechengid"].ToString();
        string kechengname = KechengInfo.getKechengname(kechengid);
        string username    = ((FormsIdentity)HttpContext.Current.User.Identity).Ticket.Name;
        string ceshiname   = TextBoxceshimingcheng.Text.Trim();                                                              //测试名称
        string xianzhiip   = (chbxianzhiip.Checked ? "是" : "否");                                                             //是否限制IP

        if (CheckCeshiName(int.Parse(kechengid), ceshiname, ((FormsIdentity)HttpContext.Current.User.Identity).Ticket.Name)) //如果该课程该试卷名称已存在,提示,返回
        {
            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "", "<script language='javascript'>alert('您的该课程的该试卷名称已使用,请选择其它名称。');</script>", false);
            return;
        }
        string ceshibanji    = DropDownList_banji.SelectedItem.Text;              //班级名称
        string banjiid       = DropDownList_banji.SelectedValue;                  //班级ID
        string zujuanfangshi = RadioButtonListzujuanfangshi.SelectedValue.Trim(); //组卷方式,三种
        string xuantifangshi = RadioButtonListxuantifangshi.SelectedValue.Trim(); //选题方式,两种+1zhong
        int    ceshishichang = int.Parse(DropDownList4.SelectedValue);            //测试时长,分钟
        string shifouyunxu   = RadioButtonList9.SelectedValue;                    //是否允许做题
        //获取测试题型
        List <string> tixingsList = new List <string>();                          //要选择哪些题型

        string[] nodeidsshuzu = HiddenFieldnodeandchildren.Value.Split(',');
        string[] tixingshuzu  = HiddenFieldtixings.Value.Split(',');
        foreach (string tixing in tixingshuzu)
        {
            if (tixing.Length > 0)
            {
                tixingsList.Add(tixing);
            }
        }
        //检查选择的题目数是否符合要求
        List <int>[] xuanzetihaoList = new List <int> [tixingsList.Count];//使用List记录每种题型选择的题号,questionid
        for (int i = 0; i < tixingshuzu.Length - 1; i++)
        {
            xuanzetihaoList[i] = new List <int>();
        }
        int manfen = 100;                                     //计划的满分分值

        int[,] timushufenzhi = new int[tixingsList.Count, 4]; //题库中现有的题目数,要选择的题目数,分值,实际选择的题目数
        //统计每种题型计划选择的题目数和预计分值
        for (int i = 0; i < tixingsList.Count; i++)
        {
            timushufenzhi[i, 0] = ((DropDownList)(PlaceHolder1.FindControl("tixing" + tixingsList[i]))).Items.Count - 1;
            timushufenzhi[i, 1] = int.Parse(((DropDownList)(PlaceHolder1.FindControl("tixing" + tixingsList[i]))).SelectedValue);
            timushufenzhi[i, 2] = int.Parse(((DropDownList)(PlaceHolder1.FindControl("timufenzhi" + tixingsList[i]))).SelectedValue);
        }
        #region 获取选择的题号、题目数量
        //获取选择的题号、题目数量
        string   xuanzetihaoliebiao = Labelhidden.Value; //选择的题号questionid,中间用两个逗号分割
        string[] xuanzetihao;                            //选择的题号数组,总的,所有的
        xuanzetihao = xuanzetihaoliebiao.Split(',');     //选择的题号数组,字符串,因为题号间用,,分割,所以该数组中有很多空字符串
        int           tixingIndex;
        string        timutixing;
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = ConfigurationManager.ConnectionStrings["kecheng2012ConnectionString"].ConnectionString;
        SqlCommand comm = conn.CreateCommand();
        conn.Open();
        for (int i = 0; i < xuanzetihao.Length; i++)//统计选择了多少道题
        {
            if (xuanzetihao[i].Length > 0)
            {
                //得到该题的题型
                comm.CommandText = "select type from tb_tiku where questionid=" + xuanzetihao[i];
                timutixing       = comm.ExecuteScalar().ToString();
                tixingIndex      = tixingsList.IndexOf(timutixing);
                //统计每种题型选择了多少道题
                timushufenzhi[tixingIndex, 3]++;
                //将选中的题目的questionid添加到对应列表中
                xuanzetihaoList[tixingIndex].Add(int.Parse(xuanzetihao[i]));//每种题型选择的questionid
            }
        }
        conn.Close();
        #endregion
        #region 判断是否按计划选够了题目
        //判断是否按计划选够了题目
        string xuantixinxi = "";
        bool   xuangoutimu = true; //已选够了题目
        if (xuantifangshi == "0")  //按所选题目组卷,选题数量应等于计划数量
        {
            for (int i = 0; i < tixingsList.Count; i++)
            {
                if (timushufenzhi[i, 3] != timushufenzhi[i, 1])
                {
                    xuantixinxi += tixingsList[i] + "计划选择" + timushufenzhi[i, 1].ToString() + "道,实际选择" + timushufenzhi[i, 3].ToString() + "道。";
                    if (timushufenzhi[i, 3] > timushufenzhi[i, 1])
                    {
                        xuantixinxi += "多选了" + (timushufenzhi[i, 3] - timushufenzhi[i, 1]).ToString() + "道,请去掉" + (timushufenzhi[i, 3] - timushufenzhi[i, 1]).ToString() + "道。";
                    }
                    else
                    {
                        xuantixinxi += "少选了" + (timushufenzhi[i, 1] - timushufenzhi[i, 3]).ToString() + "道,请再选择" + (timushufenzhi[i, 1] - timushufenzhi[i, 3]).ToString() + "道。";
                    }
                    xuangoutimu = false;
                }
            }
        }
        else//随机组卷,选题数量应大于等于计划数量
        {
            for (int i = 0; i < tixingsList.Count; i++)
            {
                if (timushufenzhi[i, 3] < timushufenzhi[i, 1])
                {
                    xuantixinxi += tixingsList[i] + "计划选择" + timushufenzhi[i, 1].ToString() + "道,实际选择" + timushufenzhi[i, 3].ToString() + "道。数量不足,请至少再选择" + (timushufenzhi[i, 1] - timushufenzhi[i, 3]).ToString() + "道。";
                    xuangoutimu  = false;
                }
            }
        }
        if (!xuangoutimu)
        {
            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "", "<script language='javascript'>alert('" + xuantixinxi + "');</script>", false);
            return;
        }
        #endregion
        #region 随机选题
        int xuanzedetihao;
        comm.CommandText = "select count(studentusername) from tb_banjistudent where banjiid=" + banjiid;
        conn.Open();
        int studentRenshu = (int)(comm.ExecuteScalar());                                      //查询学生数量
        conn.Close();
        List <int>[,] stusuijiXuantiList = new List <int> [studentRenshu, tixingsList.Count]; //记录为学生随机选择的题目,记录题型i随机选择的题目在题目ID列表中的下标
        List <int>[] teasuijiXuantiList = new List <int> [tixingsList.Count];                 //记录为教师随机选择的题目编号
        Random       rand          = new Random();
        int          yixuantimushu = 0;
        if (xuantifangshi == "1")          //随机选题//为每个学生随机选择的题目
        {
            if (zujuanfangshi == "全体学生不同") //为每个学生随机选择的题目
            {
                for (int i = 0; i < studentRenshu; i++)
                {
                    for (int j = 0; j < tixingsList.Count; j++)
                    {
                        stusuijiXuantiList[i, j] = new List <int>();
                        yixuantimushu            = 0;
                        while (yixuantimushu < timushufenzhi[j, 1])
                        {
                            xuanzedetihao = rand.Next(timushufenzhi[j, 3]);
                            if (!stusuijiXuantiList[i, j].Contains(xuanzedetihao))
                            {
                                stusuijiXuantiList[i, j].Add(xuanzedetihao);
                                yixuantimushu++;
                            }
                        }
                    }
                }
            }
            else//只组一套卷或全体学生相同
            {
                for (int i = 0; i < teasuijiXuantiList.Length; i++)
                {
                    teasuijiXuantiList[i] = new List <int>();//记录题型i随机选择的题目在题目ID列表中的下标
                }
                for (int i = 0; i < tixingshuzu.Length - 1; i++)
                {
                    yixuantimushu = 0;
                    while (yixuantimushu < timushufenzhi[i, 1])
                    {
                        xuanzedetihao = rand.Next(timushufenzhi[i, 3]);
                        if (!teasuijiXuantiList[i].Contains(xuanzedetihao))
                        {
                            teasuijiXuantiList[i].Add(xuanzedetihao);
                            yixuantimushu++;
                        }
                    }
                }
            }
        }
        #endregion
        //生成试卷,写入数据库

        int shijuanid;//试卷ID号
        int tihao;
        //查看该试卷题目是否可用
        //开始事务
        string        zujuanxinxi     = "";
        bool          chenggong       = false;
        List <string> stuusernameList = new List <string>();
        List <int>    stuxuhaoList    = new List <int>();
        List <string> stuxingmingList = new List <string>();
        StringBuilder zujuanxinxiSB   = new StringBuilder();
        conn.Open();
        comm.CommandText = "select tb_banjistudent.xuhao,tb_banjistudent.studentusername,tb_student.xingming from tb_banjistudent,tb_student where tb_banjistudent.banjiid=" + banjiid + " and tb_banjistudent.studentusername=tb_student.username";
        SqlDataReader sdr = comm.ExecuteReader();
        while (sdr.Read())
        {
            stuxuhaoList.Add(sdr.GetInt32(0));
            stuusernameList.Add(sdr.GetString(1));
            stuxingmingList.Add(sdr.GetString(2));
        }
        sdr.Close();
        //conn.Close();
        //将试卷、试题写入数据库
        //conn.Open();
        SqlTransaction st = conn.BeginTransaction();
        comm.Transaction = st;
        try
        {
            //第一步,写入教师试卷表,得到试卷id
            comm.CommandText = "insert into tb_teachershijuan(teacherusername,ceshiname,kechengid,ceshizhishidian,timelength,manfen,mingtifangshi,yunxuzuoti,ceshibanji,banjiid,yunxuchakan,xianzhiip) values('" + username + "','" + ceshiname + "'," + kechengid + ",'" + HiddenFieldzhishidianname.Value + "'," + ceshishichang + "," + manfen + ",'" + zujuanfangshi + "','" + shifouyunxu + "','" + ceshibanji + "'," + banjiid + ",'" + RadioButtonList10.SelectedValue + "','" + xianzhiip + "') select @@identity as shijuanid";
            shijuanid        = Convert.ToInt32(comm.ExecuteScalar());  //
            //第二步,写入教师题目表
            if (zujuanfangshi == "全体学生相同" || zujuanfangshi == "对学生保密") //根据组卷方式选题,全体学生相同和只组一套卷类似,都是只选一套题
            {
                if (xuantifangshi == "0")                              //严格按照所选题目组卷
                {
                    tihao = 1;
                    for (int i = 0; i < tixingsList.Count; i++)
                    {
                        for (int j = 0; j < xuanzetihaoList[i].Count; j++)
                        {
                            comm.CommandText = "insert into tb_teachershijuantimu(shijuanid,questionid,fenzhi,tihao) values(" + shijuanid + "," + xuanzetihaoList[i][j] + "," + timushufenzhi[i, 2] + "," + tihao + ")";
                            comm.ExecuteNonQuery();
                            tihao++;
                        }
                    }
                }
                else//随机选题方式
                {
                    tihao = 1;
                    for (int i = 0; i < tixingsList.Count; i++)
                    {
                        for (int j = 0; j < timushufenzhi[i, 1]; j++)
                        {
                            //关于题目的questionid,选择的题目ID在xuzetihaoList[]中,每个数组元素是一个ArrayList,
                            //每个ArrayList记录了一种题型选择的questionid
                            //随机选题时,在teasuijiXuantiList中记录了选中的题目在对应ArrayList中的位置
                            //因此,要获取选中的题目的questionid,使用:(int)(xuzetihaoList[i][(int)(teasuijiXuantiList[i][j])])
                            comm.CommandText = "insert into tb_teachershijuantimu(shijuanid,questionid,fenzhi,tihao) values(" + shijuanid + "," + xuanzetihaoList[i][teasuijiXuantiList[i][j]] + "," + timushufenzhi[i, 2] + "," + tihao + ")";
                            comm.ExecuteNonQuery();
                            tihao++;
                        }
                    }
                }
            }
            //第三步:写入学生试卷表
            if (zujuanfangshi == "全体学生相同" || zujuanfangshi == "全体学生不同")//有学生的试卷
            {
                for (int i = 0; i < stuusernameList.Count; i++)
                {
                    zujuanxinxiSB.Append("序号:" + stuxuhaoList[i] + ",姓名:" + stuxingmingList[i] + ",学号:" + stuusernameList[i] + ";<br/>");
                    comm.CommandText = "insert into tb_studentkaoshi(shijuanid,studentusername,zongfen,yunxu,kechengid,banjiid) values(" + shijuanid + ",'" + stuusernameList[i] + "',0,'" + shifouyunxu + "'," + kechengid + "," + banjiid + ")";
                    comm.ExecuteNonQuery();
                }
            }
            else
            {
                zujuanxinxiSB.Append("组卷方式为只组一套卷,对学生保密,用于生成纸质试卷,因此没有为学生生成试卷。");
            }
            //第四步:试题写入学生试题表
            if (zujuanfangshi == "全体学生相同")
            {
                if (xuantifangshi == "0")//严格组卷
                {
                    foreach (string suname in stuusernameList)
                    {
                        tihao = 1;
                        for (int i = 0; i < tixingsList.Count; i++)
                        {
                            for (int j = 0; j < timushufenzhi[i, 1]; j++)
                            {
                                comm.CommandText = "insert into tb_studentkaoshiti(studentusername,shijuanid,questionid,fenzhi,timuhao) values('" + suname + "'," + shijuanid + "," + xuanzetihaoList[i][j] + "," + timushufenzhi[i, 2] + "," + tihao + ")";
                                comm.ExecuteNonQuery();
                                tihao++;
                            }
                        }
                    }
                }
                else//随机选题方式
                {
                    foreach (string suname in stuusernameList)
                    {
                        tihao = 1;
                        for (int i = 0; i < tixingsList.Count; i++)
                        {
                            for (int j = 0; j < timushufenzhi[i, 1]; j++)
                            {
                                comm.CommandText = "insert into tb_studentkaoshiti(studentusername,shijuanid,questionid,fenzhi,timuhao) values('" + suname + "'," + shijuanid + "," + xuanzetihaoList[i][teasuijiXuantiList[i][j]] + "," + timushufenzhi[i, 2] + "," + tihao + ")";
                                comm.ExecuteNonQuery();
                                tihao++;
                            }
                        }
                    }
                }
            }
            else if (zujuanfangshi == "全体学生不同")
            {
                if (xuantifangshi == "1")//随机选题
                {
                    for (int i = 0; i < stuusernameList.Count; i++)
                    {
                        tihao = 1;
                        for (int j = 0; j < tixingsList.Count; j++)
                        {
                            for (int k = 0; k < timushufenzhi[j, 1]; k++)
                            {
                                comm.CommandText = "insert into tb_studentkaoshiti(studentusername,shijuanid,questionid,fenzhi,timuhao) values('" + stuusernameList[i] + "'," + shijuanid + "," + xuanzetihaoList[j][stusuijiXuantiList[i, j][k]] + "," + timushufenzhi[j, 2] + "," + tihao + ")";
                                comm.ExecuteNonQuery();
                                tihao++;
                            }
                        }
                    }
                }
            }
            st.Commit();
            chenggong = true;
        }
        catch (Exception ex)
        {
            st.Rollback();
            zujuanxinxi = ex.Message;
            chenggong   = false;
        }
        finally
        {
            if (conn.State == ConnectionState.Open)
            {
                conn.Close();
            }
        }
        if (chenggong)//组卷成功,显示汇总信息,跳转到完成/跳转到Completestep,显示组卷信息
        {
            Labelkecheng.Text          = kechengname;
            Labelbanji.Text            = DropDownList_banji.SelectedItem.Text;
            Labelshichang.Text         = ceshishichang.ToString();
            Labelceshimingcheng.Text   = ceshiname;
            Labeltixing.Text           = HiddenFieldtixings.Value;
            Labelyunxu.Text            = shifouyunxu;
            Labelzujuanfangshi.Text    = zujuanfangshi;
            Literalstudentxiangxi.Text = zujuanxinxiSB.ToString();
            Labelzhishidian.Text       = TreeView1.CheckedNodesText;
            Labelyunxuchakan.Text      = RadioButtonList10.SelectedValue;
            Labelxianzhiip.Text        = (chbxianzhiip.Checked ? "限制IP,学生考试时IP地址必须唯一" : "不限制IP");
            Wizard1.ActiveStepIndex    = 3;
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "", "<script language='javascript'>alert('" + zujuanxinxi + "');</script>", false);
        }
    }
    protected void StartNextButton_Click(object sender, EventArgs e)//验证是否有班级、题目,如果有,则跳转到下一步
    {
        //查询相关知识点、课程有无任课班级、题目
        bool   banjicunzai = false;
        bool   timucunzai  = false;
        string kechengid   = Session["kechengid"].ToString();
        string username    = ((FormsIdentity)HttpContext.Current.User.Identity).Ticket.Name;
        string kechengname = KechengInfo.getKechengname(kechengid);
        //查询是否有班级
        DataSet ds = BanjiInfo.GetTeacherRenkeBanji(username, int.Parse(kechengid));

        if (ds.Tables[0].Rows.Count > 0)
        {
            banjicunzai = true;
        }
        if (!banjicunzai)
        {
            ScriptManager.RegisterClientScriptBlock(this, typeof(String), "", "<script language='javascript'>alert('没有找到您任教课程" + kechengname + "的班级,请选择其他班级!');</script>", false);
            return;
        }
        //查询是否有题目
        //显示每种题型的数量,选择数量,分值
        //获取选择的知识点及其下位知识点
        List <string> nodeandchilren    = TreeView1.CheckedNodesAndChildrenIds;// 选择的知识点及其子孙知识点id
        StringBuilder nodeandchildrenSB = new StringBuilder();
        //从题库中查询符合条件的题目
        SqlConnection conn = new SqlConnection();

        conn.ConnectionString = ConfigurationManager.ConnectionStrings["kecheng2012ConnectionString"].ConnectionString;
        SqlCommand comm = conn.CreateCommand();
        //建立临时表,记录选择的知识点id号
        string temptablename = "#temptable" + username + DateTime.Now.Ticks.ToString();

        comm.CommandText = "create table " + temptablename + "(id int)";
        conn.Open();
        comm.ExecuteNonQuery();
        foreach (string nodeid in nodeandchilren)
        {
            nodeandchildrenSB.Append(nodeid + ",");
            comm.CommandText = "insert into " + temptablename + "(id) values(" + int.Parse(nodeid) + ")";
            comm.ExecuteNonQuery();
        }
        //查询符合条件的第一题
        comm.CommandText = "select top 1 questionid from tb_tiku where questionid in( select questionid from tb_timuzhishidian where questionid not in ( select questionid from tb_timuzhishidian where kechengjiegouid not in (select id from " + temptablename + ")))";
        SqlDataReader sdr = comm.ExecuteReader();

        if (sdr.HasRows)
        {
            timucunzai = true;
        }
        sdr.Close();
        conn.Close();
        HiddenFieldnodeandchildren.Value = nodeandchildrenSB.ToString();//把选择的知识点及其下位知识点保存在hiddenfield中,以便以后使用
        if (!timucunzai)
        {
            ScriptManager.RegisterClientScriptBlock(this, typeof(String), "", "<script language='javascript'>alert('没有找到您选择的知识点的题目,请选择其他知识点!');</script>", false);
        }
        if (banjicunzai && timucunzai)
        {
            Wizard1.ActiveStepIndex = 1;
        }
    }
    protected void StepNextButton_Click(object sender, EventArgs e)//检查测试名称是否可用,收集组卷信息,跳转到下一步,绑定试题
    {
        //检查测试名称是否可用
        string kechengid = Session["kechengid"].ToString();
        string username  = ((FormsIdentity)HttpContext.Current.User.Identity).Ticket.Name;
        string ceshiname = TextBoxceshimingcheng.Text.Trim();          //测试名称
        string xianzhiip = (chbxianzhiip.Checked ? "是" : "否");         //是否限制IP

        if (CheckCeshiName(int.Parse(kechengid), ceshiname, username)) //检查测试名称是否可用
        {
            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "", "<script language='javascript'>alert('您的该课程的该试卷名称已使用,请选择其它名称。');</script>", false);
            return;
        }
        SqlConnection conn = new SqlConnection();

        conn.ConnectionString = ConfigurationManager.ConnectionStrings["kecheng2012ConnectionString"].ConnectionString;
        SqlCommand comm = conn.CreateCommand();
        //检查所选班级有无学生,如果没有学生,则不能组卷
        string banjiid = DropDownList_banji.SelectedValue;//测试班级ID

        comm.CommandText = "select count(studentusername) from tb_banjistudent where banjiid=" + banjiid;
        conn.Open();
        int banjistudentshuliang = (int)(comm.ExecuteScalar());

        conn.Close();
        if (banjistudentshuliang <= 0)
        {
            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "", "<script language='javascript'>alert('所选班级没有学生,不能组卷!请前往添加学生。');</script>", false);
            return;
        }
        //收集组卷信息,跳转到下一步
        StringBuilder tixingxuanzexinxi = new StringBuilder();
        string        tishi             = "";

        if (RadioButtonListxuantifangshi.SelectedValue == "0")
        {
            tishi = "应该选择";
        }
        else
        {
            tishi = "应至少选择";
        }
        StringBuilder tishiSB = new StringBuilder();

        string[]      tixingshuzu = HiddenFieldtixings.Value.Split(','); //要选择哪些题型
        DropDownList  tixuzeshuDropdownList;                             //显示某题型有多少道题的
        List <string> tixings = new List <string>();                     //选择了哪些题型

        foreach (string tixing in tixingshuzu)
        {
            if (tixing.Length > 0)
            {
                tixuzeshuDropdownList = (DropDownList)(PlaceHolder1.FindControl("tixing" + tixing));
                if (tixuzeshuDropdownList != null && tixuzeshuDropdownList.SelectedIndex != 0)
                {
                    tixings.Add(tixing);
                    tishiSB.Append(tixing + "有" + (tixuzeshuDropdownList.Items.Count - 1).ToString() + tishi + tixuzeshuDropdownList.SelectedValue + "道.<br/>");
                }
            }
        }
        Literalxuantitishi.Text = tishiSB.ToString();
        //绑定备选题目GridView
        List <string> nodeandchildren = TreeView1.CheckedNodesAndChildrenIds;//选中的知识点及其子孙知识点
        DataTable     dt = GetTimuDataTable(nodeandchildren, tixings);

        GridView1.DataSource = dt;
        GridView1.DataBind();                                //绑定题目gridview
        if (RadioButtonListxuantifangshi.SelectedIndex != 2) //手工组卷和半自动组卷
        {
            Wizard1.ActiveStepIndex = 2;
        }
        else//全自动组卷
        {
            #region 准备工作,获取组卷数据
            List <string> nodeandchilren  = TreeView1.CheckedNodesAndChildrenIds;       //选择的知识点及其子孙知识点id
            StringBuilder timufenzhixinxi = new StringBuilder();
            int           ceshishichang   = int.Parse(DropDownList4.SelectedValue);     //测试时间长度
            string        yunxuzuoti      = RadioButtonList9.SelectedValue;             //是否允许学生做题
            string        ceshibanji      = DropDownList_banji.SelectedItem.Text;       //测试班级
            string        mingtifangshi   = RadioButtonListzujuanfangshi.SelectedValue; //命题方式,统一命题,每个学生的题目不同,对学生保密
            string        yunxuchakan     = RadioButtonList10.SelectedValue;
            int           manfen          = 100;
            #endregion
            bool          zujuanchenggong     = true;
            int           xuanzeshu           = 0;
            int           tifenzhi            = 0;
            List <string> tixingXuanzeList    = new List <string>();
            List <int>    tixingshuliangList  = new List <int>();
            List <int>    tixingfenzhiList    = new List <int>();
            List <int>    studentxuhaoList    = new List <int>();
            List <string> studentxingmingList = new List <string>();
            DropDownList  tifenzhiDropdownList;
            comm.CommandText = "select mingcheng from tb_timuleixing order by tixingid";
            conn.Open();
            SqlDataReader sdr = comm.ExecuteReader();
            while (sdr.Read())
            {
                tixuzeshuDropdownList = (DropDownList)(PlaceHolder1.FindControl("tixing" + sdr.GetString(0)));
                if (tixuzeshuDropdownList != null)
                {
                    xuanzeshu = int.Parse(tixuzeshuDropdownList.SelectedValue);
                    if (xuanzeshu > 0)
                    {
                        timufenzhixinxi.Append(sdr.GetString(0) + ":" + tixuzeshuDropdownList.SelectedValue + "道,每题");
                        tixingXuanzeList.Add(sdr.GetString(0)); //选择了哪些题型
                        tifenzhiDropdownList = (DropDownList)(PlaceHolder1.FindControl("timufenzhi" + sdr.GetString(0)));
                        tixingshuliangList.Add(xuanzeshu);      //每种题型数量
                        tifenzhi = int.Parse(tifenzhiDropdownList.SelectedValue);
                        timufenzhixinxi.Append(tifenzhi.ToString() + "分;");
                        tixingfenzhiList.Add(tifenzhi);//每种题型分值
                    }
                }
            }
            sdr.Close();
            conn.Close();
            List <int>[] beixuanTihaoList   = new List <int> [tixingXuanzeList.Count]; //各种题型备选的questionid列表
            List <int>[] xuanzhongTihaoList = new List <int> [tixingXuanzeList.Count]; //各种题型选中的questionid列表
            for (int i = 0; i < tixingXuanzeList.Count; i++)
            {
                beixuanTihaoList[i]   = new List <int>();
                xuanzhongTihaoList[i] = new List <int>();
            }
            string temptablename = "temp_table" + username + DateTime.Now.Ticks.ToString();
            comm.CommandText = "create table " + temptablename + "(id int)";
            conn.Open();
            comm.ExecuteNonQuery();
            foreach (string nodeid in nodeandchilren)
            {
                comm.CommandText = "insert into " + temptablename + "(id) values(" + int.Parse(nodeid) + ")";
                comm.ExecuteNonQuery();
            }
            string sqlstr = "select questionid,type from tb_tiku where(";
            for (int i = 0; i < tixingXuanzeList.Count; i++)//添加题型条件
            {
                if (i == 0)
                {
                    sqlstr += "type='" + tixingXuanzeList[i] + "'";
                }
                else
                {
                    sqlstr += " or type='" + tixingXuanzeList[i] + "'";
                }
            }
            sqlstr          += ")";
            sqlstr          += " and questionid in ( select questionid from tb_timuzhishidian where questionid not in ( select questionid from tb_timuzhishidian where kechengjiegouid not in (select id from " + temptablename + "))) order by type";
            comm.CommandText = sqlstr;
            sdr = comm.ExecuteReader();
            int tixinghao;
            int tihao;
            while (sdr.Read())
            {
                tixinghao = tixingXuanzeList.IndexOf(sdr.GetString(1));//得到题型在列表中的编号
                beixuanTihaoList[tixinghao].Add(sdr.GetInt32(0));
            }
            sdr.Close();
            //随机选则题目,为统一组卷,全体学生相同或对学生保密的情况
            try
            {
                comm.CommandText = "drop table " + temptablename;
                comm.ExecuteNonQuery();
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            Random r = new Random();
            for (int i = 0; i < tixingXuanzeList.Count; i++)
            {
                tixinghao = 0;
                while (tixinghao < tixingshuliangList[i])
                {
                    tihao = r.Next(beixuanTihaoList[i].Count);
                    if (!xuanzhongTihaoList[i].Contains(tihao))
                    {
                        xuanzhongTihaoList[i].Add(tihao);
                        tixinghao++;
                    }
                }
            }
            //随机选择题目,全体学生不同的情况
            List <string> stuusernameList = new List <string>();//学生用户名列表
            comm.CommandText = "select tb_banjistudent.xuhao,tb_banjistudent.studentusername,tb_student.xingming from tb_banjistudent,tb_student where tb_banjistudent.banjiid=" + banjiid + " and tb_banjistudent.studentusername=tb_student.username order by tb_banjistudent.xuhao";
            conn.Open();
            sdr = comm.ExecuteReader();
            while (sdr.Read())
            {
                studentxuhaoList.Add(sdr.GetInt32(0));
                stuusernameList.Add(sdr.GetString(1));
                studentxingmingList.Add(sdr.GetString(2));
            }
            sdr.Close();
            conn.Close();
            List <int>[,] stusuijiXuantiList = new List <int> [stuusernameList.Count, tixingshuliangList.Count];//记录题型i随机选择的题目在题目ID列表中的下标
            for (int i = 0; i < stuusernameList.Count; i++)
            {
                for (int j = 0; j < tixingshuliangList.Count; j++)
                {
                    stusuijiXuantiList[i, j] = new List <int>();
                }
            }
            //开始随机选题
            for (int i = 0; i < stuusernameList.Count; i++)
            {
                for (int j = 0; j < tixingshuliangList.Count; j++)
                {
                    int yixuantimushu = 0;
                    while (yixuantimushu < tixingshuliangList[j])
                    {
                        tihao = r.Next(beixuanTihaoList[j].Count);
                        if (!stusuijiXuantiList[i, j].Contains(tihao))
                        {
                            stusuijiXuantiList[i, j].Add(tihao);
                            yixuantimushu++;
                        }
                    }
                }
            }
            //写入数据库
            int           shijuanid          = 0;
            StringBuilder studentzujuanxinxi = new StringBuilder();
            conn.Open();
            SqlTransaction st = conn.BeginTransaction();
            comm.Transaction = st;
            try
            {
                //第一步:写入教师试卷表,得到试卷id
                comm.CommandText = "insert into tb_teachershijuan(teacherusername,ceshiname,createtime,timelength,manfen,mingtifangshi,kechengid,ceshibanji,banjiid,yunxuzuoti,yunxuchakan,xianzhiip) values('" + username + "','" + ceshiname + "','" + DateTime.Now.ToString() + "'," + ceshishichang + "," + manfen + ",'" + mingtifangshi + "'," + kechengid + ",'" + ceshibanji + "'," + banjiid + ",'" + yunxuzuoti + "','" + yunxuchakan + "','" + xianzhiip + "') select @@identity as shijuanid";
                shijuanid        = Convert.ToInt32(comm.ExecuteScalar());
                ////写入组卷知识点
                //第二步:写入教师试卷题目表
                if (mingtifangshi == "全体学生相同" || mingtifangshi == "对学生保密")
                {
                    tihao = 1;
                    for (int i = 0; i < tixingXuanzeList.Count; i++)
                    {
                        for (int j = 0; j < xuanzhongTihaoList[i].Count; j++)
                        {
                            comm.CommandText = "insert into tb_teachershijuantimu(shijuanid,questionid,fenzhi,tihao) values(" + shijuanid + "," + beixuanTihaoList[i][xuanzhongTihaoList[i][j]] + "," + tixingfenzhiList[i] + "," + tihao + ")";
                            comm.ExecuteNonQuery();
                            tihao++;
                        }
                    }
                }
                //第三步:写入学生试卷表
                if (mingtifangshi == "全体学生相同" || mingtifangshi == "全体学生不同")
                {
                    for (int i = 0; i < stuusernameList.Count; i++)
                    {
                        comm.CommandText = "insert into tb_studentkaoshi(shijuanid,studentusername,zongfen,yunxu,kechengid,banjiid,jiaojuan) values(" + shijuanid + ",'" + stuusernameList[i] + "',0,'" + yunxuzuoti + "'," + kechengid + "," + banjiid + ",'未开始')";
                        comm.ExecuteNonQuery();
                        studentzujuanxinxi.Append(studentxuhaoList[i].ToString() + ",姓名:" + studentxingmingList[i] + ",学号:" + stuusernameList[i] + ";</br>");
                    }
                }
                else
                {
                    studentzujuanxinxi.Append("组卷类型为只组一套卷,因此没有学生试卷,此试卷对学生报密。");
                }
                //第四步:写入学生试题表
                if (mingtifangshi == "全体学生相同")
                {
                    foreach (string stuusername in stuusernameList)
                    {
                        tihao = 1;
                        for (int i = 0; i < tixingXuanzeList.Count; i++)
                        {
                            for (int j = 0; j < xuanzhongTihaoList[i].Count; j++)
                            {
                                comm.CommandText = "insert into tb_studentkaoshiti(studentusername,shijuanid,questionid,fenzhi,timuhao) values('" + stuusername + "'," + shijuanid + "," + beixuanTihaoList[i][xuanzhongTihaoList[i][j]] + "," + tixingfenzhiList[i] + "," + tihao + ")";
                                comm.ExecuteNonQuery();
                                tihao++;
                            }
                        }
                    }
                }
                else if (mingtifangshi == "全体学生不同")
                {
                    for (int k = 0; k < stuusernameList.Count; k++)
                    {
                        tihao = 1;
                        for (int i = 0; i < tixingXuanzeList.Count; i++)
                        {
                            for (int j = 0; j < tixingshuliangList[i]; j++)
                            {
                                comm.CommandText = "insert into tb_studentkaoshiti(studentusername,shijuanid,questionid,fenzhi,timuhao) values('" + stuusernameList[k] + "'," + shijuanid + "," + beixuanTihaoList[i][stusuijiXuantiList[k, i][j]] + "," + tixingfenzhiList[i] + "," + tihao + ")";
                                comm.ExecuteNonQuery();
                                tihao++;
                            }
                        }
                    }
                }
                st.Commit();
                zujuanchenggong = true;
            }
            catch (Exception ex)
            {
                st.Rollback();
                zujuanchenggong = false;
                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "", "<script language='javascript'>alert('组卷失败!原因:" + ex.Message + ".');</script>", false);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            if (zujuanchenggong)
            {
                Wizard1.ActiveStepIndex    = 3;
                Labelceshimingcheng.Text   = TextBoxceshimingcheng.Text;
                Labelkecheng.Text          = KechengInfo.getKechengname(kechengid);
                Labelzujuanfangshi.Text    = RadioButtonListzujuanfangshi.SelectedValue;
                Labelzhishidian.Text       = TreeView1.CheckedNodesText;
                Labelyunxu.Text            = RadioButtonList9.SelectedValue;       //是否允许做题
                Labelshichang.Text         = DropDownList4.SelectedValue;          //时长
                Labelbanji.Text            = DropDownList_banji.SelectedItem.Text; //班级
                Labeltixing.Text           = HiddenFieldtixings.Value;
                Literalstudentxiangxi.Text = studentzujuanxinxi.ToString();
                Labelxianzhiip.Text        = (chbxianzhiip.Checked ? "限制IP,学生考试时IP地址必须唯一" : "不限制IP");
                Labelyunxuchakan.Text      = yunxuchakan;
            }
        }//end of全自动组卷
    }
示例#15
0
    protected void Buttonloginin_Click(object sender, EventArgs e)
    {
        Labelerror.Text = "";
        bool          yonghukeyong = true;
        string        username     = TextBoxusername.Text.Trim();
        string        password     = TextBoxpassword.Text.Trim();
        string        shenfen      = RadioButtonListshenfen.SelectedValue.ToString().Trim();
        SqlConnection conn         = new SqlConnection();

        conn.ConnectionString = ConfigurationManager.ConnectionStrings["kecheng2012ConnectionString"].ConnectionString;
        SqlCommand    comm      = conn.CreateCommand();
        bool          chenggong = false;
        SqlDataReader sdr;

        conn.Open();
        if (shenfen == "teacher")
        {
            comm.CommandText = "select [password],[keyong] from [tb_teacher] where [username]=@username";
            comm.Parameters.AddWithValue("@username", username);
            sdr = comm.ExecuteReader();
            if (sdr.Read())
            {
                if (sdr.GetString(0).Trim() == password)
                {
                    chenggong = true;
                }
                if (sdr.GetString(1).Trim() == "否")
                {
                    yonghukeyong = false;
                }
            }
            sdr.Close();
        }
        else if (shenfen == "student")
        {
            comm.CommandText = "select [password] from [tb_Student] where [username]= @username";
            comm.Parameters.AddWithValue("@username", username);
            sdr = comm.ExecuteReader();
            if (sdr.Read())
            {
                if (sdr.GetString(0).Trim() == password)
                {
                    chenggong = true;
                }
            }
            sdr.Close();
        }
        else//管理员
        {
            comm.CommandText = "select [password],[manager],[keyong] from [tb_teacher] where [username]=@username";
            comm.Parameters.AddWithValue("@username", username);
            sdr = comm.ExecuteReader();
            if (sdr.Read())
            {
                string userpassword = sdr.GetString(0);
                if (!sdr.IsDBNull(1))
                {
                    string ismanager = sdr.GetString(1);
                    if (userpassword == password && (ismanager == "manager" || ismanager == "supermanager"))
                    {
                        chenggong = true;
                    }
                }
                if (sdr.GetString(2).Trim() == "否")
                {
                    yonghukeyong = false;
                }
            }
            sdr.Close();
        }
        conn.Close();
        comm.Dispose();
        //创建认证票据
        if (chenggong && yonghukeyong)
        {
            FormsAuthentication.Initialize();
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                1,                                                                         //票据版本号
                username,                                                                  //票据持有者
                DateTime.Now,                                                              //分配票据的时间
                DateTime.Now.AddHours(3),                                                  //失效时间
                true,                                                                      //需要用户的cookie
                shenfen,                                                                   //用户的角色
                FormsAuthentication.FormsCookiePath);                                      //cookie有效路径
            string     hash   = FormsAuthentication.Encrypt(ticket);                       //加密
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash); //加密之后的cookie
            cookie.Expires = ticket.Expiration;
            //添加cookie到页面请求响应中
            Response.Cookies.Add(cookie);
            string returnurl = "";
            if (shenfen == "teacher")
            {
                returnurl = "teacher/Default.aspx";
            }
            else if (shenfen == "student")
            {
                if (KechengInfo.GetKechengCount() > 0)
                {
                    Session["kechengid"] = KechengInfo.MinKechengid();
                }
                returnurl = "student/Default.aspx";
            }
            else if (shenfen == "manager")
            {
                returnurl = "manager/tianjiabanji.aspx";
            }
            Response.Redirect(returnurl);
        }
        else
        {
            if (!yonghukeyong)
            {
                Labelerror.Text = "该用户已被禁用,请与管理员联系!";
            }
            else
            {
                Labelerror.Text = "用户名或密码错误!请重试!";
            }
        }
    }