public bool CreateCustomerAttribute(CustomerExtAttributesModel attInfo, out string message) { bool result = false; message = "操作失败,请与管理员联系"; CustomerAttributeGroupInfoModel GroupInfoModel = null; GroupInfoModel = CustomerAttributeGroupInfoService.Instance.GetCustomerGroupFromDatabase(attInfo.GroupId); if (attInfo.FieldType.ToLower() == "string") { if (attInfo.FieldMinLength <= 1 || attInfo.FieldMaxLength <= 1 || attInfo.FieldMaxLength <= attInfo.FieldMinLength) { message = "属性字段长度有误,请检查输入"; return(false); } } if (CheckExistAttributename(attInfo.AttributeName)) { message = string.Format("操作失败,已经存在名为【{0}】属性名称", attInfo.AttributeName); return(false); } Dictionary <string, CustomerAttributeGroupInfoModel> dict = CustomerAttributeGroupInfoService.Instance.GetCustomeGroupInfoList(false); attInfo.SortOrder = (dict == null) ? 1 : dict.Count + 1; string TableName = "customer_info_" + CharacterUtil.ConvertToPinyin(GroupInfoModel.GroupName); #region 添加属性 attInfo.ExtAttributeId = Guid.NewGuid().ToString(); attInfo.SortOrder = (dict == null) ? 1 : dict.Count + 1; attInfo.NodeId = "0"; attInfo.ParnetId = "0"; FieldInfo fieldInfo = new FieldInfo(); fieldInfo.FieldName = attInfo.AttributeName; if (attInfo.FieldType == "string" || attInfo.FieldType == "custom") { fieldInfo.FieldType = "varchar"; fieldInfo.MinLength = Convert.ToInt32(attInfo.FieldMinLength); fieldInfo.MaxLength = Convert.ToInt32(attInfo.FieldMaxLength); } else { fieldInfo.FieldType = attInfo.FieldType; fieldInfo.MinLength = Convert.ToInt32(attInfo.FieldMinLength); fieldInfo.MaxLength = Convert.ToInt32(attInfo.FieldMaxLength); } if (fieldInfo.MinLength < 0 && fieldInfo.FieldType == "varchar") { fieldInfo.MinLength = 50; } if (fieldInfo.MaxLength < 0 && fieldInfo.FieldType == "varchar") { fieldInfo.MaxLength = 50; } if (attInfo.FieldType == "text") { fieldInfo.FieldType = "varchar"; fieldInfo.MaxLength = -1; } fieldInfo.DefaultValue = attInfo.DefaultValue; fieldInfo.Description = attInfo.Description; string addFieldSQL = DTableUtil.GetAddFieldSQL(TableName, fieldInfo); #endregion try { BeginTransaction(); if (Create(attInfo) == 1) { ExecuteNonQuery(addFieldSQL); message = "成功创建客户属性"; result = true; GetCustomerAttributeList(attInfo.ExtAttributeId, true); CommitTransaction(); } else { RollbackTransaction(); result = false; message = "创建客户属性失败,请与管理员联系"; } } catch (Exception ex) { RollbackTransaction(); LogUtil.Error("创建客户属性异常", ex); throw ex; } return(result); }
public bool CreateProductCategoryAttribute(ProductCategoryAttributesModel attInfo, out string message) { bool result = false; message = "操作失败,请与管理员联系"; if (attInfo.FieldType.ToLower() == "string") { if (attInfo.FieldMinLength <= 1 || attInfo.FieldMaxLength <= 1 || attInfo.FieldMaxLength <= attInfo.FieldMinLength) { message = "属性字段长度有误,请检查输入"; return(false); } } ProductCategoryInfoModel catInfo = ProductCategoryInfoService.Instance.GetProductCategoryInfoById(attInfo.ProductCategoryId); if (catInfo == null) { message = "失败失败,不存在此产品类型ID"; return(false); } Dictionary <string, ProductCategoryAttributesModel> dict = GetProductCategoryAttributeList(attInfo.ProductCategoryId, false); if (dict == null) { message = "操作失败,不存在的产品类型ID"; return(false); } foreach (ProductCategoryAttributesModel item in dict.Values) { if (item.AttributeName == attInfo.AttributeName) { message = "操作失败,本产品类型存在相同名称属性"; return(false); } } attInfo.CategoryAttributeId = Guid.NewGuid().ToString(); attInfo.SortOrder = dict.Count + 1; attInfo.NodeId = 0; attInfo.ParentNode = 0; attInfo.IsDisplay = 0; FieldInfo fieldInfo = new FieldInfo(); fieldInfo.FieldName = attInfo.AttributeName; if (attInfo.FieldType == "string" || attInfo.FieldType == "custom") { fieldInfo.FieldType = "varchar"; fieldInfo.MinLength = Convert.ToInt32(attInfo.FieldMinLength); fieldInfo.MaxLength = Convert.ToInt32(attInfo.FieldMaxLength); } else { fieldInfo.FieldType = attInfo.FieldType; fieldInfo.MinLength = Convert.ToInt32(attInfo.FieldMinLength); fieldInfo.MaxLength = Convert.ToInt32(attInfo.FieldMaxLength); } if (fieldInfo.MinLength < 0 && fieldInfo.FieldType == "varchar") { fieldInfo.MinLength = 50; } if (fieldInfo.MaxLength < 0 && fieldInfo.FieldType == "varchar") { fieldInfo.MaxLength = 50; } if (attInfo.FieldType == "text") { fieldInfo.FieldType = "varchar"; fieldInfo.MaxLength = -1; } fieldInfo.DefaultValue = attInfo.DefaultValue; fieldInfo.Description = attInfo.Description; fieldInfo.IsNull = (attInfo.IsRequest == 0); string addFieldSQL = DTableUtil.GetAddFieldSQL(catInfo.TableName, fieldInfo); try { BeginTransaction(); ExecuteNonQuery(addFieldSQL); if (Create(attInfo) == 1) { GetProductCategoryAttributeList(attInfo.ProductCategoryId, true); message = "成功创建产品类型属性"; result = true; CommitTransaction(); } else { RollbackTransaction(); result = false; message = "创建产品类型属性失败,请与管理员联系"; } } catch (Exception ex) { RollbackTransaction(); LogUtil.Error("创建产品类型属性异常", ex); throw ex; } return(result); }