Beispiel #1
0
        public MorrisChartModel.LineChart GetSalesChartData(int Duration = 30)
        {
            myshop = new MyshopDb();
            MorrisChartModel.LineChart chart = new MorrisChartModel.LineChart();
            DateTime      lastDate           = DateTime.Now.AddDays(-Duration).Date;
            int           Seed = Duration / 10;
            StringBuilder sb   = new StringBuilder();

            var sales = myshop.Sale_Tr_Invoice.Where(x => x.IsDeleted == false && x.InvoiceDate >= DbFunctions.TruncateTime(lastDate) && x.ShopId.Equals(WebSession.ShopId)).ToList();

            if (sales != null)
            {
                sb.Append("|[");
                if (Duration == 0)
                {
                    for (int i = 0; i <= 24; i += 3)
                    {
                        sb.Append("{#y#:#" + (i) + "H#,");
                        sb.Append("#d#:" + sales.Where(x => x.InvoiceDate >= lastDate.AddHours(i) && x.InvoiceDate <= lastDate.AddHours(i + 3)).Count() + ",");
                        sb.Append("#e#:" + sales.Where(x => x.InvoiceDate >= lastDate.AddHours(i) && x.InvoiceDate <= lastDate.AddHours(i + 3)).Sum(x => x.GrandTotal - x.RefundAmount) + "},");
                    }
                }
                if (Duration != 0)
                {
                    for (int i = 0; i <= Duration; i++)
                    {
                        sb.Append("{#y#:#" + (i) + "D#,");
                        sb.Append("#d#:" + sales.Where(x => x.InvoiceDate.Date == lastDate.AddDays(i)).Count() + ",");
                        sb.Append("#e#:" + sales.Where(x => x.InvoiceDate.Date == lastDate.AddDays(i)).Sum(x => x.GrandTotal - x.RefundAmount) + "},");
                    }
                }
                //if (Duration % 7 == 0)
                //{
                //    Seed = Duration / 7;
                //    for (int i = 1; i <= 7; i++)
                //    {
                //        sb.Append("{#y#:#" + (Seed * i) + "D#,");
                //        sb.Append("#d" + count + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[0]) && x.CreatedDate.Date >= lastDate.Date && x.CreatedDate.Date <= lastDate.AddDays(i * Seed)).Count() + ",");
                //        sb.Append("#d" + (count + 1) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[1]) && x.CreatedDate.Date >= lastDate.AddDays((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddDays(i * Seed)).Count() + ",");
                //        sb.Append("#d" + (count + 2) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[2]) && x.CreatedDate.Date >= lastDate.AddDays((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddDays(i * Seed)).Count() + ",");
                //        sb.Append("#d" + (count + 3) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[3]) && x.CreatedDate.Date >= lastDate.AddDays((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddDays(i * Seed)).Count() + ",");
                //        sb.Append("#d" + (count + 4) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[4]) && x.CreatedDate.Date >= lastDate.AddDays((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddDays(i * Seed)).Count() + "},");
                //    }
                //}
                //if (Duration == 1)
                //{
                //    Seed = 24 / 8;
                //    for (int i = 1; i <= 8; i++)
                //    {
                //        sb.Append("{#y#:#" + (Seed * i) + "H#,");
                //        sb.Append("#d" + count + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[0]) && x.CreatedDate.Date >= lastDate.Date && x.CreatedDate.Date <= lastDate.AddDays(i * Seed)).Count() + ",");
                //        sb.Append("#d" + (count + 1) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[1]) && x.CreatedDate.Date >= lastDate.AddHours((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddHours(i * Seed)).Count() + ",");
                //        sb.Append("#d" + (count + 2) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[2]) && x.CreatedDate.Date >= lastDate.AddHours((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddHours(i * Seed)).Count() + ",");
                //        sb.Append("#d" + (count + 3) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[3]) && x.CreatedDate.Date >= lastDate.AddHours((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddHours(i * Seed)).Count() + ",");
                //        sb.Append("#d" + (count + 4) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[4]) && x.CreatedDate.Date >= lastDate.AddHours((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddHours(i * Seed)).Count() + "},");
                //    }
                //}
                sb.Append("]|");
                chart.Data = sb.ToString().Remove(sb.ToString().LastIndexOf(','), 1);
            }
            return(chart);
        }
Beispiel #2
0
        public MorrisChartModel.LineChart GetCustomesChartData(int[] CustType = null, int Duration = 30)
        {
            CustType = CustType ?? new int[5] {
                0, 0, 0, 0, 0
            };
            int[] CustTypeId = new int[5] {
                0, 0, 0, 0, 0
            };
            for (int i = 0; i < CustType.Length; i++)
            {
                CustTypeId[i] = CustType[i];
            }

            myshop = new MyshopDb();
            MorrisChartModel.LineChart chart = new MorrisChartModel.LineChart();
            DateTime lastDate = DateTime.Now.AddDays(-Duration);

            Array.Sort(CustTypeId);
            int           count = 1, Seed = Duration / 10, id = 0;
            StringBuilder sb = new StringBuilder();

            var customers = myshop.Gbl_Master_Customer.Where(x => CustTypeId.Contains(x.CustomerTypeId) && x.IsDeleted == false).ToList();

            chart.Labels = new string[CustTypeId.Length];
            for (int i = 0; i < CustTypeId.Length; i++)
            {
                id = CustTypeId[i];

                var proName = myshop.Gbl_Master_CustomerType.Where(x => x.CustomerTypeId.Equals(id)).FirstOrDefault();
                chart.Labels[i] = proName == null ? string.Empty : proName.CustomerType;
            }
            if (customers != null)
            {
                sb.Append("|[");
                if (Duration % 10 == 0)
                {
                    for (int i = 1; i <= 10; i++)
                    {
                        sb.Append("{#y#:#" + (Seed * i) + "D#,");
                        sb.Append("#d" + count + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[0]) && x.CreatedDate.Date >= lastDate.Date && x.CreatedDate.Date <= lastDate.AddDays(i * Seed)).Count() + ",");
                        sb.Append("#d" + (count + 1) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[1]) && x.CreatedDate.Date >= lastDate.AddDays((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddDays(i * Seed)).Count() + ",");
                        sb.Append("#d" + (count + 2) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[2]) && x.CreatedDate.Date >= lastDate.AddDays((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddDays(i * Seed)).Count() + ",");
                        sb.Append("#d" + (count + 3) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[3]) && x.CreatedDate.Date >= lastDate.AddDays((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddDays(i * Seed)).Count() + ",");
                        sb.Append("#d" + (count + 4) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[4]) && x.CreatedDate.Date >= lastDate.AddDays((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddDays(i * Seed)).Count() + "},");
                    }
                }
                if (Duration % 7 == 0)
                {
                    Seed = Duration / 7;
                    for (int i = 1; i <= 7; i++)
                    {
                        sb.Append("{#y#:#" + (Seed * i) + "D#,");
                        sb.Append("#d" + count + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[0]) && x.CreatedDate.Date >= lastDate.Date && x.CreatedDate.Date <= lastDate.AddDays(i * Seed)).Count() + ",");
                        sb.Append("#d" + (count + 1) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[1]) && x.CreatedDate.Date >= lastDate.AddDays((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddDays(i * Seed)).Count() + ",");
                        sb.Append("#d" + (count + 2) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[2]) && x.CreatedDate.Date >= lastDate.AddDays((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddDays(i * Seed)).Count() + ",");
                        sb.Append("#d" + (count + 3) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[3]) && x.CreatedDate.Date >= lastDate.AddDays((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddDays(i * Seed)).Count() + ",");
                        sb.Append("#d" + (count + 4) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[4]) && x.CreatedDate.Date >= lastDate.AddDays((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddDays(i * Seed)).Count() + "},");
                    }
                }
                if (Duration == 1)
                {
                    Seed = 24 / 8;
                    for (int i = 1; i <= 8; i++)
                    {
                        sb.Append("{#y#:#" + (Seed * i) + "H#,");
                        sb.Append("#d" + count + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[0]) && x.CreatedDate.Date >= lastDate.Date && x.CreatedDate.Date <= lastDate.AddDays(i * Seed)).Count() + ",");
                        sb.Append("#d" + (count + 1) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[1]) && x.CreatedDate.Date >= lastDate.AddHours((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddHours(i * Seed)).Count() + ",");
                        sb.Append("#d" + (count + 2) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[2]) && x.CreatedDate.Date >= lastDate.AddHours((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddHours(i * Seed)).Count() + ",");
                        sb.Append("#d" + (count + 3) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[3]) && x.CreatedDate.Date >= lastDate.AddHours((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddHours(i * Seed)).Count() + ",");
                        sb.Append("#d" + (count + 4) + "#:" + customers.Where(x => x.CustomerTypeId.Equals(CustTypeId[4]) && x.CreatedDate.Date >= lastDate.AddHours((i - 1) * Seed) && x.CreatedDate.Date <= lastDate.AddHours(i * Seed)).Count() + "},");
                    }
                }
                sb.Append("]|");
                chart.Data = sb.ToString().Remove(sb.ToString().LastIndexOf(','), 1);
            }
            return(chart);
        }