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

            message       = "操作失败,请与管理员联系";
            model.Tabname = "customer_info_" + CharacterUtil.ConvertToPinyin(model.GroupName);
            Dictionary <string, CustomerAttributeGroupInfoModel> dict = GetCustomeGroupInfoList(true);

            CustomerAttributeGroupInfoModel oldInfo = dict[model.GroupId];

            try
            {
                BeginTransaction();

                if (oldInfo.GroupName != model.GroupName)
                {
                    string NewsTableName = "customer_info_" + CharacterUtil.ConvertToPinyin(model.GroupName);
                    string TableName     = "customer_info_" + CharacterUtil.ConvertToPinyin(oldInfo.GroupName);
                    string renSQL        = DTableUtil.GetRenameTableSQL(TableName, NewsTableName);
                    ExecuteNonQuery(renSQL);
                }

                if (Update(model) == 1)
                {
                    GetGroupInfoById(model.GroupId, true);
                    message = "成功更新客户分组属性";
                    result  = true;

                    CommitTransaction();
                }
                else
                {
                    RollbackTransaction();
                    message = "更新产客户分组属性失败,请与管理员联系";
                    result  = false;
                }
            }
            catch (Exception ex)
            {
                RollbackTransaction();
                LogUtil.Error("更新客户分组属性异常", ex);
                throw ex;
            }

            return(result);
        }
        // 在此添加你的代码....


        public bool UpdateCustomerAttribute(CustomerExtAttributesModel attInfo, out string message, string oldName)
        {
            bool result = false;

            message = "操作失败,请与管理员联系";
            CustomerExtAttributesModel model = GetCustomerAttributeById(attInfo.ExtAttributeId, true);


            Dictionary <string, CustomerAttributeGroupInfoModel> dict = CustomerAttributeGroupInfoService.Instance.GetCustomeGroupInfoList(true);

            CustomerAttributeGroupInfoModel oldInfo = dict[model.GroupId];

            try
            {
                BeginTransaction();
                if (attInfo.AttributeName != oldName)
                {
                    string TableName      = "customer_info_" + CharacterUtil.ConvertToPinyin(oldInfo.GroupName);
                    string renameFieldSQL = DTableUtil.GetRenameFieldSQL(TableName, oldName, attInfo.AttributeName);
                    ExecuteNonQuery(renameFieldSQL);
                }
                if (Update(attInfo) == 1)
                {
                    GetCustomerAttributeList(attInfo.ExtAttributeId, true);
                    message = "成功更新客户属性";
                    result  = true;

                    CommitTransaction();
                }
                else
                {
                    RollbackTransaction();
                    message = "更新产客户属性失败,请与管理员联系";
                    result  = false;
                }
            }
            catch (Exception ex)
            {
                RollbackTransaction();
                LogUtil.Error("更新客户属性异常", ex);
                throw ex;
            }

            return(result);
        }
        // 在此添加你的代码...


        /// <summary>
        /// 根据ID删除客户分组属性信息。
        /// </summary>
        /// <param name="departmentId"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public bool DeleteGroupInfoById(string groupid, out string message)
        {
            message = "操作失败,请与管理员联系";
            bool result = false;
            Dictionary <string, CustomerAttributeGroupInfoModel> dict = GetCustomeGroupInfoList(true);

            CustomerAttributeGroupInfoModel oldInfo = dict[groupid];

            string TableName = "customer_info_" + CharacterUtil.ConvertToPinyin(oldInfo.GroupName);
            string deleteCustomerAttributesSQL = "DELETE FROM customer_ext_attributes WHERE group_id = $groupid$;";
            ParameterCollection pc             = new ParameterCollection();

            pc.Add("groupid", groupid);
            try
            {
                BeginTransaction();

                if (Delete(groupid) > 0)
                {
                    ExecuteNonQuery(deleteCustomerAttributesSQL, pc);
                    string dropTableSQL = DTableUtil.GetDropTableSQL(TableName);
                    ExecuteNonQuery(dropTableSQL);

                    CommitTransaction();
                    result  = true;
                    message = "成功删除客户属性信息";
                    GetCustomeGroupInfoList(true);
                }
                else
                {
                    RollbackTransaction();
                }
            }
            catch (Exception ex)
            {
                RollbackTransaction();
                LogUtil.Error("删除删除客户属性信息异常", ex);
                throw ex;
            }

            return(result);
        }
        /// <summary>
        /// 根据ID删除客户属性信息。
        /// </summary>
        /// <param name="departmentId"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public bool DeleteCustomerAttributeById(string extattributeid, out string message)
        {
            message = "操作失败,请与管理员联系";
            bool result = false;
            CustomerExtAttributesModel model = GetCustomerAttributeById(extattributeid, true);


            Dictionary <string, CustomerAttributeGroupInfoModel> dict = CustomerAttributeGroupInfoService.Instance.GetCustomeGroupInfoList(true);

            CustomerAttributeGroupInfoModel oldInfo = dict[model.GroupId];

            try
            {
                BeginTransaction();
                string TableName      = "customer_info_" + CharacterUtil.ConvertToPinyin(oldInfo.GroupName);
                string deleteFieldSQL = DTableUtil.GetDeleteFieldSQL(TableName, model.AttributeName);

                ExecuteNonQuery(deleteFieldSQL);
                if (Delete(extattributeid) > 0)
                {
                    CommitTransaction();
                    result  = true;
                    message = "成功删除客户属性信息";
                    GetCustomerAttributeList(extattributeid, true);
                }
                else
                {
                    RollbackTransaction();
                }
            }
            catch (Exception ex)
            {
                RollbackTransaction();
                LogUtil.Error("删除删除客户属性信息异常", ex);
                throw ex;
            }

            return(result);
        }
        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);
        }
Пример #6
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);
        }
Пример #7
0
        /// <summary>
        /// 删除产品类型信息。
        /// </summary>
        /// <param name="categoryId"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public bool DeleteProductCategory(string categoryId, out string message)
        {
            bool result = false;

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

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

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

            if (dict.ContainsKey(categoryId) == false)
            {
                message = "操作失败,产品类型ID不存在";
                return(false);
            }

            ProductCategoryInfoModel oldCatInfo = dict[categoryId];

            try
            {
                BeginTransaction();

                string deleteCategoryAttributeSQL      = "DELETE FROM product_category_attributes WHERE product_category_id = $categoryId$;";
                string deleteCategorySaleStatusSQL     = "DELETE FROM product_category_sales_status WHERE product_category_id = $categoryId$;";
                string deleteCategoryAttributeValueSQL = "DELETE FROM product_attributes_value WHERE product_category_id = $categoryId$;";
                ParameterCollection pc = new ParameterCollection();
                pc.Add("categoryId", categoryId);

                if (Delete(categoryId) == 1)
                {
                    ExecuteNonQuery(deleteCategoryAttributeSQL, pc);
                    ExecuteNonQuery(deleteCategorySaleStatusSQL, pc);
                    ExecuteNonQuery(deleteCategoryAttributeValueSQL, pc);

                    string dropTableSQL = DTableUtil.GetDropTableSQL(oldCatInfo.TableName);
                    ExecuteNonQuery(dropTableSQL);

                    foreach (ProductCategoryInfoModel item in dict.Values)
                    {
                        if (item.SortOrder > oldCatInfo.SortOrder)
                        {
                            item.SortOrder -= 1;
                            if (Update(item) != 1)
                            {
                                RollbackTransaction();
                                message = "重构产品类型信息排序索引失败";
                                result  = false;
                            }
                        }
                    }

                    CommitTransaction();
                    ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(categoryId, true);
                    ProductCategoryAttributesService.Instance.GetProductCategoryAttributeGroupList(categoryId, true);
                    ProductCategorySalesStatusService.Instance.GetProductCategorySalesStatusList(categoryId, true);
                    GetProductCategoryList(true);

                    message = "成功删除产品类型信息";
                    result  = true;
                }
                else
                {
                    RollbackTransaction();
                    message = "删除产品类型信息失败";
                    result  = false;
                }
            }
            catch (Exception ex)
            {
                RollbackTransaction();
                LogUtil.Error("删除产品类型信息异常", ex);
                throw ex;
            }

            return(result);
        }
Пример #8
0
        /// <summary>
        /// 更新产品信息。
        /// </summary>
        /// <param name="categoryInfo"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public bool UpdateProductCategory(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.ContainsKey(categoryInfo.ProductCategoryId) == false)
            {
                message = "操作失败,产品类型ID不存在";
                return(false);
            }

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

            ProductCategoryInfoModel oldCatInfo = dict[categoryInfo.ProductCategoryId];

            try
            {
                BeginTransaction();

                if (oldCatInfo.CategoryName != categoryInfo.CategoryName)
                {
                    categoryInfo.TableName = "product_info_" + CharacterUtil.ConvertToPinyin(categoryInfo.CategoryName);
                    string renSQL = DTableUtil.GetRenameTableSQL(oldCatInfo.TableName, categoryInfo.TableName);
                    ExecuteNonQuery(renSQL);
                }

                if (Update(categoryInfo) == 1)
                {
                    CommitTransaction();
                    GetProductCategoryList(true);
                    message = "成功更新产品类型信息";
                    result  = true;
                }
                else
                {
                    RollbackTransaction();
                    message = "更新产品类型信息失败";
                    result  = true;
                }
            }
            catch (Exception ex)
            {
                RollbackTransaction();
                LogUtil.Error("更新产品类型信息异常", ex);
                throw ex;
            }

            return(result);
        }
        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);
        }
Пример #10
0
        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);
        }
Пример #11
0
        public bool DeleteProductCategoryAttribute(string productCategoryId, string productAttributeId, out string message)
        {
            bool result = false;

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

            Dictionary <string, ProductCategoryAttributesModel> dict = GetProductCategoryAttributeList(productCategoryId, false);

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

            ProductCategoryAttributesModel currInfo = GetProductCategoryAttributeById(productCategoryId, productAttributeId);

            if (currInfo == null)
            {
                message = "操作失败,不存在的产品类型属性ID";
                return(false);
            }

            ProductCategoryInfoModel catInfo = ProductCategoryInfoService.Instance.GetProductCategoryInfoById(currInfo.ProductCategoryId);

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

            try
            {
                BeginTransaction();

                foreach (ProductCategoryAttributesModel item in dict.Values)
                {
                    if (item.SortOrder > currInfo.SortOrder)
                    {
                        item.SortOrder = item.SortOrder + 1;
                        if (Update(item) != 1)
                        {
                            message = "更新产品属性排序索引失败,请与管理员联系";
                            RollbackTransaction();
                            return(false);
                        }
                    }
                }

                string deleteFieldSQL = DTableUtil.GetDeleteFieldSQL(catInfo.TableName, currInfo.AttributeName);

                ExecuteNonQuery(deleteFieldSQL);

                if (Delete(currInfo.CategoryAttributeId) == 1)
                {
                    CommitTransaction();
                    message = "成功删除选中产品属性";
                    GetProductCategoryAttributeList(currInfo.ProductCategoryId, true);
                    result = true;
                }
            }
            catch (Exception ex)
            {
                RollbackTransaction();
                LogUtil.Error("删除选中产品类型属性异常", ex);
                result  = false;
                message = "操作失败,删除选中产品类型属性异常";
            }

            return(result);
        }