2011-12-21 84 views
1

我使用nopcommerce 1.9和創造折扣我有以下代碼使用Excel導入與實體框架,同時inseting記錄

discount = new Discount() 
      { 
       DiscountTypeId = (int)discountType, 
       DiscountRequirementId = (int)discountRequirement, 
       RequirementSpentAmount = requirementSpentAmount, 
       RequirementBillingCountryIs = requirementBillingCountryIs, 
       RequirementShippingCountryIs = requirementShippingCountryIs, 
       DiscountLimitationId = (int)discountLimitation, 
       LimitationTimes = limitationTimes, 
       Name = name, 
       UsePercentage = usePercentage, 
       DiscountPercentage = discountPercentage, 
       DiscountAmount = discountAmount, 
       StartDate = discountStartDate, 
       EndDate = discountEndDate, 
       RequiresCouponCode = requiresCouponCode, 
       CouponCode = couponCode 
      }; 
      this.DiscountService.InsertDiscount(discount); 

現在我的任務是,在'CouponCode = couponCode'我不得不更換從Excel工作表此優惠券代碼客戶在保存摺扣時上傳的列。

並且此Excel表可以有50000個優惠券代碼,因此每個優惠券都有相同的折扣信息。

在這個解決方案中我們有實體框架。我們必須將數據存儲在這種格式

D1 10% C1(coupon code from excel sheet) 
D1 10% C2(coupon code from excel sheet) 
D1 10% C3(coupon code from excel sheet) 
D1 10% C4(coupon code from excel sheet) 
D1 10% C5(coupon code from excel sheet) 
D1 10% C6(coupon code from excel sheet) 
D1 10% C7(coupon code from excel sheet) 
+0

你能否澄清一下問題所在? – Pynner 2011-12-21 14:35:09

+0

我不得不多次改變優惠券代碼= excel中的優惠券代碼 – rahularyansharma 2011-12-22 04:43:18

回答

0
if (fuXlsFile.PostedFile != null && !String.IsNullOrEmpty(fuXlsFile.FileName)) 
      { 
       DataTable dt = GetDataFromExcel(filePath, "Sheet1"); 
       foreach (DataRow dr in dt.Rows) 
       { 
        discount = new Discount() 
       { 
        DiscountTypeId = (int)discountType, 
        DiscountRequirementId = (int)discountRequirement, 
        RequirementSpentAmount = requirementSpentAmount, 
        RequirementBillingCountryIs = requirementBillingCountryIs, 
        RequirementShippingCountryIs = requirementShippingCountryIs, 
        DiscountLimitationId = (int)discountLimitation, 
        LimitationTimes = limitationTimes, 
        Name = name, 
        UsePercentage = usePercentage, 
        DiscountPercentage = discountPercentage, 
        DiscountAmount = discountAmount, 
        StartDate = discountStartDate, 
        EndDate = discountEndDate, 
        RequiresCouponCode = requiresCouponCode, 
        CouponCode = dr[0].ToString() 
       }; 


        this.DiscountService.InsertDiscount(discount); 
       } 
      } 

我發現處理這種情況在這個way.still我必須循環每個記錄的方式,但我認爲這是我的工作的必要性。