Ejemplo n.º 1
0
        public ActionResult PrivProgram(string result, string open, string Editresult,string Dropresult)
        {
            string[] gid = result.Split(',');
            string[] openstate = open.Split(',');
            Guid priid ;
            Guid priidnode;

            //userID为前台传入值,现在假设已获取
            Guid userID = new Guid("12db0a77-92c4-e011-afef-002269c9aa85");
            MemberPrivilege PrivID = (from o in dbEntity.MemberPrivileges
                                      where (o.UserID == userID && o.Deleted == false && o.Ptype == 0)
                                      select o).FirstOrDefault();
            //保存程序授权,Ptype=0
            if (PrivID != null)
            {
                priid = PrivID.Gid;
            }
            else
            {
                //程序授权Ptype=0,主表中添加
                MemberPrivilege m = new MemberPrivilege();
                m.UserID = userID;
                m.Ptype = 0;
                m.Pstatus = 1;

                dbEntity.MemberPrivileges.Add(m);
                dbEntity.SaveChanges();
                priid= m.Gid;
            }
            MemberPrivilege NodePrivID = (from o in dbEntity.MemberPrivileges
                                      where (o.UserID == userID && o.Deleted == false && o.Ptype == 1)
                                      select o).FirstOrDefault();
            if (NodePrivID != null)
            {
                priidnode = NodePrivID.Gid;
            }
            else
            {
                //程序功能点授权,Ptype=1
                    MemberPrivilege m = new MemberPrivilege();
                    m.UserID = userID;
                    m.Ptype = 1;
                    m.Pstatus = 1;

                    dbEntity.MemberPrivileges.Add(m);
                    dbEntity.SaveChanges();
                    priidnode = m.Gid;
            }

            //保存授权的程序或程序节点
            for (int i = 1; i < gid.Length - 1; i++)
            {
                Guid id = new Guid(gid[i]);
                //判断是否是程序的ID
                var IsProgram = (from o in dbEntity.GeneralPrograms
                                 where (o.Gid == id && o.Deleted == false)
                                 select o).FirstOrDefault();
                //gid[i]为程序节点ID
                if (IsProgram == null)
                {
                    var ItemNode = (from o in dbEntity.MemberPrivItems
                                    where (o.RefID == id && o.Deleted == false)
                                    select o).FirstOrDefault();
                    if (ItemNode == null)
                    {
                        GeneralProgNode ProgNode = (from o in dbEntity.GeneralProgNodes.Include("Name").Include("Optional")
                                                    where (o.Gid == id && o.Deleted == false)
                                                    select o).Single();

                        MemberPrivItem mPriItem = new MemberPrivItem();
                        mPriItem.PrivID = priid;
                        mPriItem.RefID = new Guid(gid[i]);
                        mPriItem.NodeCode = ProgNode.Code;
                        if (ProgNode.InputMode == 0)
                            mPriItem.NodeValue = Editresult;
                        else mPriItem.NodeValue = Dropresult;
                        dbEntity.MemberPrivItems.Add(mPriItem);
                        dbEntity.SaveChanges();
                    }

                }
                //gid[i]是程序ID
                else
                {
                    var ItemProg = (from o in dbEntity.MemberPrivItems
                                    where (o.Deleted == false && o.RefID == id)
                                    select o).FirstOrDefault();
                    if (ItemProg == null)
                    {
                        GeneralProgram Program = (from o in dbEntity.GeneralPrograms
                                                  where (o.Gid == id&&o.Deleted==false)
                                                  select o).Single();
                        //程序为叶子节点
                        if (Program.Terminal == true)
                        {
                            if (openstate[i] == "undefined")
                            {
                                //保存自己
                                MemberPrivItem mPriItem = new MemberPrivItem();
                                mPriItem.PrivID = priid;
                                mPriItem.RefID = new Guid(gid[i]);
                                dbEntity.MemberPrivItems.Add(mPriItem);
                                dbEntity.SaveChanges();
                                //保存所有功能节点
                                var ProgNode = from o in dbEntity.GeneralProgNodes
                                               where (o.ProgID == id && o.Deleted == false)
                                               select o;
                                foreach (var Nodeitem in ProgNode)
                                {
                                    mPriItem.PrivID = priid;
                                    mPriItem.RefID = Nodeitem.Gid;
                                    mPriItem.NodeCode = Nodeitem.Code;
                                    if (Nodeitem.InputMode == 0)
                                        mPriItem.NodeValue = Editresult;
                                    else mPriItem.NodeValue = Dropresult;
                                }
                            }
                        }
                        //程序为非叶子节点
                        else
                        {
                            if (openstate[i] == "undefined")
                            {
                                //判断是否已经存在
                                var item = (from o in dbEntity.MemberPrivItems
                                            where (o.RefID == id && o.PrivID == priid)
                                            select o).FirstOrDefault();

                                if (item == null)
                                {
                                    MemberPrivItem mPriItem = new MemberPrivItem();
                                    mPriItem.PrivID = priid;
                                    mPriItem.RefID = new Guid(gid[i]);
                                    dbEntity.MemberPrivItems.Add(mPriItem);
                                    dbEntity.SaveChanges();
                                }
                                //递归保存孩子节点
                                PrivProChild(id, priid);
                            }
                            else
                            {
                                var item = (from o in dbEntity.MemberPrivItems
                                            where (o.RefID == id && o.PrivID == priid)
                                            select o).FirstOrDefault();
                                if (item == null)
                                {
                                    MemberPrivItem mPriItem = new MemberPrivItem();
                                    mPriItem.PrivID = priid;
                                    mPriItem.RefID = new Guid(gid[i]);
                                    dbEntity.MemberPrivItems.Add(mPriItem);
                                    dbEntity.SaveChanges();
                                }
                            }
                        }
                    }

                }
            }

               return RedirectToAction("PrivProgram");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 导入用户权限
        /// </summary>
        /// <param name="sExcelFile">Excel文件名</param>
        /// <param name="sSheetName">Sheet名</param>
        public void ImportPrivileges(string sExcelFile, string sSheetName)
        {
            try
            {
                ExcelData oExcel = new ExcelData(sExcelFile, sSheetName);
                DataColumn colLoginName = oExcel.ExcelTable.Columns["登陆名"];
                DataColumn colPrivType = oExcel.ExcelTable.Columns["类型"];
                DataColumn colStatus = oExcel.ExcelTable.Columns["状态"];
                DataColumn colOrgan = oExcel.ExcelTable.Columns["组织"];
                DataColumn colRefCode = oExcel.ExcelTable.Columns["授权代码"];
                DataColumn colNodeCode = oExcel.ExcelTable.Columns["节点代码"];
                DataColumn colNodeValue = oExcel.ExcelTable.Columns["节点值"];
                DataColumn colRemark = oExcel.ExcelTable.Columns["备注"];

                string sLastUser = "";
                Guid gLastGuid = Guid.Empty;
                MemberUser oUser = null;
                foreach (DataRow row in oExcel.ExcelTable.Rows)
                {
                    string sLoginName = row[colLoginName].ToString();
                    byte nType;
                    Byte.TryParse(row[colPrivType].ToString(), out nType);
                    byte nStatus;
                    Byte.TryParse(row[colStatus].ToString(), out nStatus);
                    string sRefCode = row[colRefCode].ToString();
                    string sNodeCode = row[colNodeCode].ToString();
                    string sNodeValue = row[colNodeValue].ToString();
                    string sRemark = row[colRemark].ToString();

                    if (!String.IsNullOrEmpty(sLoginName))
                    {
                        oUser = (from u in dbEntity.MemberUsers
                                     where u.LoginName == sLoginName
                                     select u).FirstOrDefault();
                        sLastUser = sLoginName;
                    }
                    // 授权主表
                    var oPrivilege = (from p in dbEntity.MemberPrivileges
                                      where p.UserID == oUser.Gid && p.Ptype == nType
                                      select p).FirstOrDefault();
                    if (oPrivilege == null)
                    {
                        oPrivilege = new MemberPrivilege { User = oUser, Ptype = nType };
                        dbEntity.MemberPrivileges.Add(oPrivilege);
                    }
                    oPrivilege.Pstatus = nStatus;
                    dbEntity.SaveChanges();
                    // 授权项目表
                    Guid gRefID = Guid.Empty;
                    switch ((ModelEnum.UserPrivType)nType)
                    {
                        case ModelEnum.UserPrivType.PROGRAM:
                            var oProgram = (from p in dbEntity.GeneralPrograms
                                            where p.Code == sRefCode
                                            select p).FirstOrDefault();
                            gLastGuid = oProgram.Gid;
                            gRefID = oProgram.Gid;
                            break;
                        case ModelEnum.UserPrivType.PROGRAM_NODE:
                            var oProgNode = (from n in dbEntity.GeneralProgNodes
                                             where n.ProgID == gLastGuid && n.Code == sNodeCode
                                             select n).FirstOrDefault();
                            gRefID = oProgNode.Gid;
                            break;
                        case ModelEnum.UserPrivType.ORGANIZATION:
                            var oOrgan = (from o in dbEntity.MemberOrganizations
                                          where o.Code == sRefCode && o.Otype == (byte)ModelEnum.OrganizationType.CORPORATION
                                          select o).FirstOrDefault();
                            gLastGuid = oOrgan.Gid;
                            gRefID = oOrgan.Gid;
                            break;
                        case ModelEnum.UserPrivType.CHANNEL:
                            var oChannel = (from o in dbEntity.MemberChannels
                                            where o.Code == sRefCode && o.Otype == (byte)ModelEnum.OrganizationType.CHANNEL
                                            select o).FirstOrDefault();
                            gLastGuid = oChannel.Gid;
                            gRefID = oChannel.Gid;
                            break;
                        case ModelEnum.UserPrivType.WAREHOUSE:
                            var oWarehouse = (from o in dbEntity.WarehouseInformations
                                            where o.Code == sRefCode && o.Otype == (byte)ModelEnum.OrganizationType.WAREHOUSE
                                            select o).FirstOrDefault();
                            gLastGuid = oWarehouse.Gid;
                            gRefID = oWarehouse.Gid;
                            break;
                        case ModelEnum.UserPrivType.PRODUCT_CATEGORY:
                            var oCategory1 = (from c in dbEntity.GeneralPrivateCategorys
                                             where c.Organization.Code == sRefCode
                                                   && c.Code == sNodeCode
                                                   && c.Ctype == (byte)ModelEnum.PrivateCategoryType.PRODUCT
                                             select c).FirstOrDefault();
                            gLastGuid = oCategory1.Gid;
                            gRefID = oCategory1.Gid;
                            break;
                        case ModelEnum.UserPrivType.SUPPLIER_CATEGORY:
                            var oCategory2 = (from c in dbEntity.GeneralPrivateCategorys
                                             where c.Organization.Code == sRefCode
                                                   && c.Code == sNodeCode
                                                   && c.Ctype == (byte)ModelEnum.PrivateCategoryType.SUPPLIER
                                             select c).FirstOrDefault();
                            gLastGuid = oCategory2.Gid;
                            gRefID = oCategory2.Gid;
                            break;
                    }
                    MemberPrivItem oPrivItem;
                    if (nType == (byte)ModelEnum.UserPrivType.PROGRAM_NODE)
                    {
                        oPrivItem = (from i in dbEntity.MemberPrivItems
                                     where i.PrivID == oPrivilege.Gid && i.RefID == gRefID && i.NodeCode == sNodeCode
                                     select i).FirstOrDefault();
                        if (oPrivItem == null)
                        {
                            oPrivItem = new MemberPrivItem { Privilege = oPrivilege, RefID = gRefID, NodeCode = sNodeCode };
                            dbEntity.MemberPrivItems.Add(oPrivItem);
                        }
                        oPrivItem.NodeValue = sNodeValue;
                    }
                    else
                    {
                        oPrivItem = (from i in dbEntity.MemberPrivItems
                                     where i.PrivID == oPrivilege.Gid && i.RefID == gRefID
                                     select i).FirstOrDefault();
                        if (oPrivItem == null)
                        {
                            oPrivItem = new MemberPrivItem { Privilege = oPrivilege, RefID = gRefID };
                            dbEntity.MemberPrivItems.Add(oPrivItem);
                        }
                    }
                    oPrivItem.Remark = sRemark;
                    dbEntity.SaveChanges();
                    if (Utility.ConfigHelper.GlobalConst.IsDebug)
                        Debug.WriteLine("{0} {1} {2} {3} {4}", this.ToString(), sLoginName, sRefCode, sNodeCode, sRemark);
                }
                oEventBLL.WriteEvent(String.Format("导入MemberPrivilege成功: {0} {1}", sExcelFile, sSheetName),
                    ModelEnum.ActionLevel.GENERIC, ModelEnum.ActionSource.SYSTEM, this.ToString());
            }
            catch (Exception ex)
            {
                oEventBLL.WriteEvent(String.Format("导入MemberPrivilege错误: {0} {1} {2}", sExcelFile, sSheetName, ex.Message),
                    ModelEnum.ActionLevel.ERROR, ModelEnum.ActionSource.SYSTEM, this.ToString());
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 保存授权商品
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult PrivProduct(Guid? id)
        {
            Guid userID = new Guid("12db0a77-92c4-e011-afef-002269c9aa85");
            Guid PrivID = (from o in dbEntity.MemberPrivileges
                           where (o.UserID == userID && o.Ptype == 1 && o.Deleted == false)
                           select o.Gid).Single();
            GeneralPrivateCategory Product = (from o in dbEntity.GeneralPrivateCategorys
                                  where (o.Gid == id && o.Deleted == false)
                                  select o).Single();
            MemberPrivItem mPrivItem = new MemberPrivItem();
            int nCount=Product.ChildItems.ToList<GeneralPrivateCategory>().Count;
            if (nCount==0)
            {
                mPrivItem.PrivID = PrivID;
                mPrivItem.RefID = Product.Gid;
                dbEntity.MemberPrivItems.Add(mPrivItem);
                dbEntity.SaveChanges();
            }
            else
            {

                PrivProductChild(Product.ChildItems.ToList<GeneralPrivateCategory>(), PrivID);

            }
            return View();
        }
Ejemplo n.º 4
0
 public void PrivProductChild(List<GeneralPrivateCategory> list, Guid PrivID)
 {
     for (int i = 0; i < list.Count; i++)
     {
         if (list.ElementAt(i).ChildItems.Count>0)
         {
             PrivProductChild(list.ElementAt(i).ChildItems.ToList<GeneralPrivateCategory>(), PrivID);
         }
         else
         {
             MemberPrivItem mPrivItem = new MemberPrivItem();
             mPrivItem.PrivID = PrivID;
             mPrivItem.RefID = list.ElementAt(i).Gid;
             dbEntity.MemberPrivItems.Add(mPrivItem);
             dbEntity.SaveChanges();
         }
     }
 }
Ejemplo n.º 5
0
        public ActionResult PrivOrganization(MemberPrivilege memberPrivilege, int? optitemCount, string prvID)
        {
            Guid id = new Guid(prvID);
            memberPrivilege = (dbEntity.MemberPrivileges.Where(o => o.Gid == id)).Single();
            if (ModelState.IsValid)
            {
                ICollection<MemberPrivItem> memberPrivItems = new List<MemberPrivItem>();
                for (int i = 0; i < optitemCount; i++)
                {
                    MemberPrivItem memberPrivItem = new MemberPrivItem();
                    memberPrivItem.PrivID = memberPrivilege.Gid;
                    memberPrivItem.RefID = new Guid(Request.Form["privOrg" + i]);
                    memberPrivItems.Add(memberPrivItem);
                }
                memberPrivilege.PrivilegeItems = memberPrivItems;

                dbEntity.SaveChanges();
                return RedirectToAction("Index");
            }
            return View();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 递归保存子节点
        /// </summary>
        /// <param name="ID">父亲节点ID</param>
        /// <param name="PrivID"></param>
        public void PrivProChild(Guid ID, Guid PrivID)
        {
            bool flag=false;
            var ProgramList = (from o in dbEntity.GeneralPrograms.Include("Parent")
                          where (o.Parent.Gid == ID &&  o.Deleted == false)
                          select o).ToList();
            var refidlist=(from o in dbEntity.MemberPrivItems where (o.PrivID==PrivID)
                           select o).ToList();
            for (int i = 0; i < ProgramList.Count; i++)
            {
                for (int j = 0; j < refidlist.Count; j++)
                {
                    if (ProgramList[i].Gid == refidlist[j].RefID)
                        flag = true;
                    break;
                }
                if (flag == false)
                {
                    if (ProgramList.ElementAt(i).Terminal == true)
                    {
                        MemberPrivItem mPrivItem = new MemberPrivItem();
                        mPrivItem.PrivID = PrivID;
                        mPrivItem.RefID = ProgramList.ElementAt(i).Gid;
                        dbEntity.MemberPrivItems.Add(mPrivItem);
                        dbEntity.SaveChanges();
                        //是否存在程序功能节点
                        var ProgNode = (from o in dbEntity.GeneralProgNodes
                                       where (o.Deleted == false && o.ProgID == ProgramList[i].Gid)
                                       select o).ToList();
                        if (ProgNode.Count>0)
                        {
                            foreach (var Nodeitem in ProgNode)
                            {
                                MemberPrivItem NodeItem = new MemberPrivItem();
                                NodeItem.PrivID = PrivID;
                                NodeItem.RefID = ProgNode[i].Gid;
                                dbEntity.MemberPrivItems.Add(NodeItem);
                            }
                            dbEntity.SaveChanges();
                        }
                    }
                    else
                    {
                        PrivProChild(ProgramList[i].Gid, PrivID);

                    }
                }
                flag = false;
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 递归函数保存叶节点
 /// </summary>
 /// <param name="list"></param>
 /// <param name="PrivID"></param>
 public void PrivSupChild(Guid id,Guid PrivID)
 {
     //取出所有孩子
     var SupChild = from o in dbEntity.MemberOrganizations.Include("Parent")
                    where (o.Otype == 3 && o.Parent.Gid==id && o.Deleted == false)
                    select o;
     int nSupChild = SupChild.ToList().Count;
     for (int i = 0; i < nSupChild; i++)
     {
         if (SupChild.ToList().ElementAt(i).Terminal == false)
         {
             PrivSupChild(SupChild.ToList().ElementAt(i).Gid, PrivID);
         }
         else
         {
             Guid  ChildID=SupChild.ToList().ElementAt(i).Gid;
             var SupChildItem = (from o in dbEntity.MemberPrivItems
                                where (o.RefID == ChildID)
                                select o).FirstOrDefault();
             if (SupChildItem == null)
             {
                 MemberPrivItem mPrivItem = new MemberPrivItem();
                 mPrivItem.PrivID = PrivID;
                 mPrivItem.RefID = ChildID;
                 dbEntity.MemberPrivItems.Add(mPrivItem);
                 dbEntity.SaveChanges();
             }
             else
             {
                 MemberPrivItem mPrivItem = new MemberPrivItem();
                 mPrivItem.Deleted = false;
             }
         }
     }
 }
Ejemplo n.º 8
0
 public ActionResult PrivSupplier(string result, string open)
 {
     Guid userID = new Guid("12db0a77-92c4-e011-afef-002269c9aa85");
     Guid PrivID = (from o in dbEntity.MemberPrivileges
                               where (o.UserID == userID && o.Deleted == false && o.Ptype == 0)
                               select o.Gid).FirstOrDefault();
     string[] gid = result.Split(',');
     string[] openstate = open.Split(',');
     int ngid=gid.Length;
     for(int i=1;i<ngid-1;i++)
     {
         Guid id = new Guid(gid[i]);
         if (openstate[i] == "undefined")
         {
             //递归保存
         }
         else
         {
             MemberPrivItem SupItem = new MemberPrivItem();
             SupItem.PrivID = PrivID;
             SupItem.RefID = id;
             dbEntity.MemberPrivItems.Add(SupItem);
             dbEntity.SaveChanges();
         }
     }
     return RedirectToAction("PrivSupplier");
 }
Ejemplo n.º 9
0
        /// <summary>
        /// 商品分类授权
        /// </summary>
        /// <returns></returns>
        public ActionResult PrivProduct(Guid? id=null)
        {
            if (!base.CheckPrivilege("EnableEdit"))//权限验证
                return RedirectToAction("ErrorPage", "Home", new { message = "Sorry you have no privilege to visit the Page" });
            if (id == null)
            {
                int nstatus;
                MemberPrivilege oMemberPrivilege = (from o in dbEntity.MemberPrivileges where (o.Deleted == false && o.UserID == gUserID && o.Ptype == (byte)ModelEnum.UserPrivType.PRODUCT_CATEGORY) select o).FirstOrDefault();
                if (oMemberPrivilege != null)
                {
                    //获取状态,1启用,0禁用
                    nstatus = (int)oMemberPrivilege.Pstatus;
                }
                else
                    nstatus = -1;
                ViewBag.status = nstatus;
                //组织下拉框
                ViewData["Orglist"] = GetGuserSupportOrganizations();
            }
            else
            {
                Guid gPrivID = new Guid();
                MemberPrivilege oProPrivID = (from o in dbEntity.MemberPrivileges where (o.UserID == gUserID && o.Ptype == 5) select o).FirstOrDefault();
                //主表中已存在授权记录
                if (oProPrivID != null && oProPrivID.Deleted == false)
                {
                    if (oProPrivID.Pstatus == 0)
                    {
                        oProPrivID.Pstatus = 1;
                        dbEntity.SaveChanges();
                    }
                    gPrivID = oProPrivID.Gid;
                }
                //主表中的授权记录已被逻辑删除,恢复
                if (oProPrivID != null && oProPrivID.Deleted == true)
                {
                    oProPrivID.Deleted = false;
                    oProPrivID.Pstatus = 1;
                    dbEntity.SaveChanges();
                    gPrivID = oProPrivID.Gid;
                }
                //不存在授权记录,添加
                if (oProPrivID == null)
                {
                    MemberPrivilege oMemPriv = new MemberPrivilege();
                    oMemPriv.UserID = gUserID;
                    oMemPriv.Ptype = 5;
                    oMemPriv.Pstatus = 1;
                    dbEntity.MemberPrivileges.Add(oMemPriv);
                    dbEntity.SaveChanges();
                    gPrivID = oMemPriv.Gid;
                }

                MemberPrivItem oProPriItem = (from o in dbEntity.MemberPrivItems where (o.RefID == id && o.PrivID == gPrivID) select o).SingleOrDefault();
                if (oProPriItem != null && oProPriItem.Deleted == true)
                {
                    oProPriItem.Deleted = false;
                    dbEntity.SaveChanges();
                }
                if (oProPriItem == null)
                {
                    MemberPrivItem oProItem = new MemberPrivItem();
                    oProItem.PrivID = gPrivID;
                    oProItem.RefID = id;
                    dbEntity.MemberPrivItems.Add(oProItem);
                    dbEntity.SaveChanges();
                }

                return RedirectToAction("PrivProduct");
            }
            return View();
        }
Ejemplo n.º 10
0
        //=====================================================================
        public void InsertTestData()
        {
            //res 表中添加角色
            GeneralResource resRole = new GeneralResource
            {
                Code = GetRandCode(),
                Matter = "General User",
                Culture = 2052
            };
            oLiveEntities.GeneralResources.Add(resRole);
            //res 表中添加组织全名
            GeneralResource resOrg = new GeneralResource
            {
                Code = GetRandCode(),
                Matter = "筑巢信息科技有限公司",
                Culture = 2052
            };
            oLiveEntities.GeneralResources.Add(resOrg);
            //res 表中添加组织简称
            GeneralResource resShort = new GeneralResource
            {
                Code = GetRandCode(),
                Matter = "筑巢",
                Culture = 2052
            };
            oLiveEntities.GeneralResources.Add(resShort);
            //res 表中添加数据
            GeneralResource resData = new GeneralResource
            {
                Code = GetRandCode(),
                Culture = 2052,
                Matter = "A Test"
            };
            oLiveEntities.GeneralResources.Add(resData);
            GeneralResource resProg0 = new GeneralResource
            {
                Code = GetRandCode(),
                Culture = 2052,
                Matter = "Config"
            };
            oLiveEntities.GeneralResources.Add(resProg0);
            //res 表中添加程序定义
            GeneralResource resProg1 = new GeneralResource
            {
                Code = GetRandCode(),
                Matter = "generalProperty",
                Culture = 2052
            };
            oLiveEntities.GeneralResources.Add(resProg1);
            //res 表中添加程序定义
            GeneralResource resProg2 = new GeneralResource
            {
                Code = GetRandCode(),
                Matter = "Units",
                Culture = 2052
            };
            oLiveEntities.GeneralResources.Add(resProg2);
            //res 表中添加程序定义
            GeneralResource resProg3 = new GeneralResource
            {
                Code = GetRandCode(),
                Matter = "Classification",
                Culture = 2052
            };
            oLiveEntities.GeneralResources.Add(resProg3);
            //res 表中添加程序定义
            GeneralResource resProg4 = new GeneralResource
            {
                Code = GetRandCode(),
                Matter = "Organization",
                Culture = 2052
            };
            oLiveEntities.GeneralResources.Add(resProg4);
            //unit表中添加数据
            GeneralMeasureUnit oUnit = new GeneralMeasureUnit
            {
                Utype = 2,
                Code = GetRandCode(),
                Name = resData
            };
            oLiveEntities.GeneralMeasureUnits.Add(oUnit);
            //unit表中添加数据
            GeneralMeasureUnit oUnit0 = new GeneralMeasureUnit
            {
                Utype = 6,
                Code = GetRandCode(),
                Name = resData
            };
            oLiveEntities.GeneralMeasureUnits.Add(oUnit0);
            //文化表中添加数据
            GeneralCultureUnit culture = new GeneralCultureUnit
            {
                Piece = oUnit,
                Weight = oUnit0,
                Culture = 2052
            };
            oLiveEntities.GeneralCultureUnits.Add(culture);
            //组织表中添加数据
            MemberOrganization org = new MemberOrganization
            {
                Code = GetRandCode(),
                FullName = resOrg,
                ShortName = resShort,
                WorkPhone = "15121040098",
                HomeUrl = "http://www.zhuchao.com"
            };
            oLiveEntities.MemberOrganizations.Add(org);
            MemberOrganization chl = new MemberOrganization
            {
                Code = GetRandCode(),
                FullName = resOrg,
                ShortName = resShort,
                WorkPhone = "15121040098",
                HomeUrl = "http://www.zhuchao.com"
            };
            oLiveEntities.MemberOrganizations.Add(chl);
            //角色表中添加数据
            MemberRole role = new MemberRole
            {
                Name = resRole,
                Code = GetRandCode(),
                Organization = org
            };
            oLiveEntities.MemberRoles.Add(role);

            //新建渠道
            MemberChannel mChl = new MemberChannel
            {
                Code = GetRandCode(),
                CellPhone = "4525254254",
                Email = "*****@*****.**",
            };
            oLiveEntities.MemberChannels.Add(mChl);

            MemberOrgChannel oChl = new MemberOrgChannel
            {
                Organization = org,
                Channel = mChl
            };
            oLiveEntities.MemberOrgChannels.Add(oChl);
            //添加用户
            MemberUser user = new MemberUser
            {
                Organization = org,
                Channel = mChl,
                Role = role,
                LoginName = GetRandCode() + "@qq.com",
                Passcode = GetRandCode()
            };
            oLiveEntities.MemberUsers.Add(user);
            //添加用户
            MemberUser user0 = new MemberUser
            {
                Organization = org,
                Channel = mChl,
                Role = role,
                LoginName = "*****@*****.**",
                Passcode = "123"
            };
            oLiveEntities.MemberUsers.Add(user0);
            //添加程序定义
            GeneralProgram prog = new GeneralProgram
            {
                Name = resProg0,
                Code = GetRandCode()
            };
            oLiveEntities.GeneralPrograms.Add(prog);
            //添加程序定义
            GeneralProgram prog0 = new GeneralProgram
            {
                Name = resProg1,
                Code = GetRandCode()
            };
            oLiveEntities.GeneralPrograms.Add(prog0);
            //添加程序定义
            GeneralProgram prog1 = new GeneralProgram
            {
                Name = resProg2,
                Code = GetRandCode(),
                Parent = prog
            };
            oLiveEntities.GeneralPrograms.Add(prog1);
            //添加程序定义
            GeneralProgram prog2 = new GeneralProgram
            {
                Name = resProg3,
                Code = GetRandCode(),
                Parent = prog
            };
            oLiveEntities.GeneralPrograms.Add(prog2);
            //添加程序定义
            GeneralProgram prog3 = new GeneralProgram
            {
                Name = resProg4,
                Code = GetRandCode(),
                Parent = prog
            };
            oLiveEntities.GeneralPrograms.Add(prog3);
            //添加程序定义
            GeneralProgram prog5 = new GeneralProgram
            {
                Name = resProg4,
                Code = GetRandCode(),
                Parent = prog1
            };
            oLiveEntities.GeneralPrograms.Add(prog5);
            //res 表中添加程序定义
            GeneralResource resnode = new GeneralResource
            {
                Code = "resnode",
                Matter = "功能节点1",
                Culture = 2052
            };
            oLiveEntities.GeneralResources.Add(resProg1);

            GeneralResource resoptional = new GeneralResource
            {
                Code = "resnodeoption",
                Matter = "0|不显示,1|显示",
                Culture = 2052
            };
            oLiveEntities.GeneralResources.Add(resProg1);

            //添加程序功能定义
            GeneralProgNode progNode = new GeneralProgNode
            {
                Program = prog,
                Code = "prognode",
                Name = resnode,
                Optional = resoptional,
                InputMode = 1
            };
            oLiveEntities.GeneralProgNodes.Add(progNode);
            oLiveEntities.SaveChanges();
            //添加权限控制
            MemberPrivilege prol = new MemberPrivilege
            {
                User = user0,
                Ptype = 0
            };
            oLiveEntities.MemberPrivileges.Add(prol);
            //添加权限控制
            MemberPrivilege prol0 = new MemberPrivilege
            {
                User = user0,
                Ptype = 1
            };
            oLiveEntities.MemberPrivileges.Add(prol0);

            MemberPrivItem prinode = new MemberPrivItem
            {
                Privilege = prol0,
                RefID = progNode.Gid,
                NodeValue = "1"
            };
            oLiveEntities.MemberPrivItems.Add(prinode);
            //添加权限控制明细
            MemberPrivItem prolItem = new MemberPrivItem
            {
                Privilege = prol,
                RefID = prog.Gid
            };
            oLiveEntities.MemberPrivItems.Add(prolItem);
            //添加权限控制明细
            MemberPrivItem prolItem0 = new MemberPrivItem
            {
                Privilege = prol,
                RefID = prog0.Gid

            };
            oLiveEntities.MemberPrivItems.Add(prolItem0);
            //添加权限控制明细
            MemberPrivItem prolItem1 = new MemberPrivItem
            {
                Privilege = prol,
                RefID = prog1.Gid

            };
            oLiveEntities.MemberPrivItems.Add(prolItem1);
            //添加权限控制明细
            MemberPrivItem prolItem2 = new MemberPrivItem
            {
                Privilege = prol,
                RefID = prog2.Gid

            };
            oLiveEntities.MemberPrivItems.Add(prolItem2);

            oLiveEntities.SaveChanges();
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 用户组织授权
 /// </summary>
 /// <returns></returns>
 public ActionResult PrivOrganization(string orgSearchString = null, Guid? selectedOrg = null)
 {
     if (!base.CheckPrivilege("EnableEdit"))//权限验证
         return RedirectToAction("ErrorPage", "Home", new { message = "Sorry you have no privilege to visit the Page" });
     if (selectedOrg == null)
     {
         gSearchStr = orgSearchString;
         //在数据库中查找是否已存在该用户组织授权
         MemberPrivilege memberPrivilege = dbEntity.MemberPrivileges.Where(o => o.UserID == gUserID && o.Deleted == false && o.Ptype == (byte)ModelEnum.UserPrivType.ORGANIZATION).FirstOrDefault();
         if (memberPrivilege != null)
         {
             ViewBag.pStatus = memberPrivilege.Pstatus;
         }
         else
             ViewBag.pStatus = -1;
         ViewBag.orgSearchStr = orgSearchString;
     }
     else//保存
     {
         //在数据库中查找是否已存在该用户组织授权
         MemberPrivilege memberPrivilege = dbEntity.MemberPrivileges.Where(o => o.UserID == gUserID && o.Ptype == (byte)ModelEnum.UserPrivType.ORGANIZATION).FirstOrDefault();
         //如果已存在,则对该用户组织授权项进行更新
         if (memberPrivilege != null)
         {
             //更新组织授权项
             memberPrivilege.Deleted = false;
             memberPrivilege.Pstatus = (byte)ModelEnum.GenericStatus.VALID;
             //在MemberPrivItem中,查找已添加的项
             MemberPrivItem memberPrivItem = dbEntity.MemberPrivItems.Where(o => o.PrivID == memberPrivilege.Gid && o.RefID == selectedOrg).FirstOrDefault();
             if (memberPrivItem != null)
             {
                 memberPrivItem.Deleted = false;
             }
             else  //添加新增的项
             {
                 MemberPrivItem oNewMemberPrivItem = new MemberPrivItem();
                 oNewMemberPrivItem.PrivID = memberPrivilege.Gid;
                 oNewMemberPrivItem.RefID = selectedOrg;
                 dbEntity.MemberPrivItems.Add(oNewMemberPrivItem);
             }
             dbEntity.SaveChanges();
         }
         //如果不存在,则新建组织授权,并添加组织授权项
         else
         {
             //新建组织授权
             memberPrivilege = new MemberPrivilege();
             memberPrivilege.UserID = gUserID;
             memberPrivilege.Ptype = 2;
             memberPrivilege.Pstatus = 1;
             dbEntity.MemberPrivileges.Add(memberPrivilege);
             dbEntity.SaveChanges();
             //添加授权项
             MemberPrivItem memberPrivItem = new MemberPrivItem();
             memberPrivItem.PrivID = memberPrivilege.Gid;
             memberPrivItem.RefID = selectedOrg;
             dbEntity.MemberPrivItems.Add(memberPrivItem);
             dbEntity.SaveChanges();
         }
     }
     return View();
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 用模板对用户授权
 /// </summary>
 /// <param name="UserID"></param>
 /// <param name="SelectTemplateCode"></param>
 /// <returns></returns>
 public bool SetPrivilegeByTemplate(Guid UserID, string SelectTemplateCode)
 {
     if (UserID == null || String.IsNullOrEmpty(SelectTemplateCode) || SelectTemplateCode == "null")
         return false;
     List<GeneralPrivTemplate> GeneralPrivTemplateList = dbEntity.GeneralPrivTemplates.Where(g => g.Deleted == false && g.Code == SelectTemplateCode).ToList();
     //查找用户本身的权限 并且都做删除操作
     List<MemberPrivilege> oOldMemberPrivilegeList = dbEntity.MemberPrivileges.Where(m => m.UserID == UserID).ToList();
     if (oOldMemberPrivilegeList.Count > 0)
     {
         foreach (MemberPrivilege memberPriv in oOldMemberPrivilegeList)
         {
             memberPriv.Deleted = true;
             List<MemberPrivItem> oOldMemberPrivItemList = dbEntity.MemberPrivItems.Where(p => p.Deleted == false && p.PrivID == memberPriv.Gid).ToList();
             if (oOldMemberPrivItemList.Count > 0)
             {
                 foreach (MemberPrivItem memberPrivItem in oOldMemberPrivItemList)
                 {
                     memberPrivItem.Deleted = true;
                 }
             }
         }
     }
     dbEntity.SaveChanges();
     //COPY 若原来有该权限 delete恢复 若没有 则添加
     foreach (GeneralPrivTemplate oCopyPrivTemplate in GeneralPrivTemplateList)
     {
         MemberPrivilege oOldMemberPriv = oOldMemberPrivilegeList.Where(m => m.Ptype == oCopyPrivTemplate.Ptype).FirstOrDefault();
         bool bHasBefore = oOldMemberPriv == null ? false : true;
         if (bHasBefore)//之前有权限,则恢复数据
         {
             oOldMemberPriv.Deleted = false;
             oOldMemberPriv.Pstatus = oCopyPrivTemplate.Pstatus;
             oOldMemberPriv.Remark = oCopyPrivTemplate.Remark;
             List<GeneralPrivItem> oCopyGeneralPrivItemList = dbEntity.GeneralPrivItems.Where(g => g.Deleted == false && g.PrivID == oCopyPrivTemplate.Gid).ToList();//待COPY的子表
             foreach (GeneralPrivItem oCopyGeneralPrivItem in oCopyGeneralPrivItemList)
             {
                 MemberPrivItem oOldMemberPrivItem = dbEntity.MemberPrivItems.Where(m => m.PrivID == oOldMemberPriv.Gid && m.RefID == oCopyGeneralPrivItem.RefID).FirstOrDefault();
                 if (oOldMemberPrivItem != null)//子表 之前有 则恢复
                 {
                     oOldMemberPrivItem.Deleted = false;
                     oOldMemberPrivItem.NodeCode = oCopyGeneralPrivItem.NodeCode;
                     oOldMemberPrivItem.NodeValue = oCopyGeneralPrivItem.NodeValue;
                     oOldMemberPrivItem.Remark = oCopyGeneralPrivItem.Remark;
                 }
                 else//子表之前没有 则添加
                 {
                     MemberPrivItem oNewPrivItem = new MemberPrivItem
                     {
                         PrivID = oOldMemberPriv.Gid,
                         RefID = oCopyGeneralPrivItem.RefID,
                         NodeCode = oCopyGeneralPrivItem.NodeCode,
                         NodeValue = oCopyGeneralPrivItem.NodeValue,
                         Remark = oCopyGeneralPrivItem.Remark
                     };
                     dbEntity.MemberPrivItems.Add(oNewPrivItem);
                 }
             }
         }
         else//之前没有,则添加
         {
             MemberPrivilege oNewPriv = new MemberPrivilege
             {
                 UserID = UserID,
                 Ptype = oCopyPrivTemplate.Ptype,
                 Pstatus = oCopyPrivTemplate.Pstatus,
                 Remark = oCopyPrivTemplate.Remark
             };
             dbEntity.MemberPrivileges.Add(oNewPriv);
             dbEntity.SaveChanges();
             List<GeneralPrivItem> oCopyGeneralPrivItemList = dbEntity.GeneralPrivItems.Where(g => g.Deleted == false && g.PrivID == oCopyPrivTemplate.Gid).ToList();
             foreach (GeneralPrivItem oCopyGeneralPrivItem in oCopyGeneralPrivItemList)
             {
                 MemberPrivItem oNewPrivItem = new MemberPrivItem {
                     PrivID = oNewPriv.Gid,
                     RefID = oCopyGeneralPrivItem.RefID,
                     NodeCode = oCopyGeneralPrivItem.NodeCode,
                     NodeValue = oCopyGeneralPrivItem.NodeValue,
                     Remark = oCopyGeneralPrivItem.Remark
                 };
                 dbEntity.MemberPrivItems.Add(oNewPrivItem);
             }
         }
     }
     dbEntity.SaveChanges();
     return true;
 }
Ejemplo n.º 13
0
        /// <summary>
        /// 保存Node的内容到数据库
        /// </summary>
        /// <returns></returns>
        public ActionResult Save(string matter)
        {
            //MemberPrivilege表中授权主记录
            Guid gPrivID = (from o in dbEntity.MemberPrivileges
                                               where (o.Ptype == 1 && o.Deleted == false && o.UserID == gUserID)
                                               select o.Gid).SingleOrDefault();
            //授权的程序节点
            GeneralProgNode oNode = (from p in dbEntity.GeneralProgNodes
                                    where(p.Gid == ProgNodeID && p.Deleted ==false)
                                    select p).SingleOrDefault ();
            //是否对该程序节点授权过
            MemberPrivItem oMemberPrivItem = (from i in dbEntity.MemberPrivItems
                                              where (i.RefID == ProgNodeID && i.PrivID == gPrivID)
                                              select i).FirstOrDefault();
            //第一次对该程序节点授权
            if (oMemberPrivItem == null)
            {

                MemberPrivItem oMemPrivItem = new MemberPrivItem();
                oMemPrivItem.PrivID = gPrivID;
                oMemPrivItem.RefID = ProgNodeID;
                oMemPrivItem.NodeCode = oNode.Code;
                oMemPrivItem.NodeValue = matter;
                dbEntity.MemberPrivItems.Add(oMemPrivItem);
                dbEntity.SaveChanges();

            }
            //进行授权后,又进行编辑
            else
            {
                oMemberPrivItem.Deleted = false;
                oMemberPrivItem.NodeValue = matter;
                dbEntity.SaveChanges();

            }
            return View("PrivProgramNodeList");
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 供应商授权
        /// </summary>
        /// <returns></returns>
        public ActionResult PrivSupplier(Guid? id=null)
        {
            if (!base.CheckPrivilege("EnableEdit"))//权限验证
                return RedirectToAction("ErrorPage", "Home", new { message = "Sorry you have no privilege to visit the Page" });
            if (id == null)
            {
                int nstatus;
                MemberPrivilege PrivID = (from o in dbEntity.MemberPrivileges where (o.Deleted == false && o.UserID == gUserID && o.Ptype == (byte)ModelEnum.UserPrivType.SUPPLIER_CATEGORY) select o).FirstOrDefault();
                if (PrivID != null)
                {
                    nstatus = (int)PrivID.Pstatus;
                }
                else nstatus = -1;
                ViewBag.status = nstatus;
                Guid gUserOrgID = (from o in dbEntity.MemberUsers where (o.Gid == gUserID && o.Deleted == false) select o.OrgID).Single();
                List<SelectListItem> list = new List<SelectListItem>();
                //组织下拉框
                ViewData["Orglist"] = GetGuserSupportOrganizations();
            }
            else
            {
                Guid gPrivID;
                MemberPrivilege PrivID = (from o in dbEntity.MemberPrivileges where (o.UserID == gUserID && o.Ptype == (byte)ModelEnum.UserPrivType.SUPPLIER_CATEGORY) select o).FirstOrDefault();
                //主表中存在授权记录
                if (PrivID != null && PrivID.Deleted == false)
                {
                    if (PrivID.Pstatus == 0)
                    {
                        PrivID.Pstatus = 1;
                        dbEntity.SaveChanges();
                    }
                    gPrivID = PrivID.Gid;

                }
                //主表中的授权记录被删除,恢复记录
                else if (PrivID != null && PrivID.Deleted == true)
                {
                    PrivID.Deleted = false;
                    if (PrivID.Pstatus == 0) PrivID.Pstatus = 1;
                    dbEntity.SaveChanges();
                    gPrivID = PrivID.Gid;
                }
                //主表中不存在授权记录
                else
                {
                    MemberPrivilege oMemPriv = new MemberPrivilege();
                    oMemPriv.UserID = gUserID;
                    oMemPriv.Ptype = 6;
                    oMemPriv.Pstatus = 1;
                    dbEntity.MemberPrivileges.Add(oMemPriv);
                    dbEntity.SaveChanges();
                    gPrivID = oMemPriv.Gid;
                }
                if (!id.Equals(Guid.Empty))
                {
                    MemberPrivItem oSupItem = (from o in dbEntity.MemberPrivItems
                                               where (o.PrivID == gPrivID && o.RefID == id)
                                               select o).FirstOrDefault();
                    //从表中存在这条记录,但已经逻辑删除,恢复记录
                    if (oSupItem != null && oSupItem.Deleted == true)
                    {
                        oSupItem.Deleted = false;
                        dbEntity.SaveChanges();
                    }
                    //不存在记录,添加
                    if (oSupItem == null)
                    {
                        MemberPrivItem oSupItem1 = new MemberPrivItem();
                        oSupItem1.PrivID = gPrivID;
                        oSupItem1.RefID = id;
                        dbEntity.MemberPrivItems.Add(oSupItem1);
                        dbEntity.SaveChanges();
                    }
                }
                return RedirectToAction("PrivSupplier");
            }
            return View();
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 程序授权
        /// </summary>
        /// <returns></returns>
        public ActionResult PrivProgram(Guid? id=null)
        {
            if (!base.CheckPrivilege("EnableEdit"))//权限验证
                return RedirectToAction("ErrorPage", "Home", new { message = "Sorry you have no privilege to visit the Page" });
            if (id == null)
            {
                int nstatus;
                MemberPrivilege oPri = (from o in dbEntity.MemberPrivileges where (o.UserID == gUserID && o.Deleted == false && o.Ptype == (byte)ModelEnum.UserPrivType.PROGRAM) select o).FirstOrDefault();
                if (oPri != null)
                {
                    nstatus = oPri.Pstatus;
                }
                else nstatus = -1;
                ViewBag.status = nstatus;
            }
            else//保存授权程序
            {
                Guid gPrivID = new Guid();
                Guid gid = (Guid)id;
                MemberPrivilege oMemberPrivilege = (from o in dbEntity.MemberPrivileges where (o.Ptype == 0 && o.UserID == gUserID) select o).FirstOrDefault();
                //已存在对程序授权的主记录
                if (oMemberPrivilege != null && oMemberPrivilege.Deleted == false)
                {
                    if (oMemberPrivilege.Pstatus == 0)
                    {
                        oMemberPrivilege.Pstatus = 1;
                        dbEntity.SaveChanges();
                    }
                    gPrivID = oMemberPrivilege.Gid;
                }
                if (oMemberPrivilege != null && oMemberPrivilege.Deleted == true)
                {
                    if (oMemberPrivilege.Pstatus == 0) oMemberPrivilege.Pstatus = 1;
                    oMemberPrivilege.Deleted = false;
                    dbEntity.SaveChanges();
                    gPrivID = oMemberPrivilege.Gid;
                }
                if (oMemberPrivilege == null)
                {
                    MemberPrivilege oMemPriv = new MemberPrivilege();
                    oMemPriv.Ptype = 0;
                    oMemPriv.UserID = gUserID;
                    oMemPriv.Pstatus = 1;
                    dbEntity.MemberPrivileges.Add(oMemPriv);
                    dbEntity.SaveChanges();
                    gPrivID = oMemPriv.Gid;
                }
                //是否存在对该程序的授权记录
                MemberPrivItem oMemberPrivItem = (from o in dbEntity.MemberPrivItems where (o.PrivID == gPrivID && o.RefID == gid) select o).FirstOrDefault();
                if (oMemberPrivItem != null && oMemberPrivItem.Deleted == true)
                {
                    oMemberPrivItem.Deleted = false;
                    dbEntity.SaveChanges();
                }
                if (oMemberPrivItem == null)
                {
                    MemberPrivItem oMemPrivItem = new MemberPrivItem();
                    oMemPrivItem.PrivID = gPrivID;
                    oMemPrivItem.RefID = gid;
                    dbEntity.MemberPrivItems.Add(oMemPrivItem);
                    dbEntity.SaveChanges();
                }

                //如果该程序Terminal=true,保存程序节点授权主记录
                GeneralProgram oGeneralProgram = (from o in dbEntity.GeneralPrograms where (o.Gid == gid && o.Deleted == false) select o).SingleOrDefault();
                if (oGeneralProgram != null)
                {
                    if (oGeneralProgram.Terminal == true)
                    {
                        MemberPrivilege oMemPrivilege = (from o in dbEntity.MemberPrivileges where (o.Ptype == 1 && o.UserID == gUserID) select o).FirstOrDefault();
                        if (oMemPrivilege == null)
                        {
                            MemberPrivilege oNodeMemberPrivilege = new MemberPrivilege();
                            oNodeMemberPrivilege.UserID = gUserID;
                            oNodeMemberPrivilege.Ptype = 1;
                            oNodeMemberPrivilege.Pstatus = 1;
                            dbEntity.MemberPrivileges.Add(oNodeMemberPrivilege);
                            dbEntity.SaveChanges();
                        }
                        if (oMemPrivilege != null && oMemPrivilege.Deleted == true)
                        {
                            if (oMemPrivilege.Pstatus == 0) oMemPrivilege.Pstatus = 1;
                            oMemPrivilege.Deleted = false;
                            dbEntity.SaveChanges();
                        }
                    }
                }
                return RedirectToAction("PrivProgram");
            }
            return View();
        }