Esempio n. 1
0
        public static bool IsPriceCorrect(string strPrice)
        {
            if (string.IsNullOrEmpty(strPrice))
            {
                return(false);
            }

#if NO
            string       strError = "";
            CurrencyItem item     = null;
            // 解析单个金额字符串。例如 CNY10.00 或 -CNY100.00/7
            int nRet = PriceUtil.ParseSinglePrice(strPrice,
                                                  out item,
                                                  out strError);
            if (nRet == -1)
            {
                return(false);
            }

            return(true);
#endif
            if (VerifyPrice(strPrice).Count > 0)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        internal static int ParsePriceString(string strPrice,
                                             out decimal value,
                                             out string strUnit,
                                             out string strError)
        {
            value    = 0;
            strUnit  = "";
            strError = "";

            if (string.IsNullOrEmpty(strPrice) == true)
            {
                return(0);
            }

            // 解析单个金额字符串。例如 CNY10.00 或 -CNY100.00/7
            int nRet = PriceUtil.ParseSinglePrice(strPrice,
                                                  out CurrencyItem item,
                                                  out strError);

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

            strUnit = item.Prefix + item.Postfix;
            value   = item.Value;
            return(0);
        }
Esempio n. 3
0
        // 校验价格
        public static List <string> VerifyPrice(string strPrice)
        {
            List <string> errors = new List <string>();

            // 解析单个金额字符串。例如 CNY10.00 或 -CNY100.00/7
            int nRet = PriceUtil.ParseSinglePrice(strPrice,
                                                  out CurrencyItem item,
                                                  out string strError);

            if (nRet == -1)
            {
                errors.Add(strError);
            }

            // 2020/7/8
            // 检查货币字符串中是否出现了字母以外的字符
            if (string.IsNullOrEmpty(item.Postfix) == false)
            {
                errors.Add($"金额字符串 '{strPrice}' 中出现了后缀 '{item.Postfix}' ,这很不常见,一般意味着错误");
            }

            string error1 = VerifyPricePrefix(item.Prefix);

            if (error1 != null)
            {
                errors.Add(error1);
            }

            string new_value = StringUtil.ToDBC(strPrice);

            if (new_value.IndexOfAny(new char[] { '(', ')' }) != -1)
            {
                errors.Add("价格字符串中不允许出现括号 '" + strPrice + "'");
            }

            if (new_value.IndexOf(',') != -1)
            {
                errors.Add("价格字符串中不允许出现逗号 '" + strPrice + "'");
            }

            return(errors);
        }
Esempio n. 4
0
        /// <summary>
        /// 结束前的校验
        /// </summary>
        /// <param name="strError">返回错误信息</param>
        /// <returns>-1: 出错; 0: 没有错误</returns>
        internal override int FinishVerify(out string strError)
        {
            strError = "";
            int nRet = 0;

            // TODO: 将来这里要允许使用整个 location 字符串,而不仅仅是馆代码,来发起条码号校验
            string strLocation    = this.entityEditControl_editing.LocationString;
            string strLibraryCode = Global.GetLibraryCode(StringUtil.GetPureLocation(strLocation));

            string strBarcode = this.entityEditControl_editing.Barcode;

            // 检查册条码号形式是否合法
            if (String.IsNullOrEmpty(strBarcode) == false && // 2009/2/23
                this.EntityControl != null &&
                this.EntityControl.NeedVerifyItemBarcode == true)
            {
                // 形式校验条码号
                // return:
                //      -2  服务器没有配置校验方法,无法校验
                //      -1  error
                //      0   不是合法的条码号
                //      1   是合法的读者证条码号
                //      2   是合法的册条码号
                nRet = this.EntityControl.DoVerifyBarcode(
                    string.IsNullOrEmpty(Program.MainForm.BarcodeValidation) ? strLibraryCode : strLocation,    // 2019/7/12
                    strBarcode,
                    out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                // 输入的条码格式不合法
                if (nRet == 0)
                {
                    strError = "您输入的条码 " + strBarcode + " 格式不正确(" + strError + ")。请重新输入。";
                    goto ERROR1;
                }

                // 实际输入的是读者证条码号
                if (nRet == 1)
                {
                    strError = "您输入的条码号 " + strBarcode + " 是读者证条码号。请输入册条码号。";
                    goto ERROR1;
                }

                // 对于服务器没有配置校验功能,但是前端发出了校验要求的情况,警告一下
                if (nRet == -2)
                {
                    MessageBox.Show(this, "警告:前端册管理窗开启了校验条码功能,但是服务器端缺乏相应的脚本函数,无法校验条码。\r\n\r\n若要避免出现此警告对话框,请关闭前端册管理窗校验功能");
                }
            }

            // 馆藏地点字符串里面不能有星号
            // string strLocation = this.entityEditControl_editing.LocationString;
            if (strLocation.IndexOf("*") != -1)
            {
                strError = "馆藏地点字符串中不允许出现字符 '*'";
                goto ERROR1;
            }

            // 价格字符串中不允许出现 @
            string strPrice = this.entityEditControl_editing.Price;

            if (strPrice.IndexOf("@") != -1)
            {
                strError = "价格字符串中不允许出现字符 '@'";
                goto ERROR1;
            }

            if (string.IsNullOrEmpty(strPrice) == false)
            {
                CurrencyItem item = null;
                // 解析单个金额字符串。例如 CNY10.00 或 -CNY100.00/7
                nRet = PriceUtil.ParseSinglePrice(strPrice,
                                                  out item,
                                                  out strError);
                if (nRet == -1)
                {
                    strError = "价格字符串格式不合法: " + strError;
                    goto ERROR1;
                }
            }

            string strIssueDbName = "";

            if (string.IsNullOrEmpty(this.BiblioDbName) == false)
            {
                strIssueDbName = Program.MainForm.GetIssueDbName(this.BiblioDbName);
            }

            if (string.IsNullOrEmpty(strIssueDbName) == false)
            {
                // 2014/10/23
                if (string.IsNullOrEmpty(this.entityEditControl_editing.PublishTime) == false)
                {
                    // 检查出版时间范围字符串是否合法
                    // 如果使用单个出版时间来调用本函数,也是可以的
                    // return:
                    //      -1  出错
                    //      0   正确
                    nRet = LibraryServerUtil.CheckPublishTimeRange(this.entityEditControl_editing.PublishTime,
                                                                   out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }
                }

                // 2014/10/23
                if (string.IsNullOrEmpty(this.entityEditControl_editing.Volume) == false)
                {
                    List <VolumeInfo> infos = null;
                    nRet = VolumeInfo.BuildVolumeInfos(this.entityEditControl_editing.Volume,
                                                       out infos,
                                                       out strError);
                    if (nRet == -1)
                    {
                        strError = "卷期字符串 '" + this.entityEditControl_editing.Volume + "' 格式错误: " + strError;
                        goto ERROR1;
                    }
                }
            }

            return(0);

ERROR1:
            return(-1);
        }
Esempio n. 5
0
        internal static int ParsePriceString(string strPrice,
                                             out long value,
                                             out string strUnit,
                                             out string strError)
        {
            value    = 0;
            strUnit  = "";
            strError = "";

            if (string.IsNullOrEmpty(strPrice) == true)
            {
                return(0);
            }

#if NO
            string strPrefix  = "";
            string strValue   = "";
            string strPostfix = "";

            // 分析价格参数
            // 允许前面出现+ -号
            // return:
            //      -1  出错
            //      0   成功
            int nRet = PriceUtil.ParsePriceUnit(strPrice,
                                                out strPrefix,
                                                out strValue,
                                                out strPostfix,
                                                out strError);
            if (nRet == -1)
            {
                return(-1);
            }
            strUnit = strPrefix + strPostfix;
            decimal v = 0;
            if (decimal.TryParse(strValue, out v) == false)
            {
                strError = "金额字符串 '" + strPrice + "' 中数字部分 '" + strValue + "' 格式不正确";
                return(-1);
            }
#endif
            CurrencyItem item = null;
            // 解析单个金额字符串。例如 CNY10.00 或 -CNY100.00/7
            int nRet = PriceUtil.ParseSinglePrice(strPrice,
                                                  out item,
                                                  out strError);
            if (nRet == -1)
            {
                return(-1);
            }

            strUnit = item.Prefix + item.Postfix;
            try
            {
                value = (long)(item.Value * 100);
            }
            catch (Exception ex)
            {
                // 2016/3/31
                strError = "元值 '" + item.Value.ToString() + "' 折算为分值的时候出现异常:" + ex.Message;
                return(-1);
            }
            return(0);
        }