gyhlw_dotnet/网站项目/VRS/Management/Exam/MatchScene_Add.aspx.cs

242 lines
8.0 KiB
C#
Raw Permalink 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.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace VRS.Management.Exam
{
public partial class MatchScene_Add : 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_scene_open bll_open = new DataService.BLL.pro_scene_open();
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);
if (bll_user.IsAdministrator(user_login))
{
tr_school.Visible = true;
BindSchool(dp_school, "");
}
else //老师或学校管理员
{
#region
//tr_school.Visible = false;
//BindSchoolGrade(user_login.school_id, dp_schoolgrade, "");
BindSchool(dp_school, "");
dp_school.SelectedValue = user_login.school_id;
dp_school.Enabled = false;
#endregion
}
BindSceneBase(dp_scene, "");
//BindExam(dp_exam, "");
}
}
protected void dp_school_SelectedIndexChanged(object sender, Telerik.Web.UI.DropDownListEventArgs e)
{
//var value = dp_school.SelectedValue;
//BindSchoolGrade(value, dp_schoolgrade, "");
var value = dp_school.SelectedValue;
BindSchoolGrade(value, cbx_schoolgrade);
}
protected void btnSure_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(dp_scene.SelectedValue))
{
RadAjaxManager1.Alert("场景不能为空!");
return;
}
var model = new DataService.Model.pro_scene_open();
var user = DataService.BLL.admin_user.load_login();
var user_login = bll_user.GetModel(user.user_id);
if (bll_user.IsAdministrator(user_login))
{
if (!string.IsNullOrEmpty(dp_school.SelectedValue))
{
model.school_id = dp_school.SelectedValue;
}
else
{
RadAjaxManager1.Alert("学校不能为空!");
return;
}
}
else //老师或学校管理员
{
model.school_id = user_login.school_id;
}
var list = cbx_schoolgrade.CheckedItems.ToList();
string grade = string.Join(",", list.Select(s => s.Text).ToArray());
model.grade = grade;
if (!string.IsNullOrWhiteSpace(start_time.Value))
{
model.start_time = DateTime.Parse(start_time.Value);
}
if (!string.IsNullOrWhiteSpace(end_time.Value))
{
model.end_time = DateTime.Parse(end_time.Value);
}
var ts = model.end_time.Value.Subtract(model.start_time.Value).TotalSeconds;
int minute = (int)ts / 60;
/*
if (minute <= 0 || minute > 600)
{
RadAjaxManager1.Alert("考试时长应该在10小时之内");
return;
}
*/
model.span = minute;
model.open_name = batch_name.Text.Trim();
model.scene_name = dp_scene.SelectedText;
model.scene_id = dp_scene.SelectedValue;
model.open_id = BasePage.GetId();
model.create_time = DateTime.Now;
if (bll_open.Add(model))
{
log.write_log("添加开放场景成功。" + "名称:" + batch_name.Text.Trim() + "id" + model.open_id);
RadAjaxManager1.ResponseScripts.Add("alert('添加成功!');CloseAndRebind();");
}
else
{
RadAjaxManager1.Alert("添加失败!");
}
}
protected void btnSure_Click_old(object sender, EventArgs e)
{
DataService.Model.pro_exam_batch model = new DataService.Model.pro_exam_batch();
var user = DataService.BLL.admin_user.load_login();
var user_login = bll_user.GetModel(user.user_id);
if (bll_user.IsAdministrator(user_login))
{
if (!string.IsNullOrEmpty(dp_school.SelectedValue))
{
model.school_id = dp_school.SelectedValue;
}
else
{
RadAjaxManager1.Alert("学校不能为空!");
return;
}
}
else //老师只能看到自己学校的(学生和老师)
{
model.school_id = user_login.school_id;
}
/*
if (string.IsNullOrWhiteSpace(dp_schoolgrade.SelectedValue))
{
RadAjaxManager1.Alert("请选择班级!");
return;
}
model.grade = dp_schoolgrade.SelectedValue;
*/
if (string.IsNullOrEmpty(batch_name.Text.Trim()))
{
RadAjaxManager1.Alert("考场名称不能为空!");
return;
}
if (bll.GetRecordCount(string.Format(" batch_name = '{0}' and school_id='{1}' ", batch_name.Text.Trim(), model.school_id)) > 0)
{
RadAjaxManager1.Alert("考场名称禁止重复!");
return;
}
if (string.IsNullOrEmpty(ks_minute.Text.Trim()))
{
RadAjaxManager1.Alert("考试时长不能为空!");
return;
}
/*
if (string.IsNullOrEmpty(dp_exam.SelectedValue))
{
RadAjaxManager1.Alert("试卷不能为空!");
return;
}
*/
if (!string.IsNullOrWhiteSpace(start_time.Value))
{
model.start_time = DateTime.Parse(start_time.Value);
}
if (!string.IsNullOrWhiteSpace(end_time.Value))
{
model.end_time = DateTime.Parse(end_time.Value);
}
/*
int minute = -1;
int.TryParse(ks_minute.Text, out minute);
if (minute <= 0 || minute > 600)
{
RadAjaxManager1.Alert("考试时长应该在10小时之内");
return;
}
*/
var ts = model.end_time.Value.Subtract(model.start_time.Value).TotalSeconds;
int minute = (int)ts / 60;
if (minute <= 0 || minute > 600)
{
RadAjaxManager1.Alert("考试时长应该在10小时之内");
return;
}
//span
model.ks_minute = minute;
model.batch_id = BasePage.GetId();
model.batch_name = batch_name.Text.Trim();
model.sjms = "";
model.create_time = DateTime.Now;
//model.exam_id = dp_exam.SelectedValue;
model.state = int.Parse(ddp_state.SelectedValue);
//model.state = 0; //状态 0停用1启用
if (bll.Add(model))
{
log.write_log("添加考场成功。" + "名称:" + batch_name.Text.Trim() + "id" + model.batch_id);
RadAjaxManager1.ResponseScripts.Add("alert('添加成功!');CloseAndRebind();");
}
else
{
RadAjaxManager1.Alert("添加失败!");
}
}
}
}