Esempio n. 1
0
        /*
         * ~~~~~~~
         * 乐山师院数据来源多,以前的种价格字段格式著录格式多样,有“CNY25.00元”、
         * “25.00”、“¥25.00元”、“¥25.00”、“CNY25.00”、“cny25.00”、“25.00
         * 元”等等,现在他们确定以后全采用“CNY25.00”格式著录。
         * CALIS中,许可重复010$d来表达价格实录和获赠或其它币种价格。所以,可能乐山
         * 师院也有少量的此类重复价格子字段的数据。
         * 为省成本,批处理或册信息编辑窗中,建议只管一个价格字段,别的都不管(如果
         * 没有价格字段,则转换为空而非零)。
         * 转换时,是否可以兼顾到用中文全角输入的数字如“25.00”或小数点是中文
         * 全解但标点选择的是英文标点如“.”?
         *
         * ~~~~
         * 处理步骤:
         * 1) 全部字符转换为半角
         * 2) 抽出纯数字部分
         * 3) 观察前缀或者后缀,如果有CNY cny ¥ 元等字样,可以确定为人民币。
         * 前缀和后缀完全为空,也可确定为人民币。
         * 否则,保留原来的前缀。         * */
        // 正规化价格字符串
        public static string CanonicalizePrice(string strPrice,
                                               bool bForceCNY)
        {
            // 全角字符变换为半角
            strPrice = Global.ConvertQuanjiaoToBanjiao(strPrice);

            if (bForceCNY == true)
            {
                // 提取出纯数字
                string strPurePrice = PriceUtil.GetPurePrice(strPrice);

                return("CNY" + strPurePrice);
            }

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

            int nRet = Global.ParsePriceUnit(strPrice,
                                             out strPrefix,
                                             out strValue,
                                             out strPostfix,
                                             out strError);

            if (nRet == -1)
            {
                return(strPrice);    // 无法parse
            }
            bool bCNY = false;

            strPrefix  = strPrefix.Trim();
            strPostfix = strPostfix.Trim();

            if (String.IsNullOrEmpty(strPrefix) == true &&
                String.IsNullOrEmpty(strPostfix) == true)
            {
                bCNY = true;
                goto DONE;
            }


            if (strPrefix.IndexOf("CNY") != -1 ||
                strPrefix.IndexOf("cny") != -1 ||
                strPrefix.IndexOf("CNY") != -1 ||
                strPrefix.IndexOf("cny") != -1 ||
                strPrefix.IndexOf('¥') != -1)
            {
                bCNY = true;
                goto DONE;
            }

            if (strPostfix.IndexOf("元") != -1)
            {
                bCNY = true;
                goto DONE;
            }

DONE:
            // 人民币
            if (bCNY == true)
            {
                return("CNY" + strValue);
            }

            // 其他货币
            return(strPrefix + strValue + strPostfix);
        }