コード例 #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie usercookie = Request.Cookies["nowloginuser"];
        string     url        = PublicClass.CheckLogin(usercookie, "main");

        if (url != "")
        {
            Response.Write(url);
            return;
        }

        if (!IsPostBack)
        {
            string action = Request["action"];
            string sjid   = Request["sjid"];
            if (action != null && sjid != null)
            {
                int id = int.Parse(sjid);
                if (action.Equals("delete"))
                {
                    //删除服务器上面对应试卷的所有图片
                    foreach (DataRow row in TbImagesManager.GetImagesBySjid(id).Rows)
                    {
                        string path = Server.MapPath("images/" + row["Tpian"].ToString());
                        if (File.Exists(path))
                        {
                            File.Delete(path);
                        }
                    }
                    TbImagesManager.DeleteImageBySjid(id);
                    TbQuestionTypesManager.DeleteQuestionTypesBySjid(id);
                    TbTestPaperManager.DeleteTestpaperBySjid(id);
                }
            }
            GetAllTestPaperInfo();
        }
    }
コード例 #2
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        string Load = this.txtName.Text;

        #region 将上传的word文档转换为图片并保存
        try
        {
            //上传的Word文件的保存路径
            string postpath = FileUpload1.PostedFile.FileName;
            if (!postpath.Contains(':') || !postpath.Contains('\\'))
            {
                lblFileMessage.Text = "请设置您当前浏览器:工具-internet选项-安全-自定义级别-将文件上传到服务器是包含本地路径!";
                return;
            }
            this.FileUpload1.PostedFile.SaveAs(postpath);         //保存上传的Word文档
            TbTestPaper paper = new TbTestPaper();
            paper.SjName = txtName.Text;                          //试卷名称
            paper.LsName = Request.Cookies["nowloginuser"].Value; //当前用户
            paper.KmID   = int.Parse(ddlSubject.SelectedValue);   //科目编号
            paper.KsTime = DateTime.Parse(startTime.Value);       //开始时间
            paper.JsTime = DateTime.Parse(endTime.Value);         //结束时间
            paper.Remark = txtRemark.Text;                        //备注
            sjid         = TbTestPaperManager.AddPaper(paper);    //添加后的试卷ID
            Word_Convert2Image(postpath);                         //调用转换函数
        }
        catch (Exception ex)
        {
            TbTestPaperManager.DeleteTestpaperBySjid(sjid);
            lblSubMessage.Text = ex.Message;
            return;
        }
        #endregion

        if (sjid > 0)
        {
            string          dxcount  = txtdxcount.Text;  //单选题数
            string          duocount = txtduocount.Text; //多选题数
            string          pdcount  = txtpdcount.Text;  //判断题数
            string          jdcount  = txtjdcount.Text;  //简答题数
            TbQuestionTypes qtype    = new TbQuestionTypes();
            qtype.SjID = sjid;
            if (dxcount != "" && dxcount != "0")  //添加单选题
            {
                qtype.TxName  = "单选题";
                qtype.TxCount = int.Parse(dxcount);
                qtype.Txzf    = int.Parse(txtdxzf.Text);
                TbQuestionTypesManager.AddQuestionType(qtype);
            }
            if (duocount != "" && duocount != "0")  //添加多选题
            {
                qtype.TxName  = "多选题";
                qtype.TxCount = int.Parse(duocount);
                qtype.Txzf    = int.Parse(txtduozf.Text);
                TbQuestionTypesManager.AddQuestionType(qtype);
            }
            if (pdcount != "" && pdcount != "0")  //添加判断题
            {
                qtype.TxName  = "判断题";
                qtype.TxCount = int.Parse(pdcount);
                qtype.Txzf    = int.Parse(txtpdzf.Text);
                TbQuestionTypesManager.AddQuestionType(qtype);
            }
            if (jdcount != "" && jdcount != "0")  //添加简答题
            {
                qtype.TxName  = "简答题";
                qtype.TxCount = int.Parse(jdcount);
                qtype.Txzf    = int.Parse(txtjdzf.Text);
                TbQuestionTypesManager.AddQuestionType(qtype);
            }
            lblSubMessage.Text = "试卷生成成功!";
        }
    }