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 ExamTheory_BatchAdd : 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_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) { BindDeviceType("TheoryBaseKnow", dp_know, ""); DataLoad(); } } protected override void DataLoad() { StringBuilder query = new StringBuilder(" 1 = 1 "); var exam_id = Request.Params["Id"]; var list2 = bll_exam_theory.GetModelList("exam_id='" + exam_id + "'"); if (list2.Count > 0) { var array = list2.Select(s => s.content).ToArray(); List dest = new List(); 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 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"); } */ if (!string.IsNullOrWhiteSpace(txt_question.Text.Trim())) { query.AppendFormat(" AND question LIKE '%{0}%' ", txt_question.Text.Trim()); } if (!string.IsNullOrEmpty(dp_kind.SelectedValue)) { query.AppendFormat(" AND kind = '{0}' ", dp_kind.SelectedValue); } if (!string.IsNullOrEmpty(dp_know.SelectedValue)) { query.AppendFormat(" AND target = '{0}' ", dp_know.SelectedValue); } var qry = query.ToString(); var list = bll_theory_base.GetModelList(qry); dataList.DataSource = list; dataList.Rebind(); } 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) { bll.Delete(IdInput.Value); DataLoad(); } protected void btnBatchDel_Click(object sender, EventArgs e) { var count = dataList.SelectedItems.Count; if (count <= 0) { RadAjaxManager1.Alert("成绩不能为空!"); return; } List list_result = new List(); 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 btnBatchAdd_Click(object sender, EventArgs e) { var count = dataList.SelectedItems.Count; if (count <= 0) { RadAjaxManager1.Alert("请选择需要添加的记录!"); return; } /* if (!per_score.Value.HasValue) { RadAjaxManager1.Alert("请配置分数!"); return; } */ List list_result = new List(); foreach (var obj in dataList.SelectedItems) { GridDataItem item = obj as GridDataItem; var result_id = item.GetDataKeyValue("id").ToString(); var model = bll_theory_base.GetModel(result_id); if (null != model) { list_result.Add(model); } } var exam_id = Request.Params["Id"]; var id = BasePage.GetId(); int index = 1; var now = DateTime.Now; var user = DataService.BLL.admin_user.load_login(); var user_login = bll_user.GetModel(user.user_id); int success_count = 0; var kind = dp_kind.SelectedValue; int max_no = 1; 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; } foreach (var item in list_result) { 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 = (decimal)per_score.Value; model.per_score = 0; model.no = max_no++; if (bll_exam_theory.Add(model)) { success_count++; } } if (success_count>0) { RadAjaxManager1.ResponseScripts.Add("alert('添加成功"+ success_count + "道题目!');CloseAndRebind();"); } } } }