//Grid绑定数据源 private void BindGrid() { BLL.tb_SYS_Menu bllMenu = new BLL.tb_SYS_Menu(); DataSet dsMenu = bllMenu.GetList("1=1 order by MenuNO"); DataTable dtSource = PublicMethod.sortToTree(dsMenu.Tables[0], "MenuNO", "ID", "ParentID"); gridMenu.DataSource = dtSource; gridMenu.DataBind(); }
//加载数据 private void LoadData() { //btnClose.OnClientClick = ActiveWindow.GetHidePostBackReference(); //绑定修改前数据 BLL.tb_SYS_Menu bllMenu = new BLL.tb_SYS_Menu(); DataSet dsMenu = bllMenu.GetList("ID='" + Request.QueryString["ID"] + "'"); nbbMenuNO.Text = dsMenu.Tables[0].Rows[0]["MenuNO"].ToString(); txbMenuName.Text = dsMenu.Tables[0].Rows[0]["MenuName"].ToString(); txbMenuUrl.Text = dsMenu.Tables[0].Rows[0]["MenuUrl"].ToString(); tgbParentName.Text = Request.QueryString["ParentName"].ToString(); //txbImageUrl.Text = dsMenu.Tables[0].Rows[0]["ImageUrl"].ToString(); ddlState.SelectedValue = dsMenu.Tables[0].Rows[0]["State"].ToString(); hdfParentID.Text = dsMenu.Tables[0].Rows[0]["ParentID"].ToString(); hdfParentNO.Text = (int.Parse(nbbMenuNO.Text) - 1).ToString(); }
//保存修改 protected void btnSave_Click(object sender, EventArgs e) { #region 逻辑检查 StringBuilder strWhere = new StringBuilder("MenuName='"); strWhere.Append(txbMenuName.Text.ToString()); strWhere.Append("' and ID!='"); strWhere.Append(Request.QueryString["ID"]); strWhere.Append("'"); BLL.tb_SYS_Menu bllMenu = new BLL.tb_SYS_Menu(); DataSet dsMenu = bllMenu.GetList(strWhere.ToString()); if (dsMenu.Tables[0].Rows.Count > 0) { Alert.ShowInTop("该菜单名称已存在", "提示信息", MessageBoxIcon.Error); return; } #endregion #region 保存数据 Model.tb_SYS_Menu modelMenu = new Model.tb_SYS_Menu(); modelMenu.ID = Request.QueryString["ID"]; modelMenu.MenuNO = nbbMenuNO.Text.ToString(); modelMenu.MenuName = txbMenuName.Text.ToString(); modelMenu.MenuUrl = txbMenuUrl.Text.ToString(); //modelMenu.ImageUrl = txbImageUrl.Text.ToString(); modelMenu.ParentID = hdfParentID.Text.ToString(); modelMenu.State = ddlState.SelectedValue.ToString(); modelMenu.UpdateID = Session["AccountID"].ToString(); modelMenu.UpdateTime = DateTime.Now; bool result = bllMenu.Update(modelMenu); if (!result) { Alert.ShowInTop("更新失败", "提示信息", MessageBoxIcon.Error, ActiveWindow.GetHideRefreshReference()); } else { Alert.ShowInTop("更新成功", "提示信息", MessageBoxIcon.Information, ActiveWindow.GetHideRefreshReference()); } #endregion //关闭本窗体,然后刷新父窗体 //PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); }
//删除选中记录集 protected void btnDelete_Click(object sender, EventArgs e) { #region 可用 //int selectedCount = gridMenu.SelectedRowIndexArray.Length; //int deletedCount = 0; //StringBuilder sb = new StringBuilder(); //foreach (int row in gridMenu.SelectedRowIndexArray) //{ // sb.Append("'"); // sb.Append(gridMenu.DataKeys[row][0].ToString()); // sb.Append("',"); //} //sb.Append("''"); //BLL.tb_SYS_Menu bllMenu = new BLL.tb_SYS_Menu(); //bool result = bllMenu.DeleteList(sb.ToString()); //if(result) //{ // deletedCount = selectedCount; //} //Alert.ShowInTop("你选择了" + selectedCount.ToString() + "行\n成功删除" + deletedCount.ToString() + "行"); //BindGrid(); #endregion #region 2016/01/30修正 string id = gridMenu.DataKeys[gridMenu.SelectedRowIndex][0].ToString(); BLL.tb_SYS_Menu bllMenu = new BLL.tb_SYS_Menu(); string result = bllMenu.Delete(id); if (result == "0") { Alert.ShowInTop("删除成功", "提示信息", MessageBoxIcon.Information); BindGrid(); } else { hdfMarkRawNO.Text = gridMenu.SelectedRowIndex.ToString(); Alert.ShowInTop("该项被其他项引用,不能删除!", "提示信息", MessageBoxIcon.Error, "highlightRows();"); } #endregion }
//保存修改 protected void btnSave_Click(object sender, EventArgs e) { #region 逻辑检查 BLL.tb_SYS_Menu bllMenu = new BLL.tb_SYS_Menu(); DataSet dsMenu = bllMenu.GetList("MenuName='" + txbMenuName.Text.ToString() + "'"); if (dsMenu.Tables[0].Rows.Count > 0) { Alert.ShowInTop("该菜单名称已存在", "提示信息", MessageBoxIcon.Error); return; } #endregion #region 保存数据 Model.tb_SYS_Menu modelMenu = new Model.tb_SYS_Menu(); modelMenu.ID = Guid.NewGuid().ToString(); modelMenu.MenuNO = nbbMenuNO.Text.ToString(); modelMenu.MenuName = txbMenuName.Text.ToString(); modelMenu.MenuUrl = txbMenuUrl.Text.ToString(); //modelMenu.ImageUrl = txbImageUrl.Text.ToString(); modelMenu.ParentID = hdfParentID.Text.ToString(); modelMenu.State = ddlState.SelectedValue.ToString(); modelMenu.CreateID = Session["AccountID"].ToString(); modelMenu.CreateTime = DateTime.Now; bool result = bllMenu.Add(modelMenu); if (!result) { Alert.ShowInTop("添加失败", "提示信息", MessageBoxIcon.Error, ActiveWindow.GetHideRefreshReference()); } else { Alert.ShowInTop("添加成功", "提示信息", MessageBoxIcon.Information, ActiveWindow.GetHideRefreshReference()); } #endregion //关闭本窗体,然后刷新父窗体 //PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); }