示例#1
0
        public ViewResult Index(int?CustomerId, int?SalerId, string Code)
        {
            var start     = Request["start"];
            var end       = Request["end"];
            var startDate = Request["startDate"];
            var endDate   = Request["endDate"];
            IQueryable <ReceiptViewModel> q = ReceiptRepository.GetAllvwReceipt()
                                              .Select(item => new ReceiptViewModel
            {
                Id            = item.Id,
                CreatedUserId = item.CreatedUserId,
                //CreatedUserName = item.CreatedUserName,
                CreatedDate    = item.CreatedDate,
                ModifiedUserId = item.ModifiedUserId,
                //ModifiedUserName = item.ModifiedUserName,
                ModifiedDate = item.ModifiedDate,
                Name         = item.Name,
                Code         = item.Code,
                Amount       = item.Amount,
                Address      = item.Address,
                Note         = item.Note,
                Payer        = item.Payer,
                SalerId      = item.SalerId,
                CompanyName  = item.CompanyName,
                VoucherDate  = item.VoucherDate,
                SalerName    = item.SalerName,
                CustomerId   = item.CustomerId,
            }).OrderByDescending(x => x.CreatedDate);

            if (!string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate))
            {
                DateTime start_d;
                if (DateTime.TryParseExact(startDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out start_d))
                {
                    DateTime end_d;
                    if (DateTime.TryParseExact(endDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out end_d))
                    {
                        end_d = end_d.AddHours(23);
                        q     = q.Where(x => start_d <= x.CreatedDate && x.CreatedDate <= end_d);
                    }
                }
            }
            if (!string.IsNullOrEmpty(start) && !string.IsNullOrEmpty(end))
            {
                DateTime start_d;
                if (DateTime.TryParseExact(start, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out start_d))
                {
                    DateTime end_d;
                    if (DateTime.TryParseExact(end, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out end_d))
                    {
                        end_d = end_d.AddHours(23);
                        q     = q.Where(x => start_d <= x.VoucherDate && x.VoucherDate <= end_d);
                    }
                }
            }
            if (CustomerId != null && CustomerId.Value > 0)
            {
                q = q.Where(x => x.CustomerId == CustomerId);
            }
            if (SalerId != null && SalerId.Value > 0)
            {
                q = q.Where(x => x.SalerId == SalerId);
            }
            if (!string.IsNullOrEmpty(Code))
            {
                q = q.Where(x => x.Code.Contains(Code));
            }
            ViewBag.SuccessMessage = TempData["SuccessMessage"];
            ViewBag.FailedMessage  = TempData["FailedMessage"];
            ViewBag.AlertMessage   = TempData["AlertMessage"];
            return(View(q));
        }