Ejemplo n.º 1
0
        public void IsNumericTest()
        {
            Assert.True(RegexUtil.IsNumeric("1"));
            Assert.True(RegexUtil.IsNumeric("0.1"));
            Assert.True(RegexUtil.IsNumeric("-1"));
            Assert.True(RegexUtil.IsNumeric("-0.1"));
            Assert.True(RegexUtil.IsNumeric("+1"));
            Assert.True(RegexUtil.IsNumeric("+0.1"));

            Assert.False(RegexUtil.IsNumeric(" "));
            Assert.False(RegexUtil.IsNumeric(" 1"));
            Assert.False(RegexUtil.IsNumeric("1 "));
            Assert.False(RegexUtil.IsNumeric("a"));
            Assert.False(RegexUtil.IsNumeric("0.a"));
            Assert.False(RegexUtil.IsNumeric("-a"));
            Assert.False(RegexUtil.IsNumeric("0.1."));
            Assert.False(RegexUtil.IsNumeric("0.1.2"));
            Assert.False(RegexUtil.IsNumeric("--1"));
            Assert.False(RegexUtil.IsNumeric("++1"));
        }
Ejemplo n.º 2
0
        public JsonResult DoAddProductInfo()
        {
            string message = "操作失败,请与管理员联系";

            string productCategoryId = GetFormData("productCategory");
            Dictionary <string, ProductCategoryAttributesModel> catAttList = ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(productCategoryId, false);

            if (catAttList == null)
            {
                return(FailedJson("操作失败,不存在的产品类型ID"));
            }

            ProductInfoDomainModel productInfo = new ProductInfoDomainModel();

            productInfo.BasicInfo             = new ProductInfoModel();
            productInfo.BasicInfo.CategoryId  = productCategoryId;
            productInfo.BasicInfo.ProductId   = Guid.NewGuid().ToString();
            productInfo.BasicInfo.ProductCode = (GetFormData("productCode") == "AUTO" || GetFormData("productCode") == null) ? productInfo.BasicInfo.ProductId : GetFormData("productCode");
            productInfo.BasicInfo.ProductName = GetFormData("productName");
            productInfo.BasicInfo.SalesStatus = GetFormData("productSaleStatus");

            productInfo.AttributeList = new Dictionary <string, string>();

            string attValue = "";

            foreach (ProductCategoryAttributesModel item in catAttList.Values)
            {
                if (item.AttributeName == "产品代码")
                {
                    productInfo.AttributeList.Add(item.CategoryAttributeId, productInfo.BasicInfo.ProductCode);
                }
                else if (item.AttributeName == "产品名称")
                {
                    productInfo.AttributeList.Add(item.CategoryAttributeId, productInfo.BasicInfo.ProductName);
                }
                else if (item.AttributeName == "销售状态")
                {
                    productInfo.AttributeList.Add(item.CategoryAttributeId, productInfo.BasicInfo.SalesStatus);
                }
                else
                {
                    attValue = GetFormData(item.AttributeName);
                    if (item.IsRequest == 0 && string.IsNullOrEmpty(attValue))
                    {
                        return(FailedJson("操作失败,请检查所有必填项是否全部输入"));
                    }

                    switch (item.FieldType)
                    {
                    case "string":
                        if (attValue.Length < item.FieldMinLength || attValue.Length > item.FieldMaxLength)
                        {
                            return(FailedJson(string.Format("操作失败,【{0}】属性长度不符合要求,请检查输入", item.AttributeName)));
                        }
                        break;

                    case "decimal":
                        if (RegexUtil.IsNumeric(attValue) == false)
                        {
                            return(FailedJson(string.Format("操作失败,【{0}】属性为数值类型,请检查输入", item.AttributeName)));
                        }
                        break;

                    case "datetime":
                        if (RegexUtil.IsDateTime(attValue) == false)
                        {
                            return(FailedJson(string.Format("操作失败,【{0}】属性为日期时间类型,请检查输入", item.AttributeName)));
                        }
                        break;

                    case "custom":
                        if (item.CustomValue.Split('\n').ToList().Contains(attValue) == false)
                        {
                            return(FailedJson(string.Format("操作失败,【{0}】属性值输入不在枚举范围内,请检查输入", item.AttributeName)));
                        }
                        break;

                    default:
                        break;
                    }
                    productInfo.AttributeList.Add(item.CategoryAttributeId, attValue);
                }
            }

            if (ProductInfoService.Instance.CreateProductInfo(productInfo, out message))
            {
                return(SuccessedJson(message, "ProductCenter_ProductStockMgr", "ProductCenter_ProductStockMgr", "forward", "/productcenter/ProductStockMgr?catid=" + productInfo.BasicInfo.CategoryId + "&=" + DateTime.Now.ToString("yyyyMMddHHmmssfff")));
            }
            else
            {
                return(FailedJson(message));
            }
        }