Skip to main content
 首页 » 编程设计

c#之方法没有重载需要 0 个参数,我缺少什么

2024年02月13日18cloudgamer

我有一个方法 iv'e 连接到我的 MVC NopCommerce 应用程序中的按钮。我只需要在调试器中得到结果,不需要在 View 中显示结果。此方法位于 OrderServiceReport 类中。

问题是当我在 Controller 类中调用我的方法时,我得到:“方法的重载不接受 0 个参数”。想我可能需要在这里添加参数?

这是我的代码..

IOrderReportService:

IList<BestsellersReportLine> DailyBestsellersReport(DateTime? startTime, 
    DateTime? endTime, OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss, 
    int billingCountryId = 0, 
    int recordsToReturn = 5, int orderBy = 1, int groupBy = 1, bool showHidden = false); 

OrderReportService 类:

public IList<BestsellersReportLine> DailyBestsellersReport(DateTime? startTime, 
        DateTime? endTime, OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss, 
        int billingCountryId = 0, 
        int recordsToReturn = 5, int orderBy = 1, int groupBy = 1, bool showHidden = false) 
    { 
 
 
 
        int? orderStatusId = null; 
        if (os.HasValue) 
            orderStatusId = (int)os.Value; 
 
        int? paymentStatusId = null; 
        if (ps.HasValue) 
            paymentStatusId = (int)ps.Value; 
 
        int? shippingStatusId = null; 
        if (ss.HasValue) 
            shippingStatusId = (int)ss.Value; 
 
 
        var query1 = from opv in _opvRepository.Table 
                     join o in _orderRepository.Table on opv.OrderId equals o.Id 
                     join pv in _productVariantRepository.Table on opv.ProductVariantId equals pv.Id 
                     join p in _productRepository.Table on pv.ProductId equals p.Id 
                     where (!startTime.HasValue || startTime.Value <= o.CreatedOnUtc) && 
                     (!endTime.HasValue || endTime.Value >= o.CreatedOnUtc) && 
                     (!orderStatusId.HasValue || orderStatusId == o.OrderStatusId) && 
                     (!paymentStatusId.HasValue || paymentStatusId == o.PaymentStatusId) && 
                     (!shippingStatusId.HasValue || shippingStatusId == o.ShippingStatusId) && 
                     (!o.Deleted) && 
                     (!p.Deleted) && 
                     (!pv.Deleted) && 
                     (billingCountryId == 0 || o.BillingAddress.CountryId == billingCountryId) && 
                     (showHidden || p.Published) && 
                     (showHidden || pv.Published) 
                     select opv; 
 
 
        var query2 = groupBy == 1 ? 
            //group by product variants 
               from opv in query1 
               group opv by opv.ProductVariantId into g 
               select new 
               { 
                   EntityId = g.Key, 
                   TotalAmount = g.Sum(x => x.PriceExclTax), 
                   TotalQuantity = g.Sum(x => x.Quantity), 
               } 
               : 
            //group by products 
               from opv in query1 
               group opv by opv.ProductVariant.ProductId into g 
               select new 
               { 
                   EntityId = g.Key, 
                   TotalAmount = g.Sum(x => x.PriceExclTax), 
                   TotalQuantity = g.Sum(x => x.Quantity), 
               } 
               ; 
 
        switch (orderBy) 
        { 
            case 1: 
                { 
                    query2 = query2.OrderByDescending(x => x.TotalQuantity); 
                } 
                break; 
            case 2: 
                { 
                    query2 = query2.OrderByDescending(x => x.TotalAmount); 
                } 
                break; 
            default: 
                throw new ArgumentException("Wrong orderBy parameter", "orderBy"); 
        } 
 
        if (recordsToReturn != 0 && recordsToReturn != int.MaxValue) 
            query2 = query2.Take(recordsToReturn); 
 
        var result = query2.ToList().Select(x => 
        { 
            var reportLine = new BestsellersReportLine() 
            { 
                EntityId = x.EntityId, 
                TotalAmount = x.TotalAmount, 
                TotalQuantity = x.TotalQuantity 
            }; 
            return reportLine; 
        }).ToList(); 
 
 
 
        return result; 
 
    } 

订单 Controller 类:

public ActionResult SendDailyReport() 
        { 
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) 
                return AccessDeniedView(); 
 
            try 
            { 
                _orderReportService.DailyBestsellersReport(); 
 
 
            } 
            catch (Exception ex) 
            { } 
            return RedirectToAction("List"); 
        } 

查看:

<a href="@Url.Action("SendDailyReport")" class="t-button">@T("Admin.Common.DailyBestsellersSend.All")</a> 

怎么了??

谢谢

请您参考如下方法:

no overload for method takes 0 arguments, what am i missing?

参数,就像错误解释的那样。

没有默认值的参数 (= 42) 需要提供一个值,在可为 null 的值类型或引用类型的情况下,该值可能为 null。

如果您查看生成的 WCF 客户端代理代码(或者您如何调用该服务),您可以看到它期望的参数以及可用的重载(如果有)。

从界面上看,至少前五个需要一个值:

_orderReportService.DailyBestsellersReport(null, null, null, null, null); 

但我不确定您使用的客户端是否也接受这个或者它是否需要设置所有 参数。

您可能还想考虑使用数据协定而不是那么多参数。