private void SQLQueryCallback(SQLQueryResult queryResult)
        {
            if (queryResult.MesResult == MessageQueryResult.Done)
            {
                _reportViewer.Reset();

                _reportViewer.LocalReport.ReportPath = Path.GetFullPath(@"Implement/Windows/MainScreenWindow/MVVM/Views/ReportViewers/ComprehensiveReport.rdlc");

                MSW_RP_ComprehensiveReportOV result = queryResult.Result as MSW_RP_ComprehensiveReportOV;

                ReportParameter[] reportParameters = new ReportParameter[9];
                reportParameters[0] = new ReportParameter("NgayBaoCao",
                                                          "Từ " + RPViewModel.ComprehensiveReportStartDate.ToString("dd/MM/yyyy") + " đến " + RPViewModel.ComprehensiveReportEndDate.ToString("dd/MM/yyyy"));
                reportParameters[1] = new ReportParameter("TongGiaTriNhap", result.TongGiaTriNhap.ToString());
                reportParameters[2] = new ReportParameter("TongGiaTriXuat", result.TongGiaTriXuat.ToString());
                reportParameters[3] = new ReportParameter("TongNoKH", result.TongNoKH.ToString());
                reportParameters[4] = new ReportParameter("TongNoNCC", result.TongNoNCC.ToString());
                reportParameters[5] = new ReportParameter("ThuBanHang", result.ThuBanHang.ToString());
                reportParameters[6] = new ReportParameter("ThuKhac", result.ThuKhac.ToString());
                reportParameters[7] = new ReportParameter("TongChi", result.TongChi.ToString());
                reportParameters[8] = new ReportParameter("LaiGop", result.LaiGop.ToString());
                _reportViewer.LocalReport.SetParameters(reportParameters);

                _reportViewer.SetDisplayMode(DisplayMode.PrintLayout);
                _reportViewer.ZoomMode    = ZoomMode.Percent;
                _reportViewer.ZoomPercent = 100;
                _reportViewer.RefreshReport();
            }
            else
            {
                App.Current.ShowApplicationMessageBox("Lỗi khởi tạo báo cáo!");
            }
            RPViewModel.ButtonCommandOV.IsInitComprehensiveReportButtonRunning = false;
        }
Пример #2
0
        private SQLQueryResult GetInfoForComprehensiveReport(PharmacyDBContext appDBContext, object[] paramaters)
        {
            DateTime            startDate           = (DateTime)paramaters[0];
            DateTime            endDate             = (DateTime)paramaters[1];
            ReportPageViewModel reportPageViewModel = (ReportPageViewModel)paramaters[2];

            SQLQueryResult result = new SQLQueryResult(null, MessageQueryResult.Non);

            try
            {
                MSW_RP_ComprehensiveReportOV output = new MSW_RP_ComprehensiveReportOV(reportPageViewModel);
                var orders           = appDBContext.tblOrders.Where <tblOrder>(order => order.IsActive && order.OrderTime >= startDate && order.OrderTime <= endDate).ToList();
                var warehouseImports = appDBContext.tblWarehouseImports.Where(o => o.IsActive && o.ImportTime >= startDate && o.ImportTime <= endDate).ToList();

                output.TongGiaTriNhap = warehouseImports.Sum(o => o.TotalPrice);
                output.TongGiaTriXuat = orders.Sum(o => o.TotalPrice);

                //Tinh tong no KH
                output.TongNoKH = 0;
                foreach (var item in appDBContext.tblCustomers.Where(o => o.IsActive))
                {
                    foreach (var order in item.tblOrders.Where(o => o.IsActive && o.OrderTime >= startDate && o.OrderTime <= endDate))
                    {
                        if (order.TotalPrice > order.PurchasePrice)
                        {
                            output.TongNoKH += order.TotalPrice - order.PurchasePrice;
                        }
                        else if (order.TotalPrice < order.PurchasePrice)
                        {
                            output.TongNoKH -= order.PurchasePrice - order.TotalPrice;
                        }
                    }
                }

                //Tinh tong no NCC
                output.TongNoNCC = 0;
                foreach (var item in appDBContext.tblSuppliers.Where(o => o.IsActive))
                {
                    foreach (var order in item.tblWarehouseImports.Where(o => o.IsActive && o.ImportTime >= startDate && o.ImportTime <= endDate))
                    {
                        if (order.TotalPrice > order.PurchasePrice)
                        {
                            output.TongNoNCC += order.TotalPrice - order.PurchasePrice;
                        }
                        else if (order.TotalPrice < order.PurchasePrice)
                        {
                            output.TongNoNCC -= order.PurchasePrice - order.TotalPrice;
                        }
                    }
                }

                output.ThuBanHang = output.TongGiaTriXuat;
                var incomeList = appDBContext.tblOtherPayments.Where(o => o.IsActive && o.PaymentType == 0 && o.PaymentTime >= startDate && o.PaymentTime <= endDate).ToList();
                output.ThuKhac = incomeList != null && incomeList.Count > 0 ? incomeList.Sum(o => o.TotalPrice) : 0;
                var outcomeList = appDBContext.tblOtherPayments.Where(o => o.IsActive && o.PaymentType == 1 && o.PaymentTime >= startDate && o.PaymentTime <= endDate).ToList();
                output.TongChi = outcomeList != null && outcomeList.Count > 0 ? outcomeList.Sum(o => o.TotalPrice) : 0;

                decimal loiNhuan = 0;
                foreach (var item in appDBContext.tblOrders.Where(o => o.IsActive && o.OrderTime >= startDate && o.OrderTime <= endDate))
                {
                    loiNhuan += item.TotalPrice - item.tblOrderDetails.Where(o => o.IsActive).Sum(o => o.UnitBidPrice * (decimal)o.Quantity);
                }
                output.LaiGop = output.ThuKhac + loiNhuan;

                result = new SQLQueryResult(output, MessageQueryResult.Done);
            }
            catch (Exception e)
            {
                ShowErrorMessageBox(e);
                result = new SQLQueryResult(null, MessageQueryResult.Aborted, "Lỗi load dữ liệu hóa đơn!");
            }
            return(result);
        }