306 lines
11 KiB
C#
306 lines
11 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Web;
|
||
using System.Web.UI;
|
||
using System.Web.UI.WebControls;
|
||
using Telerik.Web.UI;
|
||
|
||
namespace VRS.Management.VSAT
|
||
{
|
||
public partial class ExamTheory_RandomAdd : BasePage
|
||
{
|
||
DataService.BLL.pro_exam_theory bll_exam_theory = new DataService.BLL.pro_exam_theory();
|
||
DataService.BLL.pro_examination bll_examination = new DataService.BLL.pro_examination();
|
||
//DataService.BLL.pro_theory_base bll_examination = new DataService.BLL.pro_theory_base();
|
||
|
||
DataService.BLL.pro_theory_base bll_theory_base = new DataService.BLL.pro_theory_base();
|
||
DataService.BLL.admin_user bll_user = new DataService.BLL.admin_user();
|
||
protected override void Page_Load(object sender, EventArgs e)
|
||
{
|
||
if (!IsPostBack)
|
||
{
|
||
var exam_id = Request.Params["Id"];
|
||
hid_examId.Value = exam_id;
|
||
|
||
//loadData();
|
||
|
||
loadData();
|
||
}
|
||
}
|
||
|
||
public void loadData()
|
||
{
|
||
var exam_id = hid_examId.Value;
|
||
StringBuilder query = new StringBuilder(" 1 = 1 ");
|
||
var list_exam_theory = bll_exam_theory.GetModelList("exam_id='" + exam_id + "'");
|
||
if (list_exam_theory.Count > 0)
|
||
{
|
||
var array = list_exam_theory.Select(s => s.content).ToArray();
|
||
List<string> dest = new List<string>();
|
||
foreach (var sub in array)
|
||
{
|
||
dest.Add("'" + sub + "'");
|
||
}
|
||
var id_list = string.Join(",", dest.ToArray());
|
||
query.AppendFormat(" AND id not in ({0}) ", id_list);
|
||
}
|
||
var qry = query.ToString();
|
||
var list_base = bll_theory_base.GetModelList(qry);
|
||
var list_type = list_base.Select(s => s.kind).Distinct().ToList();
|
||
|
||
List<DataService.Model.theory_type_count> list_res = new List<DataService.Model.theory_type_count>();
|
||
int id = 1;
|
||
foreach (var item in list_type)
|
||
{
|
||
var model = new DataService.Model.theory_type_count();
|
||
model.theory_type = item;
|
||
model.no = id++;
|
||
var count = list_base.Where(s => s.kind == item).Count();
|
||
model.theory_count = count;
|
||
list_res.Add(model);
|
||
}
|
||
var exam = bll_examination.GetModel(exam_id);
|
||
if (null != exam)
|
||
{
|
||
span_exam_name.InnerHtml = exam.exam_name;
|
||
//span_total_score.InnerHtml = exam.total_score;
|
||
}
|
||
dataList.DataSource = list_res;
|
||
dataList.DataBind();
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/// <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();
|
||
}
|
||
*/
|
||
}
|
||
|
||
//批量设置分数
|
||
protected void btnSure_Click(object sender, EventArgs e)
|
||
{
|
||
var list_type_count = new List<DataService.Model.theory_type_count>();
|
||
bool success = computeItemsCount(out string msg, out double totalscore, list_type_count);
|
||
if (!success)
|
||
{
|
||
span_name.InnerHtml = msg;
|
||
return;
|
||
}
|
||
|
||
#region 判断试卷分值
|
||
/*
|
||
var exam_id = hid_examId.Value;
|
||
var exam = bll_examination.GetModel(exam_id);
|
||
var exam_total = double.Parse(exam.total_score);
|
||
if (totalscore != exam_total)
|
||
{
|
||
msg = string.Format("当前分值:{0},不等于试卷分值:{1}", totalscore, exam_total);
|
||
RadAjaxManager1.Alert(msg);
|
||
return;
|
||
}
|
||
*/
|
||
#endregion
|
||
|
||
//以下为具体实现方式
|
||
/*
|
||
if (totalscore!=100)
|
||
{
|
||
RadAjaxManager1.Alert("分数不是100分!");
|
||
return;
|
||
}
|
||
*/
|
||
|
||
var exam_id = Request.Params["Id"];
|
||
var now = DateTime.Now;
|
||
var user = DataService.BLL.admin_user.load_login();
|
||
var user_login = bll_user.GetModel(user.user_id);
|
||
|
||
var list_insert = new List<DataService.Model.pro_exam_theory>();
|
||
|
||
foreach (var type_count in list_type_count)
|
||
{
|
||
List<DataService.Model.pro_theory_base> list_base = new List<DataService.Model.pro_theory_base>();
|
||
var flag = getRandomItems(type_count, exam_id, list_base);
|
||
if(!flag)
|
||
{
|
||
span_name.InnerHtml = "题目数量有变动";
|
||
return;
|
||
}
|
||
int max_no = 1;
|
||
var kind = type_count.theory_type;
|
||
var list = bll_exam_theory.GetModelList("exam_id='" + exam_id + "' and question_kind='" + kind + "'");
|
||
if (list.Count > 0)
|
||
{
|
||
max_no = list.Max(s => s.no) + 1;
|
||
}
|
||
var id = BasePage.GetId();
|
||
int index = 1;
|
||
foreach (var item in list_base)
|
||
{
|
||
var model = new DataService.Model.pro_exam_theory();
|
||
model.id = BasePage.GetNextId(id, index++);
|
||
model.exam_id = exam_id;
|
||
model.content = item.id;
|
||
model.question_kind = item.kind;
|
||
|
||
if (model.question_kind == "判断题")
|
||
{
|
||
model.question_difficult = "0";
|
||
}
|
||
else if (model.question_kind == "单选题")
|
||
{
|
||
model.question_difficult = "1";
|
||
}
|
||
else if (model.question_kind == "多选题")
|
||
{
|
||
model.question_difficult = "2";
|
||
}
|
||
else if (model.question_kind == "填空题")
|
||
{
|
||
model.question_difficult = "3";
|
||
}
|
||
else if (model.question_kind == "简答题")
|
||
{
|
||
model.question_difficult = "4";
|
||
}
|
||
|
||
model.create_time = now;
|
||
model.create_by = user_login.user_id;
|
||
|
||
model.per_score = 0;
|
||
model.no = max_no++;
|
||
list_insert.Add(model);
|
||
}
|
||
}
|
||
var success_count = bll_exam_theory.BatchAdd(list_insert);
|
||
if (success_count > 0)
|
||
{
|
||
RadAjaxManager1.ResponseScripts.Add("alert('添加题目成功!');CloseAndRebind();");
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 获取随机题目
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
/// <param name="exam_id"></param>
|
||
/// <param name="list_insert"></param>
|
||
/// <returns></returns>
|
||
public bool getRandomItems(DataService.Model.theory_type_count model, string exam_id,List<DataService.Model.pro_theory_base> list_insert)
|
||
{
|
||
StringBuilder query = new StringBuilder(" 1 = 1 ");
|
||
var list_exam_theory = bll_exam_theory.GetModelList("exam_id='" + exam_id + "'");
|
||
if (list_exam_theory.Count > 0)
|
||
{
|
||
var array = list_exam_theory.Select(s => s.content).ToArray();
|
||
List<string> dest = new List<string>();
|
||
foreach (var sub in array)
|
||
{
|
||
dest.Add("'" + sub + "'");
|
||
}
|
||
var id_list = string.Join(",", dest.ToArray());
|
||
query.AppendFormat(" AND id not in ({0}) ", id_list);
|
||
}
|
||
query.AppendFormat(" AND kind = '{0}' ", model.theory_type);
|
||
var qry = query.ToString();
|
||
var list = bll_theory_base.GetModelList(qry);
|
||
if (list.Count < model.score)
|
||
{
|
||
return false;
|
||
}
|
||
var list_result = list.OrderBy(s => Guid.NewGuid()).Take((int)model.score).ToList();
|
||
list_insert.AddRange(list_result);
|
||
return true;
|
||
}
|
||
|
||
public bool computeItemsCount(out string msg, out double totalscore, List<DataService.Model.theory_type_count> list_type_count)
|
||
{
|
||
double total_score = 0;
|
||
var sb = new StringBuilder();
|
||
totalscore = 0;
|
||
|
||
for (int i = 0; i < dataList.Items.Count; i++)
|
||
{
|
||
var item = dataList.Items[i];
|
||
var txt = item.FindControl("per_score") as RadNumericTextBox;
|
||
|
||
var no = int.Parse(item.GetDataKeyValue("no").ToString());
|
||
var theory_type = item.GetDataKeyValue("theory_type").ToString();
|
||
var theory_count = int.Parse(item.GetDataKeyValue("theory_count").ToString());
|
||
|
||
if (!txt.Value.HasValue)
|
||
{
|
||
msg = theory_type + ",新增数量不能为空!";
|
||
return false;
|
||
}
|
||
|
||
var per_count = txt.Value.Value;
|
||
if (per_count < 0)
|
||
{
|
||
msg = theory_type + ",新增数量应不小于0!";
|
||
return false;
|
||
}
|
||
if (per_count > theory_count)
|
||
{
|
||
msg = theory_type + string.Format(",新增数量不大于{0}!", theory_count);
|
||
return false;
|
||
}
|
||
|
||
//double theory_score = theory_count * per_score;
|
||
//total_score += theory_score;
|
||
|
||
var model = new DataService.Model.theory_type_count();
|
||
model.no = no;
|
||
model.theory_type = theory_type;
|
||
model.theory_count = theory_count;
|
||
model.score = per_count;
|
||
|
||
if (per_count > 0)
|
||
{
|
||
list_type_count.Add(model);
|
||
sb.AppendFormat(",{0}:剩余数量{1},新增数量:{2} ", theory_type, theory_count, per_count);
|
||
}
|
||
//sb.AppendFormat(",{0}:{1} 分值:{2} 总分:{3}", theory_type, theory_count, per_score, theory_score);
|
||
}
|
||
|
||
/*
|
||
if (dataList.Items.Count > 0)
|
||
{
|
||
var total_dsc = string.Format("总分:" + total_score);
|
||
sb.Insert(0, total_dsc);
|
||
}
|
||
*/
|
||
|
||
var text = sb.ToString();
|
||
msg = text;
|
||
totalscore = total_score;
|
||
return true;
|
||
}
|
||
|
||
protected void per_score_TextChanged(object sender, EventArgs e)
|
||
{
|
||
var list_type_count = new List<DataService.Model.theory_type_count>();
|
||
bool success = computeItemsCount(out string msg, out double score, list_type_count);
|
||
if (!success)
|
||
{
|
||
span_name.InnerHtml = msg;
|
||
}
|
||
}
|
||
|
||
}
|
||
} |