Exemplo n.º 1
0
        private void ConvertColumnFromRow(DataRow row, EnumColumnList enumColumns, CodeNamePairColumnList codeNamePairColunms)
        {
            if (enumColumns != null && enumColumns.Count > 0)
            {
                foreach (var entry in enumColumns)
                {
                    Type enumType = entry.EnumType;
                    if (!enumType.IsEnum)
                    {
                        throw new ArgumentException("The type '" + enumType.AssemblyQualifiedName + "' is not enum.", "enumColumns");
                    }
                    int columnIndex = entry.ColumnIndex.HasValue ? entry.ColumnIndex.Value : row.Table.Columns.IndexOf(entry.ColumnName + "_ECCentral_Auto_Removed_820319");
                    if (columnIndex < 0)
                    {
                        continue;
                    }
                    if (row[columnIndex] == null || row[columnIndex] == DBNull.Value)
                    {
                        row[entry.NewColumnIndex] = DBNull.Value;
                        continue;
                    }
                    object orignalData = row[columnIndex];
                    object tmp;
                    if (orignalData == null || orignalData == DBNull.Value || orignalData.ToString().Trim().Length <= 0)
                    {
                        row[entry.NewColumnIndex] = DBNull.Value;
                    }
                    else if (EnumCodeMapper.TryGetEnum(orignalData, enumType, out tmp))
                    {
                        row[entry.NewColumnIndex] = tmp;
                    }
                    else
                    {
                        row[entry.NewColumnIndex] = Enum.Parse(enumType, orignalData.ToString(), true);
                    }
                }
            }

            if (codeNamePairColunms != null && codeNamePairColunms.Count > 0)
            {
                foreach (var entry in codeNamePairColunms)
                {
                    int columnIndex = entry.ColumnIndex.HasValue ? entry.ColumnIndex.Value : row.Table.Columns.IndexOf(entry.ColumnName + "_ECCentral_Auto_Removed_820319");
                    if (row[columnIndex] == null || row[columnIndex] == DBNull.Value)
                    {
                        row[entry.NewColumnIndex] = DBNull.Value;
                        continue;
                    }
                    List <CodeNamePair> list = CodeNamePairManager.GetList(entry.DomainName, entry.Key);
                    string       code        = row[columnIndex].ToString();
                    CodeNamePair option      = list.Find(x => x.Code == code);
                    if (option != null)
                    {
                        row[entry.NewColumnIndex] = option.Name;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public System.Data.DataTable QuerySaleGift(SaleGiftQueryFilter filter, out int totalCount)
        {
            PagingInfoEntity pagingEntity = new PagingInfoEntity();

            pagingEntity.SortField     = filter.PageInfo.SortBy;
            pagingEntity.MaximumRows   = filter.PageInfo.PageSize;
            pagingEntity.StartRowIndex = filter.PageInfo.PageIndex * filter.PageInfo.PageSize;
            var cmd = DataCommandManager.CreateCustomDataCommandFromConfig("SaleGift_QueryGift");


            using (var sqlBuilder = new DynamicQuerySqlBuilder(cmd.CommandText, cmd, pagingEntity, "SysNo DESC"))
            {
                //sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.AND, "A.WebChannelID", DbType.AnsiStringFixedLength,
                //    "@WebChannelID", QueryConditionOperatorType.Equal, filter.ChannelID);
                sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.AND, "A.CompanyCode", DbType.AnsiStringFixedLength,
                                                             "@CompanyCode", QueryConditionOperatorType.Equal, filter.CompanyCode);


                sqlBuilder.ConditionConstructor.BeginGroupCondition(QueryConditionRelationType.AND);
                sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.OR, "B.BrandSysNo",
                                                             DbType.Int32, "@BrandSysNo", QueryConditionOperatorType.Equal, filter.BrandSysNo);
                sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.OR, "D.BrandSysNo",
                                                             DbType.Int32, "@BrandSysNo", QueryConditionOperatorType.Equal, filter.BrandSysNo);
                sqlBuilder.ConditionConstructor.EndGroupCondition();

                sqlBuilder.ConditionConstructor.BeginGroupCondition(QueryConditionRelationType.AND);
                sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.OR, "B.C3SysNo",
                                                             DbType.Int32, "@Category3SysNo", QueryConditionOperatorType.Equal, filter.Category3SysNo);
                sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.OR, "D.Category3SysNo",
                                                             DbType.Int32, "@Category3SysNo", QueryConditionOperatorType.Equal, filter.Category3SysNo);
                sqlBuilder.ConditionConstructor.EndGroupCondition();

                #region Jack.G.tang 2013-1-7 update Bug 95316

                /*修改原因:新增Category1和Category2的查询条件
                 */

                if (filter.Category1SysNo > 0)
                {
                    sqlBuilder.ConditionConstructor.BeginGroupCondition(QueryConditionRelationType.AND);
                    sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.OR, "C3.Category1SysNo",
                                                                 DbType.Int32, "@Category1SysNo", QueryConditionOperatorType.Equal, filter.Category1SysNo);
                    sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.OR, "Category3.Category1SysNo",
                                                                 DbType.Int32, "@Category1SysNo", QueryConditionOperatorType.Equal, filter.Category1SysNo);
                    sqlBuilder.ConditionConstructor.EndGroupCondition();
                }

                if (filter.Category2SysNo > 0)
                {
                    sqlBuilder.ConditionConstructor.BeginGroupCondition(QueryConditionRelationType.AND);
                    sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.OR, "C3.Category2SysNo",
                                                                 DbType.Int32, "@Category2SysNo", QueryConditionOperatorType.Equal, filter.Category2SysNo);
                    sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.OR, "Category3.Category2SysNo",
                                                                 DbType.Int32, "@Category2SysNo", QueryConditionOperatorType.Equal, filter.Category2SysNo);
                    sqlBuilder.ConditionConstructor.EndGroupCondition();
                }

                #endregion

                if (filter.MasterProductSysNo.HasValue)
                {
                    ProductBasic pMaster = GetProductBasic(filter.MasterProductSysNo.Value);
                    sqlBuilder.ConditionConstructor.BeginGroupCondition(QueryConditionRelationType.AND);

                    sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.OR, "B.ProductSysNo",
                                                                 DbType.Int32, "@MasterProductSysNo", QueryConditionOperatorType.Equal, filter.MasterProductSysNo);
                    if (pMaster.C3SysNo.HasValue)
                    {
                        sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.OR, "B.C3SysNo",
                                                                     DbType.Int32, "@MasterC3SysNo", QueryConditionOperatorType.Equal, pMaster.C3SysNo);
                    }
                    if (pMaster.BrandSysNo.HasValue)
                    {
                        sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.OR, "B.BrandSysNo",
                                                                     DbType.Int32, "@MasterBrandSysNo", QueryConditionOperatorType.Equal, pMaster.BrandSysNo);
                    }

                    sqlBuilder.ConditionConstructor.EndGroupCondition();
                }

                sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.AND, "C.ProductSysNo",
                                                             DbType.Int32, "@GiftProductSysNo", QueryConditionOperatorType.Equal, filter.GiftProductSysNo);

                sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.AND, "A.InUser",
                                                             DbType.String, "@PMUser", QueryConditionOperatorType.Equal, filter.PMUser);
                sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.AND, "A.SysNo",
                                                             DbType.Int32, "@SysNo", QueryConditionOperatorType.Equal, filter.SysNo);
                sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.AND, "A.Status",
                                                             DbType.AnsiStringFixedLength, "@Status", QueryConditionOperatorType.Equal, filter.Status);
                if (!string.IsNullOrEmpty(filter.PromotionName))
                {
                    sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.AND, "A.PromotionName",
                                                                 DbType.String, "@PromotionName", QueryConditionOperatorType.Like, filter.PromotionName);
                }
                sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.AND, "A.Type",
                                                             DbType.AnsiStringFixedLength, "@Type", QueryConditionOperatorType.Equal, filter.Type);
                if (filter.ActivityDateFrom.HasValue)
                {
                    sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.AND, "A.BeginDate",
                                                                 DbType.DateTime, "@BeginDate", QueryConditionOperatorType.MoreThanOrEqual, filter.ActivityDateFrom);
                }
                if (filter.ActivityDateTo.HasValue)
                {
                    sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.AND, "A.EndDate",
                                                                 DbType.DateTime, "@EndDate", QueryConditionOperatorType.LessThan, filter.ActivityDateTo.Value);
                }

                if (filter.VendorSysNo > 0)
                {
                    sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.AND, "VendorSysNo", DbType.Int32, "@VendorSysNo", QueryConditionOperatorType.Equal, filter.VendorSysNo);
                }

                cmd.CommandText = sqlBuilder.BuildQuerySql();
                DataSet   ds  = cmd.ExecuteDataSet();
                DataTable dt1 = ds.Tables[0];
                DataTable dt2 = ds.Tables[1];
                DataTable dt3 = ds.Tables[2];
                if (dt1 != null && dt1.Rows.Count > 0)
                {
                    foreach (DataRow row in dt1.Rows)
                    {
                        object status;
                        EnumCodeMapper.TryGetEnum(row["Status"], typeof(SaleGiftStatus), out status);
                        row["Status"] = status;
                        if (status != null)
                        {
                            row["StatusName"] = ((SaleGiftStatus)status).ToDisplayText();
                        }

                        object type;
                        EnumCodeMapper.TryGetEnum(row["Type"], typeof(SaleGiftType), out type);
                        row["Type"] = type;
                        if (type != null)
                        {
                            row["TypeName"] = ((SaleGiftType)type).ToDisplayText();
                        }

                        if (((SaleGiftType)type) == SaleGiftType.Full)
                        {
                            row["MasterProducts"] = "商品范围";
                        }
                        else
                        {
                            if (dt2 != null && dt2.Rows.Count > 0)
                            {
                                string masterProducts = "";
                                foreach (DataRow row2 in dt2.Rows)
                                {
                                    if (row2["SysNo"].ToString() == row["SysNo"].ToString())
                                    {
                                        masterProducts += row2["ProductID"].ToString() + Environment.NewLine;
                                    }
                                }
                                row["MasterProducts"] = masterProducts;
                            }
                        }

                        if (dt3 != null && dt3.Rows.Count > 0)
                        {
                            string giftProducts = "";
                            foreach (DataRow row3 in dt3.Rows)
                            {
                                if (row3["SysNo"].ToString() == row["SysNo"].ToString())
                                {
                                    giftProducts += row3["ProductID"].ToString() + Environment.NewLine;
                                }
                            }
                            row["GiftProducts"] = giftProducts;
                        }
                    }
                }

                totalCount = Convert.ToInt32(cmd.GetParameterValue("@TotalCount"));
                return(dt1);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 加载团购信息
        /// </summary>
        /// <param name="sysNo"></param>
        /// <returns></returns>
        public GroupBuyingInfo Load(int sysNo)
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("GetProductGroupBuyingEntity");

            cmd.SetParameterValue("@SysNo", sysNo);

            var             ds     = cmd.ExecuteDataSet();
            GroupBuyingInfo result = null;

            if (ds.Tables[0].Rows.Count > 0)
            {
                result = new GroupBuyingInfo();
                //DataMapper.AutoMap<GroupBuyingInfo>(result, ds.Tables[0].Rows[0]);

                DataRow row = ds.Tables[0].Rows[0];
                result.CompanyCode              = row["CompanyCode"].ToString();
                result.SysNo                    = Convert.ToInt32(row["SysNo"]);
                result.ProductSysNo             = Convert.ToInt32(row["ProductSysNo"]);
                result.ProductID                = row["ProductID"].ToString();
                result.GroupBuyingTypeSysNo     = Convert.ToInt32(row["GroupBuyingTypeSysNo"]);
                result.GroupBuyingAreaSysNo     = Convert.ToInt32(row["GroupBuyingAreaSysNo"]);
                result.GroupBuyingVendorSysNo   = row["VendorSysNo"] == DBNull.Value ? 0 : Convert.ToInt32(row["VendorSysNo"]);
                result.RequestSysNo             = row["RequestSysNo"] == DBNull.Value ? 0 : Convert.ToInt32(row["RequestSysNo"]);
                result.GroupBuyingVendorName    = row["VendorName"] == null ? "" : row["VendorName"].ToString();
                result.GroupBuyingTitle         = new LanguageContent(row["GroupBuyingTitle"].ToString());
                result.GroupBuyingRules         = new LanguageContent(row["GroupBuyingRules"].ToString());
                result.GroupBuyingDesc          = new LanguageContent(row["GroupBuyingDesc"].ToString());
                result.GroupBuyingDescLong      = new LanguageContent(row["GroupBuyingDescLong"].ToString());
                result.GroupBuyingPicUrl        = new LanguageContent(row["GroupBuyingPicUrl"].ToString());
                result.Reasons                  = row["Reasons"] == null ? string.Empty : row["Reasons"].ToString();
                result.InUser                   = row["InUser"] == null ? string.Empty : row["InUser"].ToString();
                result.GroupBuyingMiddlePicUrl  = new LanguageContent(row["GroupBuyingMiddlePicUrl"].ToString());
                result.GroupBuyingSmallPicUrl   = new LanguageContent(row["GroupBuyingSmallPicUrl"].ToString());
                result.BeginDate                = Convert.ToDateTime(row["BeginDate"]);
                result.EndDate                  = Convert.ToDateTime(row["EndDate"]);
                result.IsByGroup                = row["IsByGroup"].Equals(1);
                result.LimitOrderCount          = Convert.ToInt32(row["LimitOrderCount"]);
                result.MaxCountPerOrder         = Convert.ToInt32(row["MaxPerOrder"]);
                result.OriginalPrice            = Convert.ToDecimal(row["OriginalPrice"]);
                result.GBPrice                  = Convert.ToDecimal(row["GBPrice"]);
                result.CurrentSellCount         = Convert.ToInt32(row["CurrentSellCount"]);
                result.CouponValidDate          = row["CouponValidDate"] == DBNull.Value ? default(DateTime?) : Convert.ToDateTime(row["CouponValidDate"]);
                result.LotteryRule              = row["LotteryRule"] == null ? string.Empty : row["LotteryRule"].ToString();
                result.GroupBuyingCategorySysNo = (row["GroupBuyingCategorySysNo"] == null || row["GroupBuyingCategorySysNo"] == DBNull.Value)? default(int?) : Convert.ToInt32(row["GroupBuyingCategorySysNo"]);
                result.IsWithoutReservation     = Convert.ToInt32(row["IsWithoutReservation"]) == 1;
                result.IsVouchers               = Convert.ToInt32(row["IsVouchers"]) == 1;
                object categoryType;
                if (EnumCodeMapper.TryGetEnum(row["GroupBuyingCategoryType"], typeof(GroupBuyingCategoryType), out categoryType))
                {
                    result.CategoryType = (GroupBuyingCategoryType)categoryType;
                }

                object settlementStatus;
                if (EnumCodeMapper.TryGetEnum(row["SettlementStatus"], typeof(GroupBuyingStatus), out settlementStatus))
                {
                    result.SettlementStatus = (GroupBuyingSettlementStatus)settlementStatus;
                }
                object status;
                if (EnumCodeMapper.TryGetEnum(row["Status"], typeof(GroupBuyingStatus), out status))
                {
                    result.Status = (GroupBuyingStatus)status;
                }
                if (row["Priority"] != DBNull.Value)
                {
                    result.Priority = Convert.ToInt32(row["Priority"]);
                }
                if (row["SuccessDate"] != DBNull.Value)
                {
                    result.SuccessDate = Convert.ToDateTime(row["SuccessDate"]);
                }
                //result.InUser = row["InUser"].ToString();

                //result.PriceRankList = DataMapper.GetEntityList<PSPriceDiscountRule, List<PSPriceDiscountRule>>(ds.Tables[1].Rows);
                result.PriceRankList = new List <PSPriceDiscountRule>();
                foreach (DataRow item in ds.Tables[1].Rows)
                {
                    if (result.GroupBuyingTypeSysNo == 6)
                    {
                        result.GroupBuyingPoint = Convert.ToInt32(item["GroupBuyingPoint"]);
                    }
                    result.PriceRankList.Add(new PSPriceDiscountRule()
                    {
                        MinQty        = Convert.ToInt32(item["SellCount"]),
                        DiscountValue = Convert.ToDecimal(item["GroupBuyingPrice"]),
                        ProductSysNo  = Convert.ToInt32(item["SysNo"]),
                    });
                    decimal?costAmt = item["CostAmt"] != DBNull.Value ? Convert.ToDecimal(item["CostAmt"]) : default(decimal?);
                    if (costAmt.HasValue)
                    {
                        result.CostAmt = costAmt;
                    }
                }
                //团购类型
                result.GroupBuyingTypeList = this.GetGroupBuyingTypes();
                //地区
                result.GroupBuyingAreaList = this.GetGroupBuyingAreas();
            }
            return(result);
        }
Exemplo n.º 4
0
        public static Coupon Load(int?sysNo)
        {
            Coupon      info = null;
            DataCommand cmd  = DataCommandManager.GetDataCommand("LoadCoupon");

            cmd.SetParameterValue("@SysNo", sysNo);
            DataSet ds = cmd.ExecuteDataSet();

            if (ds != null && ds.Tables.Count > 0)
            {
                DataTable dtMaster = ds.Tables[0];
                if (dtMaster.Rows.Count > 0)
                {
                    info = DataMapper.GetEntity <Coupon>(dtMaster.Rows[0]);
                    info.DiscountRules = new List <CouponDiscountRule>();
                    info.BindRule      = new CouponBindRule();
                    info.SaleRule      = new CouponSaleRule();

                    info.SaleRule.ProductRange          = new ProductRelation();
                    info.SaleRule.ProductRange.Products = new List <RelProduct>();

                    info.SaleRule.CustomerRange           = new CustomerRelation();
                    info.SaleRule.CustomerRange.Customers = new List <RelCustomer>();

                    info.BindRule.ProductRange          = new ProductRelation();
                    info.BindRule.ProductRange.Products = new List <RelProduct>();

                    DataTable dtDiscountRules = ds.Tables[1];
                    if (dtDiscountRules.Rows.Count > 0)
                    {
                        #region Coupon_DiscountRules的数据绑定
                        foreach (DataRow dr in dtDiscountRules.Rows)
                        {
                            CouponDiscountRule rule = new CouponDiscountRule();
                            if (dr["RulesType"].ToString().Trim().ToUpper() == "P")
                            {
                                rule.RulesType = CouponDiscountRuleType.Percentage;
                            }
                            else if (dr["RulesType"].ToString().Trim().ToUpper() == "D")
                            {
                                rule.RulesType = CouponDiscountRuleType.Discount;
                            }
                            rule.Value  = decimal.Parse(dr["Value"].ToString().Trim());
                            rule.Amount = decimal.Parse(dr["Amount"].ToString().Trim());
                            info.DiscountRules.Add(rule);
                        }
                        #endregion
                    }


                    DataTable dtBindRule = ds.Tables[2];
                    if (dtBindRule.Rows.Count > 0)
                    {
                        #region Coupon_BindRules的数据绑定
                        DataRow dr = dtBindRule.Rows[0];
                        if (!string.IsNullOrEmpty(dr["BindCondition"].ToString()))
                        {
                            object bindConditionType;
                            EnumCodeMapper.TryGetEnum(dr["BindCondition"], typeof(CouponsBindConditionType), out bindConditionType);
                            info.BindRule.BindCondition = (CouponsBindConditionType)bindConditionType;
                        }

                        if (!string.IsNullOrEmpty(dr["ValidPeriod"].ToString()))
                        {
                            object validPeriod;
                            EnumCodeMapper.TryGetEnum(dr["ValidPeriod"], typeof(CouponValidPeriodType), out validPeriod);
                            info.BindRule.ValidPeriod = (CouponValidPeriodType)validPeriod;
                        }

                        if (!string.IsNullOrEmpty(dr["BindBeginDate"].ToString()))
                        {
                            info.BindRule.BindBeginDate = DateTime.Parse(dr["BindBeginDate"].ToString().Trim());
                        }
                        if (!string.IsNullOrEmpty(dr["BindEndDate"].ToString()))
                        {
                            info.BindRule.BindEndDate = DateTime.Parse(dr["BindEndDate"].ToString().Trim());
                        }

                        if (!string.IsNullOrEmpty(dr["AmountLimit"].ToString()))
                        {
                            info.BindRule.AmountLimit = decimal.Parse(dr["AmountLimit"].ToString().Trim());
                        }

                        if (!string.IsNullOrEmpty(dr["LimitType"].ToString()))
                        {
                            if (dr["LimitType"].ToString().Trim().ToLower() == "A".ToLower())
                            {
                                info.BindRule.ProductRange.ProductRangeType = ProductRangeType.All;
                            }
                            else
                            {
                                info.BindRule.ProductRange.ProductRangeType = ProductRangeType.Limit;
                            }
                        }
                        else
                        {
                            info.BindRule.ProductRange.ProductRangeType = ProductRangeType.All;
                        }
                        #endregion
                    }

                    DataTable dtBindRuleItems = ds.Tables[3];
                    if (dtBindRuleItems.Rows.Count > 0)
                    {
                        #region Coupon_BindRuleItems的数据绑定
                        foreach (DataRow dr in dtBindRuleItems.Rows)
                        {
                            if (dr["RuleItemType"].ToString().Trim().ToUpper() == "I")
                            {
                                RelProduct product = new RelProduct();
                                if (!string.IsNullOrEmpty(dr["ItemDataSysNo"].ToString()))
                                {
                                    product.ProductSysNo = int.Parse(dr["ItemDataSysNo"].ToString());
                                }

                                if (!string.IsNullOrEmpty(dr["ProductID"].ToString()))
                                {
                                    product.ProductID = dr["ProductID"].ToString();
                                }

                                if (!string.IsNullOrEmpty(dr["ProductName"].ToString()))
                                {
                                    product.ProductName = dr["ProductName"].ToString();
                                }

                                if (!string.IsNullOrEmpty(dr["RelationType"].ToString()))
                                {
                                    if (dr["RelationType"].ToString().Trim() == "Y")
                                    {
                                        info.BindRule.ProductRange.RelationType = RelationType.Y;
                                    }
                                    else
                                    {
                                        info.BindRule.ProductRange.RelationType = RelationType.N;
                                    }
                                }
                                if (!string.IsNullOrEmpty(dr["ProductStatus"].ToString()))
                                {
                                    ProductStatus productStatus;
                                    if (Enum.TryParse <ProductStatus>(dr["ProductStatus"].ToString(), out productStatus))
                                    {
                                        product.ProductStatus = EnumHelper.GetDescription(productStatus);
                                    }
                                }
                                info.BindRule.ProductRange.Products.Add(product);
                            }
                        }
                        #endregion
                    }

                    DataTable dtSaleRules_Ex = ds.Tables[4];
                    if (dtSaleRules_Ex.Rows.Count > 0)
                    {
                        #region Coupon_SaleRules_Ex的数据绑定
                        DataRow dr = dtSaleRules_Ex.Rows[0];

                        if (!string.IsNullOrEmpty(dr["OrderAmountLimit"].ToString()))
                        {
                            info.SaleRule.OrderAmountLimit = decimal.Parse(dr["OrderAmountLimit"].ToString().Trim());
                            if (info.SaleRule.OrderAmountLimit == 0m)
                            {
                                info.SaleRule.OrderAmountLimit = null;
                            }
                        }

                        if (!string.IsNullOrEmpty(dr["OrderMaxDiscount"].ToString()))
                        {
                            info.SaleRule.OrderMaxDiscount = decimal.Parse(dr["OrderMaxDiscount"].ToString().Trim());
                        }

                        if (!string.IsNullOrEmpty(dr["CustomerMaxFrequency"].ToString()))
                        {
                            info.SaleRule.CustomerMaxFrequency = int.Parse(dr["CustomerMaxFrequency"].ToString());
                        }
                        if (!string.IsNullOrEmpty(dr["MaxFrequency"].ToString()))
                        {
                            info.SaleRule.MaxFrequency = int.Parse(dr["MaxFrequency"].ToString());
                        }

                        #endregion
                    }
                    DataTable dtSaleRules = ds.Tables[5];
                    if (dtSaleRules.Rows.Count > 0)
                    {
                        if (!string.IsNullOrEmpty(dtMaster.Rows[0]["ProductRangeType"].ToString()))
                        {
                            object productRangeType;
                            EnumCodeMapper.TryGetEnum(dtMaster.Rows[0]["ProductRangeType"], typeof(ProductRangeType), out productRangeType);
                            info.SaleRule.ProductRange.ProductRangeType = (ProductRangeType)productRangeType;
                        }

                        #region Coupon_SaleRules的数据绑定
                        foreach (DataRow dr in dtSaleRules.Rows)
                        {
                            if (dr["Type"].ToString().Trim().ToUpper() == "I")
                            {
                                RelProduct product = new RelProduct();
                                if (!string.IsNullOrEmpty(dr["ProductSysNo"].ToString()))
                                {
                                    product.ProductSysNo = int.Parse(dr["ProductSysNo"].ToString());
                                }

                                if (!string.IsNullOrEmpty(dr["ProductID"].ToString()))
                                {
                                    product.ProductID = dr["ProductID"].ToString();
                                }

                                if (!string.IsNullOrEmpty(dr["ProductName"].ToString()))
                                {
                                    product.ProductName = dr["ProductName"].ToString();
                                }

                                if (!string.IsNullOrEmpty(dr["RelationType"].ToString()))
                                {
                                    if (dr["RelationType"].ToString().Trim() == "Y")
                                    {
                                        info.SaleRule.ProductRange.RelationType = RelationType.Y;
                                    }
                                    else
                                    {
                                        info.SaleRule.ProductRange.RelationType = RelationType.N;
                                    }
                                }
                                if (!string.IsNullOrEmpty(dr["ProductStatus"].ToString()))
                                {
                                    ProductStatus productStatus;
                                    if (Enum.TryParse <ProductStatus>(dr["ProductStatus"].ToString(), out productStatus))
                                    {
                                        product.ProductStatus = EnumHelper.GetDescription(productStatus);
                                    }
                                }
                                info.SaleRule.ProductRange.Products.Add(product);
                            }
                        }

                        #endregion
                    }



                    DataTable dtSaleRulesCustomer = ds.Tables[6];
                    if (dtSaleRulesCustomer.Rows.Count > 0)
                    {
                        #region Coupon_SaleRulesCustomer的数据绑定
                        foreach (DataRow dr in dtSaleRulesCustomer.Rows)
                        {
                            RelCustomer customer = new RelCustomer();
                            //cs.Customer = new SampleObject(int.Parse(dr["CustomerSysNo"].ToString()));
                            customer.CustomerSysNo = int.Parse(dr["CustomerSysNo"].ToString());

                            customer.CustomerID   = string.IsNullOrEmpty(dr["CustomerID"].ToString()) ? null : dr["CustomerID"].ToString().Trim();
                            customer.CustomerName = string.IsNullOrEmpty(dr["CustomerName"].ToString()) ? null : dr["CustomerName"].ToString().Trim();
                            info.SaleRule.CustomerRange.Customers.Add(customer);
                            info.SaleRule.CustomerRange.CustomerRangeType = CouponCustomerRangeType.Limit;
                        }
                        #endregion
                    }
                    else
                    {
                        info.SaleRule.CustomerRange.CustomerRangeType = CouponCustomerRangeType.All;
                    }

                    if (info != null &&
                        info.BindRule != null &&
                        info.BindRule.BindCondition == CouponsBindConditionType.None)
                    {
                        List <CouponCode> codes = LoadCouponCodes(info.SysNo);
                        if (codes != null && codes.Count > 0)
                        {
                            info.CouponCodes = codes;
                            if (codes[0].CodeType == CouponCodeType.Common)
                            {
                                info.GeneralCode = codes[0];
                            }
                            else
                            {
                                string BatchCode = "";
                                for (int i = 0; i < codes.Count; i++)
                                {
                                    if (i == codes.Count - 1)
                                    {
                                        BatchCode += codes[i].Code;
                                    }
                                    else
                                    {
                                        BatchCode += codes[i].Code + "\n";
                                    }
                                }
                                info.ThrowInCodes = BatchCode;
                            }
                        }
                    }

                    if (info != null && (info.Status == CouponStatus.Run ||
                                         info.Status == CouponStatus.Finish ||
                                         info.Status == CouponStatus.Stoped))
                    {
                        info.CouponCodes = LoadCouponCodes(info.SysNo);
                    }
                }
            }
            return(info);
        }