public bool CreateGroupInfo(CustomerAttributeGroupInfoModel model, out string message)
        {
            bool result = false;

            message       = "操作失败,请与管理员联系";
            model.GroupId = GetGuid();
            model.Tabname = "customer_info_" + CharacterUtil.ConvertToPinyin(model.GroupName);
            if (CheckExistGroupname(model.GroupName))
            {
                message = string.Format("操作失败,已经存在名为【{0}】属性名称", model.GroupName);
                return(false);
            }

            string TableName = "customer_info_" + CharacterUtil.ConvertToPinyin(model.GroupName);

            #region 创建表字段

            List <FieldInfo> fieldList = new List <FieldInfo>();
            FieldInfo        field     = new FieldInfo();
            field.FieldName    = "customer_id";
            field.FieldType    = "varchar";
            field.MinLength    = 50;
            field.MaxLength    = 50;
            field.IsNull       = false;
            field.IsPrimaryKey = true;
            fieldList.Add(field);

            field              = new FieldInfo();
            field.FieldName    = "created_on";
            field.FieldType    = "datetime";
            field.IsNull       = false;
            field.IsPrimaryKey = false;
            fieldList.Add(field);

            field              = new FieldInfo();
            field.FieldName    = "created_by";
            field.FieldType    = "varchar";
            field.MinLength    = 50;
            field.MaxLength    = 50;
            field.IsNull       = false;
            field.IsPrimaryKey = false;
            fieldList.Add(field);

            field              = new FieldInfo();
            field.FieldName    = "modified_on";
            field.FieldType    = "datetime";
            field.IsNull       = true;
            field.IsPrimaryKey = false;
            fieldList.Add(field);

            field              = new FieldInfo();
            field.FieldName    = "modified_by";
            field.FieldType    = "varchar";
            field.MinLength    = 50;
            field.MaxLength    = 50;
            field.IsNull       = true;
            field.IsPrimaryKey = false;
            fieldList.Add(field);

            field           = new FieldInfo();
            field.FieldName = "status_code";
            field.FieldType = "int";
            field.IsNull    = true;
            fieldList.Add(field);

            string createTableSql = DTableUtil.GetCreateTableSQL(TableName, fieldList);

            #endregion



            try
            {
                BeginTransaction();
                ExecuteNonQuery(createTableSql);
                if (Create(model) == 1)
                {
                    message = "成功创建分组属性";
                    result  = true;
                    GetGroupInfoById(model.GroupId, true);
                    CommitTransaction();
                }
                else
                {
                    RollbackTransaction();
                    result  = false;
                    message = "创建客户分组属性失败,请与管理员联系";
                }
            }
            catch (Exception ex)
            {
                RollbackTransaction();
                LogUtil.Error("创建客户分组属性异常", ex);
                throw ex;
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 创建产品型信息。
        /// </summary>
        /// <param name="categoryInfo"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public bool CreateProductCategory(ProductCategoryInfoModel categoryInfo, out string message)
        {
            bool result = false;

            message = "操作失败,请与管理员联系";

            if (categoryInfo == null || string.IsNullOrEmpty(categoryInfo.CategoryName))
            {
                message = "缺少参数,请与管理员联系";
                return(false);
            }

            Dictionary <string, ProductCategoryInfoModel> dict = GetProductCategoryList(false);

            if (dict != null)
            {
                foreach (ProductCategoryInfoModel item in dict.Values)
                {
                    if (item.CategoryName == categoryInfo.CategoryName)
                    {
                        message = "操作失败,当前存在相同的产品类型名称";
                        return(false);
                    }
                }
            }

            CustomDataDomainModel SaleCity = CustomDataInfoService.Instance.GetCustomDataDomainModelByName("销售城市", false);
            string saleCityString          = null;

            foreach (CustomDataValueDomainModel item in SaleCity.ValueList.Values)
            {
                saleCityString += item.DataValue + " ";
            }

            categoryInfo.ProductCategoryId = GetGuid();
            categoryInfo.SortOrder         = (dict == null) ? 1 : dict.Count + 1;
            categoryInfo.TableName         = "product_info_" + CharacterUtil.ConvertToPinyin(categoryInfo.CategoryName);

            #region 创建表字段

            List <FieldInfo> fieldList = new List <FieldInfo>();
            FieldInfo        field     = new FieldInfo();
            field.FieldName    = "product_id";
            field.FieldType    = "varchar";
            field.MinLength    = 50;
            field.MaxLength    = 50;
            field.IsNull       = false;
            field.IsPrimaryKey = true;
            fieldList.Add(field);

            field              = new FieldInfo();
            field.FieldName    = "product_category_id";
            field.FieldType    = "varchar";
            field.MinLength    = 50;
            field.MaxLength    = 50;
            field.IsNull       = false;
            field.IsPrimaryKey = false;
            fieldList.Add(field);

            field              = new FieldInfo();
            field.FieldName    = "category_group_id";
            field.FieldType    = "varchar";
            field.MinLength    = 50;
            field.MaxLength    = 50;
            field.IsNull       = false;
            field.IsPrimaryKey = false;
            fieldList.Add(field);

            field              = new FieldInfo();
            field.FieldName    = "item_price";
            field.FieldType    = "decimal";
            field.MinLength    = 18;
            field.MaxLength    = 2;
            field.DefaultValue = "0";
            field.IsNull       = false;
            field.IsPrimaryKey = false;
            fieldList.Add(field);

            field              = new FieldInfo();
            field.FieldName    = "created_on";
            field.FieldType    = "datetime";
            field.IsNull       = false;
            field.IsPrimaryKey = false;
            fieldList.Add(field);

            field              = new FieldInfo();
            field.FieldName    = "created_by";
            field.FieldType    = "varchar";
            field.MinLength    = 50;
            field.MaxLength    = 50;
            field.IsNull       = false;
            field.IsPrimaryKey = false;
            fieldList.Add(field);

            field              = new FieldInfo();
            field.FieldName    = "modified_on";
            field.FieldType    = "datetime";
            field.IsNull       = true;
            field.IsPrimaryKey = false;
            fieldList.Add(field);

            field              = new FieldInfo();
            field.FieldName    = "modified_by";
            field.FieldType    = "varchar";
            field.MinLength    = 50;
            field.MaxLength    = 50;
            field.IsNull       = true;
            field.IsPrimaryKey = false;
            fieldList.Add(field);

            field           = new FieldInfo();
            field.FieldName = "status_code";
            field.FieldType = "int";
            field.IsNull    = true;
            fieldList.Add(field);

            string createTableSql = DTableUtil.GetCreateTableSQL(categoryInfo.TableName, fieldList);

            #endregion

            try
            {
                BeginTransaction();

                ExecuteNonQuery(createTableSql);

                if (Create(categoryInfo) == 1)
                {
                    GetProductCategoryList(true);

                    #region 创建默认字段

                    ProductCategoryAttributesModel att = new ProductCategoryAttributesModel();
                    att.AttributeName       = "产品代码";
                    att.CategoryAttributeId = GetGuid();
                    att.FieldMinLength      = 50;
                    att.FieldType           = "string";
                    att.IsDisplay           = 0;
                    att.IsRequest           = 0;
                    att.NodeId            = 0;
                    att.ProductCategoryId = categoryInfo.ProductCategoryId;
                    att.SortOrder         = 1;
                    att.Status            = 0;
                    if (!ProductCategoryAttributesService.Instance.CreateProductCategoryAttribute(att, out message))
                    {
                        RollbackTransaction();
                        return(false);
                    }
                    ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(categoryInfo.ProductCategoryId, true);

                    att = new ProductCategoryAttributesModel();
                    att.AttributeName       = "产品名称";
                    att.CategoryAttributeId = GetGuid();
                    att.FieldMinLength      = 50;
                    att.FieldType           = "string";
                    att.IsDisplay           = 0;
                    att.IsRequest           = 0;
                    att.NodeId            = 0;
                    att.ProductCategoryId = categoryInfo.ProductCategoryId;
                    att.SortOrder         = 2;
                    att.Status            = 0;
                    if (!ProductCategoryAttributesService.Instance.CreateProductCategoryAttribute(att, out message))
                    {
                        RollbackTransaction();
                        return(false);
                    }
                    ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(categoryInfo.ProductCategoryId, true);

                    att = new ProductCategoryAttributesModel();
                    att.AttributeName       = "销售状态";
                    att.CategoryAttributeId = GetGuid();
                    att.FieldMinLength      = 50;
                    att.FieldType           = "custom";
                    att.CustomValue         = "已建档";
                    att.IsDisplay           = 0;
                    att.IsRequest           = 0;
                    att.NodeId            = 0;
                    att.ProductCategoryId = categoryInfo.ProductCategoryId;
                    att.SortOrder         = 3;
                    att.Status            = 0;
                    if (!ProductCategoryAttributesService.Instance.CreateProductCategoryAttribute(att, out message))
                    {
                        RollbackTransaction();
                        return(false);
                    }
                    ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(categoryInfo.ProductCategoryId, true);

                    att = new ProductCategoryAttributesModel();
                    att.AttributeName       = "销售城市";
                    att.CategoryAttributeId = GetGuid();
                    att.FieldMinLength      = 50;
                    att.FieldType           = "custom";
                    att.CustomValue         = "所有";
                    att.IsDisplay           = 0;
                    att.IsRequest           = 0;
                    att.NodeId            = 0;
                    att.ProductCategoryId = categoryInfo.ProductCategoryId;
                    att.SortOrder         = 3;
                    att.Status            = 0;
                    if (!ProductCategoryAttributesService.Instance.CreateProductCategoryAttribute(att, out message))
                    {
                        RollbackTransaction();
                        return(false);
                    }
                    ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(categoryInfo.ProductCategoryId, true);


                    att = new ProductCategoryAttributesModel();
                    att.AttributeName       = "销售价格";
                    att.CategoryAttributeId = GetGuid();
                    att.FieldMinLength      = 18;
                    att.FieldMaxLength      = 2;
                    att.FieldType           = "decimal";
                    att.CustomValue         = "0";
                    att.IsDisplay           = 0;
                    att.IsRequest           = 0;
                    att.NodeId            = 0;
                    att.ProductCategoryId = categoryInfo.ProductCategoryId;
                    att.SortOrder         = 4;
                    att.Status            = 0;
                    if (!ProductCategoryAttributesService.Instance.CreateProductCategoryAttribute(att, out message))
                    {
                        RollbackTransaction();
                        return(false);
                    }
                    ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(categoryInfo.ProductCategoryId, true);

                    #endregion

                    #region 创建默认的销售状态

                    ProductCategorySalesStatusModel saleStatus = new ProductCategorySalesStatusModel();
                    saleStatus.ProductCategoryId = categoryInfo.ProductCategoryId;
                    saleStatus.SalesStatusId     = GetGuid();
                    saleStatus.SalestatusName    = "已建档";
                    saleStatus.SortOrder         = 1;
                    saleStatus.Status            = 0;

                    if (!ProductCategorySalesStatusService.Instance.CreateProductCategorySaleStatus(saleStatus, out message))
                    {
                        RollbackTransaction();
                        return(false);
                    }
                    ProductCategorySalesStatusService.Instance.GetProductCategorySalesStatusList(categoryInfo.ProductCategoryId, true);

                    #endregion

                    #region 创建默认的销售城市

                    ProductCategorySalesStatusModel saleCityList = new ProductCategorySalesStatusModel();
                    saleCityList.ProductCategoryId = categoryInfo.ProductCategoryId;
                    saleCityList.SalesStatusId     = GetGuid();
                    saleCityList.SalestatusName    = "所有";
                    saleCityList.SortOrder         = 1;
                    saleCityList.Status            = 0;

                    if (!ProductCategorySalesStatusService.Instance.CreateProductCategorySaleStatus(saleCityList, out message))
                    {
                        RollbackTransaction();
                        return(false);
                    }
                    ProductCategorySalesStatusService.Instance.GetProductCategorySalesStatusList(categoryInfo.ProductCategoryId, true);

                    #endregion


                    ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(categoryInfo.ProductCategoryId, true);
                    GetProductCategoryList(true);
                    message = "成功创建产品类型信息";
                    result  = true;

                    CommitTransaction();
                }
                else
                {
                    RollbackTransaction();
                    message = "创建产品类型信息失败";
                    result  = false;
                }
            }
            catch (Exception ex)
            {
                RollbackTransaction();
                LogUtil.Error("创建产品类型异常", ex);
                throw ex;
            }

            return(result);
        }