همانطور که گفتم قصد دارم داده ها از DAL فراخوانی شده، به BLL ارسال شده و از آنجا در اختیار XtraReport قرار بدم. سناریو به این شکل هستش:
در لایه DA
public static List<t_Products> GetAllProductList() {
try
{
return objContext.t_Products.OrderBy(c => c.f_ProName).ToList();
}
......
}
در لایه BL
public static List<t_Products> GetAllProductList() {
return DAL.DALProducts.GetAllProductList();
}
در UI
List<t_Products> ProductList = BLLProducts.GetAllProductList();
var queryProduct=ProductList.Where(oo => oo.f_ProTypeID == 1)
.Select(current=>new {current.f_ProductID,current.f_ProCode,current.f_P roName,current.f_ProWeight,current.f_ProTypeID});
//ساخت یک DataTable از کوئری LINQ
productDT =Utilities.IEnumerableToDataTable.LINQToDataTable( queryProduct);
//در رویداد کلیک یک دکمه داریم:
private void simpleButton1_Click(object sender, EventArgs e)
{
if (productDT.Rows.Count > 0)
{
//ارسال DataTable مرتبط با محصولات به نام productDT به XtraReport ی به نام ProductsAndBOM
Reports.XtraReports.ProductsAndBOM x = new Reports.XtraReports.ProductsAndBOM(productDT);
x.Report();
}
else
.... }
و در آخر این که در داخل XtraReport که نام آن را ProductAndBOM گذاشتم یک DataSet دارم به نام mahshamDataSet که در آن جدولی به نام t_Product وجود دارد. فیلدهای این جدول را روی Report قرار داده ام. DataTable ارسال شده به Report را با استفاده از دستور Merge در دیتاتیبل t_Product قرار میدهم:
public partial class ProductsAndBOM : DevExpress.XtraReports.UI.XtraReport
{
public ProductsAndBOM()
{
InitializeComponent();
}
System.Data.DataTable requiredRawMaterilSource;
System.Data.DataTable productsSource;
public ProductsAndBOM(System.Data.DataTable products)
{
productsSource = products;
}
new public void Report()
{
mahshamDataSet1.t_Products.Merge(productsSource);
ProductsAndBOM productBOMXtraReport = new ProductsAndBOM();
ReportPrintTool printTool = new ReportPrintTool(productBOMXtraReport);
UserLookAndFeel lookAndFeel = new UserLookAndFeel(this);
lookAndFeel.UseDefaultLookAndFeel = false;
lookAndFeel.SkinName = "Office 2016 Colorful";
printTool.ShowRibbonPreview(lookAndFeel);
}
}
متاسفانه در هنگام Merge کردن جدول ارسالی به Report با جدول mahshamDataSet1.t_Products خطای زیر را دریافت می کنم:
An unhandled exception of type 'System.NullReferenceException' occurred in Mahsham.UI.exe
Additional information: Object reference not set to an instance of an object.
دوستان لطف کنید کدها رو بررسی کنید ببینید باید چه کار کنم تا این خطا رو دیافت نکنم و این که این روش به نظر شما دست هستش. کارفرما گیر داده که در UI و Report ها نباید به Database ارتباط برقرار بشه. ممنون