Exemplo n.º 1
0
        private async Task <DataPaging <List <CourierExportModel> > > SearchByModel(CourierSearchRequestModel request)
        {
            var datas = await _rpCourierProfile.GetHosoCourrier(request.freeText, request.courierId, GlobalData.User.IDUser, request.status, request.PageNumber, request.limit, request.groupId, request.provinceId, request.salecode);

            var totalRecord = (datas != null && datas.Any()) ? datas[0].TotalRecord : 0;

            try
            {
                var profiles = _mapper.Map <List <CourierExportModel> >(datas);
                var result   = DataPaging.Create(profiles, totalRecord);
                return(result);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> ExportFile(string freeText = null, int provinceId = 0, int courierId = 0, string status = null, int groupId = 0, int page = 1, int limit = 10, string salecode = null)
        {
            var request = new CourierSearchRequestModel
            {
                freeText   = freeText,
                provinceId = provinceId,
                courierId  = courierId,
                status     = status,
                groupId    = groupId,
                page       = page,
                limit      = limit,
                salecode   = salecode
            };

            try
            {
                string destDirectory = VS_LOAN.Core.Utility.Path.DownloadBill + "/" + DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString() + "/";
                bool   exists        = System.IO.Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + destDirectory);
                if (!exists)
                {
                    System.IO.Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + destDirectory);
                }
                string fileName = "Report-DSHS" + DateTime.Now.ToString("ddMMyyyyHHmmssfff") + ".xlsx";
                using (FileStream stream = new FileStream(Server.MapPath(destDirectory + fileName), FileMode.CreateNew))
                {
                    Byte[] info = System.IO.File.ReadAllBytes(Server.MapPath(VS_LOAN.Core.Utility.Path.ReportTemplate + "CourierExportTemplate.xlsx"));
                    stream.Write(info, 0, info.Length);
                    using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Update))
                    {
                        string     nameSheet   = "DSHS";
                        ExcelOOXML excelOOXML  = new ExcelOOXML(archive);
                        int        rowindex    = 2;
                        long       totalRecord = 100;
                        decimal    totalPage   = 10;

                        for (int p = 1; p <= totalPage; p++)
                        {
                            var result = await SearchByModel(request);

                            if (p == 1)
                            {
                                excelOOXML.InsertRow(nameSheet, rowindex, result.Datas.Count - 1, true);
                            }
                            totalPage = Math.Ceiling((decimal)result.TotalRecord / request.limit);
                            if (result != null)
                            {
                                totalRecord = result.TotalRecord;


                                for (int i = 0; i < result.Datas.Count; i++)// dòng
                                {
                                    excelOOXML.SetCellData(nameSheet, "A" + rowindex, (i + 1).ToString());
                                    excelOOXML.SetCellData(nameSheet, "B" + rowindex, result.Datas[i].CustomerName.ToString());
                                    excelOOXML.SetCellData(nameSheet, "C" + rowindex, result.Datas[i].Phone);
                                    excelOOXML.SetCellData(nameSheet, "D" + rowindex, result.Datas[i].Cmnd);
                                    excelOOXML.SetCellData(nameSheet, "E" + rowindex, result.Datas[i].Status);
                                    excelOOXML.SetCellData(nameSheet, "F" + rowindex, result.Datas[i].DistrictName);
                                    excelOOXML.SetCellData(nameSheet, "G" + rowindex, result.Datas[i].ProvinceName);
                                    excelOOXML.SetCellData(nameSheet, "H" + rowindex, result.Datas[i].AssignUser);
                                    excelOOXML.SetCellData(nameSheet, "I" + rowindex, result.Datas[i].LastNote);
                                    excelOOXML.SetCellData(nameSheet, "J" + rowindex, result.Datas[i].CreatedTime);
                                    excelOOXML.SetCellData(nameSheet, "K" + rowindex, result.Datas[i].CreatedUser);
                                    excelOOXML.SetCellData(nameSheet, "L" + rowindex, result.Datas[i].UpdatedTime);
                                    excelOOXML.SetCellData(nameSheet, "M" + rowindex, result.Datas[i].UpdatedBy);

                                    rowindex++;
                                }

                                //rowindex++;
                            }
                        }

                        archive.Dispose();
                    }
                    stream.Dispose();
                }
                var file = "/File/GetFile?path=" + destDirectory + fileName;
                return(ToResponse(true, null, file));
            }
            catch (Exception e)
            {
                return(ToResponse(false));
            }
            //var result = await ExportUtil.Export<CourierSearchRequestModel, CourierExportModel>(Response, SearchByModel, request, "CourierProfiles.csv", columns, filePath);
        }