📄 a_expbooking.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ExpReserve;
public partial class A_ExpBooking : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Admin aAdmin = (Admin)this.Master;
aAdmin.ManageTitle = "实验项目批次管理";
aAdmin.MenuSelectedValue = "ExpBatch";
this.fsItem.Visible = false;
Initialize();
ExpReserve.Batch aBatch = SingleInitials.DbAccess.GetABatch(CurrentBatchID);
//legendList.InnerText = string.Format("实验项目\"{0}\"的预约学生名单", aBatch.CourseDetailName);
lblDetailName.Text = aBatch.CourseDetailName;
lblExpTime.Text = aBatch.Date.ToString("yyyy-MM-dd") + " " + UIControls.CaculateWeekDay(aBatch.Date) + " " + aBatch.ClassNo;
lblExpAddress.Text = aBatch.Address;
lblTeacher.Text = aBatch.TeacherName;
BindDisplayList(0,"");
this.lbMsg.Text = "";
}
}
#region 属性
static int m_ColID = 0;
static int m_ColClass = 4;
public long CurrentBatchID
{
get
{
try
{
return JKLib.Utility.MyConvert.ToInt32IgnErr(Request.QueryString["BatchID"].ToString());
}
catch
{
return 0;
}
}
}
#endregion
#region 操作函数
/// <summary>
/// 返回所有的实验项目批次
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="sortExpression">要排序的字段</param>
private void BindDisplayList(int pageIndex, string sortExpression)
{
lbMsg.Text = "";
StudentList.Columns[m_ColID].Visible = true;
StudentList.SelectedIndex = -1;
DataTable dt = SingleInitials.DbAccess.GetBookingList(this.CurrentBatchID).Tables[0];//返回所有列表
if (sortExpression == null || sortExpression == string.Empty)
{
JKLib.Web.GridViewOperation.BindPagingGridView(StudentList, dt.DefaultView, pageIndex);
}
else
{
JKLib.Web.GridViewOperation.BindPagingGridView(StudentList, dt.DefaultView, pageIndex, sortExpression, true, JKLib.Web.GridViewOperation.BindPagingGridViewType.Sorting);
}
StudentList.Columns[m_ColID].Visible = false;
}
private void Initialize()
{
UIControls.BindClassesDDL(ddlClasses);
}
private bool CheckInput(ref string strError)
{
strError = "";
bool result = true;
if (0 == ddlStudents.SelectedIndex)
{
strError += "请选择一个学生";
result = false;
}
if (SingleInitials.DbAccess.GetABatchIsFull(CurrentBatchID))
{
strError += "该实验批次预约人数已经达到上限";
result = false;
}
if (SingleInitials.DbAccess.getStudentIsBooking(CurrentBatchID, long.Parse(ddlStudents.SelectedValue)))
{
strError += "一个学生只能预定一个实验批次";
result = false;
}
if (SingleInitials.DbAccess.GetStudentHasABookingInATime(long.Parse(ddlStudents.SelectedValue), CurrentBatchID))
{
lbMsg.Text += "一个学生在相同的时间点(相同日期,相同批次)只能预约一个实验批次";
result = false;
}
if (SingleInitials.DbAccess.GetStudentHasBookACourse(long.Parse(ddlStudents.SelectedValue), CurrentBatchID))
{
lbMsg.Text += "一个学生只能预约对同一个实验项目只能预约一次";
result = false;
}
if (0 == CurrentBatchID)
{
strError += "非法的批次ID";
result = false;
}
if (this.tbxMark.Text == "")
{
strError += "分数不能为空";
result = false;
}
if (!JKLib.Utility.MyJudge.IsNumber(this.tbxMark.Text))
{
strError += "分数中含有非法字符";
result = false;
}
return result;
}
private bool EditInputCheck(ref string strError)
{
strError = "";
bool result = true;
if (0 == CurrentBatchID)
{
strError += "非法的批次ID";
result = false;
}
if (this.tbxMark.Text == "")
{
strError += "分数不能为空";
result = false;
}
if (!JKLib.Utility.MyJudge.IsNumber(this.tbxMark.Text))
{
strError += "分数中含有非法字符";
result = false;
}
return result;
}
private bool Save()
{
if (this.tbxKeyID.Text == "-1")//添加
{
string errStr = "";
if (!CheckInput(ref errStr))
{
lbMsg.Text = errStr;
return false;
}
try
{
Booking aBooking = new Booking();
aBooking.BatchID = this.CurrentBatchID;
aBooking.StudentID = long.Parse(ddlStudents.SelectedValue);
aBooking.Time = DateTime.Now;
aBooking.Grade = this.ddlGrade.SelectedValue;
aBooking.Mark = float.Parse(this.tbxMark.Text);
return SingleInitials.DbAccess.AddABooking(aBooking);
}
catch (Exception ex)
{
return false;
}
}
else//评分
{
string errStr = "";
if (!EditInputCheck(ref errStr))
{
lbMsg.Text = errStr;
return false;
}
try
{
long aStudentID = long.Parse(this.tbxKeyID.Text);
Booking aBooking = SingleInitials.DbAccess.GetABooking(aStudentID,this.CurrentBatchID);
aBooking.Grade = this.ddlGrade.SelectedValue;
aBooking.Mark = float.Parse(this.tbxMark.Text);
return SingleInitials.DbAccess.EditABooking(aBooking);
}
catch (Exception ex)
{
return false;
}
}
}
private void NewItem()
{
//// 清空编辑界面
ddlClasses.SelectedIndex = 0;
ddlStudents.Items.Clear();
this.ddlClasses.Enabled = true;
this.ddlStudents.Enabled = true;
this.ddlGrade.SelectedIndex = 0;
this.tbxMark.Text = "0";
}
#endregion
#region 表格处理
protected void BatchList_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
BindDisplayList(e.NewPageIndex, null);
}
protected void BatchList_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "BookingDel")
{
//删除操作
StudentList.SelectedIndex = int.Parse(e.CommandArgument.ToString());
string theID = StudentList.Rows[int.Parse(e.CommandArgument.ToString())].Cells[m_ColID].Text;
long aStudentID = long.Parse(theID);
try
{
int lastPageIndex = this.StudentList.PageIndex;
SingleInitials.DbAccess.DelABooking(aStudentID,this.CurrentBatchID);
//更新列表
BindDisplayList(0, "");
if (lastPageIndex < this.StudentList.PageCount)
{
BindDisplayList(lastPageIndex, "");
}
}
catch(Exception ex)
{
this.lbMsg.Text = ex.Message;
}
}
if (e.CommandName == "GiveMark")
{
StudentList.SelectedIndex = int.Parse(e.CommandArgument.ToString());
string theID = StudentList.Rows[int.Parse(e.CommandArgument.ToString())].Cells[m_ColID].Text;
string theClass = StudentList.Rows[int.Parse(e.CommandArgument.ToString())].Cells[m_ColClass].Text.Trim();
long aStudentID = long.Parse(theID);
this.tbxKeyID.Text = aStudentID.ToString();
Booking aBooking = SingleInitials.DbAccess.GetABooking(aStudentID, this.CurrentBatchID);
Student aStudent = SingleInitials.DbAccess.GetAStudent(aStudentID);
this.ddlStudents.Items.Clear();
this.ddlStudents.Items.Add(aStudent.Name);
this.ddlStudents.SelectedValue = aStudent.Name;
this.ddlClasses.SelectedValue = theClass;
this.ddlClasses.Enabled = false;
this.ddlStudents.Enabled = false;
this.ddlGrade.SelectedValue = aBooking.Grade;
this.tbxMark.Text = aBooking.Mark.ToString("###0.#");
this.legendItem.InnerText = "评分";
this.fsItem.Visible = true;
}
}
protected void BatchList_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Pager)
JKLib.Web.GridViewOperation.GridRowCreated(sender, e);
}
protected void BatchList_RowDataBound(object sender, GridViewRowEventArgs e)
{
////Button btn = (Button)e.Row.Cells[2].Controls[0];
////btn.Attributes.Add("onclick","return confirm('您真的要删除吗?');");
//LinkButton btn = (LinkButton)e.Row.Cells[2].Controls[0];
//btn.Attributes.Add("onclick", "return confirm('您真的要删除吗?');");
//在服务器端添加删除确认
//if (e.Row.RowType == DataControlRowType.DataRow)
//{
// Button btnDelete = (Button)e.Row.FindControl("Button1");
// btnDelete.Attributes.Add("onclick", "return confirm('确实要删除吗?')");
//}
}
protected void BatchList_Sorting(object sender, GridViewSortEventArgs e)
{
BindDisplayList(StudentList.PageIndex, e.SortExpression);
}
#endregion
#region 列表事件处理
protected void ddlClasses_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlClasses.SelectedIndex != 0)
{
UIControls.BindStudentsDDL(ddlStudents, ddlClasses.SelectedValue);
}
else
{
this.ddlStudents.Items.Clear();
}
}
#endregion
#region 按钮事件
protected void btnNewBatch_Click(object sender, EventArgs e)
{
this.tbxKeyID.Text = "-1";
legendItem.InnerText = "新增";
NewItem();
this.fsItem.Visible = true;
}
protected void btn_Save_Click(object sender, EventArgs e)
{
int lastPageIndex = this.StudentList.PageIndex;
if (Save())
{
if ("-1" == this.tbxKeyID.Text)//添加
{
this.BindDisplayList(0, "");//更新列表
}
else//修改
{
this.BindDisplayList(lastPageIndex, "");//更新列表
}
this.fsItem.Visible = false;//隐藏添加列表
}
}
#endregion
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -