public void LoadData()
        {
            string   SKU        = String.Empty;
            int      CategoryID = 0;
            DateTime fromdate   = DateTime.Today;
            DateTime todate     = fromdate.AddDays(1).AddMinutes(-1);

            string CreatedBy           = "";
            int    totalRemainQuantity = 0;
            int    totalSoldQuantity   = 0;
            int    totalRefundQuantity = 0;
            double totalCost           = 0;
            double totalProfit         = 0;
            double totalRefundProfit   = 0;
            double totalRevenue        = 0;

            int day = 0;

            if (!String.IsNullOrEmpty(Request.QueryString["SKU"]))
            {
                SKU = Request.QueryString["SKU"];

                var product = ProductController.GetBySKU(SKU);
                if (product != null)
                {
                    fromdate = Convert.ToDateTime(product.CreatedDate);
                }
            }

            if (!String.IsNullOrEmpty(Request.QueryString["categoryid"]))
            {
                CategoryID = Request.QueryString["categoryid"].ToInt(0);
            }

            if (!String.IsNullOrEmpty(Request.QueryString["createdby"]))
            {
                CreatedBy = Request.QueryString["createdby"];
            }

            if (!String.IsNullOrEmpty(Request.QueryString["fromdate"]))
            {
                fromdate = Convert.ToDateTime(Request.QueryString["fromdate"]);
            }

            if (!String.IsNullOrEmpty(Request.QueryString["todate"]))
            {
                todate = Convert.ToDateTime(Request.QueryString["todate"]).AddDays(1).AddMinutes(-1);
            }

            txtTextSearch.Text         = SKU;
            ddlCategory.SelectedValue  = CategoryID.ToString();
            ddlCreatedBy.SelectedValue = CreatedBy;
            rFromDate.SelectedDate     = fromdate;
            rToDate.SelectedDate       = todate;
            day = Convert.ToInt32((todate - fromdate).TotalDays);

            if (day <= 0)
            {
                day = 1;
            }

            this.ltrTotalRemain.Text       = String.Empty;
            this.ltrTotalRemainPerDay.Text = String.Empty;
            this.ltrTotalSold.Text         = String.Empty;
            this.ltrTotalRefund.Text       = String.Empty;
            this.ltrTotalProfit.Text       = String.Empty;
            this.ltrTotalRevenue.Text      = String.Empty;
            this.ltrTotalStock.Text        = String.Empty;
            this.ltrTotalStockValue.Text   = String.Empty;

            var productReport = OrderController.getProductReport(SKU, CategoryID, CreatedBy, fromdate, todate);

            totalSoldQuantity = productReport.Sum(x => x.totalSold);
            totalRevenue      = productReport.Sum(x => x.totalRevenue);
            totalCost         = productReport.Sum(x => x.totalCost);
            totalProfit       = totalRevenue - totalCost;

            var productRefundReport = RefundGoodController.getRefundProductReport(SKU, CategoryID, CreatedBy, fromdate, todate);

            totalRefundQuantity = productRefundReport.Sum(x => x.totalRefund);
            double totalRefundRevenue = productRefundReport.Sum(x => x.totalRevenue);
            double totalRefundCost    = productRefundReport.Sum(x => x.totalCost);
            double totalRefundFee     = productRefundReport.Sum(x => x.totalRefundFee);

            totalRefundProfit = totalRefundRevenue - totalRefundCost;

            totalRemainQuantity = totalSoldQuantity - totalRefundQuantity;

            var productStockReport = ProductController.getProductStockReport(SKU, CategoryID);

            totalProfit = totalProfit - totalRefundProfit + totalRefundFee;

            ltrTotalSold.Text         = totalSoldQuantity.ToString();
            ltrTotalRefund.Text       = totalRefundQuantity.ToString();
            ltrTotalRemain.Text       = totalRemainQuantity.ToString();
            ltrTotalRemainPerDay.Text = (totalRemainQuantity / day).ToString() + " cái/ngày";
            ltrTotalRevenue.Text      = string.Format("{0:N0}", totalRevenue);
            ltrTotalProfit.Text       = string.Format("{0:N0}", totalProfit);
            ltrAverageProfit.Text     = string.Format("{0:N0}", totalProfit / day).ToString();
            ltrTotalStock.Text        = productStockReport.totalStock.ToString() + " cái";
            ltrTotalStockValue.Text   = string.Format("{0:N0}", productStockReport.totalStockValue);

            if (day > 1)
            {
                string chartLabelDays           = "";
                string chartTotalRemainQuantity = "";

                List <string> dataDays = new List <string>();
                List <string> dataTotalRemainQuantity = new List <string>();

                while (fromdate < todate)
                {
                    // Ngày biểu đồ
                    dataDays.Add(String.Format("'{0:d/M}'", fromdate));

                    // Biểu đồ sản lượng
                    int TotalSoldQuantity   = productReport.Where(x => x.reportDate.Date == fromdate).Sum(x => x.totalSold);
                    int TotalRefundQuantity = productRefundReport.Where(x => x.reportDate == fromdate).Sum(x => x.totalRefund);
                    dataTotalRemainQuantity.Add((TotalSoldQuantity - TotalRefundQuantity).ToString());

                    // Thêm 1 ngày chạy vòng lặp
                    fromdate = fromdate.AddDays(1);
                }

                chartLabelDays           = String.Join(", ", dataDays);
                chartTotalRemainQuantity = String.Join(", ", dataTotalRemainQuantity);

                StringBuilder html = new StringBuilder();
                html.Append("<script>");
                html.Append("var lineChartData = {");
                html.Append("	labels: ["+ chartLabelDays + "],");
                html.Append("	datasets: [{");
                html.Append("		label: 'Sản lượng',");
                html.Append("		borderColor: 'rgb(255, 99, 132)',");
                html.Append("		backgroundColor: 'rgb(255, 99, 132)',");
                html.Append("		fill: false,");
                html.Append("		data: ["+ chartTotalRemainQuantity + "],");
                html.Append("		yAxisID: 'y-axis-1',");
                html.Append("	}]");
                html.Append("};");
                html.Append("</script>");

                ltrChartData.Text = html.ToString();
            }
        }
        public void LoadData()
        {
            string username = Request.Cookies["usernameLoginSystem"].Value;
            var    acc      = AccountController.GetByUsername(username);

            if (acc != null)
            {
                string   user       = acc.Username;
                string   SKU        = String.Empty;
                int      CategoryID = 0;
                DateTime fromdate   = DateTime.Today;
                DateTime todate     = fromdate.AddDays(1).AddMinutes(-1);

                if (!String.IsNullOrEmpty(Request.QueryString["SKU"]))
                {
                    SKU = Request.QueryString["SKU"];

                    var product = ProductController.GetBySKU(SKU);
                    if (product != null)
                    {
                        fromdate = Convert.ToDateTime(product.CreatedDate);
                    }
                }

                if (!String.IsNullOrEmpty(Request.QueryString["categoryid"]))
                {
                    CategoryID = Request.QueryString["categoryid"].ToInt(0);
                }

                if (!String.IsNullOrEmpty(Request.QueryString["fromdate"]))
                {
                    fromdate = Convert.ToDateTime(Request.QueryString["fromdate"]);
                }

                if (!String.IsNullOrEmpty(Request.QueryString["todate"]))
                {
                    todate = Convert.ToDateTime(Request.QueryString["todate"]).AddDays(1).AddMinutes(-1);
                }

                txtTextSearch.Text        = SKU;
                ddlCategory.SelectedValue = CategoryID.ToString();
                rFromDate.SelectedDate    = fromdate;
                rToDate.SelectedDate      = todate;

                // Tính theo thời gian đã chọn
                var uReport   = OrderController.getReport(SKU, CategoryID, user, fromdate, todate);
                var sysReport = OrderController.getReport(SKU, CategoryID, "", fromdate, todate);

                // Tính tháng trước
                DateTime fromdateLastMonth = fromdate.FirstDayOfMonth().AddMonths(-1);
                DateTime todateLastMonth   = fromdateLastMonth.LastDayOfMonth().AddDays(1).AddMinutes(-1);
                var      uReportLastMonth  = OrderController.getReport(SKU, CategoryID, user, fromdateLastMonth, todateLastMonth);

                int totalDays = Convert.ToInt32((todate - fromdate).TotalDays);

                string compareTotalRemainQuantity   = "";
                string compareTotalSoldQuantity     = "";
                string compareTotalSaleOrder        = "";
                string compareNewCustomer           = "";
                string compareTotalRefundQuantity   = "";
                string compareAverageRemainQuantity = "";

                if (totalDays > 1)
                {
                    // So sánh tổng số lượng còn lại với tháng trước
                    int diffTotalRemainQuantity    = uReport.totalRemainQuantity - uReportLastMonth.totalRemainQuantity;
                    int percentTotalRemainQuantity = uReport.totalRemainQuantity * 100 / uReportLastMonth.totalRemainQuantity - 100;
                    if (diffTotalRemainQuantity > 0)
                    {
                        compareTotalRemainQuantity += "<span class='font-green' title='Tăng so với Tổng tháng " + fromdateLastMonth.Month + "'>+" + diffTotalRemainQuantity + " (+" + percentTotalRemainQuantity + "%)</span>";
                    }
                    else
                    {
                        compareTotalRemainQuantity += "<span class='font-red' title='Giảm so với Tổng tháng " + fromdateLastMonth.Month + "'>" + diffTotalRemainQuantity + " (" + percentTotalRemainQuantity + "%)</span>";
                    }

                    // So sánh tổng số lượng bán ra với tháng trước
                    int diffTotalSoldQuantity    = uReport.totalSoldQuantity - uReportLastMonth.totalSoldQuantity;
                    int percentTotalSoldQuantity = uReport.totalSoldQuantity * 100 / uReportLastMonth.totalSoldQuantity - 100;
                    if (diffTotalSoldQuantity > 0)
                    {
                        compareTotalSoldQuantity += "<span class='font-green' title='Tăng so với Tổng tháng " + fromdateLastMonth.Month + "'>+" + diffTotalSoldQuantity + " (+" + percentTotalSoldQuantity + "%)</span>";
                    }
                    else
                    {
                        compareTotalSoldQuantity += "<span class='font-red' title='Giảm so với Tổng tháng " + fromdateLastMonth.Month + "'>" + diffTotalSoldQuantity + " (" + percentTotalSoldQuantity + "%)</span>";
                    }

                    // So sánh tổng số đơn với tháng trước
                    int diffTotalSaleOrder    = uReport.totalSaleOrder - uReportLastMonth.totalSaleOrder;
                    int percentTotalSaleOrder = uReport.totalSaleOrder * 100 / uReportLastMonth.totalSaleOrder - 100;
                    if (diffTotalSaleOrder > 0)
                    {
                        compareTotalSaleOrder += "<span class='font-green' title='Tăng so với Tổng tháng " + fromdateLastMonth.Month + "'>+" + diffTotalSaleOrder + " (+" + percentTotalSaleOrder + "%)</span>";
                    }
                    else
                    {
                        compareTotalSaleOrder += "<span class='font-red' title='Giảm so với Tổng tháng " + fromdateLastMonth.Month + "'>" + diffTotalSaleOrder + " (" + percentTotalSaleOrder + "%)</span>";
                    }

                    // So sánh số lượng hàng trả với tháng trước
                    int diffTotalRefundQuantity = uReport.totalRefundQuantity - uReportLastMonth.totalRefundQuantity;
                    if (diffTotalRefundQuantity > 0)
                    {
                        compareTotalRefundQuantity += "<span class='font-red' title='Tăng so với Tổng tháng " + fromdateLastMonth.Month + "'>+" + diffTotalRefundQuantity + "</span>";
                    }
                    else
                    {
                        compareTotalRefundQuantity += "<span class='font-green' title='Giảm so với Tổng tháng " + fromdateLastMonth.Month + "'>" + diffTotalRefundQuantity + "</span>";
                    }

                    // So sánh số khách mới với tháng trước
                    int diffNewCustomer    = uReport.totalNewCustomer - uReportLastMonth.totalNewCustomer;
                    int percentNewCustomer = uReport.totalNewCustomer * 100 / uReportLastMonth.totalNewCustomer - 100;
                    if (diffNewCustomer > 0)
                    {
                        compareNewCustomer += "<span class='font-green' title='Tăng so với Tổng tháng " + fromdateLastMonth.Month + "'>+" + diffNewCustomer + " (+" + percentNewCustomer + "%)</span>";
                    }
                    else
                    {
                        compareNewCustomer += "<span class='font-red' title='Giảm so với Tổng tháng " + fromdateLastMonth.Month + "'>" + diffNewCustomer + " (" + percentNewCustomer + "%)</span>";
                    }
                }

                // So sánh trung bình số lượng còn lại với tháng này (chỉ so sánh khi số ngày == 1)
                if (totalDays >= 1)
                {
                    // So sánh trung bình số lượng còn lại với tháng trước
                    int diffAverageRemainQuantity    = uReport.averageRemainQuantity - uReportLastMonth.averageRemainQuantity;
                    int percentAverageRemainQuantity = uReport.averageRemainQuantity * 100 / uReportLastMonth.averageRemainQuantity - 100;
                    if (diffAverageRemainQuantity > 0)
                    {
                        compareAverageRemainQuantity += "<span class='font-green' title='Tăng so với Trung bình tháng " + fromdateLastMonth.Month + "'>+" + diffAverageRemainQuantity + " (+" + percentAverageRemainQuantity + "%)</span>";
                    }
                    else
                    {
                        compareAverageRemainQuantity += "<span class='font-red' title='Giảm so với Trung bình tháng " + fromdateLastMonth.Month + "'>" + diffAverageRemainQuantity + " (" + percentAverageRemainQuantity + "%)</span>";
                    }

                    // Tính tháng này
                    DateTime fromdateThisMonth = fromdate.FirstDayOfMonth();
                    DateTime todateThisMonth   = fromdate.LastDayOfMonth().AddDays(1).AddMinutes(-1);
                    if (fromdateThisMonth.Month == DateTime.Today.Month)
                    {
                        todateThisMonth = DateTime.Today.AddDays(1).AddMinutes(-1);
                    }
                    var uReportThisMonth = OrderController.getReport(SKU, CategoryID, user, fromdateThisMonth, todateThisMonth);
                    int diffThisMonthAverageRemainQuantity    = uReport.averageRemainQuantity - uReportThisMonth.averageRemainQuantity;
                    int percentThisMonthAverageRemainQuantity = uReport.averageRemainQuantity * 100 / uReportThisMonth.averageRemainQuantity - 100;
                    if (diffThisMonthAverageRemainQuantity > 0)
                    {
                        compareAverageRemainQuantity += " <span class='font-blue' title='Tăng so với Trung bình tháng " + todateThisMonth.Month + "'>+" + diffThisMonthAverageRemainQuantity + " (+" + percentThisMonthAverageRemainQuantity + "%)</span>";
                    }
                    else if (diffThisMonthAverageRemainQuantity < 0)
                    {
                        compareAverageRemainQuantity += " <span class='font-red' title='Giảm so với Trung bình tháng " + todateThisMonth.Month + "'>" + diffThisMonthAverageRemainQuantity + " (" + percentThisMonthAverageRemainQuantity + "%)</span>";
                    }
                }

                // Tính phần trăm / toàn hệ thống
                double PercentOfSystem = 0;
                if (sysReport.totalProfit > 0)
                {
                    PercentOfSystem = uReport.totalProfit * 100 / sysReport.totalProfit;
                }

                ltrTotalSaleOrder.Text        = uReport.totalSaleOrder + " đơn " + compareTotalSaleOrder;
                ltrAverageSaleOrder.Text      = uReport.averageSaleOrder.ToString() + " đơn/ngày";
                ltrTotalSoldQuantity.Text     = uReport.totalSoldQuantity.ToString() + " cái " + compareTotalSoldQuantity;
                ltrAverageSoldQuantity.Text   = uReport.averageSoldQuantity.ToString() + " cái/ngày";
                ltrTotalRefundQuantity.Text   = uReport.totalRefundQuantity.ToString() + " cái (chiếm " + (uReport.totalRefundQuantity * 100 / (uReport.totalSoldQuantity > 0 ? uReport.totalSoldQuantity : 1)) + "%) " + compareTotalRefundQuantity;
                ltrAverageRefundQuantity.Text = uReport.averageRefundQuantity.ToString() + " cái/ngày";
                ltrTotalRemainQuantity.Text   = uReport.totalRemainQuantity.ToString() + " cái " + compareTotalRemainQuantity;
                ltrAverageRemainQuantity.Text = uReport.averageRemainQuantity.ToString() + " cái/ngày " + compareAverageRemainQuantity;
                ltrPercentOfSystem.Text       = Math.Round(PercentOfSystem, 1).ToString() + "%";
                ltrTotalNewCustomer.Text      = uReport.totalNewCustomer.ToString() + " khách mới " + compareNewCustomer;

                // Xử lý biểu đồ
                int day = Convert.ToInt32((todate - fromdate).TotalDays);
                if (day > 1)
                {
                    string chartLabelDays           = "";
                    string chartTotalNewCustomer    = "";
                    string chartTotalRemainQuantity = "";
                    string chartPercentOfSystem     = "";

                    List <string> dataDays                = new List <string>();
                    List <string> dataTotalNewCustomer    = new List <string>();
                    List <string> dataTotalRemainQuantity = new List <string>();
                    List <string> dataPercentOfSystem     = new List <string>();

                    while (fromdate < todate)
                    {
                        var userReport       = OrderController.getProductReport(SKU, CategoryID, user, fromdate, todate);
                        var userRefundReport = RefundGoodController.getRefundProductReport(SKU, CategoryID, user, fromdate, todate);
                        var newCustomer      = CustomerController.Report(user, fromdate, todate);
                        // Ngày biểu đồ
                        dataDays.Add(String.Format("'{0:d/M}'", fromdate));

                        // Biểu đồ sản lượng
                        int TotalSoldQuantity   = userReport.Where(x => x.reportDate.Date == fromdate).Sum(x => x.totalSold);
                        int TotalRefundQuantity = userRefundReport.Where(x => x.reportDate == fromdate).Sum(x => x.totalRefund);
                        dataTotalRemainQuantity.Add((TotalSoldQuantity - TotalRefundQuantity).ToString());

                        // Biểu đồ khách mới
                        int TotalNewCustomer = newCustomer.Where(x => x.CreatedDate.Value.Date == fromdate).Count();
                        dataTotalNewCustomer.Add(TotalNewCustomer.ToString());

                        // Thêm 1 ngày chạy vòng lặp
                        fromdate = fromdate.AddDays(1);
                    }

                    chartLabelDays           = String.Join(", ", dataDays);
                    chartTotalNewCustomer    = String.Join(", ", dataTotalNewCustomer);
                    chartTotalRemainQuantity = String.Join(", ", dataTotalRemainQuantity);
                    chartPercentOfSystem     = String.Join(", ", dataPercentOfSystem);

                    StringBuilder html = new StringBuilder();
                    html.Append("<script>");
                    html.Append("var lineChartData = {");
                    html.Append("	labels: ["+ chartLabelDays + "],");
                    html.Append("	datasets: [{");
                    html.Append("		label: 'Sản lượng còn lại',");
                    html.Append("		borderColor: 'rgb(255, 99, 132)',");
                    html.Append("		backgroundColor: 'rgb(255, 99, 132)',");
                    html.Append("		fill: false,");
                    html.Append("		data: ["+ chartTotalRemainQuantity + "],");
                    html.Append("		yAxisID: 'y-axis-1',");
                    html.Append("	}]");
                    html.Append("};");
                    html.Append("var lineChartData2 = {");
                    html.Append("	labels: ["+ chartLabelDays + "],");
                    html.Append("	datasets: [{");
                    html.Append("		label: 'Khách mới',");
                    html.Append("		borderColor: 'rgb(54, 162, 235)',");
                    html.Append("		backgroundColor: 'rgb(54, 162, 235)',");
                    html.Append("		fill: false,");
                    html.Append("		data: ["+ chartTotalNewCustomer + "],");
                    html.Append("		yAxisID: 'y-axis-1'");
                    html.Append("	}]");
                    html.Append("};");
                    html.Append("</script>");

                    ltrChartData.Text = html.ToString();
                }
            }
        }