560 lines
20 KiB
C#
560 lines
20 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Web;
|
||
using System.Web.UI;
|
||
using System.Web.UI.WebControls;
|
||
using Telerik.Web.UI;
|
||
|
||
namespace VRS.Management.VSAT
|
||
{
|
||
public partial class ExamTheoryBase_Edit_Custom : BasePage
|
||
{
|
||
DataService.BLL.pro_exam_batch bll = new DataService.BLL.pro_exam_batch();
|
||
|
||
DataService.BLL.admin_log log = new DataService.BLL.admin_log();
|
||
DataService.BLL.admin_user bll_user = new DataService.BLL.admin_user();
|
||
DataService.BLL.pro_theory_base bll_theory_base = new DataService.BLL.pro_theory_base();
|
||
|
||
DataService.BLL.pro_theory_base_item bll_theory_base_item = new DataService.BLL.pro_theory_base_item();
|
||
protected override void Page_Load(object sender, EventArgs e)
|
||
{
|
||
base.Page_Load(sender, e);
|
||
if (!IsPostBack)
|
||
{
|
||
//var user = DataService.BLL.admin_user.load_login();
|
||
//var user_login = bll_user.GetModel(user.user_id);
|
||
|
||
BindDeviceType("TheoryBaseKnow", dp_know, "");
|
||
DataLoad();
|
||
}
|
||
}
|
||
|
||
public void DataLoad()
|
||
{
|
||
|
||
string Id = Request.Params["Id"];
|
||
var theory_base = bll_theory_base.GetModel(Id);
|
||
if (null != theory_base)
|
||
{
|
||
question_name.Text = theory_base.question;
|
||
dp_kind.SelectedValue = theory_base.kind;
|
||
dp_know.SelectedValue = theory_base.target;
|
||
|
||
//r1.Text = theory_base.r1;
|
||
}
|
||
|
||
var list = bll_theory_base_item.GetModelList("theory_base_id='" + Id + "'").OrderBy(s => s.no).ToList();
|
||
for (int i = 0; i < list.Count; i++)
|
||
{
|
||
var model = list[i];
|
||
RadListBoxDestination.Items.Add(new RadListBoxItem(model.item));
|
||
var list_item = RadListBoxDestination.Items[i];
|
||
|
||
RadTextBox box = list_item.FindControl("option_name") as RadTextBox;
|
||
if (null != box)
|
||
{
|
||
box.Text = model.item;
|
||
}
|
||
RadioButtonList radbuttonlist = list_item.FindControl("RadioButtonList_Answer") as RadioButtonList;
|
||
if (null != radbuttonlist)
|
||
{
|
||
radbuttonlist.SelectedValue = model.is_answer.ToString();
|
||
}
|
||
}
|
||
|
||
RadListBoxDestination.DataBind();
|
||
|
||
ReorderAZ();
|
||
|
||
/*
|
||
RadListBoxDestination.DataSource = list;
|
||
RadListBoxDestination.DataValueField = "id";
|
||
RadListBoxDestination.DataTextField = "question";
|
||
RadListBoxDestination.DataSortField = "question";
|
||
RadListBoxDestination.DataBind();
|
||
*/
|
||
var kind = dp_kind.SelectedValue;
|
||
if (kind == "填空题" || kind == "简答题")
|
||
{
|
||
answer_write.Text = theory_base.answer;
|
||
}
|
||
|
||
|
||
if (kind == "单选题" || kind == "多选题")
|
||
{
|
||
btnAddItem.Visible = true;
|
||
answer_write.Text = "";
|
||
answer_write.Enabled = false;
|
||
}
|
||
else if (kind == "判断题")
|
||
{
|
||
btnAddItem.Visible = true;
|
||
answer_write.Text = "";
|
||
answer_write.Enabled = false;
|
||
}
|
||
else
|
||
{
|
||
btnAddItem.Visible = false;
|
||
answer_write.Enabled = true;
|
||
}
|
||
}
|
||
|
||
protected void RadListBoxDestination_Reordered(object sender, RadListBoxEventArgs e)
|
||
{
|
||
RadListBoxDestination.DataBind();
|
||
ReorderAZ();
|
||
}
|
||
|
||
protected void RadListBoxDestination_Deleted(object sender, RadListBoxEventArgs e)
|
||
{
|
||
span_name.InnerHtml = "";
|
||
RadListBoxDestination.DataBind();
|
||
ReorderAZ();
|
||
}
|
||
|
||
protected void RadListBoxDestination_Deleting(object sender, RadListBoxDeletingEventArgs e)
|
||
{
|
||
if (RadListBoxDestination.Items.Count <= 2)
|
||
{
|
||
span_name.InnerHtml = "至少有两个选项!";
|
||
e.Cancel = true;
|
||
}
|
||
}
|
||
|
||
//添加单个选项
|
||
protected void btnAddItem_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
|
||
/*
|
||
var item = new RadListBoxItem();
|
||
item.Text = txt_additem.Text.Trim();
|
||
var addItem = new RadListBoxItem(item.Text, item.Text);
|
||
RadListBoxDestination.Items.Add(addItem);
|
||
RadioButtonList radbuttonlist = addItem.FindControl("RadioButtonList_Answer") as RadioButtonList;
|
||
if (null != radbuttonlist)
|
||
{
|
||
radbuttonlist.SelectedValue = RadioButtonList_answer.SelectedValue;
|
||
}
|
||
RadListBoxDestination.DataBind();
|
||
*/
|
||
|
||
var kind = dp_kind.SelectedValue;
|
||
if (string.IsNullOrEmpty(kind))
|
||
{
|
||
span_name.InnerHtml = "题目类型不能为空!";
|
||
return;
|
||
}
|
||
if (kind == "简答题" || kind == "填空题")
|
||
{
|
||
span_name.InnerHtml = "该题目类型不能添加选项!";
|
||
return;
|
||
}
|
||
if (kind == "判断题")
|
||
{
|
||
if (RadListBoxDestination.Items.Count >= 2)
|
||
{
|
||
span_name.InnerHtml = "判断题只有两个选项!";
|
||
return;
|
||
}
|
||
}
|
||
else if (kind == "单选题")
|
||
{
|
||
|
||
}
|
||
else if (kind == "多选题")
|
||
{
|
||
|
||
}
|
||
span_name.InnerHtml = "";
|
||
AddNewItem();
|
||
RadListBoxDestination.DataBind();
|
||
}
|
||
|
||
|
||
|
||
protected void btnSure_Click(object sender, EventArgs e)
|
||
{
|
||
btnSure.Enabled = false;
|
||
string Id = Request.Params["Id"];
|
||
var model = bll_theory_base.GetModel(Id);
|
||
|
||
var user = DataService.BLL.admin_user.load_login();
|
||
/*
|
||
if (string.IsNullOrEmpty(dp_kind.SelectedValue))
|
||
{
|
||
RadAjaxManager1.Alert("题目类型不能为空!");
|
||
return;
|
||
}
|
||
*/
|
||
|
||
if (string.IsNullOrEmpty(question_name.Text.Trim()))
|
||
{
|
||
RadAjaxManager1.Alert("题干不能为空!");
|
||
btnSure.Enabled = true;
|
||
return;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(dp_know.SelectedValue))
|
||
{
|
||
RadAjaxManager1.Alert("知识领域不能为空!");
|
||
btnSure.Enabled = true;
|
||
return;
|
||
}
|
||
|
||
int right_count = 0;
|
||
List<string> list_answer = new List<string>();
|
||
var questionTK = question_name.Text.Trim();
|
||
var answerTK = answer_write.Text.Trim();
|
||
if (dp_kind.SelectedValue != "简答题" && dp_kind.SelectedValue != "填空题")
|
||
{
|
||
var flag = CheckRightAnswerCount(RadListBoxDestination, ref right_count, list_answer);
|
||
if (!flag)
|
||
{
|
||
RadAjaxManager1.Alert("选项值不能为空!");
|
||
btnSure.Enabled = true;
|
||
return;
|
||
}
|
||
}
|
||
var total_count = RadListBoxDestination.Items.Count;
|
||
|
||
//判断题、单选题、多选题
|
||
if (dp_kind.SelectedValue == "判断题")
|
||
{
|
||
if (total_count != 2)
|
||
{
|
||
RadAjaxManager1.Alert("判断题只有两个选项!");
|
||
btnSure.Enabled = true;
|
||
return;
|
||
}
|
||
if (right_count != 1)
|
||
{
|
||
RadAjaxManager1.Alert("判断题只有1个选项答案!");
|
||
btnSure.Enabled = true;
|
||
return;
|
||
}
|
||
}
|
||
else if (dp_kind.SelectedValue == "单选题")
|
||
{
|
||
if (total_count < 2)
|
||
{
|
||
RadAjaxManager1.Alert("单选题至少两个选项!");
|
||
btnSure.Enabled = true;
|
||
return;
|
||
}
|
||
if (right_count != 1)
|
||
{
|
||
RadAjaxManager1.Alert("单选题只有1个选项答案!");
|
||
btnSure.Enabled = true;
|
||
return;
|
||
}
|
||
}
|
||
else if (dp_kind.SelectedValue == "多选题")
|
||
{
|
||
if (total_count < 2)
|
||
{
|
||
RadAjaxManager1.Alert("多选题至少两个选项!");
|
||
btnSure.Enabled = true;
|
||
return;
|
||
}
|
||
if (right_count < 2)
|
||
{
|
||
RadAjaxManager1.Alert("多选题至少2个选项答案!");
|
||
btnSure.Enabled = true;
|
||
return;
|
||
}
|
||
}
|
||
else if (dp_kind.SelectedValue == "简答题")
|
||
{
|
||
var answer = answer_write.Text.Trim();
|
||
if (string.IsNullOrEmpty(answer))
|
||
{
|
||
RadAjaxManager1.Alert("简答题答案不能为空!");
|
||
btnSure.Enabled = true;
|
||
return;
|
||
}
|
||
}
|
||
else if (dp_kind.SelectedValue == "填空题")
|
||
{
|
||
var answer = answer_write.Text.Trim();
|
||
if (string.IsNullOrEmpty(answer))
|
||
{
|
||
RadAjaxManager1.Alert("填空题答案不能为空!");
|
||
btnSure.Enabled = true;
|
||
return;
|
||
}
|
||
|
||
var line2 = "__";
|
||
|
||
questionTK = questionTK.Replace("__________", line2)
|
||
.Replace("_________", line2)
|
||
.Replace("________", line2)
|
||
.Replace("_______", line2)
|
||
.Replace("______", line2)
|
||
.Replace("_____", line2)
|
||
.Replace("____", line2)
|
||
.Replace("___", line2);
|
||
// var question_array = question.Split(new string[] { line2 }, StringSplitOptions.RemoveEmptyEntries);
|
||
var question_count = ExamTheoryBase_Add_Custom.CountSubstringOccurrences(questionTK, line2);
|
||
|
||
|
||
answerTK = answerTK.Replace("__________", line2)
|
||
.Replace("_________", line2)
|
||
.Replace("________", line2)
|
||
.Replace("_______", line2)
|
||
.Replace("______", line2)
|
||
.Replace("_____", line2)
|
||
.Replace("____", line2)
|
||
.Replace("___", line2);
|
||
var answer_array = answerTK.Split(new string[] { line2 }, StringSplitOptions.None);
|
||
|
||
if (question_count != answer_array.Length)
|
||
{
|
||
RadAjaxManager1.Alert(string.Format("填空题空格数:{0} ,与答案数:{1} 不一致!", question_count, answer_array.Length));
|
||
btnSure.Enabled = true;
|
||
return;
|
||
}
|
||
}
|
||
|
||
#region 旧有判断
|
||
/* old
|
||
if (dp_kind.SelectedValue == "简答题")
|
||
{
|
||
if (string.IsNullOrEmpty(anwser_jianda.Text.Trim()))
|
||
{
|
||
RadAjaxManager1.Alert("简答题答案不能为空!");
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (dp_answer.CheckedItems.Count <= 0)
|
||
{
|
||
RadAjaxManager1.Alert("请选择答案!");
|
||
return;
|
||
}
|
||
}
|
||
*/
|
||
#endregion
|
||
|
||
var now = DateTime.Now;
|
||
|
||
model.target = dp_know.SelectedValue;
|
||
|
||
//model.kind = dp_kind.SelectedValue;
|
||
model.question = question_name.Text.Trim();
|
||
|
||
model.update_time = now;
|
||
model.update_by = user.user_id;
|
||
//model.r1 = r1.Text.Trim();
|
||
//model.answer = string.Join(",", list_answer);
|
||
if (dp_kind.SelectedValue == "填空题")
|
||
{
|
||
model.question = questionTK;
|
||
model.answer = answerTK;
|
||
}
|
||
else if (dp_kind.SelectedValue == "简答题")
|
||
{
|
||
model.answer = answer_write.Text.Trim();
|
||
|
||
}
|
||
else //其它题型
|
||
{
|
||
model.answer = string.Join(",", list_answer);
|
||
}
|
||
|
||
var id = model.id;
|
||
int index = 1;
|
||
|
||
if (bll_theory_base.Update(model))
|
||
{
|
||
//log.write_log("添加题目成功。" + "名称:" + model.question + ",id:" + model.id);
|
||
var list = bll_theory_base_item.GetModelList("theory_base_id='" + Id + "'").ToList();
|
||
List<string> list_id = new List<string>();
|
||
foreach (var xx in list)
|
||
{
|
||
list_id.Add("'" + xx.id + "'");
|
||
}
|
||
|
||
if (list.Count > 0)
|
||
{
|
||
var cmd = string.Join(",", list_id);
|
||
var delete_flag = bll_theory_base_item.DeleteList(cmd);
|
||
}
|
||
|
||
Dictionary<int, string> dic = new Dictionary<int, string>();
|
||
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||
var length = alphabet.Length;
|
||
for (int i = 0; i < 26; i++)
|
||
{
|
||
dic.Add(i, alphabet.Substring(i, 1));
|
||
}
|
||
|
||
for (int i = 0; i < RadListBoxDestination.Items.Count; i++)
|
||
{
|
||
var list_item = RadListBoxDestination.Items[i];
|
||
var item = new DataService.Model.pro_theory_base_item();
|
||
item.id = BasePage.GetNextId(id, index++);
|
||
item.theory_base_id = id;
|
||
item.no = (i + 1);
|
||
if (dic.ContainsKey(i))
|
||
{
|
||
item.item_letter = dic[i];
|
||
}
|
||
item.create_by = user.user_id;
|
||
item.create_time = now;
|
||
item.item = list_item.Text;
|
||
RadTextBox box = list_item.FindControl("option_name") as RadTextBox;
|
||
if (null != box)
|
||
{
|
||
|
||
}
|
||
RadioButtonList radbuttonlist = list_item.FindControl("RadioButtonList_Answer") as RadioButtonList;
|
||
if (null != radbuttonlist)
|
||
{
|
||
item.is_answer = int.Parse(radbuttonlist.SelectedValue);
|
||
}
|
||
|
||
bll_theory_base_item.Add(item);
|
||
}
|
||
RadAjaxManager1.ResponseScripts.Add("alert('修改题目成功!');CloseAndRebind();");
|
||
}
|
||
else
|
||
{
|
||
RadAjaxManager1.Alert("修改题目失败!");
|
||
btnSure.Enabled = true;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
protected void btnRowEdit_Click(object sender, EventArgs e)
|
||
{
|
||
var item = sender as LinkButton;
|
||
var rad_item = item.Parent as RadListBoxItem; //item
|
||
//var rad_list = item.Parent.Parent; //radlist
|
||
var text = rad_item.Text;
|
||
var value = rad_item.Value;
|
||
|
||
var txtbox = rad_item.FindControl("option_name") as RadTextBox;
|
||
if (txtbox.Text != text)
|
||
{
|
||
rad_item.Text = txtbox.Text.Trim();
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新选项值
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void option_name_TextChanged(object sender, EventArgs e)
|
||
{
|
||
var txtBox = sender as RadTextBox;
|
||
var rad_item = txtBox.Parent as RadListBoxItem;
|
||
if (null != rad_item)
|
||
{
|
||
rad_item.Text = txtBox.Text.Trim();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 检查选项值
|
||
/// </summary>
|
||
/// <param name="RadListBoxDestination"></param>
|
||
/// <param name="count"></param>
|
||
/// <returns></returns>
|
||
public static bool CheckRightAnswerCount(RadListBox RadListBoxDestination, ref int _right_count, List<string> list_answer)
|
||
{
|
||
int right_count = 0;
|
||
|
||
Dictionary<int, string> dic = new Dictionary<int, string>();
|
||
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||
var length = alphabet.Length;
|
||
for (int i = 0; i < 26; i++)
|
||
{
|
||
dic.Add(i, alphabet.Substring(i, 1));
|
||
}
|
||
|
||
for (int i = 0; i < RadListBoxDestination.Items.Count; i++)
|
||
{
|
||
var list_item = RadListBoxDestination.Items[i];
|
||
/*
|
||
RadTextBox box = list_item.FindControl("option_name") as RadTextBox;
|
||
if (null != box){}*/
|
||
if (string.IsNullOrEmpty(list_item.Text))
|
||
{
|
||
return false;
|
||
}
|
||
RadioButtonList radbuttonlist = list_item.FindControl("RadioButtonList_Answer") as RadioButtonList;
|
||
if (null != radbuttonlist)
|
||
{
|
||
if (radbuttonlist.SelectedValue == "1")
|
||
{
|
||
//list_answer.Add((i + 1).ToString());
|
||
list_answer.Add(dic[i]);
|
||
right_count++;
|
||
}
|
||
}
|
||
}
|
||
_right_count = right_count;
|
||
return true;
|
||
}
|
||
|
||
|
||
|
||
public void AddNewItem()
|
||
{
|
||
Dictionary<int, string> dic = new Dictionary<int, string>();
|
||
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||
var length = alphabet.Length;
|
||
for (int i = 0; i < 26; i++)
|
||
{
|
||
dic.Add(i, alphabet.Substring(i, 1));
|
||
}
|
||
var item = new RadListBoxItem();
|
||
item.Text = txt_additem.Text.Trim();
|
||
var addItem = new RadListBoxItem(item.Text, item.Text);
|
||
RadListBoxDestination.Items.Add(addItem);
|
||
|
||
var added_index = addItem.Index;
|
||
|
||
Label labelAZ = addItem.FindControl("labelAZ") as Label;
|
||
if (null != labelAZ)
|
||
{
|
||
if (dic.ContainsKey(added_index))
|
||
{
|
||
labelAZ.Text = dic[added_index];
|
||
}
|
||
}
|
||
}
|
||
|
||
public void ReorderAZ()
|
||
{
|
||
Dictionary<int, string> dic = new Dictionary<int, string>();
|
||
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||
var length = alphabet.Length;
|
||
for (int i = 0; i < 26; i++)
|
||
{
|
||
dic.Add(i, alphabet.Substring(i, 1));
|
||
}
|
||
for (int i = 0; i < RadListBoxDestination.Items.Count; i++)
|
||
{
|
||
var item = RadListBoxDestination.Items[i];
|
||
var added_index = item.Index;
|
||
Label labelAZ = item.FindControl("labelAZ") as Label;
|
||
if (null != labelAZ)
|
||
{
|
||
if (dic.ContainsKey(added_index))
|
||
{
|
||
labelAZ.Text = dic[added_index];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
} |