public JsonResult DoAddProductCategoryAttribute() { ProductCategoryAttributesModel attInfo = new ProductCategoryAttributesModel(); string message = "操作失败,请与管理员联系"; try { attInfo.ProductCategoryId = GetFormData("categoryId"); attInfo.AttributeName = GetFormData("attributeName"); attInfo.CustomValue = GetFormData("customValue"); attInfo.FieldMaxLength = (GetFormData("maxLength") == null || GetFormData("maxLength") == "") ? -1 : Convert.ToInt32(GetFormData("maxLength")); attInfo.FieldMinLength = (GetFormData("minLength") == null || GetFormData("minLength") == "") ? -1 : Convert.ToInt32(GetFormData("minLength")); attInfo.FieldType = GetFormData("fieldType"); attInfo.DefaultValue = (attInfo.FieldType == "string" || attInfo.FieldType == "decimal" || attInfo.FieldType == "text") ? GetFormData("defaultValue1") : GetFormData("defaultValue2"); attInfo.GroupName = GetFormData("groupName"); attInfo.IsRequest = (GetFormData("isRequest") == "0") ? 0 : 1; attInfo.Status = (GetFormData("Status") == "0") ? 0 : 1; attInfo.Description = GetFormData("attDesc"); } catch (Exception ex) { return(FailedJson("操作异常,请检查输入项," + ex.Message)); } if (ProductCategoryAttributesService.Instance.CreateProductCategoryAttribute(attInfo, out message)) { return(SuccessedJson(message, "ProductCenter_ProductCategoryAttribute", "ProductCenter_ProductCategoryAttribute", "forward", "/productcenter/ProductCategoryAttribute?catid=" + attInfo.ProductCategoryId.ToString() + "&=" + DateTime.Now.ToString("yyyyMMddHHmmssfff"))); } else { return(FailedJson(message)); } }
/// <summary> /// 删除 /// </summary> /// <param name="pc">pc</param> /// <returns>影响的记录行数</returns> public int DeleteMultiple(ParameterCollection pc) { int ret = 0; ProductCategoryAttributesModel productcategoryattributes = new ProductCategoryAttributesModel(); ret = DbUtil.Current.DeleteMultiple(productcategoryattributes, pc); return(ret); }
/// <summary> /// 更新 /// </summary> /// <param name="productcategoryattributes">实体</param> /// <param name="pc">pc</param> /// <returns>影响的记录行数</returns> public int UpdateMultiple(ProductCategoryAttributesModel productcategoryattributes, ParameterCollection pc) { int ret = 0; productcategoryattributes.ModifiedBy = SessionUtil.Current.UserId; productcategoryattributes.ModifiedOn = DateTime.Now; ret = DbUtil.Current.UpdateMultiple(productcategoryattributes, pc); return(ret); }
/// <summary> /// 更新 /// </summary> /// <param name="productcategoryattributes">实体</param> /// <returns>影响的记录行数</returns> public int Update(ProductCategoryAttributesModel productcategoryattributes) { int ret = 0; productcategoryattributes.ModifiedBy = SessionUtil.Current.UserId; productcategoryattributes.ModifiedOn = DateTime.Now; ret = DbUtil.Current.Update(productcategoryattributes); return(ret); }
/// <summary> /// 删除 /// </summary> /// <param name="categoryattributeid"></param> /// <returns>影响的记录行数</returns> public int Delete(string categoryattributeid) { int ret = 0; ProductCategoryAttributesModel productcategoryattributes = new ProductCategoryAttributesModel(); productcategoryattributes.CategoryAttributeId = categoryattributeid; ret = DbUtil.Current.Delete(productcategoryattributes); return(ret); }
/// <summary> /// 新建 /// </summary> /// <param name="productcategoryattributes">实体</param> /// <returns>影响的记录行数</returns> public int Create(ProductCategoryAttributesModel productcategoryattributes) { int ret = 0; productcategoryattributes.CreatedBy = (SessionUtil.Current == null) ? "C792D747-6B74-4A58-BB5B-D98EF420F99F" : SessionUtil.Current.UserId; productcategoryattributes.CreatedOn = DateTime.Now; productcategoryattributes.ModifiedBy = (SessionUtil.Current == null) ? "C792D747-6B74-4A58-BB5B-D98EF420F99F" : SessionUtil.Current.UserId; productcategoryattributes.ModifiedOn = DateTime.Now; productcategoryattributes.StatusCode = 0; ret = DbUtil.Current.Create(productcategoryattributes); return(ret); }
/// <summary> /// 根据条件获取实体集合 /// </summary> /// <param name="pc">pc</param> /// <param name="obc">obc</param> /// <returns>实体</returns> public List <ProductCategoryAttributesModel> RetrieveMultiple(ParameterCollection pc, OrderByCollection obc) { List <ProductCategoryAttributesModel> productcategoryattributess = new List <ProductCategoryAttributesModel>(); ProductCategoryAttributesModel productcategoryattributes = new ProductCategoryAttributesModel(); DataTable dt = DbUtil.Current.RetrieveMultiple(productcategoryattributes, pc, obc); for (int i = 0; i < dt.Rows.Count; i++) { productcategoryattributes = new ProductCategoryAttributesModel(); productcategoryattributes.ConvertFrom(dt, i); productcategoryattributess.Add(productcategoryattributes); } return(productcategoryattributess); }
/// <summary> /// 根据主键获取实体 /// </summary> /// <param name="categoryattributeid"></param> /// <returns>实体</returns> public ProductCategoryAttributesModel Retrieve(string categoryattributeid) { ProductCategoryAttributesModel productcategoryattributes = new ProductCategoryAttributesModel(); productcategoryattributes.CategoryAttributeId = categoryattributeid; DataTable dt = DbUtil.Current.Retrieve(productcategoryattributes); if (dt.Rows.Count < 1) { return(null); } productcategoryattributes.ConvertFrom(dt); return(productcategoryattributes); }
public bool ImportProductCategoryAttributes(DataTable attTable, out string importLogs, out string message) { bool result = false; message = "操作失败,请与管理员联系"; importLogs = ""; if (attTable == null && attTable.Rows.Count == 0) { message = "产品类型属性信息表为空,请检查Excel文件是否正确"; importLogs = message; return(false); } Dictionary <string, ProductCategoryInfoModel> categoryList = ProductCategoryInfoService.Instance.GetProductCategoryList(true); //Dictionary<string, ProductCategoryGroupInfoModel> groupList = ProductCategoryGroupInfoService.Instance.GetProductCategoryGroupList(true); ProductCategoryGroupInfoModel groupInfo = null; if (categoryList == null || categoryList.Count == 0) { message = "数据库中产品类型信息表为空,请检查"; importLogs = message; return(false); } try { BeginTransaction(); ProductCategoryAttributesModel attInfo = null; string[] defaultListValue = null; for (int i = 0; i < attTable.Rows.Count; i++) { if (string.IsNullOrEmpty(attTable.Rows[i]["操作"].ToString())) { continue; } try { attInfo = new ProductCategoryAttributesModel(); defaultListValue = attTable.Rows[i]["属性名称"].ToString().Split(','); attInfo.AttributeName = attTable.Rows[i]["属性名称"].ToString(); if (attInfo.AttributeName == "销售状态" || attInfo.AttributeName == "产品代码" || attInfo.AttributeName == "产品名称") { continue; } attInfo.Description = attTable.Rows[i]["描述信息"].ToString(); attInfo.FieldMaxLength = (attTable.Rows[i]["最大长度"] == DBNull.Value) ? 50 : Convert.ToInt32(attTable.Rows[i]["最大长度"]); attInfo.FieldMinLength = (attTable.Rows[i]["最小长度"] == DBNull.Value) ? 4 : Convert.ToInt32(attTable.Rows[i]["最小长度"]); attInfo.IsDisplay = 0; attInfo.IsRequest = (attTable.Rows[i]["是否必填项"].ToString() == "是") ? 0 : 1; attInfo.Status = (attTable.Rows[i]["状态"].ToString() == "启用") ? 0 : 1; attInfo.NodeId = 0; attInfo.ParentNode = 0; attInfo.GroupName = attTable.Rows[i]["产品类型分组名称"].ToString(); switch (attTable.Rows[i]["字段类型"].ToString()) { case "字符串": attInfo.FieldType = "string"; //attInfo.DefaultValue = (string.IsNullOrEmpty(attTable.Rows[i]["默认值"].ToString()) || attTable.Rows[i]["默认值"] == DBNull.Value) ? null : attTable.Rows[i]["默认值"].ToString(); if (attInfo.FieldMaxLength <= attInfo.FieldMinLength) { RollbackTransaction(); message = string.Format("操作失败,Excel中产品属性【{0}】【{1}】最大长度与最小长度设置错误", attTable.Rows[i]["产品类型分组名称"], attTable.Rows[i]["属性名称"]); return(false); } break; case "数值": attInfo.FieldType = "decimal"; attInfo.FieldMaxLength = (attTable.Rows[i]["最大长度"] == DBNull.Value) ? 12 : Convert.ToInt32(attTable.Rows[i]["最大长度"]); attInfo.FieldMinLength = (attTable.Rows[i]["最小长度"] == DBNull.Value) ? 4 : Convert.ToInt32(attTable.Rows[i]["最小长度"]); break; case "日期时间": attInfo.FieldType = "datetime"; break; case "自定义枚举": attInfo.FieldType = "custom"; attInfo.FieldMaxLength = -1; break; case "长文本": attInfo.FieldType = "text"; attInfo.FieldMaxLength = -1; break; default: break; } if (defaultListValue != null && defaultListValue.Length > 0) { for (int j = 0; j < defaultListValue.Length; j++) { attInfo.CustomValue += defaultListValue[j] + "\n"; } } if (attTable.Rows[i]["操作"].ToString() == "新建") { foreach (ProductCategoryInfoModel catInfo in categoryList.Values) { if (catInfo.GroupName == ProductCategoryGroupInfoService.Instance.GetProductCategoryGroupByName(attTable.Rows[i]["产品类型分组名称"].ToString()).ProductCategoryGroupId) { attInfo.CategoryAttributeId = GetGuid(); attInfo.ProductCategoryId = catInfo.ProductCategoryId; #region 创建产品类型属性 Dictionary <string, ProductCategoryAttributesModel> dict = ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(attInfo.ProductCategoryId, false); if (dict == null) { message = "操作失败,不存在的产品类型ID"; return(false); } bool execute = true; foreach (ProductCategoryAttributesModel item in dict.Values) { if (item.AttributeName == attInfo.AttributeName) { message = "操作失败,本产品类型存在相同名称属性"; execute = false; break; } } if (execute) { if (ProductCategoryAttributesService.Instance.CreateProductCategoryAttribute(attInfo, out message) == false) { RollbackTransaction(); return(false); } } #endregion } } } } catch (Exception ex2) { RollbackTransaction(); throw ex2; } } CommitTransaction(); } catch (Exception ex) { RollbackTransaction(); LogUtil.Error("导入产品类型属性异常", ex); throw ex; } return(result); }
/// <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); }
public bool MoveDownProductCategoryAttribute(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); } if (currInfo.SortOrder == dict.Count) { message = "操作失败,当前产品类型属性已经是最下序列"; return(false); } ProductCategoryAttributesModel downInfo = null; foreach (ProductCategoryAttributesModel item in dict.Values) { if (item.SortOrder == currInfo.SortOrder + 1) { downInfo = item; break; } } currInfo.SortOrder = currInfo.SortOrder + 1; downInfo.SortOrder = downInfo.SortOrder - 1; try { BeginTransaction(); if (Update(currInfo) == 1 && Update(downInfo) == 1) { CommitTransaction(); GetProductCategoryAttributeList(productCategoryId, true); result = true; message = "成功下移选中产品类型属性"; } else { RollbackTransaction(); result = false; message = "操作失败,下移选中产品类型属性失败"; } } catch (Exception ex) { RollbackTransaction(); LogUtil.Error("下移选中产品类型属性异常", ex); result = false; message = "操作失败,下移选中产品类型属性异常"; } 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); }
public bool UpdateProductCategoryAttribute(ProductCategoryAttributesModel attInfo, out string message) { bool result = false; message = "操作失败,请与管理员联系"; Dictionary <string, ProductCategoryAttributesModel> dict = GetProductCategoryAttributeList(attInfo.ProductCategoryId, false); if (dict == null) { message = "操作失败,不存在的产品类型ID"; return(false); } ProductCategoryInfoModel catInfo = ProductCategoryInfoService.Instance.GetProductCategoryInfoById(attInfo.ProductCategoryId); if (catInfo == null) { message = "操作失败,不存在的产品类型ID"; return(false); } foreach (ProductCategoryAttributesModel item in dict.Values) { if (item.AttributeName == attInfo.AttributeName && item.CategoryAttributeId != attInfo.CategoryAttributeId) { message = "操作失败,本产品类型存在相同名称属性"; return(false); } } ProductCategoryAttributesModel oldAttInfo = ProductCategoryAttributesService.Instance.GetProductCategoryAttributeById(attInfo.ProductCategoryId, attInfo.CategoryAttributeId); if (attInfo.FieldType != oldAttInfo.FieldType || attInfo.AttributeName != oldAttInfo.AttributeName) { message = "更改产品属性将直接影响现有本类型产品信息,系统暂不提供该功能,请与管理员联系使用其他方式实现"; return(false); } try { BeginTransaction(); //if (attInfo.AttributeName != oldAttInfo.AttributeName) //{ // string renameFieldSQL = DTableUtil.GetRenameFieldSQL(catInfo.TableName, oldAttInfo.AttributeName, attInfo.AttributeName); // ExecuteNonQuery(renameFieldSQL); //} if (Update(attInfo) == 1) { GetProductCategoryAttributeList(attInfo.ProductCategoryId, true); message = "成功更新产品类型属性"; result = true; CommitTransaction(); } else { RollbackTransaction(); message = "更新产品类型属性失败,请与管理员联系"; result = false; } } catch (Exception ex) { RollbackTransaction(); LogUtil.Error("更新产品类型属性异常", ex); throw ex; } return(result); }
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); }