Example #1
0
        private void deleteRoleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //删除角色
            try
            {
                TreeNode tn = treeView1.SelectedNode;
                if (tn.Name == "OP001")
                {
                    throw new Exception("管理员权限为系统权限,不能删除!");
                }

                DialogResult dr = MessageBox.Show(this, "是否删除\"" + tn.Text + "\"角色", "删除角色", MessageBoxButtons.YesNo);
                if (dr == DialogResult.Yes)
                {
                    using (AMSEntities amsContext = new AMSEntities())
                    {
                        //tbLimit limit = new tbLimit();
                        //limit.vcLimitCode = tn.Name;
                        //limit.vcLimitName = tn.Text;

                        tbLimit limit = amsContext.tbLimit.FirstOrDefault(l => l.vcLimitCode == tn.Name);
                        amsContext.DeleteObject(limit);

                        var opers = amsContext.tbOperLimit.Where(ol => ol.vcLimitCode == tn.Name);
                        foreach (tbOperLimit operLimit in opers)
                        {
                            amsContext.DeleteObject(operLimit);
                        }
                        amsContext.SaveChanges();
                        SetRole(amsContext);
                        MessageBox.Show(this, "角色删除成功", "删除角色");
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLog.Write(this, ex);
            }
        }
Example #2
0
        private void treeView2_AfterCheck(object sender, TreeViewEventArgs e)
        {
            if (e.Node.Tag.ToString().Length > 1 && treeView1.SelectedNode.Name != "limit")
            {
                tbOperLimit ol = new tbOperLimit();
                ol.vcLimitCode = treeView1.SelectedNode.Name;
                ol.vcMenu1     = e.Node.Tag.ToString().Substring(0, 1);
                ol.vcMenu2     = e.Node.Tag.ToString().Substring(1, 1);
                using (AMSEntities amsContext = new AMSEntities())
                {
                    try
                    {
                        //amsContext.s
                        tbOperLimit ol2 = amsContext.tbOperLimit.FirstOrDefault(l => l.vcLimitCode == ol.vcLimitCode && l.vcMenu1 == ol.vcMenu1 && l.vcMenu2 == ol.vcMenu2);

                        if (e.Node.Checked)
                        {
                            if (ol2 == null)
                            {
                                amsContext.AddTotbOperLimit(ol);
                                amsContext.SaveChanges();
                            }
                        }
                        else
                        {
                            if (ol2 != null)
                            {
                                amsContext.DeleteObject(ol2);
                                amsContext.SaveChanges();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ErrorLog.Write(this, ex);
                    }
                }
            }
        }