C# 7 is a major update with a lot of interesting new capabilities. And while there are plenty of articles on what you can do with it, there aren't quite as many on what you should do with it. Using the principles found in the .NET Framework Design Guidelines, we're going to take a first pass at laying down strategies for getting the most from these new features.
بازخوردهای پروژهها
مشکل با نوشتن تابع تجمعی سفارشی(از طریق پیاده سازی IAggregateFunction)
با سلام؛ ضمن تشکر از اینکه تجربیاتتون رو رایگان در اختیار بقیه قرار میدید، به شخصه خیلی استفاده کردم.
و همچنین این هم تنظیمات ستونی که از این تابع تجمعی میخوام استفاده کنم.
ممنون میشم در صورت امکان کمکم کنید.
سوالی داشتم در رابطه با پیاده سازی اینترفیس IAggregateFunction
من میخوام یه گزارش بنویسم که تو اون ستون آخرش میخواد مانده تجمعی را حساب کنه.
بنابراین میخواستم با پیاده سازی این اینترفیس و همچنین بازنویسی متد ProcessingBoundary آخرین مقدار رو به عنوان خروجی تابع تجمعی ارسال کنم.
public object ProcessingBoundary(IList<SummaryCellData> columnCellsSummaryData) { if (columnCellsSummaryData == null || !columnCellsSummaryData.Any()) return 0; var list = columnCellsSummaryData; var lastItem = list.Last(); return lastItem.CellData.PropertyValue; }
در پروژهی دیگه ای این اینترفیس رو پیاده سازی کردم و مشکلی نبود ولی در پروژه جاری
که پروژه ایست با مشخصات:
نوع پروژه : WPF with MVVM
از Prism و Unity هم برای ماژولار شدن استفاده کردم.
خطای زیر رو میده :
Method 'set_DisplayFormatFormula' in type 'Hezareh.Modules.Accounting.Reporting.ViewModels.MySampleAggregateFunction' from assembly 'Hezareh.Modules.Accounting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
در صورتی که اینترفیس IAggregateFunction به صورت کامل توسط کلاس MySampleAggregateFunction پیاده سازی شده است و این هم کد کامل کلاس که همون کد مثال Sum خودتونه، که فقط تابع ProcessingBoundary رو تغییر دادم. این هم کد کاملش :
public class MySampleAggregateFunction : IAggregateFunction { public MySampleAggregateFunction() { } /// <summary> /// Fires before rendering of this cell. /// Now you have time to manipulate the received object and apply your custom formatting function. /// It can be null. /// </summary> public Func<object, string> DisplayFormatFormula { set; get; } #region Fields (6) double _groupAvg; long _groupRowNumber; double _groupSum; double _overallAvg; long _overallRowNumber; double _overallSum; #endregion Fields #region Properties (2) /// <summary> /// Returns current groups' aggregate value. /// </summary> public object GroupValue { get { return _groupAvg; } } /// <summary> /// Returns current row's aggregate value without considering the presence of the groups. /// </summary> public object OverallValue { get { return _overallAvg; } } #endregion Properties #region Methods (4) // Public Methods (1) /// <summary> /// Fires after adding a cell to the main table. /// </summary> /// <param name="cellDataValue">Current cell's data</param> /// <param name="isNewGroupStarted">Indicated starting a new group</param> public void CellAdded(object cellDataValue, bool isNewGroupStarted) { checkNewGroupStarted(isNewGroupStarted); _overallRowNumber++; _groupRowNumber++; double cellValue; if (double.TryParse(cellDataValue.ToSafeString(), NumberStyles.AllowThousands | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out cellValue)) { groupAvg(cellValue); overallAvg(cellValue); } } // Private Methods (3) private void checkNewGroupStarted(bool newGroupStarted) { if (newGroupStarted) { _groupRowNumber = 0; _groupAvg = 0; _groupSum = 0; } } private void groupAvg(double cellValue) { _groupSum += cellValue; _groupAvg = _groupSum / _groupRowNumber; } private void overallAvg(double cellValue) { _overallSum += cellValue; _overallAvg = _overallSum / _overallRowNumber; } /// <summary> /// A general method which takes a list of data and calculates its corresponding aggregate value. /// It will be used to calculate the aggregate value of each pages individually, with considering the previous pages data. /// </summary> /// <param name="columnCellsSummaryData">List of data</param> /// <returns>Aggregate value</returns> public object ProcessingBoundary(IList<SummaryCellData> columnCellsSummaryData) { if (columnCellsSummaryData == null || !columnCellsSummaryData.Any()) return 0; var list = columnCellsSummaryData; var lastItem = list.Last(); return lastItem.CellData.PropertyValue; } #endregion Methods }
columns.AddColumn(column => { column.PropertyName<VoucherRowPrintViewModel>(x => x.CaclulatedRemains); column.CellsHorizontalAlignment(PdfRpt.Core.Contracts.HorizontalAlignment.Right); column.IsVisible(true); column.Order(5); column.Width(1.5f); column.ColumnItemsTemplate(template => { template.TextBlock(); template.DisplayFormatFormula(obj => obj == null ? string.Empty : string.Format("{0:n0}", obj)); }); column.AggregateFunction(aggregateFunction => { aggregateFunction.CustomAggregateFunction(new MySampleAggregateFunction()); aggregateFunction.DisplayFormatFormula(obj => obj == null ? string.Empty : string.Format("{0:n0}", obj)); }); column.HeaderCell("مانده"); });
We developers spend lot of our time reading code. We read code so that we know how to change it to implement a new feature, fix a bug, etc. It is much better to work in a code base where code is easy to read and understand.
One thing that can make code readable is good naming. Giving variables, classes, and methods good names makes code easier to read.
اشتراکها
آزمون A/B در ASP.NET MVC
اشتراکها
کتابخانه readable
Readable is a small jQuery plugin to help you make your paragraphs,
well, more readable. It injects styling between the 45th and 75th
character of every p tag on your page. Demo
اشتراکها
کتابخانه Nex
Nex slider is a blazing fast fullscreen slider
optimized for best performances and compatible with all platforms. It
allows you to embed images, videos and even google maps in the same
slider. Demo