コード例 #1
0
ファイル: VolumeInfo.cs プロジェクト: zhangandding/chord
        // 解析卷期范围序列。例如“2001,no.1-12=总.101-112=v.25*12”
        public static int BuildVolumeInfos(string strText,
                                           out List <VolumeInfo> infos,
                                           out string strError)
        {
            int nRet = 0;

            strError = "";
            infos    = new List <VolumeInfo>();

            string strYearString   = "";
            string strNoString     = "";
            string strVolumeString = "";
            string strZongString   = "";

            List <string> notdef_segments = new List <string>();

            string[] segments = strText.Split(new char[] { '=' });
            for (int i = 0; i < segments.Length; i++)
            {
                string strSegment = segments[i].Trim();
                if (String.IsNullOrEmpty(strSegment) == true)
                {
                    continue;
                }
                if (strSegment.IndexOf("y.") != -1)
                {
                    strYearString = strSegment;
                }
                else if (strSegment.IndexOf("no.") != -1)
                {
                    strNoString = strSegment;
                }
                else if (strSegment.IndexOf("v.") != -1)
                {
                    strVolumeString = strSegment;
                }
                else if (strSegment.IndexOf("总.") != -1)
                {
                    strZongString = strSegment;
                }
                else
                {
                    notdef_segments.Add(strSegment);
                }
            }

            // 2012/4/25
            // 当年期号序列很重要,如果缺了,光有总期号和卷号是不行的
            if (string.IsNullOrEmpty(strNoString) == true &&
                (string.IsNullOrEmpty(strZongString) == false || string.IsNullOrEmpty(strVolumeString) == false))
            {
                strError = "当年期号序列不能省却。'" + strText + "'";
                if (notdef_segments.Count > 0)
                {
                    strError += "。字符串中出现了无法识别的序列: " + StringUtil.MakePathList(notdef_segments, "=");
                }
                return(-1);
            }

            if (String.IsNullOrEmpty(strNoString) == false)
            {
                // 去掉"y."部分
                if (StringUtil.HasHead(strYearString, "y.") == true)
                {
                    strYearString = strYearString.Substring(2).Trim();
                }

                // 解析no.序列
                nRet = ExpandNoString(strNoString,
                                      strYearString,
                                      out infos,
                                      out strError);
                if (nRet == -1)
                {
                    strError = "解析序列 '" + strNoString + "' (年份'" + strYearString + "')时发生错误: " + strError;
                    return(-1);
                }
            }

            // 去掉"总."部分
            if (StringUtil.HasHead(strZongString, "总.") == true)
            {
                strZongString = strZongString.Substring(2).Trim();
            }

            if (String.IsNullOrEmpty(strZongString) == false)
            {
                List <string> zongs = null;

                try
                {
                    zongs = ExpandSequence(strZongString);
                }
                catch (Exception ex)
                {
                    strError = "总. 序列 '" + strZongString + "' 格式错误:" + ex.Message;
                    return(-1);
                }

                for (int i = 0; i < infos.Count; i++)
                {
                    VolumeInfo info = infos[i];
                    if (i < zongs.Count)
                    {
                        info.Zong = zongs[i];
                    }
                    else
                    {
                        break;
                    }
                }
            }

            // 去掉"v."部分
            if (StringUtil.HasHead(strVolumeString, "v.") == true)
            {
                strVolumeString = strVolumeString.Substring(2).Trim();
            }

            if (String.IsNullOrEmpty(strVolumeString) == false)
            {
                List <string> volumes = null;

                try
                {
                    volumes = ExpandSequence(strVolumeString);
                }
                catch (Exception ex)
                {
                    strError = "v.序列 '" + strVolumeString + "' 格式错误:" + ex.Message;
                    return(-1);
                }

                string strLastValue = "";
                for (int i = 0; i < infos.Count; i++)
                {
                    VolumeInfo info = infos[i];
                    if (i < volumes.Count)
                    {
                        info.Volume  = volumes[i];
                        strLastValue = info.Volume; // 记忆最后一个
                    }
                    else
                    {
                        info.Volume = strLastValue; // 沿用最后一个
                    }
                }
            }

            // 2015/5/8 如果 strText 内容为“绿笔采风”之类的,就无法分析出部件
            if (infos.Count == 0 && notdef_segments.Count > 0)
            {
                strError += "卷期范围字符串中出现了无法识别的序列: " + StringUtil.MakePathList(notdef_segments, "=");
                return(-1);
            }

            return(0);
        }
コード例 #2
0
ファイル: PriceUtil.cs プロジェクト: distinct2010/dp2
        public PriceUtil Operator(string strText, string strOperator)
        {
            int    nRet      = 0;
            string strError  = "";
            string strResult = "";

            if (strOperator == "*" || strOperator == "/")
            {
                if (string.IsNullOrEmpty(this._current) ||
                    string.IsNullOrEmpty(strText))
                {
                    throw new ArgumentException("乘法和除法运算要求两个操作数都不能为空");
                }

                string strString = this._current + strOperator + strText;
                nRet = SumPrices(strString,
                                 out strResult,
                                 out strError);
                if (nRet == -1)
                {
                    strError = strError + " (SumPrices)'" + strString + "'";
                    throw new Exception(strError);
                }
                this._current = strResult;
                return(this);
            }


            if (string.IsNullOrEmpty(strText))
            {
                return(this);
            }

            List <string> prices = new List <string>();
            string        s1     = "";

            nRet = SumPrices(this._current,
                             out s1,
                             out strError);
            if (nRet == -1)
            {
                strError = strError + " (SumPrices)'" + this._current + "'";
                throw new Exception(strError);
            }

            string s2 = "";

            if (strOperator == "-")
            {
                nRet = NegativePrices(strText,
                                      true,
                                      out s2,
                                      out strError);
                if (nRet == -1)
                {
                    strError = strError + " (NegativePrices)'" + strText + "'";
                    throw new Exception(strError);
                }
            }
            else
            {
                nRet = SumPrices(strText,
                                 out s2,
                                 out strError);
                if (nRet == -1)
                {
                    strError = strError + " (SumPrices)'" + strText + "'";
                    throw new Exception(strError);
                }
            }

            prices.Add(s1);
            prices.Add(s2);

            nRet = TotalPrice(prices,
                              out strResult,
                              out strError);
            if (nRet == -1)
            {
                strError = strError + " (TotalPrices)'" + StringUtil.MakePathList(prices) + "'";
                throw new Exception(strError);
            }
            this._current = strResult;
            return(this);
        }
コード例 #3
0
ファイル: PriceUtil.cs プロジェクト: distinct2010/dp2
        // 2012/3/7
        // 校验金额字符串格式正确性
        // return:
        //      -1  有错
        //      0   没有错
        public static int VerifyPriceFormat(
            List <string> valid_formats,
            string strString,
            out string strError)
        {
            strError = "";

            // 没有格式定义,就不作校验
            if (valid_formats.Count == 0)
            {
                return(0);
            }

            string strPrefix  = "";
            string strValue   = "";
            string strPostfix = "";

            int nRet = ParsePriceUnit(strString,
                                      out strPrefix,
                                      out strValue,
                                      out strPostfix,
                                      out strError);

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

            foreach (string fmt in valid_formats)
            {
                string[] parts            = fmt.Split(new char[] { '|' });
                string   strPrefixFormat  = "";
                string   strValueFormat   = "";
                string   strPostfixFormat = "";
                if (parts.Length > 0)
                {
                    strPrefixFormat = parts[0];
                }
                if (parts.Length > 1)
                {
                    strValueFormat = parts[1];
                }
                if (parts.Length > 2)
                {
                    strPostfixFormat = parts[2];
                }

                if (string.IsNullOrEmpty(strPrefixFormat) == false &&
                    strPrefix != strPrefixFormat)
                {
                    continue;
                }

                // 暂时不校验value部分

                if (string.IsNullOrEmpty(strPostfixFormat) == false &&
                    strPostfix != strPostfixFormat)
                {
                    continue;
                }

                return(0);
            }

            strError = "金额字符串 '" + strString + "' 的格式不符合定义 '" + StringUtil.MakePathList(valid_formats) + "' 的要求";
            return(-1);
        }
コード例 #4
0
        // 观察一个馆藏分配字符串,看看是否在指定用户权限的管辖范围内
        // parameters:
        // return:
        //      -1  出错
        //      0   超过管辖范围(至少出现一处超过范围)。strError中有解释
        //      1   在管辖范围内
        public static int DistributeInControlled(string strDistribute,
                                                 string strLibraryCodeList,
                                                 out bool bAllOutOf,
                                                 out string strError)
        {
            strError  = "";
            bAllOutOf = false;

            //      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);
            }

            List <string> outof_list = new List <string>();

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

                // 解析
                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;
                    outof_list.Add(strLibraryCode);
                }
            }

            if (outof_list.Count > 0)
            {
                strError = "馆代码 '" + StringUtil.MakePathList(outof_list) + "' 不在范围 '" + strLibraryCodeList + "' 内";
                if (outof_list.Count == locations.Count)
                {
                    bAllOutOf = true;
                }
                return(0);
            }

            return(1);
        }