Example #1
0
        /// <summary>
        /// 加载产品
        /// </summary>
        protected virtual void LoadProducts()
        {
            if (string.IsNullOrEmpty(Request.QueryString["Id"]))
            {
                return;
            }
            var query = new QueryInfo();

            query.Query <ProductEntity>().Where(it => it.Goods.Id == Request.QueryString["Id"].Convert <long>())
            .OrderBy(it => it.Id);
            ProductEntities = Ioc.Resolve <IApplicationService, ProductEntity>().GetEntities <ProductEntity>(query);
            var builder = new StringBuilder();

            builder.Append("[");
            var tempEntities = ProductEntities == null ? null : ProductEntities.Where(it => it.Sku != "").ToList();

            if (tempEntities != null && tempEntities.Count > 0)
            {
                foreach (var info in tempEntities)
                {
                    builder.Append("{");
                    builder.AppendFormat("Id:'{0}',Price:{1},Cost:{2},Count:{3},OrderMinCount:{4},OrderStepCount:{5},DataId:'{6}',DepositRate:{7},IsCustom:{8},IsReturn:{9},IsSales:'{10}',Sku:'{11}',OrderLimitCount:{12}",
                                         info.Id, info.Price, info.Cost, info.Count, info.OrderMinCount, info.OrderStepCount, info.DataId, info.DepositRate,
                                         info.IsCustom.ToString().ToLower(), info.IsReturn.ToString().ToLower(), info.IsSales.ToString().ToLower(),
                                         string.IsNullOrEmpty(info.Sku) ? "" : info.Sku.Replace("\"", "\\\""), info.Promotion == null?0:info.Promotion.OrderLimitCount);
                    builder.Append("},");
                }
                builder.Remove(builder.Length - 1, 1);
            }
            builder.Append("]");
            Products = builder.ToString();
            var defaultEntity = ProductEntities == null ? null : ProductEntities.FirstOrDefault(it => it.Sku == "");

            if (defaultEntity != null)
            {
                hfProductId.Value = defaultEntity.Id.ToString();
            }
        }