📄 a_terms.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_Terms : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Admin aAdmin = (Admin)this.Master;
aAdmin.ManageTitle = "学期管理";
aAdmin.MenuSelectedValue = "TermManage";
this.fsItem.Visible = false;
Initialize();
this.btnDel.Attributes.Add("onclick", "return confirm('您真的要删除吗?');");
this.lbMsg.Text = "";
}
}
#region 属性
static int m_ColID = 1;
#endregion
#region 操作函数
/// <summary>
/// 返回所有的实验项目批次
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="sortExpression">要排序的字段</param>
private void BindDisplayList(int pageIndex, string sortExpression)
{
lbMsg.Text = "";
TermsList.SelectedIndex = -1;
DataTable dt = SingleInitials.DbAccess.GetTermList().Tables[0];//返回所有列表
if (sortExpression == null || sortExpression == string.Empty)
{
JKLib.Web.GridViewOperation.BindPagingGridView(TermsList, dt.DefaultView, pageIndex);
}
else
{
JKLib.Web.GridViewOperation.BindPagingGridView(TermsList, dt.DefaultView, pageIndex, sortExpression, true, JKLib.Web.GridViewOperation.BindPagingGridViewType.Sorting);
}
}
private void Initialize()
{
this.BindDisplayList(0,"");
}
private void DisplayItem(string mID)
{
fsItem.Visible = true;
if (mID == "-1")
{
btnDel.Visible = false;
legendItem.InnerText = "新增";
NewItem();
}
else
{
btnDel.Visible = true;
legendItem.InnerText = "修改";
LoadItem(mID);
}
}
private bool CheckInput(ref string strError)
{
strError = "";
bool retValue = true;
if (tbxTermName.Text == "")
{
strError += "请输入学期名;";
retValue = false;
}
if (this.tbxKeyID.Text == "-1" && SingleInitials.DbAccess.GetIsTermExists(tbxTermName.Text))//添加时候才确认
{
strError += "学期名已存在;";
retValue = false;
}
if (dpBeginTime.Value == "")
{
strError += "请输入开始日期;";
retValue = false;
}
if (dpEndTime.Value == "")
{
strError += "请输入结束日期;";
retValue = false;
}
if (this.tbxKeyID.Text == "-1")//添加
{
if (cbIsActive.Checked)//如果设置为活动学期
{
if ("" != SingleInitials.DbAccess.GetActiveTerm())//已经有活动学期
{
strError += "只能有一个学期为活动学期;";
retValue = false;
}
}
}
else//修改
{
if (cbIsActive.Checked)//如果设置为活动学期
{
if ("" != SingleInitials.DbAccess.GetActiveTerm())//已经有活动学期
{
if (!SingleInitials.DbAccess.GetATermIsActive(tbxKeyID.Text))//活动学期不是正在修改的学期
{
strError += "只能有一个学期为活动学期;";
retValue = false;
}
}
}
}
return retValue;
}
private bool Save()
{
string errStr = "";
if (!CheckInput(ref errStr))
{
lbMsg.Text = errStr;
return false;
}
try
{
if (this.tbxKeyID.Text == "-1")
{
//添加
Term aTerm = new Term();
aTerm.TermName = this.tbxTermName.Text;
aTerm.BeginTime = dpBeginTime.DateValue;
aTerm.EndTime = dpEndTime.DateValue;
aTerm.IsActive = cbIsActive.Checked.ToString();
return SingleInitials.DbAccess.AddATerm(aTerm);
}
else
{
//修改
Term aTerm = new Term();
aTerm.TermName = this.tbxKeyID.Text;//不能修改学期名
aTerm.BeginTime = dpBeginTime.DateValue;
aTerm.EndTime = dpEndTime.DateValue;
aTerm.IsActive = cbIsActive.Checked.ToString();
return SingleInitials.DbAccess.EditATerm(aTerm);
}
}
catch (Exception ex)
{
lbMsg.Text = ex.Message;
return false;
}
}
private void NewItem()
{
// 清空编辑界面
tbxTermName.Text = "";
dpBeginTime.Value = "";
dpEndTime.Value = "";
cbIsActive.Checked = false;
}
private void LoadItem(string aTermName)
{
Term aTerm = SingleInitials.DbAccess.GetATerm(aTermName);
tbxKeyID.Text = aTerm.TermName;
tbxTermName.Text = aTerm.TermName;
dpBeginTime.DateValue = aTerm.BeginTime;
dpEndTime.DateValue = aTerm.EndTime;
cbIsActive.Checked = bool.Parse(aTerm.IsActive);
}
#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 == "TermEdit")
{
TermsList.SelectedIndex = int.Parse(e.CommandArgument.ToString());
string theID = TermsList.Rows[int.Parse(e.CommandArgument.ToString())].Cells[m_ColID].Text;
tbxKeyID.Text = theID;
DisplayItem(theID);
}
}
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)
{
}
protected void BatchList_Sorting(object sender, GridViewSortEventArgs e)
{
BindDisplayList(TermsList.PageIndex, e.SortExpression);
}
#endregion
#region 列表事件处理
#endregion
#region 按钮事件
protected void btnNewBatch_Click(object sender, EventArgs e)
{
this.tbxKeyID.Text = "-1";
DisplayItem(tbxKeyID.Text);
}
protected void btnDel_Click(object sender, EventArgs e)
{
if (SingleInitials.DbAccess.GetATermIsActive(this.tbxKeyID.Text))
{
lbMsg.Text = "不能删除活动学期";
return;
}
try
{
//if
int lastPageIndex = this.TermsList.PageIndex;
SingleInitials.DbAccess.DeleteATerm(tbxKeyID.Text);
BindDisplayList(0, "");//更新列表
if (lastPageIndex < this.TermsList.PageCount)
{
BindDisplayList(lastPageIndex, "");//更新列表
}
fsItem.Visible = false;
}
catch (Exception ex)
{
lbMsg.Text = ex.Message;
}
}
protected void btn_Save_Click(object sender, EventArgs e)
{
if (Save())
{
int lastPageIndex = this.TermsList.PageIndex;
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 + -