コード例 #1
0
ファイル: PriceUtil.cs プロジェクト: distinct2010/dp2
        // 判断两个价格字符串是否相等
        public static bool IsEqual(string strPrice1, string strPrice2, string strDefaultPrefix = "CNY")
        {
            if (strPrice1 == strPrice2)
            {
                return(true);
            }

            try
            {
                CurrencyItem item1 = CurrencyItem.Parse(strPrice1);
                CurrencyItem item2 = CurrencyItem.Parse(strPrice2);
                if (string.IsNullOrEmpty(item1.Prefix))
                {
                    item1.Prefix = strDefaultPrefix;
                }
                if (string.IsNullOrEmpty(item2.Prefix))
                {
                    item2.Prefix = strDefaultPrefix;
                }
                if (item1.Prefix == item2.Prefix &&
                    item1.Value == item2.Value &&
                    item1.Postfix == item2.Postfix)
                {
                    return(true);
                }
                return(false);
            }
            catch
            {
                return(false);
            }
        }
コード例 #2
0
        // 检查订购价是否合法。注意,这是检查一个单个的订购价,即,内容中不允许包含 [] 符号
        // return:
        //      -1  校验过程出错
        //      0   校验正确
        //      1   校验发现错误
        public static int VerifyOrderPrice(string strPrice, out string strError)
        {
            strError = "";
            if (string.IsNullOrEmpty(strPrice))
            {
                return(1);
            }
            if (strPrice.IndexOfAny(new char[] { '[', ']' }) != -1)
            {
                strError = "校验价格字符串 '" + strPrice + "' 时出错:不应包含 [] 字符";
                return(-1);
            }

            try
            {
                CurrencyItem item = CurrencyItem.Parse(strPrice);
            }
            catch (Exception ex)
            {
                strError = "价格字符串 '" + strPrice + "' 不合法:" + ex.Message;
                return(1);
            }

            return(0);
        }