public override List <string> queryActorRoles(string actor_id)
        {
            // 查詢指定使用者{動作者}的權限清單
            // 如果使用者為動作者的話,會包含其所屬{動作者、部門、群組}權限與動作者所屬部門所屬群組權限
            var qry       = new NsDbQuery();
            var actor_ids = new List <string>();

            var rowe = NsDmHelper.EO_Employee.wherepk(actor_id).queryFirst();

            if (rowe != null)
            {
                #region [動作者]
                //動作者所屬部門、群組
                qry.setSelect(s =>
                {
                    var t1  = s.from <EO_DeptMember>();
                    s.Where = t1.EODM_MemberId == actor_id.toConstReq1();
                    s.select(t1.EODM_DeptId);
                });
                var keys1 = qry.queryKeys <string>();

                //部門所屬群組
                qry.setSelect(s =>
                {
                    var t1  = s.from <EO_DeptMember>();
                    s.Where = t1.EODM_MemberId.batchin(keys1.toConstReq1());
                    s.select(t1.EODM_DeptId);
                });
                var keys2 = qry.queryKeys <string>();

                //得到 部門 群組
                actor_ids = keys1.Union(keys2).Distinct().ToList();
                #endregion
            }
            else
            {
                #region [部門、群組]
                //部門所屬群組
                qry.setSelect(s =>
                {
                    var t1  = s.from <EO_DeptMember>();
                    s.Where = t1.EODM_MemberId == actor_id.toConstReq1();
                    s.select(t1.EODM_DeptId);
                });
                var keys1 = qry.queryKeys <string>();
                keys1.Add(actor_id);

                //得到 部門 群組
                actor_ids = keys1;
                #endregion
            }
            return(actor_ids);
        }
        /// <summary>
        /// 查詢動作者{人、部門、群組}所擁有的權限(不及物)
        /// </summary>
        public override List <string> queryActorsPremissons(List <string> actor_ids)
        {
            var qry = new NsDbQuery();

            //動作者所擁有的權限
            qry.setSelect(s =>
            {
                var t1 = s.from <EO_PermissionSetting>();
                var t2 = s.join <EO_Permission>()
                         .on(t => t.EOP_PermissionId == t1.EOPS_PermissionId);
                s.select(t2.EOP_PermissionCode);
                s.Where =
                    t1.EOPS_PermissionUserId.batchin(actor_ids.toConstReq1())
                    & t2.EOP_IsObjectNeed == "N" //免物件
                ;
                s.groupBy(t2.EOP_PermissionCode);
                s.unionAll(_s =>
                {
                    var _t1  = _s.from <EO_Permission>();
                    _s.Where = _t1.EOP_IsEveryOneAllow == "Y";
                    _s.select(_t1.EOP_PermissionCode);
                });
            });
            var names = qry.queryKeys <string>().Distinct().ToList();

            return(names);
        }
Esempio n. 3
0
        /// <summary>
        /// 查詢指定使用者的權限清單
        /// 如果使用者為人員的話,會包含其所屬部門權限
        /// </summary>
        public EO_PermissionSettingDataTable queryPermissionSettingsForUserId(string userId, string[] extendFieldNames)
        {
            //取得人員與其所屬群組代號
            List <string> userIds = new List <string>();
            var           qry     = new NsDbQuery();

            qry.setSelect(s3 =>
            {
                var t11 = s3.from <EO_PermissionSetting>();
                s3.select(t11.EOPS_PermissionSettingId);
                s3.Where = qry.inquery(t11.EOPS_PermissionUserId,
                                       s2 =>
                {
                    s2.fromEmpty(AppDataName.EO);
                    s2.select(userId.toConst().As("UserId"));
                    s2.Where = userId.toConstReq1() != "";
                    s2.union(s =>
                    {
                        var t1 = s.from <EO_DeptMember>();
                        s.select(t1.EODM_DeptId);
                        s.Where = t1.EODM_MemberId == userId.toConstReq(userId.StartsWith("EOE_"))
                        ;
                        s.groupBy(t1.EODM_DeptId);
                    });
                });
            });

            var keys = qry.queryKeys <string>();
            var dt   = NsDmHelper.EO_PermissionSetting
                       .selectAll(extendFieldNames)
                       .where (t0 => t0.EOPS_PermissionSettingId.batchin(keys.toConstReq1()))
                       .query();

            return(dt);
        }
Esempio n. 4
0
        /// <summary>
        /// 修正人員部門為群組者
        /// </summary>
        public static void step2()
        {
            var qry = new NsDbQuery();

            qry.setSelect(s => {
                var t1 = s.from <EO_Employee>();
                var t2 = s.join <EO_Department>()
                         .on(t => t1.EOE_DepartmentId == t.EOD_DepartmentId);
                s.Where = t2.EOD_DepartmentType == "B";
                s.select(t1.EOE_EmployeeId);
            });
            var pks = qry.queryKeys <string>();

            var dt = NsDmHelper.EO_Employee.wherepks(pks).query();

            foreach (var row in dt)
            {
                row.EOE_DepartmentId = "";
            }
            dt.ns_update();
        }
Esempio n. 5
0
        protected override void onSchemaLoaded()
        {
            addTypedCalcHandler()
            .setColumns(AppDataName.EOMS_NodeType_XX)
            .setReferences(AppDataName.EOMS_ParentId)
            .setHandler(dt => {
                foreach (var row in dt)
                {
                    if (row.EOMS_ParentId.isNullOrEmpty())
                    {
                        row.EOMS_NodeType_XX = "A";
                    }
                }
                var rows2 = dt.Where(x => x.EOMS_NodeType_XX.isNullOrEmpty()).Select(x => x).ToArray();
                var pks   = rows2.Select(x => x.EOMS_NodeId).ToArray();
                var qry   = new NsDbQuery();
                qry.setSelect(s => {
                    var t1 = s.from <EO_MenuStruct>();
                    s.select(t1.EOMS_ParentId);
                    s.Where = t1.EOMS_ParentId.batchin(pks.toConstReq1());
                    s.groupBy(t1.EOMS_ParentId);
                });

                //有子的節點
                var pks2 = qry.queryKeys <string>().ToDictionary(x => x);

                foreach (var row2 in rows2)
                {
                    row2.EOMS_NodeType_XX = pks2.ContainsKey(row2.EOMS_NodeId) ? "B" : "C";
                }
            });

            addTypedCalcHandler()
            .setColumns(AppDataName.EOMS_MatchSiteId_XX)
            .setReferences(AppDataName.EOMS_ClickMode, AppDataName.EOMS_Url)
            .setHandler(dt => {
                //var qry = new NsDbQuery();
                //qry.setSelect(s => {
                //    var t1 = s.from<EO_SignSite>();
                //    s.select(t1.EOSS_SiteId, t1.EOSS_FilterUrl1, t1.EOSS_FilterUrl2);
                //    s.Where = t1.EOSS_FilterUrl1 != "" | t1.EOSS_FilterUrl2 != "";
                //});
                //var dt1 = qry.queryData<EO_SignSiteDataTable>();

                //foreach (var row in dt)
                //{
                //    if (row.EOMS_ClickMode != "U" || row.EOMS_Url.isNullOrEmpty())
                //        continue;

                //    foreach (var row1 in dt1)
                //    {
                //        if (!row1.EOSS_FilterUrl1.isNullOrEmpty())
                //        {
                //            if (row.EOMS_Url.StartsWith(row1.EOSS_FilterUrl1, true, CultureInfo.InvariantCulture))
                //            {
                //                row.EOMS_MatchSiteId_XX = row1.EOSS_SiteId;
                //                break;
                //            }
                //        }

                //        if (!row1.EOSS_FilterUrl2.isNullOrEmpty())
                //        {
                //            if (row.EOMS_Url.StartsWith(row1.EOSS_FilterUrl2, true, CultureInfo.InvariantCulture))
                //            {
                //                row.EOMS_MatchSiteId_XX = row1.EOSS_SiteId;
                //                break;
                //            }
                //        }
                //    }
                //}
            });

            addTypedCalcHandler()
            .setColumns(AppDataName.EOMS_ChildCount_XX
                        , AppDataName.EOMS_BrotherCount_XX
                        , AppDataName.EOMS_RootId_XX
                        , AppDataName.EOMS_LevelNo_XX
                        , AppDataName.EOMS_TreeLeftNo_XX
                        , AppDataName.EOMS_TreeRightNo_XX
                        )
            .setReferences(AppDataName.EOMS_ParentId)
            .setHandler(dt => {
                var qry = new NsDbQuery();
                //調出全部的結構
                qry.setSelect(s => {
                    var t1 = s.from <EO_MenuStruct>();
                    s.select(t1.EOMS_NodeId, t1.EOMS_ParentId, t1.EOMS_SortNo);
                    //s.Where = t1.EOMS_Viewable == "Y";
                });
                var dt1 = qry.queryData <EO_MenuStructDataTable>();

                //計算樹結構
                FtdDataHelper.TableTree.calcTreeNo(dt1, "X_TreeNo1", "X_TreeNo2", "X_Level",
                                                   dt11 => dt11.Where(x => x.EOMS_ParentId.isNullOrEmpty()).Select(x => x)
                                                   , (dt11, row11) =>
                {
                    var pk = ((EO_MenuStructRow)row11).EOMS_NodeId;
                    return(dt11.Where(x => x.EOMS_ParentId == pk));
                }
                                                   );

                var keys = dt1
                           .GroupBy(x => x.EOMS_ParentId.nullOrEmptyAs("@"))
                           .Select(x => new { ID = x.Key, ChildCount = x.Count() })
                           .ToDictionary(x => x.ID);

                var roots = dt1.Where(x => x.EOMS_ParentId.isNullOrEmpty()).Select(x => x).ToArray();

                //計算結點的資訊
                foreach (var row in dt)
                {
                    //if (!row.EOMS_Viewable.equalIgnoreCase("Y"))
                    //{
                    //    //row.EOMS_RootId_XX = root.EOMS_NodeId;
                    //    //row.EOMS_LevelNo_XX = level;
                    //    //row.EOMS_TreeLeftNo_XX = no1;
                    //    //row.EOMS_TreeRightNo_XX = no2;
                    //    continue;
                    //}

                    var key = keys.findKey(row.EOMS_NodeId);
                    //1
                    if (row.EOMS_ParentId.isNullOrEmpty())
                    {
                        row.EOMS_NodeType_XX = "A";
                    }
                    else
                    {
                        row.EOMS_NodeType_XX = key != null ? "B" : "C";
                    }

                    //2
                    var pkey = keys.findKey(row.EOMS_ParentId.nullOrEmptyAs("@"));
                    row.EOMS_BrotherCount_XX = (pkey == null) ? 0 : pkey.ChildCount;

                    //3
                    if (key != null)
                    {
                        row.EOMS_ChildCount_XX = key.ChildCount;
                    }
                    else
                    {
                        row.EOMS_ChildCount_XX = 0;
                    }

                    //4
                    var row1                = dt1.findByPrimaryKey(row.EOMS_NodeId);
                    var no1                 = row1.getInt("X_TreeNo1").Value;
                    var no2                 = row1.getInt("X_TreeNo2").Value;
                    var level               = row1.getInt("X_Level").Value;
                    var root                = roots.Where(x => no1 >= x.getInt("X_TreeNo1").Value&& no2 <= x.getInt("X_TreeNo2").Value).First();
                    row.EOMS_RootId_XX      = root.EOMS_NodeId;
                    row.EOMS_LevelNo_XX     = level;
                    row.EOMS_TreeLeftNo_XX  = no1;
                    row.EOMS_TreeRightNo_XX = no2;
                }
            });

            base.onSchemaLoaded();
        }