示例#1
0
        private MemoryStream stmCustomer(Api.CustomerController.queryParam q)
        {
            MemoryStream outputStream = new MemoryStream();

            try
            {
                db0 = getDB0();

                XLWorkbook   excel    = new XLWorkbook();
                IXLWorksheet getSheet = excel.Worksheets.Add("會員資料");

                #region 取得資料
                var items = getCustomerData(q);
                #endregion


                #region Excel Handle
                makeCustomer(items, getSheet);
                #endregion

                excel.SaveAs(outputStream);
                outputStream.Position = 0;
                excel.Dispose();
                return(outputStream);
            }
            catch (Exception ex)
            {
                //logger.Error(ex);
                return(null);
            }
        }
示例#2
0
        public FileResult Excel_Customer(Api.CustomerController.queryParam q)
        {
            var    outputStream = stmCustomer(q);
            string setFileName  = "會員資料-" + Guid.NewGuid().ToString() + ".xlsx";

            return(File(outputStream, "application/vnd.ms-excel", setFileName));
        }
示例#3
0
        private List <Customer> getCustomerData(Api.CustomerController.queryParam q)
        {
            List <Customer> res = new List <Customer>();

            using (var db0 = getDB0())
            {
                #region getdata
                var predicate = PredicateBuilder.True <Customer>();

                if (q.name != null)
                {
                    predicate = predicate.And(x => x.c_name.Contains(q.name) || x.email.Contains(q.name) ||
                                              x.tel.Contains(q.name) || x.mobile.Contains(q.name) ||
                                              x.zip.Contains(q.name) || x.address.Contains(q.name));
                }

                res = db0.Customer.AsExpandable().Where(predicate).ToList();
                #endregion
            }
            return(res);
        }