コード例 #1
0
        protected void btnExportExcel_Click(object sender, EventArgs e)
        {
            var payableProvider     = new PayableProvider();
            var DataSource          = payableProvider.GetResultPayables().ToList();
            var CollectionsListData = from payableModel in DataSource
                                      select new PayableDurationModel
            {
                JournalID      = payableModel.JournalID,
                JournalNo      = payableModel.JournalNo,
                ApplicationNo  = payableModel.ApplicationNo,
                ProcessingDays = payableProvider.CalculateProcessDay((DateTime)payableModel.PaymentDate, payableModel.CreateDate),
                LatePayment    = payableProvider.IsPaymentlate(payableModel.CreateDate)
            };

            var FileName = "PaymentDurationData.xlsx";

            var memoryStream = new MemoryStream();

            CreateExcelFile.CreateExcelDocument(CollectionsListData.ToList(), memoryStream, "Payment Durations Report");

            HttpResponse httpresponse = HttpContext.Current.Response;

            httpresponse.ClearContent();
            httpresponse.ClearHeaders();
            httpresponse.Buffer      = true;
            httpresponse.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            httpresponse.AddHeader("content-Disposition", "attachment;filename=\"" + FileName);
            httpresponse.BinaryWrite(memoryStream.ToArray());
            httpresponse.Flush();
            httpresponse.End();
        }
コード例 #2
0
        public string GetPayableDatas()
        {
            var providerData  = new PayableProvider();
            var echo          = int.Parse(HttpContext.Current.Request.Params["sEcho"]);
            var displayLength = int.Parse(HttpContext.Current.Request.Params["iDisplayLength"]);
            var displayStart  = int.Parse(HttpContext.Current.Request.Params["iDisplayStart"]);
            var sortOrder     = HttpContext.Current.Request.Params["sSortDir_0"].ToString(CultureInfo.CurrentCulture);
            var sortBy        = int.Parse(HttpContext.Current.Request.Params["iSortCol_0"]);
            //var searchTerm = HttpContext.Current.Request.Params["sSearch"].ToString(CultureInfo.CurrentCulture);

            var recordData = providerData.GetResultPayables();
            //.Where(p=>   Convert.ToString(p.JournalID).Contains(searchTerm) ||
            //    Convert.ToString(p.JournalNo).Contains(searchTerm) ||
            //    Convert.ToString(p.EditJournalID).Contains(searchTerm)
            //    );

            var recordCount = recordData.Count();

            if (recordData == null)
            {
                return(string.Empty);
            }

            switch (sortBy)
            {
            case 1:
                recordData =
                    sortOrder == "asc" ?
                    recordData.OrderBy(p => p.JournalID) :
                    recordData.OrderByDescending(p => p.JournalID);
                break;

            case 3:
                recordData =
                    sortOrder == "asc" ?
                    recordData.OrderBy(p => p.JournalNo) :
                    recordData.OrderByDescending(p => p.JournalNo);
                break;

            default:
                recordData =
                    sortOrder == "asc" ?
                    recordData.OrderBy(p => p.JournalNo) :
                    recordData.OrderByDescending(p => p.JournalNo);
                break;
            }

            var pageResult = recordData.Skip(displayStart).Take(displayLength).ToList();

            return(JsonConvert.SerializeObject(new
            {
                sEcho = echo,
                recordsTotal = recordCount,
                recordsFiltered = recordCount,
                iTotalRecords = recordCount,
                iTotalDisplayRecords = recordCount,

                aaData = from payableModel in pageResult
                         select new PayableDurationModel
                {
                    JournalID = payableModel.JournalID,
                    JournalNo = payableModel.JournalNo,
                    ApplicationNo = payableModel.ApplicationNo,
                    ProcessingDays = providerData.CalculateProcessDay((DateTime)payableModel.PaymentDate, payableModel.CreateDate),
                    LatePayment = providerData.IsPaymentlate(payableModel.CreateDate)
                }
            }));
        }