using System; using System.Linq; using BLL; namespace FineUIPro.Web.HSSE.EduTrain { public partial class StudyZoneSave : PageBase { #region 定义变量 /// /// 主键 /// public string StudyZoneId { get { return (string)ViewState["StudyZoneId"]; } set { ViewState["StudyZoneId"] = value; } } /// /// 上级ID /// public string SupStudyZoneId { get { return (string)ViewState["SupStudyZoneId"]; } set { ViewState["SupStudyZoneId"] = value; } } #endregion #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.GetButtonPower(); btnClose.OnClientClick = ActiveWindow.GetHideReference(); this.drpIsEndLever.DataTextField = "TypeName"; drpIsEndLever.DataValueField = "TypeId"; drpIsEndLever.DataSource = BLL.TrainingService.GetIsEndLeverList(); drpIsEndLever.DataBind(); this.StudyZoneId = Request.QueryString["StudyZoneId"]; this.SupStudyZoneId = Request.QueryString["SupStudyZoneId"]; if (!string.IsNullOrEmpty(StudyZoneId)) { var q = BLL.StudyZoneService.GetStudyZoneById(StudyZoneId); if (q != null) { txtStudyZoneCode.Text = q.StudyZoneCode; txtStudyZoneName.Text = q.StudyZoneName; if (q.IsEndLever == true) { this.drpIsEndLever.SelectedValue = "true"; } else { this.drpIsEndLever.SelectedValue = "false"; } } } } } #endregion #region 保存 /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { Model.Training_StudyZone model = new Model.Training_StudyZone(); model.StudyZoneCode = this.txtStudyZoneCode.Text.Trim(); model.StudyZoneName = this.txtStudyZoneName.Text.Trim(); model.IsEndLever = Convert.ToBoolean(drpIsEndLever.SelectedValue); if (!string.IsNullOrEmpty(this.StudyZoneId)) { Model.Training_StudyZone t = BLL.StudyZoneService.GetStudyZoneById(this.StudyZoneId); if (t != null) { model.SupStudyZoneId = t.SupStudyZoneId; } model.StudyZoneId = this.StudyZoneId; BLL.StudyZoneService.UpdateStudyZone(model); } else { model.SupStudyZoneId = this.SupStudyZoneId; this.StudyZoneId = SQLHelper.GetNewID(typeof(Model.Training_StudyZone)); model.StudyZoneId = this.StudyZoneId; BLL.StudyZoneService.AddStudyZone(model); } // 2. 关闭本窗体,然后刷新父窗体 // PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); // 2. 关闭本窗体,然后回发父窗体 PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); //PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(trainingId) + ActiveWindow.GetHideReference()); } #endregion #region 验证学习园地资料名称是否存在 /// /// 验证学习园地资料名称是否存在 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { var model = Funs.DB.Training_StudyZone.FirstOrDefault(x => x.SupStudyZoneId == this.SupStudyZoneId && x.StudyZoneName == this.txtStudyZoneName.Text.Trim() && (x.StudyZoneId != this.StudyZoneId || (this.StudyZoneId == null && x.StudyZoneId != null))); if (model != null) { ShowNotify("输入的名称已存在!", MessageBoxIcon.Warning); } } #endregion #region 按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.StudyZoneMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnSave)) { this.btnSave.Hidden = false; } } } #endregion } }