protected void imgBtnSave_Click(object sender, ImageClickEventArgs e) { if (Page.IsValid) { Course course = new Course(); //创建试卷科目对象 if (course.IsCourseNameExist(txtName.Text.Trim())) { AjaxCommond ac = new AjaxCommond(); ac.OpenDialogForButton((ImageButton)sender, "该名称已被占用!!!"); txtName.Text = ""; } else { course.Name = txtName.Text; //设置试卷科目对象属性 if (course.InsertByProc()) //调用添加试卷科目方法添加试卷科目 { lblMessage.Text = "成功添加该试卷科目!"; txtName.Text = ""; } else { lblMessage.Text = "添加该试卷科目失败!"; } } } }
protected void LinkButton1_Click(object sender, EventArgs e) { AjaxCommond ac = new AjaxCommond(); if (IsPaperNameNotExist()) { ac.OpenDialogForLinkButton((LinkButton)sender, "该试卷名可以用!!!"); } else { ac.OpenDialogForLinkButton((LinkButton)sender, "很遗憾!该试卷名称已经存在!!!"); } }
protected void CheckPagerName_Click(object sender, EventArgs e) { AjaxCommond ac = new AjaxCommond(); //创建数据阅读器 SqlDataReader read = ExceRead("select * from Papermr where PaperName='" + this.txtPaperName.Text + "'"); read.Read(); //打开数据阅读器 if (read.HasRows) //判断是否有数据 { if (this.txtPaperName.Text == read["PaperName"].ToString()) { //弹出AJAX环境中的对话框 ac.OpenDialogForButton((Button)sender, "很遗憾!该试卷名称已经存在!!!"); } } else { //弹出AJAX环境中的对话框 ac.OpenDialogForButton((Button)sender, "恭喜您!该试卷名称可以添加!!!"); } read.Close(); //关闭数据阅读器 }
//将生成试卷保存到数据库 protected void imgBtnSave_Click(object sender, EventArgs e) { DataBase database = new DataBase(); //实例化公共类DataBase AjaxCommond ac = new AjaxCommond(); //实例化公共类AjaxCommond string insertExamPage = "insert into Papermr(CourseID,PaperName,PaperState) values(" + int.Parse(MyddlCourse.SelectedValue) + ",'" + txtPaperName.Text + "',1) SELECT @@IDENTITY as id"; int autopageID = GetIDInsert(insertExamPage); //保存试卷,并返回自动生成的试卷编号 if (autopageID > 0) { //生成单选题信息,并保存在数据库中 for (int i = 0; i < this.GridView1.Rows.Count; i++) { bool isChecked = ((CheckBox)GridView1.Rows[i].FindControl("chkSelect1")).Checked; if (isChecked) { string sqlstr1 = ((Label)GridView1.Rows[i].FindControl("Label3")).Text; string singlepaper = "insert into PaperDetailmr(PaperID,Type,TitleID,Mark) values(" + autopageID + ",'单选题'," + sqlstr1 + "," + int.Parse(txtSingleFen.Text) + ")"; database.Insert(singlepaper); } } //生成多选题信息,并保存在数据库中 for (int i = 0; i < this.GridView2.Rows.Count; i++) { bool isChecked = ((CheckBox)GridView2.Rows[i].FindControl("chkSelect2")).Checked; if (isChecked) { string sqlstr2 = ((Label)GridView2.Rows[i].FindControl("Label6")).Text; string multipaper = "insert into PaperDetailmr(PaperID,Type,TitleID,Mark) values(" + autopageID + ",'多选题'," + sqlstr2 + "," + int.Parse(txtMultiFen.Text) + ")"; database.Insert(multipaper); } } //生成判断题信息,并保存在数据库中 for (int i = 0; i < this.GridView3.Rows.Count; i++) { bool isChecked = ((CheckBox)GridView3.Rows[i].FindControl("chkSelect3")).Checked; if (isChecked) { string sqlstr3 = ((Label)GridView3.Rows[i].FindControl("Label7")).Text; string judgepaper = "insert into PaperDetailmr(PaperID,Type,TitleID,Mark) values(" + autopageID + ",'判断题'," + sqlstr3 + "," + int.Parse(txtJudgeFen.Text) + ")"; database.Insert(judgepaper); } } //生成填空题信息,并保存在数据库中 for (int i = 0; i < this.GridView4.Rows.Count; i++) { bool isChecked = ((CheckBox)GridView4.Rows[i].FindControl("chkSelect4")).Checked; if (isChecked) { string sqlstr4 = ((Label)GridView4.Rows[i].FindControl("Label8")).Text; string fillpaper = "insert into PaperDetailmr(PaperID,Type,TitleID,Mark) values(" + autopageID + ",'填空题'," + sqlstr4 + "," + int.Parse(txtFillFen.Text) + ")"; database.Insert(fillpaper); } } //生成问答题信息,并保存在数据库中 for (int i = 0; i < this.GridView5.Rows.Count; i++) { bool isChecked = ((CheckBox)GridView5.Rows[i].FindControl("chkSelect5")).Checked; if (isChecked) { string sqlstr5 = ((Label)GridView5.Rows[i].FindControl("Label23")).Text; string quepaper = "insert into PaperDetailmr(PaperID,Type,TitleID,Mark) values(" + autopageID + ",'问答题'," + sqlstr5 + "," + int.Parse(txtQuestionFen.Text) + ")"; database.Insert(quepaper); } } } //弹出ajax环境中的提示对话框 ac.OpenDialogForButton((Button)sender, "数据保存成功!"); //跳转到试卷维护页 Response.Redirect("PaperLists.aspx"); }
//将生成试卷保存到数据库 protected void imgBtnSave_Click(object sender, ImageClickEventArgs e) { AjaxCommond ac = new AjaxCommond(); if (IsPaperNameNotExist()) { DataBase db = new DataBase(); string insertpaper = "insert into Paper(CourseID,PaperName,PaperState,NeedTime) values(" + int.Parse(ddlCourse.SelectedValue) + ",'" + txtPaperName.Text + "',0," + int.Parse(ddlNeedTime.SelectedValue) * 60 + ") SELECT @@IDENTITY as id"; int afterID = GetIDInsert(insertpaper);//保存试卷,并返回自动生成的试卷编号 if (afterID > 0) { for (int i = 0; i < this.GridView11.Rows.Count; i++) { bool isChecked = ((CheckBox)GridView11.Rows[i].FindControl("chkSelect1")).Checked; if (isChecked) { string str1 = ((Label)GridView11.Rows[i].FindControl("Label3")).Text; string single = "insert into PaperDetail(PaperID,Type,TitleID,Mark) values(" + afterID + ",'单选题'," + str1 + "," + int.Parse(txtSingleFen.Text) + ")"; db.Insert(single); } } for (int i = 0; i < this.GridView2.Rows.Count; i++) { bool isChecked = ((CheckBox)GridView2.Rows[i].FindControl("chkSelect2")).Checked; if (isChecked) { string str2 = ((Label)GridView2.Rows[i].FindControl("Label6")).Text; string multi = "insert into PaperDetail(PaperID,Type,TitleID,Mark) values(" + afterID + ",'多选题'," + str2 + "," + int.Parse(txtMultiFen.Text) + ")"; db.Insert(multi); } } for (int i = 0; i < this.GridView3.Rows.Count; i++) { bool isChecked = ((CheckBox)GridView3.Rows[i].FindControl("chkSelect3")).Checked; if (isChecked) { string str3 = ((Label)GridView3.Rows[i].FindControl("Label7")).Text; string judge = "insert into PaperDetail(PaperID,Type,TitleID,Mark) values(" + afterID + ",'判断题'," + str3 + "," + int.Parse(txtJudgeFen.Text) + ")"; db.Insert(judge); } } for (int i = 0; i < this.GridView4.Rows.Count; i++) { bool isChecked = ((CheckBox)GridView4.Rows[i].FindControl("chkSelect4")).Checked; if (isChecked) { string str4 = ((Label)GridView4.Rows[i].FindControl("Label8")).Text; string fill = "insert into PaperDetail(PaperID,Type,TitleID,Mark) values(" + afterID + ",'填空题'," + str4 + "," + int.Parse(txtFillFen.Text) + ")"; db.Insert(fill); } } for (int i = 0; i < this.GridView5.Rows.Count; i++) { bool isChecked = ((CheckBox)GridView5.Rows[i].FindControl("chkSelect5")).Checked; if (isChecked) { string str5 = ((Label)GridView5.Rows[i].FindControl("Label23")).Text; string que = "insert into PaperDetail(PaperID,Type,TitleID,Mark) values(" + afterID + ",'问答题'," + str5 + "," + int.Parse(txtQuestionFen.Text) + ")"; db.Insert(que); } } } txtPaperName.Text = ""; ac.OpenDialogForButtonWithLocation((ImageButton)sender, "保存成功!"); } else { ac.OpenDialogForButton((ImageButton)sender, "很遗憾!该试卷名称已经存在!!!"); return; } }