Beispiel #1
0
        public JsonResult DoUpdateProductCategory()
        {
            this.ValidateRequest = false;
            ProductCategoryInfoModel categoryInfo = new ProductCategoryInfoModel();

            categoryInfo.ProductCategoryId = GetFormData("categoryId");
            categoryInfo.SaleCity          = GetFormData("saleCity");
            categoryInfo.CategoryCode      = GetFormData("categoryCode");
            categoryInfo.CategoryName      = GetFormData("categoryName");
            categoryInfo.GroupName         = GetFormData("groupName");
            categoryInfo.Description       = Request.Form["description"]; // GetFormDataNotValidate("description");
            categoryInfo.SalesGuide        = Request.Form["salesGuide"];  // GetFormDataNotValidate("salesGuide");
            categoryInfo.TableName         = GetFormData("tableName");
            categoryInfo.ItemPrice         = Convert.ToDecimal(GetFormData("itemPrice"));
            categoryInfo.Status            = (GetFormData("Status") == "0") ? 0 : 1;
            categoryInfo.SortOrder         = Convert.ToInt32(GetFormData("sortOrder"));
            this.ValidateRequest           = true;
            string message = "操作失败,请与管理员联系";

            if (ProductCategoryInfoService.Instance.UpdateProductCategory(categoryInfo, out message))
            {
                return(SuccessedJson(message, "ProductCenter_ProductCategoryMgr", "ProductCenter_ProductCategoryMgr", "closeCurrent", "/productcenter/productcategorymgr"));
            }
            else
            {
                return(FailedJson(message));
            }
        }
Beispiel #2
0
        private string GetCreateProductSQL(ProductCategoryInfoModel catInfo, ProductInfoDomainModel productInfo, Dictionary <string, ProductCategoryAttributesModel> catAttList)
        {
            StringBuilder sql = new StringBuilder();

            sql.AppendFormat(@"INSERT INTO [{0}] ([product_id],[created_on],[created_by],[modified_on],[modified_by],[status_code]", catInfo.TableName);

            foreach (ProductCategoryAttributesModel item in catAttList.Values)
            {
                sql.AppendFormat(",[{0}]", item.AttributeName);
            }

            sql.AppendFormat(@") VALUES ('{0}',GETDATE(),'{1}',NULL,NULL, 0", productInfo.BasicInfo.ProductId, SessionUtil.Current.UserId);

            foreach (ProductCategoryAttributesModel item in catAttList.Values)
            {
                if (item.FieldType == "int" || item.FieldType == "decimal")
                {
                    sql.AppendFormat(", {0}", productInfo.AttributeList[item.CategoryAttributeId]);
                }
                else
                {
                    sql.AppendFormat(", '{0}'", productInfo.AttributeList[item.CategoryAttributeId]);
                }
            }

            sql.Append(");");

            return(sql.ToString());
        }
Beispiel #3
0
        public ProductCategoryDomainModel GetProductCategoryDomainModelById(string productCategoryId)
        {
            ProductCategoryDomainModel result = null;

            ProductCategoryInfoModel      basicInfo = ProductCategoryInfoService.Instance.GetProductCategoryInfoById(productCategoryId);
            ProductCategoryGroupInfoModel groupInfo = null;

            if (basicInfo != null)
            {
                groupInfo = ProductCategoryGroupInfoService.Instance.GetProductCategoryGroupById(basicInfo.GroupName);
            }

            Dictionary <string, ProductCategoryAttributesModel> AttributeList = ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(productCategoryId, true);

            Dictionary <string, ProductCategorySalesStatusModel> SalestatusList = ProductCategorySalesStatusService.Instance.GetProductCategorySalesStatusList(productCategoryId, true);

            if (basicInfo == null || groupInfo == null || AttributeList == null || SalestatusList == null)
            {
                return(null);
            }

            result                = new ProductCategoryDomainModel();
            result.BasicInfo      = basicInfo;
            result.GroupInfo      = groupInfo;
            result.AttributeList  = AttributeList;
            result.SalestatusList = SalestatusList;

            return(result);
        }
        public ProductCategoryGroupInfoModel GetProductCategoryGroupByCategoryId(string productCategoryId)
        {
            ProductCategoryGroupInfoModel result  = null;
            ProductCategoryInfoModel      catInfo = ProductCategoryInfoService.Instance.GetProductCategoryInfoById(productCategoryId);

            if (catInfo == null)
            {
                return(null);
            }

            Dictionary <string, ProductCategoryGroupInfoModel> dict = GetProductCategoryGroupList(false);

            if (dict != null)
            {
                foreach (ProductCategoryGroupInfoModel item in dict.Values)
                {
                    if (item.ProductCategoryGroupId == catInfo.GroupName)
                    {
                        result = item;
                        break;
                    }
                }
            }

            return(result);
        }
Beispiel #5
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="pc">pc</param>
        /// <returns>影响的记录行数</returns>
        public int DeleteMultiple(ParameterCollection pc)
        {
            int ret = 0;

            ProductCategoryInfoModel productcategoryinfo = new ProductCategoryInfoModel();

            ret = DbUtil.Current.DeleteMultiple(productcategoryinfo, pc);

            return(ret);
        }
Beispiel #6
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="productcategoryinfo">实体</param>
        /// <param name="pc">pc</param>
        /// <returns>影响的记录行数</returns>
        public int UpdateMultiple(ProductCategoryInfoModel productcategoryinfo, ParameterCollection pc)
        {
            int ret = 0;

            productcategoryinfo.ModifiedBy = SessionUtil.Current.UserId;
            productcategoryinfo.ModifiedOn = DateTime.Now;

            ret = DbUtil.Current.UpdateMultiple(productcategoryinfo, pc);

            return(ret);
        }
Beispiel #7
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="productcategoryinfo">实体</param>
        /// <returns>影响的记录行数</returns>
        public int Update(ProductCategoryInfoModel productcategoryinfo)
        {
            int ret = 0;

            productcategoryinfo.ModifiedBy = (SessionUtil.Current == null) ? "C792D747-6B74-4A58-BB5B-D98EF420F99F" : SessionUtil.Current.UserId;
            productcategoryinfo.ModifiedOn = DateTime.Now;

            ret = DbUtil.Current.Update(productcategoryinfo);

            return(ret);
        }
Beispiel #8
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="productcategoryid"></param>
        /// <returns>影响的记录行数</returns>
        public int Delete(string productcategoryid)
        {
            int ret = 0;

            ProductCategoryInfoModel productcategoryinfo = new ProductCategoryInfoModel();

            productcategoryinfo.ProductCategoryId = productcategoryid;

            ret = DbUtil.Current.Delete(productcategoryinfo);

            return(ret);
        }
Beispiel #9
0
        private ProductInfoDomainModel GetProductDomainInfoByProductIdFromDatabase(string productId)
        {
            ProductInfoDomainModel domainInfo = null;
            ProductInfoModel       basicInfo  = Retrieve(productId);

            if (basicInfo != null)
            {
                domainInfo           = new ProductInfoDomainModel();
                domainInfo.BasicInfo = basicInfo;

                ProductCategoryInfoModel catInfo = ProductCategoryInfoService.Instance.GetProductCategoryInfoById(basicInfo.CategoryId);
                if (catInfo == null)
                {
                    LogUtil.Debug(string.Format("产品表中存在未知类型ID的记录,CategoryId: {0}, ProductId: {1}", basicInfo.CategoryId, productId));
                    return(null);
                }

                Dictionary <string, ProductCategoryAttributesModel> catAttList = ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(catInfo.ProductCategoryId, false);
                if (catAttList == null)
                {
                    LogUtil.Debug(string.Format("产品表中类型ID为{0}的记录无扩展属性", basicInfo.CategoryId, productId));
                    return(null);
                }

                string getDetailSQL = string.Format("SELECT * FROM [{0}] WHERE product_id = $product_id$", catInfo.TableName);

                ParameterCollection pc = new ParameterCollection();
                pc.Add("product_id", basicInfo.ProductId);

                DataTable dt = ExecuteDataTable(getDetailSQL, pc);
                if (dt != null && dt.Rows.Count > 0)
                {
                    domainInfo.AttributeList = new Dictionary <string, string>();
                    foreach (ProductCategoryAttributesModel item in catAttList.Values)
                    {
                        domainInfo.AttributeList.Add(item.AttributeName, dt.Rows[0][item.AttributeName].ToString());
                    }

                    if (dt.Rows.Count > 1)
                    {
                        LogUtil.Debug(string.Format("产品表中存在相同ProductId的记录,CategoryId: {0}, ProductId: {1}", basicInfo.CategoryId, productId));
                        return(null);
                    }
                }
            }

            return(domainInfo);
        }
Beispiel #10
0
        /// <summary>
        /// 根据条件获取实体集合
        /// </summary>
        /// <param name="pc">pc</param>
        /// <param name="obc">obc</param>
        /// <returns>实体</returns>
        public List <ProductCategoryInfoModel> RetrieveMultiple(ParameterCollection pc, OrderByCollection obc)
        {
            List <ProductCategoryInfoModel> productcategoryinfos = new List <ProductCategoryInfoModel>();

            ProductCategoryInfoModel productcategoryinfo = new ProductCategoryInfoModel();
            DataTable dt = DbUtil.Current.RetrieveMultiple(productcategoryinfo, pc, obc);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                productcategoryinfo = new ProductCategoryInfoModel();
                productcategoryinfo.ConvertFrom(dt, i);
                productcategoryinfos.Add(productcategoryinfo);
            }

            return(productcategoryinfos);
        }
Beispiel #11
0
        /// <summary>
        /// 根据主键获取实体
        /// </summary>
        /// <param name="productcategoryid"></param>
        /// <returns>实体</returns>
        public ProductCategoryInfoModel Retrieve(string productcategoryid)
        {
            ProductCategoryInfoModel productcategoryinfo = new ProductCategoryInfoModel();

            productcategoryinfo.ProductCategoryId = productcategoryid;

            DataTable dt = DbUtil.Current.Retrieve(productcategoryinfo);

            if (dt.Rows.Count < 1)
            {
                return(null);
            }

            productcategoryinfo.ConvertFrom(dt);

            return(productcategoryinfo);
        }
        protected string GetImportProductInfoSQL(ProductCategoryInfoModel catInfo, Dictionary <string, ProductCategoryAttributesModel> proAttList)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("INSERT INTO [{0}] ( ", catInfo.TableName);
            foreach (ProductCategoryAttributesModel item in proAttList.Values)
            {
                sb.AppendFormat(" [{0}],", item.AttributeName);
            }
            sb.Append("product_id, product_category_id, category_group_id, created_on, created_by, status_code ) VALUES ( ");
            foreach (ProductCategoryAttributesModel item in proAttList.Values)
            {
                sb.AppendFormat(" ${0}$,", CharacterUtil.ConvertToPinyin(item.AttributeName));
            }

            sb.AppendFormat("$product_id$, $product_category_id$, $category_group_id$, $created_on$, $created_by$, 0 ) ");

            return(sb.ToString());
        }
Beispiel #13
0
        public ProductCategoryInfoModel GetProductCategoryInfoByCategoryCode(string code)
        {
            ProductCategoryInfoModel result = null;
            Dictionary <string, ProductCategoryInfoModel> dict = GetProductCategoryList(false);

            if (dict != null)
            {
                foreach (ProductCategoryInfoModel item in dict.Values)
                {
                    if (item.CategoryCode == code)
                    {
                        result = item;
                        break;
                    }
                }
            }

            return(result);
        }
Beispiel #14
0
        public bool CreateProductCategorySaleStatus(ProductCategorySalesStatusModel statusInfo, out string message)
        {
            bool result = false;

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

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

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

            Dictionary <string, ProductCategorySalesStatusModel> dict = GetProductCategorySalesStatusList(catInfo.ProductCategoryId, false);

            if (dict != null)
            {
                foreach (ProductCategorySalesStatusModel item in dict.Values)
                {
                    if (item.SalestatusName == statusInfo.SalestatusName)
                    {
                        message = "操作失败,存在相同名称的销售状态";
                        return(false);
                    }
                }
            }

            statusInfo.SalesStatusId = Guid.NewGuid().ToString();
            statusInfo.SortOrder     = (dict == null) ? 1 : dict.Count + 1;

            if (Create(statusInfo) == 1)
            {
                GetProductCategorySalesStatusList(statusInfo.ProductCategoryId, true);
                result  = true;
                message = "成功创建本产品类型销售状态";
            }

            return(result);
        }
Beispiel #15
0
        public bool UpdateProductCategorySaleStatus(ProductCategorySalesStatusModel statusInfo, out string message)
        {
            bool result = false;

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

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

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

            Dictionary <string, ProductCategorySalesStatusModel> dict = GetProductCategorySalesStatusList(catInfo.ProductCategoryId, false);

            if (dict != null)
            {
                foreach (ProductCategorySalesStatusModel item in dict.Values)
                {
                    if (item.SalestatusName == statusInfo.SalestatusName && item.SalesStatusId != statusInfo.SalesStatusId)
                    {
                        message = "操作失败,存在相同名称的销售状态";
                        return(false);
                    }
                }
            }

            if (Update(statusInfo) == 1)
            {
                GetProductCategorySalesStatusList(statusInfo.ProductCategoryId, true);
                result  = true;
                message = "成功更新本产品类型销售状态";
            }

            return(result);
        }
        public bool ImportProductInfoList(DataSet productDataSet, out string importLogs, out string message)
        {
            bool result = false;

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

            if (productDataSet == null && productDataSet.Tables.Count == 0)
            {
                message = "Excel数据文件异常,请检查";
                return(false);
            }
            Dictionary <string, ProductCategoryInfoModel> productCategoryList = ProductCategoryInfoService.Instance.GetProductCategoryList(false);

            if (productCategoryList == null || productCategoryList.Count == 0)
            {
                message = "数据库中无产品类型信息,请检查";
                return(false);
            }

            string productCategoryCode = null, importSQL = null;
            Dictionary <string, ProductCategoryAttributesModel> proAttList = null;
            ProductCategoryInfoModel catInfo = null;
            ParameterCollection      pc      = new ParameterCollection();
            ProductInfoModel         proInfo = null;

            try
            {
                BeginTransaction();
                for (int t = 0; t < productDataSet.Tables.Count; t++)
                {
                    if (productDataSet.Tables[t].TableName.Contains("-") == false)
                    {
                        continue;
                    }

                    if (productDataSet.Tables[t].TableName.Split('-')[1] != "产品信息表")
                    {
                        continue;
                    }



                    for (int i = 0; i < productDataSet.Tables[t].Rows.Count; i++)
                    {
                        productCategoryCode = productDataSet.Tables[t].Rows[i]["商品编号"].ToString();
                        catInfo             = ProductCategoryInfoService.Instance.GetProductCategoryInfoByCategoryCode(productCategoryCode);

                        if (productDataSet.Tables[t].Rows[i]["操作"].ToString() == "")
                        {
                            break;
                        }

                        if (catInfo == null)
                        {
                            RollbackTransaction();
                            message = string.Format("数据库中不存在产品类型编码为【{0}】的产品类型,数据导入失败", productCategoryCode);
                            return(false);
                        }

                        proAttList = ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(catInfo.ProductCategoryId, false);
                        if (proAttList == null)
                        {
                            RollbackTransaction();
                            message = string.Format("数据库中不存在产品类型编码为【{0}】的产品类型属性数据,数据导入失败", productCategoryCode);
                            return(false);
                        }

                        Dictionary <string, ProductCategorySalesStatusModel> statusList = ProductCategorySalesStatusService.Instance.GetProductCategorySalesStatusList(catInfo.ProductCategoryId, false);
                        if (proAttList == null)
                        {
                            RollbackTransaction();
                            message = string.Format("数据库中不存在产品类型编码为【{0}】的产品类型销售状态数据,数据导入失败", productCategoryCode);
                            return(false);
                        }


                        importSQL = GetImportProductInfoSQL(catInfo, proAttList);
                        pc.Clear();

                        foreach (ProductCategoryAttributesModel attInfo in proAttList.Values)
                        {
                            if (attInfo.FieldType == "decmial" && productDataSet.Tables[t].Rows[i][attInfo.AttributeName].ToString() == "")
                            {
                                pc.Add(string.Format("{0}", CharacterUtil.ConvertToPinyin(attInfo.AttributeName)), 0);
                            }
                            else
                            {
                                if (attInfo.AttributeName == "销售状态")
                                {
                                    pc.Add(string.Format("{0}", CharacterUtil.ConvertToPinyin(attInfo.AttributeName)), GetProductSaleStatusId(statusList, productDataSet.Tables[t].Rows[i][attInfo.AttributeName].ToString()));
                                }
                                else
                                {
                                    pc.Add(string.Format("{0}", CharacterUtil.ConvertToPinyin(attInfo.AttributeName)), productDataSet.Tables[t].Rows[i][attInfo.AttributeName].ToString());
                                }
                            }
                        }

                        proInfo             = new ProductInfoModel();
                        proInfo.ProductId   = GetGuid();
                        proInfo.CreatedOn   = DateTime.Now;
                        proInfo.CategoryId  = catInfo.ProductCategoryId;
                        proInfo.ItemPrice   = Convert.ToDecimal(productDataSet.Tables[t].Rows[i]["销售价格"].ToString());
                        proInfo.ProductCode = productDataSet.Tables[t].Rows[i]["产品代码"].ToString();
                        proInfo.ProductName = productDataSet.Tables[t].Rows[i]["产品名称"].ToString();
                        proInfo.SalesStatus = productDataSet.Tables[t].Rows[i]["销售状态"].ToString();// productDataSet.Tables[t].Rows[i]["销售状态"].ToString();
                        // proInfo.SalesStatus = GetProductSaleStatusId(statusList, productDataSet.Tables[t].Rows[i]["销售状态"].ToString());// productDataSet.Tables[t].Rows[i]["销售状态"].ToString();
                        proInfo.Status = 0;

                        pc.Add("product_id", proInfo.ProductId);
                        pc.Add("product_category_id", proInfo.CategoryId);
                        pc.Add("category_group_id", catInfo.GroupName);
                        pc.Add("created_on", proInfo.CreatedOn);
                        pc.Add("created_by", "C792D747-6B74-4A58-BB5B-D98EF420F99F");

                        if (Create(proInfo) != 1)
                        {
                            RollbackTransaction();
                            message = "导入Excel数据失败";
                            return(false);
                        }
                        else
                        {
                            if (ExecuteNonQuery(importSQL, pc) != 1)
                            {
                                RollbackTransaction();
                                message = "导入Excel数据失败";
                                return(false);
                            }
                        }
                    }
                }

                CommitTransaction();
            }
            catch (Exception ex)
            {
                RollbackTransaction();
                LogUtil.Error("从Excel导入产品数据异常", ex);
                throw ex;
            }

            return(result);
        }
        public bool ImportProductCategories(DataTable categoryTable, out string importLogs, out string message)
        {
            message    = "操作失败,请与管理员联系";
            importLogs = "";
            bool result = false;

            if (categoryTable == null && categoryTable.Rows.Count == 0)
            {
                message    = "产品类型信息表为空,请检查Excel文件是否正确";
                importLogs = message;
                return(false);
            }

            try
            {
                ProductCategoryInfoService.Instance.GetProductCategoryList(true);
                CustomDataDomainModel SaleCity = CustomDataInfoService.Instance.GetCustomDataDomainModelByName("销售城市", false);

                BeginTransaction();
                ProductCategoryInfoModel      catInfo   = null;
                ProductCategoryGroupInfoModel groupInfo = null;

                for (int i = 0; i < categoryTable.Rows.Count; i++)
                {
                    catInfo = new ProductCategoryInfoModel();
                    catInfo.CategoryName = categoryTable.Rows[i]["产品类型名称"].ToString();
                    catInfo.CategoryCode = categoryTable.Rows[i]["产品类型编码"].ToString();
                    catInfo.Description  = categoryTable.Rows[i]["描述信息"].ToString();

                    groupInfo = ProductCategoryGroupInfoService.Instance.GetProductCategoryGroupByName(categoryTable.Rows[i]["所属分组名称"].ToString());
                    if (groupInfo != null)
                    {
                        catInfo.GroupName = groupInfo.ProductCategoryGroupId;
                    }
                    else
                    {
                        groupInfo                        = new ProductCategoryGroupInfoModel();
                        groupInfo.Description            = string.Format("【{0}】导入数据创建产品分组【{1}】", DateTime.Now, categoryTable.Rows[i]["所属分组名称"].ToString());
                        groupInfo.GroupName              = categoryTable.Rows[i]["所属分组名称"].ToString();
                        groupInfo.IsItemPrice            = (categoryTable.Rows[i]["是否独立价格"].ToString() == "是") ? 0 : 1;
                        groupInfo.Status                 = 0;
                        groupInfo.ProductCategoryGroupId = GetGuid();

                        if (ProductCategoryGroupInfoService.Instance.CreateProductCategoryGroupInfo(groupInfo, out message))
                        {
                            catInfo.GroupName = groupInfo.ProductCategoryGroupId;
                        }
                        else
                        {
                            RollbackTransaction();
                            message = "创建产品分组失败";
                            return(false);
                        }
                    }

                    catInfo.ProductCategoryId = GetGuid();
                    catInfo.ItemPrice         = Convert.ToDecimal(categoryTable.Rows[i]["本类产品价格"]);

                    catInfo.Status = (categoryTable.Rows[i]["状态"].ToString() == "启用") ? 0 : 1;

                    foreach (CustomDataValueDomainModel item in SaleCity.ValueList.Values)
                    {
                        if (item.DataValue == categoryTable.Rows[i]["销售城市"].ToString())
                        {
                            catInfo.SaleCity = item.ValueId;
                            break;
                        }
                    }

                    //if (string.IsNullOrEmpty(catInfo.SaleCity))
                    //{
                    //    RollbackTransaction();
                    //    message = "Excel中存在未定义的销售城市";
                    //    return false;
                    //}

                    if (categoryTable.Rows[i]["操作"].ToString() == "新建")
                    {
                        if (ProductCategoryInfoService.Instance.CreateProductCategory(catInfo, out message) == false)
                        {
                            RollbackTransaction();
                            return(false);
                        }
                    }
                }

                CommitTransaction();
                message = "成功导入产品类型信息表";
                ProductCategoryInfoService.Instance.GetProductCategoryList(true);
                result = true;
            }
            catch (Exception ex)
            {
                RollbackTransaction();
                LogUtil.Error("导入产品类型信息异常", ex);
                throw ex;
            }

            return(result);
        }
Beispiel #18
0
        public List <string> GetProductList(string productCategoryId, Dictionary <string, QueryItemDomainModel> queryCollection, int pageIndex, int pageSize, string orderField, string orderDirection, out int total)
        {
            List <string> result = new List <string>();

            total = 0;
            ProductCategoryInfoModel catInfo = ProductCategoryInfoService.Instance.GetProductCategoryInfoById(productCategoryId);

            if (catInfo == null)
            {
                Exception ex = new Exception("获取产品列表方法异常, 不存在的产品类型ID");
                LogUtil.Error("获取产品列表方法异常, 不存在的产品类型ID", ex);
                throw ex;
            }

            Dictionary <string, ProductCategoryAttributesModel> attList = ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(productCategoryId, false);

            if (attList == null)
            {
                Exception ex = new Exception("获取产品列表方法异常, 不存在的产品类型ID");
                LogUtil.Error("获取产品列表方法异常, 不存在的产品类型ID", ex);
                throw ex;
            }

            StringBuilder sqlBuilder = new StringBuilder();

            sqlBuilder.AppendFormat(@"FROM [{0}] WHERE 1=1 ", catInfo.TableName);

            ParameterCollection pc = new ParameterCollection();

            int count = 0;

            foreach (KeyValuePair <string, QueryItemDomainModel> item in queryCollection)
            {
                switch (item.Value.Operation)
                {
                case "equal":
                    sqlBuilder.AppendFormat(@" AND [{0}] = $value{1}$", attList[item.Key].AttributeName, count);
                    pc.Add("value" + count.ToString(), item.Value.SearchValue);
                    break;

                case "notequal":
                    sqlBuilder.AppendFormat(@" AND [{0}] <> $value{1}$", attList[item.Key].AttributeName, count);
                    pc.Add("value" + count.ToString(), item.Value.SearchValue);
                    break;

                case "contain":
                    sqlBuilder.AppendFormat(@" AND [{0}] LIKE $value{1}$", attList[item.Key].AttributeName, count);
                    pc.Add("value" + count.ToString(), "%" + item.Value.SearchValue + "%");
                    break;

                case "greater":
                    sqlBuilder.AppendFormat(@" AND [{0}] > $value{1}$", attList[item.Key].AttributeName, count);
                    pc.Add("value" + count.ToString(), item.Value.SearchValue);
                    break;

                case "greaterequal":
                    sqlBuilder.AppendFormat(@" AND [{0}] >= $value{1}$", attList[item.Key].AttributeName, count);
                    pc.Add("value" + count.ToString(), item.Value.SearchValue);
                    break;

                case "less":
                    sqlBuilder.AppendFormat(@" AND [{0}] < $value{1}$", attList[item.Key].AttributeName, count);
                    pc.Add("value" + count.ToString(), item.Value.SearchValue);
                    break;

                case "lessequal":
                    sqlBuilder.AppendFormat(@" AND [{0}] <= $value{1}$", attList[item.Key].AttributeName, count);
                    pc.Add("value" + count.ToString(), item.Value.SearchValue);
                    break;

                case "between":
                    sqlBuilder.AppendFormat(@" AND [{0}] BETWEEN $begin{1}$ AND $end{1}$", attList[item.Key].AttributeName, count);
                    pc.Add("begin" + count.ToString(), item.Value.BeginTime);
                    pc.Add("end" + count.ToString(), item.Value.EndTime);
                    break;

                case "today":
                    sqlBuilder.AppendFormat(@" AND DATEDIFF(DAY,[{0}],GETDATE()) = 0", attList[item.Key].AttributeName);
                    break;

                case "week":
                    sqlBuilder.AppendFormat(@" AND DATEDIFF(WEEK,[{0}],GETDATE()) = 0", attList[item.Key].AttributeName);
                    break;

                case "month":
                    sqlBuilder.AppendFormat(@" AND DATEDIFF(MONTH,[{0}],GETDATE()) = 0", attList[item.Key].AttributeName);
                    break;

                case "quarter":
                    sqlBuilder.AppendFormat(@" AND DATEDIFF(QUARTER,[{0}],GETDATE()) = 0", attList[item.Key].AttributeName);
                    break;

                case "year":
                    sqlBuilder.AppendFormat(@" AND DATEDIFF(YEAR,[{0}],GETDATE()) = 0", attList[item.Key].AttributeName);
                    break;

                default:
                    break;
                }


                count++;
            }

            string totalSql = string.Format(@"SELECT COUNT(1) {0} ", sqlBuilder.ToString());

            total = Convert.ToInt32(ExecuteScalar(totalSql, pc));

            DataTable dt = ExecuteDataTable("SELECT product_id " + sqlBuilder.ToString(), pc, pageIndex, pageSize, OrderByCollection.Create(orderField, orderDirection));

            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    result.Add(dt.Rows[i][0].ToString());
                }
            }

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

        public bool ImportSalePackageFromExcel(DataSet ds, out string importLogs, out string message)
        {
            bool result = false;

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

            if (ds == null && ds.Tables.Count == 0)
            {
                message = "Excel数据文件异常,请检查";
                return(false);
            }

            Dictionary <string, ProductCategoryInfoModel> productCategoryList = ProductCategoryInfoService.Instance.GetProductCategoryList(false);

            if (productCategoryList == null || productCategoryList.Count == 0)
            {
                message = "数据库中无产品类型信息,请检查";
                return(false);
            }

            ParameterCollection      pc           = new ParameterCollection();
            CustomDataDomainModel    SaleCityList = CustomDataInfoService.Instance.GetCustomDataDomainModelByName("销售城市", false);
            SalesPackageInfoModel    salePackInfo = null;
            ProductCategoryInfoModel proCatInfo   = null;
            List <string>            proCatList   = new List <string>();

            try
            {
                BeginTransaction();
                for (int t = 0; t < ds.Tables.Count; t++)
                {
                    if (ds.Tables[t].TableName.Contains("-") == false)
                    {
                        continue;
                    }

                    if (ds.Tables[t].TableName.Split('-')[0] != "营销计划")
                    {
                        continue;
                    }

                    string saleCityName = ds.Tables[t].TableName.Split('-')[1];
                    CustomDataValueDomainModel saleCityInfo = SaleCityList.GetCustomDataValueDomainByDataValue(saleCityName);
                    if (saleCityInfo == null)
                    {
                        RollbackTransaction();
                        message = string.Format("数据库中不存在销售城市为【{0}】的营销计划,数据导入失败", saleCityName);
                        return(false);
                    }

                    for (int i = 0; i < ds.Tables[t].Rows.Count; i++)
                    {
                        salePackInfo                  = new SalesPackageInfoModel();
                        salePackInfo.BeginTime        = Convert.ToDateTime(ds.Tables[t].Rows[i]["有效起始时间"]);
                        salePackInfo.EndTime          = Convert.ToDateTime(ds.Tables[t].Rows[i]["有效截止时间"]);
                        salePackInfo.Location         = ds.Tables[t].Rows[i]["产品定位"].ToString();
                        salePackInfo.MonthKeepPrice   = Convert.ToDecimal(ds.Tables[t].Rows[i]["每月补存"]);
                        salePackInfo.MonthReturnPrice = Convert.ToDecimal(ds.Tables[t].Rows[i]["每月返还"]);
                        salePackInfo.PackageName      = ds.Tables[t].Rows[i]["项目名称"].ToString();
                        salePackInfo.PriceTotal       = Convert.ToDecimal(ds.Tables[t].Rows[i]["业务总额"]);
                        salePackInfo.Remark           = ds.Tables[t].Rows[i]["备注信息"].ToString();
                        salePackInfo.ReturnMonths     = Convert.ToInt32(ds.Tables[t].Rows[i]["返还月数"]);
                        salePackInfo.SalePrice        = Convert.ToDecimal(ds.Tables[t].Rows[i]["购机金额"]);
                        salePackInfo.SalesCityId      = saleCityInfo.ValueId;
                        salePackInfo.SalesCityName    = saleCityInfo.DataValue;
                        salePackInfo.SalesPackageId   = GetGuid();
                        salePackInfo.StagePrice       = Convert.ToDecimal(ds.Tables[t].Rows[i]["每期金额"]);
                        salePackInfo.Stages           = Convert.ToInt32(ds.Tables[t].Rows[i]["分期数"]);
                        salePackInfo.Status           = 0;
                        salePackInfo.StoredPrice      = Convert.ToDecimal(ds.Tables[t].Rows[i]["预存话费"]);


                        proCatList.Clear();

                        string[] catNameList = ds.Tables[t].Rows[i]["包含产品"].ToString().Split(',');
                        if (catNameList == null || catNameList.Length == 0)
                        {
                            RollbackTransaction();
                            message = string.Format("销售城市为【{0}】的营销计划中,营销项目{1}中没有设置包含产品类型名称,数据导入失败", saleCityName, salePackInfo.PackageName);
                            return(false);
                        }


                        for (int j = 0; j < catNameList.Length; j++)
                        {
                            proCatInfo = ProductCategoryInfoService.Instance.GetProductCategoryInfoByName(catNameList[j]);
                            if (proCatInfo == null)
                            {
                                RollbackTransaction();
                                message = string.Format("销售城市为【{0}】的营销计划中,营销项目{1}中设置包含产品类型名称{2}不存在于数据库,数据导入失败", saleCityName, salePackInfo.PackageName, catNameList[j]);
                                return(false);
                            }

                            proCatList.Add(proCatInfo.ProductCategoryId);
                        }


                        if (SalesPackageInfoService.Instance.CreateSalePackageInfo(salePackInfo, proCatList, out message) == false)
                        {
                            RollbackTransaction();
                            message = string.Format("销售城市为【{0}】的营销计划中,营销项目{1}数据导入失败", saleCityName, salePackInfo.PackageName);
                            return(false);
                        }
                    }
                }

                CommitTransaction();
            }
            catch (Exception ex)
            {
                RollbackTransaction();
                LogUtil.Error("从Excel导入产品数据异常", ex);
                throw ex;
            }

            return(result);
        }
Beispiel #20
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);
        }
Beispiel #21
0
        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);
        }
Beispiel #22
0
        public bool CreateProductInfo(ProductInfoDomainModel productInfo, out string message)
        {
            bool result = false;

            message = "操作失败,请与管理员联系";
            if (productInfo == null || productInfo.BasicInfo == null || productInfo.AttributeList == null)
            {
                message = "操作失败,产品参数不完整";
                return(false);
            }

            ProductCategoryInfoModel catInfo = ProductCategoryInfoService.Instance.GetProductCategoryInfoById(productInfo.BasicInfo.CategoryId);

            Dictionary <string, ProductCategoryAttributesModel> catAttList = ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(productInfo.BasicInfo.CategoryId, false);

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

            string InsProductSQL = GetCreateProductSQL(catInfo, productInfo, catAttList);

            try
            {
                BeginTransaction();

                if (Create(productInfo.BasicInfo) == 1)
                {
                    ProductAttributesValueModel valueInfo = null;
                    foreach (KeyValuePair <string, string> item in productInfo.AttributeList)
                    {
                        valueInfo                   = new ProductAttributesValueModel();
                        valueInfo.ValueId           = GetGuid();
                        valueInfo.AttributeId       = item.Key;
                        valueInfo.AttributeValue    = item.Value;
                        valueInfo.ProductCategoryId = productInfo.BasicInfo.CategoryId;
                        valueInfo.ProductId         = productInfo.BasicInfo.ProductId;

                        if (ProductAttributesValueService.Instance.Create(valueInfo) != 1)
                        {
                            RollbackTransaction();
                            message = "操作失败,保存产品属性值失败";
                            return(false);
                        }
                    }

                    if (ExecuteNonQuery(InsProductSQL) != 1)
                    {
                        RollbackTransaction();
                        message = "操作失败,插入产品信息表失败";
                        return(false);
                    }

                    CommitTransaction();
                    message = "成功创建产品信息";
                    GetProductDomainInfoByProductId(productInfo.BasicInfo.ProductId, true);
                    result = true;
                }
            }
            catch (Exception ex)
            {
                RollbackTransaction();
                LogUtil.Error("创建产品信息异常", ex);
                throw ex;
            }

            return(result);
        }
Beispiel #23
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);
        }
Beispiel #24
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);
        }
Beispiel #25
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);
        }
Beispiel #26
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);
        }