Example #1
0
        // 从 source 中复制 count 个元素构成一个新的 collection
        // 注: 若 source 中元素少于 count,则有多少复制多少
        // 注:本函数为浅复制。即结果集合中的元素也是源集合中的元素
        public static LocationCollection CopyItems(LocationCollection source, int count)
        {
            LocationCollection result = new LocationCollection();
            int i = 0;

            foreach (Location location in source)
            {
                result.Add(location);
                i++;
                if (i >= count)
                {
                    break;
                }
            }

            return(result);
        }
Example #2
0
        // 合并两个馆藏地点字符串
        public static int MergeTwoLocationString(string strLocationString1,
                                                 string strLocationString2,
                                                 bool bOutputID,
                                                 out string strLocationString,
                                                 out string strError)
        {
            strError          = "";
            strLocationString = "";

            LocationCollection items_1 = new LocationCollection();
            int nRet = items_1.Build(strLocationString1,
                                     out strError);

            if (nRet == -1)
            {
                return(-1);
            }

            LocationCollection items_2 = new LocationCollection();

            nRet = items_2.Build(strLocationString2,
                                 out strError);
            if (nRet == -1)
            {
                return(-1);
            }

            LocationCollection items = new LocationCollection();

            items.AddRange(items_1);
            items.AddRange(items_2);

            // 归并。让相同的事项靠近。和排序不同,它不改变已有的基本的序。
            // return:
            //      0   unchanged
            //      1   changed
            items.Merge();

            strLocationString = items.ToString(bOutputID);

            return(0);
        }
Example #3
0
        // 观察一个馆藏分配字符串,看看是否在指定用户权限的管辖范围内
        // parameters:
        // return:
        //      -1  出错
        //      0   超过管辖范围。strError中有解释
        //      1   在管辖范围内
        public static int DistributeInControlled(string strDistribute,
                                                 string strLibraryCodeList,
                                                 out string strError)
        {
            strError = "";

            //      bNarrow 如果为 true,表示 馆代码 "" 只匹配总馆,不包括各个分馆;如果为 false,表示 馆代码 "" 匹配总馆和所有分馆
            bool bNarrow = strLibraryCodeList == "[仅总馆]";

            if (strLibraryCodeList == "[仅总馆]")
            {
                strLibraryCodeList = "";
            }

            if (bNarrow == false && IsGlobalUser(strLibraryCodeList) == true)
            {
                return(1);
            }

            // 2018/5/9
            if (string.IsNullOrEmpty(strDistribute))
            {
                // 去向分配字符串为空,表示谁都可以控制它。这样便于分馆用户修改。
                // 若这种情况返回 0,则分馆用户修改不了,只能等总馆用户才有权限修改
                return(1);
            }

            LocationCollection locations = new LocationCollection();
            int nRet = locations.Build(strDistribute, out strError);

            if (nRet == -1)
            {
                strError = "馆藏分配字符串 '" + strDistribute + "' 格式不正确";
                return(-1);
            }

            foreach (Location location in locations)
            {
                // 空的馆藏地点被视为不在分馆用户管辖范围内
                if (bNarrow == false && string.IsNullOrEmpty(location.Name) == true)
                {
                    strError = "馆代码 '' 不在范围 '" + strLibraryCodeList + "' 内";
                    return(0);
                }

                // 解析
                ParseCalendarName(location.Name,
                                  out string strLibraryCode,
                                  out string strPureName);

                if (string.IsNullOrEmpty(strLibraryCode) && string.IsNullOrEmpty(strLibraryCodeList))
                {
                    continue;
                }

                if (StringUtil.IsInList(strLibraryCode, strLibraryCodeList) == false)
                {
                    strError = "馆代码 '" + strLibraryCode + "' 不在范围 '" + strLibraryCodeList + "' 内";
                    return(0);
                }
            }

            return(1);
        }