660 lines
23 KiB
C#
660 lines
23 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Configuration;
|
||
using System.Data;
|
||
using System.IO;
|
||
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 : BaseListPage
|
||
{
|
||
DataService.BLL.pro_result bll = new DataService.BLL.pro_result();
|
||
DataService.BLL.pro_result_detail bll_result_detail = new DataService.BLL.pro_result_detail();
|
||
DataService.BLL.admin_user bll_user = new DataService.BLL.admin_user();
|
||
DataService.BLL.pro_file bll_file = new DataService.BLL.pro_file();
|
||
|
||
DataService.BLL.pro_theory_base bll_theory_base = new DataService.BLL.pro_theory_base();
|
||
|
||
DataService.BLL.pro_examination bll_examination = new DataService.BLL.pro_examination();
|
||
DataService.BLL.pro_exam_theory bll_exam_theory = new DataService.BLL.pro_exam_theory();
|
||
|
||
|
||
protected override void Page_Load(object sender, EventArgs e)
|
||
{
|
||
base.Page_Load(sender, e);
|
||
if (!IsPostBack)
|
||
{
|
||
//start.SelectedDate = DateTime.Today.AddDays(-365);
|
||
//end.SelectedDate = DateTime.Today;
|
||
DataLoad();
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
public List<DataService.Model.pro_result> getDataSet()
|
||
{
|
||
var start_date = start.SelectedDate.HasValue ? start.SelectedDate.Value.ToString("yyyy-MM-dd") : "";
|
||
var end_date = end.SelectedDate.HasValue ? end.SelectedDate.Value.ToString("yyyy-MM-dd") : "";
|
||
if (!string.IsNullOrEmpty(end_date))
|
||
{
|
||
end_date = DateTime.Parse(end_date).AddDays(1).ToString("yyyy-MM-dd");
|
||
}
|
||
//var query = new StringBuilder(" 1 = 1 and subject_id!='00003' "); //排除故障现象考试
|
||
// 身份证号、姓名、部门、性别、科目、船型、时间联合筛选 (3列)
|
||
|
||
|
||
var query = new StringBuilder(" 1 = 1 "); //不排除故障现象考试
|
||
|
||
var user = DataService.BLL.admin_user.load_login();
|
||
var userModel = bll_user.GetModel(user.user_id);
|
||
if (bll_user.IsAdministrator(userModel))
|
||
{
|
||
|
||
}
|
||
else //老师只能看到自己的单位的 $$
|
||
{
|
||
//query.AppendFormat(" AND unit_id = '{0}' ", userModel.unit_id);
|
||
|
||
}
|
||
|
||
//开始时间、结束时间
|
||
if (!string.IsNullOrWhiteSpace(start_date))
|
||
{
|
||
query.AppendFormat(" AND examine_time >= '{0}' ", start_date);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(end_date))
|
||
{
|
||
query.AppendFormat(" AND examine_time < '{0}' ", end_date);
|
||
}
|
||
|
||
var data = bll.GetModelList(query.ToString());
|
||
|
||
for (int i = 0; i < data.Count; i++)
|
||
{
|
||
var model = data[i];
|
||
var boat = BasePage.list_sign_boat.FirstOrDefault(s => s.type_id == model.examine_kind);
|
||
if (null != boat)
|
||
{
|
||
model.examine_kind_dsc = boat.type_name;
|
||
}
|
||
|
||
model.has_video = "0";
|
||
var file = bll_file.GetModelByOutid(model.result_id);
|
||
if (null != file)
|
||
{
|
||
if (!file.file_url.Contains("http")) //本地
|
||
{
|
||
string path = Context.Server.MapPath("~/" + file.file_url);
|
||
if (File.Exists(path))
|
||
{
|
||
model.has_video = "1";
|
||
var video_title = model.real_name + "-" + model.subject_name + "-" + model.total_result + "分";
|
||
model.video_title = video_title;
|
||
model.video_url = "/" + file.file_url;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
model.has_video = "1";
|
||
var video_title = model.real_name + "-" + model.subject_name + "-" + model.total_result + "分";
|
||
model.video_title = video_title;
|
||
model.video_url = file.file_url;
|
||
}
|
||
|
||
}
|
||
}
|
||
return data.OrderByDescending(s => s.examine_time).ToList(); ;
|
||
}
|
||
|
||
protected override void DataLoad()
|
||
{
|
||
var id = Request.Params["Id"];
|
||
|
||
hid_examid.Value = id;
|
||
var exam = bll_examination.GetModel(id);
|
||
if (null != exam)
|
||
{
|
||
//txt_exam_name.Text = exam.exam_name;
|
||
dp_exam_status.SelectedValue = exam.exam_status.Value.ToString();
|
||
span_exam_name.InnerHtml = exam.exam_name;
|
||
|
||
span_total_score.InnerHtml = exam.total_score;
|
||
|
||
}
|
||
var table = bll_exam_theory.QueryResultByExamId(id).Tables[0];
|
||
//dataList.DataSource = table;
|
||
//dataList.Rebind();
|
||
|
||
RadListBoxDestination.Items.Clear();
|
||
|
||
for (int i = 0; i < table.Rows.Count; i++)
|
||
{
|
||
var row = table.Rows[i];
|
||
var question = row["question"].ToString();
|
||
var answer = row["answer"].ToString();
|
||
var question_kind = row["question_kind"].ToString();
|
||
|
||
var addItem = new RadListBoxItem();
|
||
addItem.Attributes.Add("question_kind", question_kind);
|
||
|
||
var per_score = row["per_score"].ToString();
|
||
addItem.Text = BasePage.RemoveTrailingZeros(per_score);
|
||
addItem.ToolTip = question;
|
||
|
||
RadListBoxDestination.Items.Add(addItem);
|
||
|
||
|
||
var list_item = RadListBoxDestination.Items[i];
|
||
|
||
var label = list_item.FindControl("lb_question_kind") as Label;
|
||
if (null != label)
|
||
{
|
||
label.Text = question_kind;
|
||
}
|
||
var hid_content = list_item.FindControl("hid_content") as HiddenField;
|
||
if (null != hid_content)
|
||
{
|
||
var content = row["content"].ToString();
|
||
hid_content.Value = content;
|
||
}
|
||
}
|
||
RadListBoxDestination.DataBind();
|
||
var dsc = Get_RadList_Score();
|
||
Label lb = RadListBoxDestination.Header.FindControl("lb_score_header") as Label;
|
||
lb.Text = dsc;
|
||
span_name.InnerHtml = dsc;
|
||
}
|
||
|
||
protected override void GridList_PageIndexChanged(object sender, GridPageChangedEventArgs e)
|
||
{
|
||
DataLoad();
|
||
}
|
||
|
||
protected override void GridList_PageSizeChanged(object sender, GridPageSizeChangedEventArgs e)
|
||
{
|
||
DataLoad();
|
||
}
|
||
|
||
protected override void GridList_SortCommand(object sender, GridSortCommandEventArgs e)
|
||
{
|
||
DataLoad();
|
||
}
|
||
|
||
protected override void GrdList_DeleteCommand(object sender, GridCommandEventArgs e)
|
||
{
|
||
string Id = (e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"].ToString();
|
||
bll.Delete(Id);
|
||
DataLoad();
|
||
}
|
||
|
||
protected override void AjaxManager_AjaxRequest(object sender, AjaxRequestEventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
protected void btnSelect_Click(object sender, EventArgs e)
|
||
{
|
||
DataLoad();
|
||
}
|
||
|
||
protected void btnDelete_Click(object sender, EventArgs e)
|
||
{
|
||
if (bll_exam_theory.Delete(IdInput.Value))
|
||
{
|
||
DataLoad();
|
||
}
|
||
}
|
||
|
||
protected void btnCheck_Click(object sender, EventArgs e)
|
||
{
|
||
var list_insert = new List<DataService.Model.pro_exam_theory>();
|
||
var valid = checkInsertItems(out string msg, list_insert);
|
||
if (!valid)
|
||
{
|
||
//RadAjaxManager1.Alert(msg);
|
||
return;
|
||
}
|
||
}
|
||
|
||
protected void btnBatchDel_Click(object sender, EventArgs e)
|
||
{
|
||
var count = dataList.SelectedItems.Count;
|
||
if (count <= 0)
|
||
{
|
||
RadAjaxManager1.Alert("成绩不能为空!");
|
||
return;
|
||
}
|
||
|
||
List<DataService.Model.pro_result> list_result = new List<DataService.Model.pro_result>();
|
||
foreach (var obj in dataList.SelectedItems)
|
||
{
|
||
GridDataItem item = obj as GridDataItem;
|
||
var result_id = item.GetDataKeyValue("result_id").ToString();
|
||
var model = bll.GetModel(result_id);
|
||
if (null != model)
|
||
{
|
||
list_result.Add(model);
|
||
}
|
||
}
|
||
var flag = false;
|
||
//批量删除
|
||
if (list_result.Count > 0)
|
||
{
|
||
for (int i = 0; i < list_result.Count; i++)
|
||
{
|
||
var result = list_result[i];
|
||
if (bll.Delete(result.result_id))
|
||
{
|
||
flag = true;
|
||
bll_result_detail.DeleteByResultId(result.result_id);
|
||
}
|
||
}
|
||
}
|
||
|
||
if (flag)
|
||
{
|
||
DataLoad();
|
||
}
|
||
}
|
||
|
||
|
||
protected void RadListBoxDestination_Reordered(object sender, RadListBoxEventArgs e)
|
||
{
|
||
RadListBoxDestination.DataBind();
|
||
var dsc = Get_RadList_Score();
|
||
Label lb = RadListBoxDestination.Header.FindControl("lb_score_header") as Label;
|
||
lb.Text = dsc;
|
||
span_name.InnerHtml = dsc;
|
||
}
|
||
|
||
protected void RadListBoxDestination_Deleted(object sender, RadListBoxEventArgs e)
|
||
{
|
||
RadListBoxDestination.DataBind();
|
||
var dsc = Get_RadList_Score();
|
||
Label lb = RadListBoxDestination.Header.FindControl("lb_score_header") as Label;
|
||
lb.Text = dsc;
|
||
span_name.InnerHtml = dsc;
|
||
}
|
||
|
||
/// <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)
|
||
{
|
||
var score = txtBox.Text.Trim();
|
||
decimal per_score = -1; //decimal per_score = 0;
|
||
if (decimal.TryParse(score, out per_score))
|
||
{
|
||
//if (per_score > 0) //$$$
|
||
if (per_score >= 0)
|
||
{
|
||
rad_item.Text = txtBox.Text.Trim();
|
||
|
||
var dsc = Get_RadList_Score(false);
|
||
Label lb = RadListBoxDestination.Header.FindControl("lb_score_header") as Label;
|
||
lb.Text = dsc;
|
||
span_name.InnerHtml = dsc;
|
||
}
|
||
else
|
||
{
|
||
txtBox.Text = rad_item.Text;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
txtBox.Text = rad_item.Text;
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除单个题目
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnDeleteOne_Click(object sender, EventArgs e)
|
||
{
|
||
var btn = sender as RadButton;
|
||
var rad_item = btn.Parent as RadListBoxItem;
|
||
if (null != rad_item)
|
||
{
|
||
RadListBoxDestination.Items.Remove(rad_item);
|
||
RadListBoxDestination.DataBind();
|
||
|
||
var dsc = Get_RadList_Score();
|
||
Label lb = RadListBoxDestination.Header.FindControl("lb_score_header") as Label;
|
||
lb.Text = dsc;
|
||
span_name.InnerHtml = dsc;
|
||
|
||
SaveAll();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 批量删除题目
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnBatchDeleteItem_Click(object sender, EventArgs e)
|
||
{
|
||
var remove = false;
|
||
for (int i = RadListBoxDestination.Items.Count - 1; i >= 0; i--)
|
||
{
|
||
var item = RadListBoxDestination.Items[i];
|
||
var chk = item.FindControl("chk_item") as CheckBox;
|
||
if (null!= chk)
|
||
{
|
||
if (chk.Checked)
|
||
{
|
||
RadListBoxDestination.Items.Remove(item);
|
||
remove = true;
|
||
}
|
||
}
|
||
}
|
||
if (remove)
|
||
{
|
||
RadListBoxDestination.DataBind();
|
||
|
||
var dsc = Get_RadList_Score();
|
||
Label lb = RadListBoxDestination.Header.FindControl("lb_score_header") as Label;
|
||
lb.Text = dsc;
|
||
span_name.InnerHtml = dsc;
|
||
|
||
SaveAll();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 批量选择题目
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnBatchSelectAll_Click(object sender, EventArgs e)
|
||
{
|
||
var remove = false;
|
||
for (int i = RadListBoxDestination.Items.Count - 1; i >= 0; i--)
|
||
{
|
||
var item = RadListBoxDestination.Items[i];
|
||
var chk = item.FindControl("chk_item") as CheckBox;
|
||
if (null != chk)
|
||
{
|
||
//if (chk.Checked)
|
||
//{
|
||
// RadListBoxDestination.Items.Remove(item);
|
||
// remove = true;
|
||
//}
|
||
chk.Checked = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
public string Get_RadList_Score(bool updateUI= true)
|
||
{
|
||
List<DataService.Model.pro_exam_theory> list = new List<DataService.Model.pro_exam_theory>();
|
||
for (int i = 0; i < RadListBoxDestination.Items.Count; i++)
|
||
{
|
||
var item = RadListBoxDestination.Items[i];
|
||
|
||
RadTextBox box = item.FindControl("option_name") as RadTextBox;
|
||
var lb_question_kind = item.FindControl("lb_question_kind") as Label;
|
||
|
||
var score = box.Text;
|
||
decimal per_score = decimal.Parse(score);
|
||
|
||
if (updateUI)
|
||
{
|
||
var jd=ConfigurationManager.AppSettings["jd"];
|
||
|
||
if (lb_question_kind.Text == "简答题")
|
||
{
|
||
if (jd != "1")
|
||
{
|
||
box.Enabled = false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
box.Enabled = true;
|
||
}
|
||
}
|
||
|
||
|
||
var model = new DataService.Model.pro_exam_theory();
|
||
model.question_kind = lb_question_kind.Text;
|
||
model.per_score = per_score;
|
||
list.Add(model);
|
||
}
|
||
if (list.Count<=0)
|
||
{
|
||
return "题目列表为空";
|
||
}
|
||
|
||
var list_pand = list.Where(s => s.question_kind == "判断题").ToList();
|
||
var list_danx = list.Where(s => s.question_kind == "单选题").ToList();
|
||
var list_duox = list.Where(s => s.question_kind == "多选题").ToList();
|
||
var list_tiankong = list.Where(s => s.question_kind == "填空题").ToList();
|
||
var list_wenda = list.Where(s => s.question_kind == "简答题").ToList();
|
||
|
||
|
||
var score_pand = list_pand.Select(s => s.per_score).Sum();
|
||
var score_danx = list_danx.Select(s => s.per_score).Sum();
|
||
var score_duox = list_duox.Select(s => s.per_score).Sum();
|
||
var score_tiankong = list_tiankong.Select(s => s.per_score).Sum();
|
||
var score_wenda = list_wenda.Select(s => s.per_score).Sum();
|
||
|
||
var score_total = list.Select(s => s.per_score).Sum();
|
||
|
||
|
||
var sb = new StringBuilder();
|
||
sb.AppendFormat("总题目:{0} 总分值:{1}", list.Count, score_total);
|
||
sb.AppendFormat("(判断题:{0} 分值:{1}", list_pand.Count, score_pand);
|
||
sb.AppendFormat("、单选题:{0} 分值:{1}", list_danx.Count, score_danx);
|
||
sb.AppendFormat("、多选题:{0} 分值:{1}", list_duox.Count, score_duox);
|
||
sb.AppendFormat("、填空题:{0} 分值:{1}", list_tiankong.Count, score_tiankong);
|
||
sb.AppendFormat("、简答题:{0} 分值:{1})", list_wenda.Count, score_wenda);
|
||
var str = sb.ToString();
|
||
return str;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 检查题目选项并提示
|
||
/// </summary>
|
||
/// <param name="msg"></param>
|
||
/// <returns></returns>
|
||
public bool checkInsertItems(out string msg, List<DataService.Model.pro_exam_theory> list_insert)
|
||
{
|
||
var exam_id = hid_examid.Value;
|
||
msg = "";
|
||
|
||
var index = 1;
|
||
var now = DateTime.Now;
|
||
var user = DataService.BLL.admin_user.load_login();
|
||
var user_login = bll_user.GetModel(user.user_id);
|
||
|
||
decimal total_score = 0;
|
||
|
||
for (int i = 0; i < RadListBoxDestination.Items.Count; i++)
|
||
{
|
||
var item = RadListBoxDestination.Items[i];
|
||
//分值
|
||
RadTextBox box = item.FindControl("option_name") as RadTextBox;
|
||
var lb_question_kind = item.FindControl("lb_question_kind") as Label;
|
||
|
||
var score = box.Text;
|
||
decimal per_score = 0;
|
||
string dsc = (i+1).ToString()+"、"+lb_question_kind.Text+ ":" + item.ToolTip;
|
||
|
||
if (!decimal.TryParse(score,out per_score))
|
||
{
|
||
msg = dsc + ", 分值字符不符合要求";
|
||
return false;
|
||
}
|
||
else
|
||
{
|
||
if (lb_question_kind.Text != "简答题")
|
||
{
|
||
if (per_score < 0)
|
||
{
|
||
msg = dsc + ", 分值应不小于0";
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
|
||
total_score += per_score;
|
||
|
||
var hid_content = item.FindControl("hid_content") as HiddenField;
|
||
|
||
var model = new DataService.Model.pro_exam_theory();
|
||
model.id = BasePage.GetNextId(exam_id, index++);
|
||
model.exam_id = exam_id;
|
||
model.content = hid_content.Value;
|
||
model.question_kind = lb_question_kind.Text;
|
||
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 = per_score;
|
||
list_insert.Add(model);
|
||
}
|
||
|
||
var exam = bll_examination.GetModel(exam_id);
|
||
var exam_total = decimal.Parse( exam.total_score);
|
||
|
||
if (total_score!= exam_total)
|
||
{
|
||
msg = string.Format("当前分值:{0},不等于试卷分值:{1}", total_score, exam_total);
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public void SaveAll( bool tip = false)
|
||
{
|
||
#region 校验分值
|
||
|
||
var list_insert = new List<DataService.Model.pro_exam_theory>();
|
||
var valid = checkInsertItems(out string msg, list_insert);
|
||
|
||
#region 100分值提示 $$$$
|
||
//if (!valid)
|
||
//{
|
||
// RadAjaxManager1.Alert(msg);
|
||
// return;
|
||
//}
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
//设置no
|
||
var list1 = list_insert.Where(s => s.question_difficult == "0").ToList();
|
||
var list2 = list_insert.Where(s => s.question_difficult == "1").ToList();
|
||
var list3 = list_insert.Where(s => s.question_difficult == "2").ToList();
|
||
|
||
var list4 = list_insert.Where(s => s.question_difficult == "3").ToList();
|
||
var list5 = list_insert.Where(s => s.question_difficult == "4").ToList();
|
||
for (int i = 0; i < list1.Count; i++)
|
||
{
|
||
list1[i].no = (i + 1);
|
||
}
|
||
for (int i = 0; i < list2.Count; i++)
|
||
{
|
||
list2[i].no = (i + 1);
|
||
}
|
||
|
||
for (int i = 0; i < list3.Count; i++)
|
||
{
|
||
list3[i].no = (i + 1);
|
||
}
|
||
|
||
for (int i = 0; i < list4.Count; i++)
|
||
{
|
||
list4[i].no = (i + 1);
|
||
}
|
||
|
||
for (int i = 0; i < list5.Count; i++)
|
||
{
|
||
list5[i].no = (i + 1);
|
||
}
|
||
|
||
var exam_id = hid_examid.Value;
|
||
int success_count = bll_exam_theory.BatchAdd_Update(list_insert, exam_id);
|
||
if (success_count > 0)
|
||
{
|
||
//RadAjaxManager1.ResponseScripts.Add("alert('保存成功!');CloseAndRebind();");
|
||
if (tip)
|
||
{
|
||
RadAjaxManager1.ResponseScripts.Add("alert('保存成功!');");
|
||
}
|
||
DataLoad();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 批量保存题目---保存所有
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnBatchSaveItem_Click(object sender, EventArgs e)
|
||
{
|
||
SaveAll(true);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 计算分值
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnBatchComputeItem_Click(object sender, EventArgs e)
|
||
{
|
||
var list_insert = new List<DataService.Model.pro_exam_theory>();
|
||
var valid = checkInsertItems(out string msg, list_insert);
|
||
//if (!valid)
|
||
//{
|
||
// RadAjaxManager1.Alert(msg);
|
||
// return;
|
||
//}
|
||
}
|
||
|
||
protected void RadListBoxDestination_ItemDataBound(object sender, RadListBoxItemEventArgs e)
|
||
{
|
||
var DataItem = e.Item.DataItem;
|
||
var DataKey = e.Item.DataKey;
|
||
}
|
||
}
|
||
} |