示例#1
0
        public void BusByDateExport(string bbdi)
        {
            var busByDateId = -1;

            try
            {
                busByDateId = Int32.Parse(bbdi);
            }
            catch { }
            var busByDate = TransferRequestByDateBLL.BusByDateGetById(busByDateId);

            if (busByDate == null || busByDate.Id <= 0)
            {
                return;
            }
            using (var memoryStream = new MemoryStream())
            {
                using (var excelPackage = new ExcelPackage(new FileInfo(Server.MapPath("/Modules/Sails/Admin/ExportTemplates/TourCommandAndWelcomeBoard.xlsx"))))
                {
                    ExportTour(excelPackage, busByDate);
                    ExportWelcomeBoard(excelPackage, busByDate);
                    excelPackage.Workbook.Worksheets.Delete("Welcome Board");
                    excelPackage.Workbook.Worksheets.Delete("Tour Command");
                    excelPackage.Workbook.View.ActiveTab = 0;
                    excelPackage.SaveAs(memoryStream);
                }
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
                HttpContext.Current.Response.ContentType     = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                HttpContext.Current.Response.BinaryWrite(memoryStream.ToArray());
                HttpContext.Current.Response.Flush();
                HttpContext.Current.Response.SuppressContent = true;
                HttpContext.Current.ApplicationInstance.CompleteRequest();
            }
            Dispose();
        }
示例#2
0
        public void TransferRequestDTOSaveOrUpdate(TransferRequestDTO tr, string d)
        {
            var      listRouteDTO = tr.ListRouteDTO;
            DateTime?date         = null;

            try
            {
                date = DateTime.ParseExact(d, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            catch { }
            foreach (var routeDTO in listRouteDTO)
            {
                var route = TransferRequestByDateBLL.RouteGetById(routeDTO.Id);
                foreach (var busTypeDTO in routeDTO.ListBusTypeDTO)
                {
                    var busType = TransferRequestByDateBLL.BusTypeGetById(busTypeDTO.Id);
                    foreach (var busByDateDTO in busTypeDTO.ListBusByDateDTO)
                    {
                        //Tạo hoặc update Busbydate
                        var busByDate = TransferRequestByDateBLL.BusByDateGetById(busByDateDTO.Id);//Tìm Busbydate theo id của BusbydateDTO
                        if (busByDate == null)
                        {
                            busByDate = new BusByDate();//Nếu không có tạo mới
                        }
                        //--//
                        //Update thông tin vào Busbydate vừa lấy được
                        busByDate.Group   = busByDateDTO.Group;
                        busByDate.BusType = busType;
                        busByDate.Route   = route;
                        busByDate.Date    = date;
                        var supplierId = busByDateDTO.SupplierId ?? 0;
                        var supplier   = TransferRequestByDateBLL.AgencyGetById(supplierId);
                        if (supplier != null && supplier.Id <= 0)
                        {
                            supplier = null;
                        }
                        busByDate.Supplier     = supplier;
                        busByDate.Driver_Name  = busByDateDTO.Driver_Name;
                        busByDate.Driver_Phone = busByDateDTO.Driver_Phone;
                        //Lấy thông tin guide gắn vào bus
                        busByDate.BusByDatesGuides.Clear();
                        foreach (var busByDateGuideDTO in busByDateDTO.BusByDatesGuidesDTO)
                        {
                            var guideId = 0;
                            if (busByDateGuideDTO.GuideDTO != null)
                            {
                                guideId = busByDateGuideDTO.GuideDTO.Id ?? 0;
                            }
                            Guide guide = null;
                            guide = transferRequestByDateBLL.GuideGetById(guideId);
                            if (guide != null && guide.Id <= 0)
                            {
                                guide = null;
                            }
                            var busByDateGuide = new BusByDateGuide()
                            {
                                Guide     = guide,
                                BusByDate = busByDate,
                            };
                            busByDate.BusByDatesGuides.Add(busByDateGuide);
                        }
                        TransferRequestByDateBLL.BusByDateSaveOrUpdate(busByDate);
                        //--//
                        //Xóa Busbydate nếu đã được lưu nhưng bị đánh dấu deleted
                        if (busByDateDTO.Deleted)
                        {
                            if (busByDate.Id > 0)
                            {
                                TransferRequestByDateBLL.BusByDateDelete(busByDate);
                                continue;
                            }
                        }
                        //--//
                        BusByDateCloneForRouteBackNextDay(busByDate);
                    }
                }
            }
            Dispose();
        }