public override void Init() { //逻辑对象赋值 bll = PagePowerSignBll.GetInstence(); //表格对象赋值 grid = Grid1; }
/// <summary>读取数据</summary> public override void LoadData() { int positionId = ConvertHelper.Cint0(hidPositionId.Text); if (positionId != 0) { //获取指定ID的职位内容 var model = PositionBll.GetInstence().GetModelForCache(x => x.Id == positionId); if (model == null) { return; } //对页面窗体进行赋值 txtName.Text = model.Name; //设置下拉列表选择项 labBranchName.Text = model.Branch_Name; //设置页面权限 _pagePower = model.PagePower; //设置页面控件权限 _controlPower = model.ControlPower; } else { //设置部门 var branchModel = BranchBll.GetInstence().GetModelForCache(ConvertHelper.Cint0(hidBranchId.Text)); labBranchName.Text = branchModel.Name; } //创建树节点 var tnode = new FineUI.TreeNode(); //设置节点名称 tnode.Text = "菜单"; //设置节点ID tnode.NodeID = "0"; //设置当前节点是否为最终节点 tnode.Leaf = false; //是否可以选择(打勾) tnode.EnableCheckBox = true; //是否已经选择 tnode.Checked = true; //是否自动扩大 tnode.Expanded = true; //开启点击节点全选或取消事件 tnode.EnableCheckEvent = true; //根据指定的父ID去查询相关的子集ID var dt = MenuInfoBll.GetInstence().GetDataTable(); //获取全部页面权限 var pgdt = PagePowerSignBll.GetInstence().GetDataTable(); //从一级菜单开始添加 AddNode(dt, pgdt, tnode, "0"); MenuTree.Nodes.Add(tnode); }
/// <summary> /// 清空绑定控件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ButtonEmpty_Click(object sender, EventArgs e) { //获取当前选择的菜单项 var index = ConvertHelper.Cint0(hidId.Text); //如果没有选择项,则直接退出 if (index == 0) { return; } //删除已绑定控件 PagePowerSignBll.GetInstence().Delete(this, x => x.MenuInfo_Id == index); BindGrid(); }
/// <summary> /// 取消绑定控件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ButtonCancel_Click(object sender, EventArgs e) { //获取当前选择的菜单项 var index = ConvertHelper.Cint0(hidId.Text); //获取当前用户选择的全部记录Id var id = GridViewHelper.GetSelectedKeyIntArray(Grid2); //如果没有选择项,则直接退出 if (index == 0 || id == null || id.Length == 0) { return; } //删除已绑定控件 PagePowerSignBll.GetInstence().Delete(this, id); BindGrid(); }
private void BindGrid() { var index = ConvertHelper.Cint0(hidId.Text); if (index == 0) { return; } //设置查询条件 var wheres = new List <ConditionHelper.SqlqueryCondition>(); wheres.Add(new ConditionHelper.SqlqueryCondition(ConstraintType.And, PagePowerSignTable.MenuInfo_Id, Comparison.Equals, index)); //设置排序 var _order = new List <string>(); _order.Add(PagePowerSignTable.Id); //获取DataTable var dt = PagePowerSignBll.GetInstence().GetDataTable(false, 0, null, 0, 0, wheres, _order); if (dt == null || dt.Rows.Count == 0) { Grid2.DataSource = null; Grid2.DataBind(); PagePowerSignPublicBll.GetInstence().BindGrid(Grid1, 0, 0, null, _order); } else { //绑定到表格——已绑定控件列表 //PagePowerSignBll.GetInstence().BindGrid(Grid2, 0, 0, list, _order); Grid2.DataSource = dt; Grid2.DataBind(); var id = DataTableHelper.GetArrayInt(dt, PagePowerSignTable.PagePowerSignPublic_Id); wheres = new List <ConditionHelper.SqlqueryCondition>(); wheres.Add(new ConditionHelper.SqlqueryCondition(ConstraintType.And, PagePowerSignPublicTable.Id, Comparison.NotIn, id)); PagePowerSignPublicBll.GetInstence().BindGrid(Grid1, 0, 0, wheres, _order); } }
/// <summary> /// 删除记录 /// </summary> /// <returns></returns> public override string Delete() { //获取要删除的ID int id = ConvertHelper.Cint0(GridViewHelper.GetSelectedKey(Grid1, true)); //如果没有选择记录,则直接退出 if (id == 0) { return("请选择要删除的记录。"); } try { //删除前判断一下 if (MenuInfoBll.GetInstence().Exist(x => x.ParentId == id)) { return("删除失败,本菜单下面存在子菜单,不能直接删除!"); } //删除前判断一下 if (PagePowerSignBll.GetInstence().Exist(x => x.MenuInfo_Id == id)) { return("删除失败,本菜单已绑定有页面控件权限标志,不能直接删除!"); } //删除记录 bll.Delete(this, id); return("删除编号ID为[" + id + "]的数据记录成功。"); } catch (Exception e) { string result = "尝试删除编号ID为[" + id + "]的数据记录失败!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); return(result); } }
/// <summary> /// 页面绑定控件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ButtonEmpower_Click(object sender, EventArgs e) { //获取当前选择的菜单项 var index = ConvertHelper.Cint0(hidId.Text); //获取当前用户选择的全部记录Id var id = GridViewHelper.GetSelectedKeyIntArray(Grid1); //如果没有选择项,则直接退出 if (index == 0 || id == null || id.Length == 0) { return; } //添加到绑定表中 foreach (var i in id) { //检查当前控件是否已添加 //添加前判断一下本权限标签是否已添加过了,没有则进行添加 if (!PagePowerSignBll.GetInstence().Exist(x => x.MenuInfo_Id == index && x.PagePowerSignPublic_Id == i)) { var ppsp = PagePowerSignPublicBll.GetInstence().GetModelForCache(i); if (ppsp == null) { continue; } var model = new PagePowerSign(); model.MenuInfo_Id = index; model.PagePowerSignPublic_Id = i; model.CName = ppsp.CName; model.EName = ppsp.EName; PagePowerSignBll.GetInstence().Save(this, model); } } BindGrid(); }
/// <summary> /// 删除记录 /// </summary> /// <returns></returns> public override string Delete() { //获取要删除的Id组 var id = GridViewHelper.GetSelectedKeyIntArray(Grid1); //如果没有选择记录,则直接退出 if (id == null) { return("请选择要删除的记录。"); } try { //逐个判断是否可以删除 foreach (var i in id) { //删除前检查 if (PagePowerSignBll.GetInstence().Exist(x => x.PagePowerSignPublic_Id == i)) { return("删除失败,Id为【" + i + "】的记录已被引用,不能直接删除!"); } } //删除记录 bll.Delete(this, id); return("删除编号Id为[" + string.Join(",", id) + "]的数据记录成功。"); } catch (Exception e) { string result = "尝试删除编号ID为[" + string.Join(",", id) + "]的数据记录失败!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); return(result); } }
/// <summary> /// 数据保存 /// </summary> /// <returns></returns> public override string Save() { string result = string.Empty; int id = ConvertHelper.Cint0(hidId.Text); try { #region 数据验证 if (string.IsNullOrEmpty(txtCName.Text.Trim())) { return(txtCName.Label + "不能为空!"); } var sName = StringHelper.Left(txtCName.Text, 20); if (PagePowerSignPublicBll.GetInstence().Exist(x => x.CName == sName && x.Id != id)) { return(txtCName.Label + "已存在!请重新输入!"); } if (string.IsNullOrEmpty(txtEName.Text.Trim())) { return(txtEName.Label + "不能为空!"); } var sEname = StringHelper.Left(txtEName.Text, 50); if (PagePowerSignPublicBll.GetInstence().Exist(x => x.EName == sEname && x.Id != id)) { return(txtEName.Label + "已存在!请重新输入!"); } #endregion #region 赋值 //定义是否更新标识——即当前记录的名称是否改变了 bool isUpdate = false; //获取实体 var model = new PagePowerSignPublic(x => x.Id == id); //判断是否有改变名称 if (id > 0 && (sName != model.CName || sEname != model.EName)) { isUpdate = true; } //设置名称 model.CName = sName; //设置英文名称 model.EName = sEname; #endregion //---------------------------------------------------------- //存储到数据库 PagePowerSignPublicBll.GetInstence().Save(this, model); //判断是否需要同步更新关联表字段 if (isUpdate) { //调用更新函数,同步更新对应的所有记录 PagePowerSignBll.GetInstence().UpdateValue_For_PagePowerSignPublic_Id(this, model.Id, PagePowerSignTable.CName, model.CName, PagePowerSignTable.EName, model.EName); } } catch (Exception e) { result = "保存失败!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); } return(result); }
/// <summary> /// Grid点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Grid4_RowCommand(object sender, FineUI.GridCommandEventArgs e) { GridRow gr = Grid4.Rows[e.RowIndex]; //获取当前点击列的主键ID int id_public = int.Parse(gr.DataKeys[0].ToString()); switch (e.CommandName) { case "IsOrNotLink": string id_menu = GridViewHelper.GetSelectedKey(Grid3, true); //获取未分配的 勾选的Id if (Grid3.SelectedRowIndexArray.Length > 1 || Grid3.SelectedRowIndexArray.Length == 0) { Alert.Show("请选择一行!", MessageBoxIcon.Warning); break; } //更新状态 // MenuInfoBll.GetInstence().UpdateIsDisplay(this, ConvertHelper.Cint0(id), ConvertHelper.Cint0(e.CommandArgument)); if (e.CommandArgument == "0") { //删除PagePowerSign if (Grid3.SelectedRowIndexArray.Length == 0) { Alert.Show("请搜选菜单项!", MessageBoxIcon.Information); } GridRow gr1 = Grid3.Rows[Grid3.SelectedRowIndex]; menuInfoId_ = int.Parse(gr1.Values[0].ToString()); var model1 = new Solution.DataAccess.DataModel.PagePowerSignPublic(x => x.Id == id_public); var model_p = PagePowerSign.SingleOrDefault(x => x.PagePowerSignPublic_Id == model1.Id && x.MenuInfo_Id == menuInfoId); // PagePowerSignBll.GetInstence().GetModel(model1.Id, menuInfoId_, true); //获取PagePowerSign表 PagePowerSignBll.GetInstence().Delete(this, model_p.Id); int id = ConvertHelper.Cint0(hidId.Text); //获取页面传值 var model = new DataAccess.Model.Position(); //获取指定ID的菜单内容,如果不存在,则创建一个菜单实体 model = PositionBll.GetInstence().GetModelForCache(x => x.Id == id); string new_control = model.ControlPower.Replace(id_menu + "|" + id_public + ",", ""); // model.ControlPower = new_control; PositionBll.GetInstence().UpdateValue(this, id, "ControlPower", new_control, "", true, false); //.UpdateControlPower(this, id, new_control, false, false); // PositionBll.GetInstence().SetModelForCache(model); } else //添加PagePowerSign //Solution.DataAccess.Model.PagePowerSign model = new DataAccess.Model.PagePowerSign(); //model.PagePowerSignPublic_Id = (int)id; //model.CName = { var model1 = new Solution.DataAccess.DataModel.PagePowerSignPublic(x => x.Id == id_public); Solution.DataAccess.DataModel.PagePowerSign pps = new DataAccess.DataModel.PagePowerSign(); pps.PagePowerSignPublic_Id = model1.Id; pps.CName = model1.Cname; pps.EName = model1.Ename; pps.MenuInfo_Id = int.Parse(id_menu); PagePowerSignBll.GetInstence().Save(this, pps); int id = ConvertHelper.Cint0(hidId.Text); //获取页面传值 var model = new DataAccess.Model.Position(); //获取指定ID的菜单内容,如果不存在,则创建一个菜单实体 model = PositionBll.GetInstence().GetModelForCache(x => x.Id == id); string new_control = model.ControlPower + id_menu + "|" + id_public + ","; //model.ControlPower = new_control; PositionBll.GetInstence().UpdateValue(this, id, "ControlPower", new_control, "", true, false); //PositionBll.GetInstence().UpdateControlPower(this, id, new_control, false, false); //PositionBll.GetInstence().SetModelForCache(model); } //重新加载 conditionList = new List <ConditionFun.SqlqueryCondition>(); conditionList.Add(new ConditionFun.SqlqueryCondition(ConstraintType.Where, "1", Comparison.Equals, "1", false, false)); //bll.BindGrid(Grid1, 0, sortList); bll.BindGrid(Grid4, 0, 0, conditionList, sortList); break; } }