gyhlw_dotnet/网站项目/VRS/Management/VSAT/ExamTheoryOrder.aspx.cs

530 lines
19 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
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 ExamTheoryOrder : 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);
var kind = dp_kind.SelectedValue;
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;
}
span_kind.InnerHtml = "当前题型:"+ kind;
var table = bll_exam_theory.QueryResultByExamIdAndKind(id, kind).Tables[0];
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 = 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;
}
var hid_id = list_item.FindControl("hid_id") as HiddenField;
if (null != hid_id)
{
var content = row["id"].ToString();
hid_id.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 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 = 0;
if (decimal.TryParse(score, out per_score))
{
if (per_score > 0)
{
rad_item.Text = txtBox.Text.Trim();
var dsc = Get_RadList_Score();
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 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;
}
}
public string Get_RadList_Score()
{
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);
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 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_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);
var str = sb.ToString();
return str;
}
public void getOrderItems( List<DataService.Model.pro_exam_theory> list_order)
{
for (int i = 0; i < RadListBoxDestination.Items.Count; i++)
{
var item = RadListBoxDestination.Items[i];
var lb_question_kind = item.FindControl("lb_question_kind") as Label;
var hid_content = item.FindControl("hid_content") as HiddenField;
var model = new DataService.Model.pro_exam_theory();
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";
}
var hid_id = item.FindControl("hid_id") as HiddenField;
model.id = hid_id.Value;
model.no = (i + 1);
list_order.Add(model);
}
}
/// <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 (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;
}
/// <summary>
/// 批量保存题目---保存所有
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnBatchSaveItem_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;
}
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('保存成功!');");
DataLoad();
}
*/
var list_order = new List<DataService.Model.pro_exam_theory>();
getOrderItems(list_order);
var success_count = bll_exam_theory.BatchOrder_Update(list_order);
if (success_count > 0)
{
RadAjaxManager1.ResponseScripts.Add("alert('保存成功!');");
DataLoad();
}
}
protected void dp_kind_SelectedIndexChanged(object sender, DropDownListEventArgs e)
{
DataLoad();
}
}
}