Beispiel #1
0
        private void BusByDateCloneForRouteBackNextDay(BusByDate busByDate)
        {
            if (busByDate == null)
            {
                return;
            }
            var route = busByDate.Route;

            if (route.Way != "To")
            {
                return;
            }
            var routeBack = TransferRequestByDateBLL.RouteBackGetByRouteTo(busByDate.Route);
            var date      = busByDate.Date;
            var tomorrow  = date.HasValue ? date.Value.AddDays(1) : date;

            if (!busByDate.Cloned)
            {
                var clonedBusByDateRouteBack = new BusByDate()
                {
                    BusType = busByDate.BusType,
                    Date    = tomorrow,
                    Group   = busByDate.Group,
                    Guide   = busByDate.Guide,
                    Route   = routeBack,
                };
                TransferRequestByDateBLL.BusByDateSaveOrUpdate(clonedBusByDateRouteBack);
                busByDate.BusByDateRouteBackRef = clonedBusByDateRouteBack;
                busByDate.Cloned = true;
                TransferRequestByDateBLL.BusByDateSaveOrUpdate(busByDate);
            }
        }
Beispiel #2
0
        public IQueryOver <BookingBusByDate, BookingBusByDate> BookingBusByDateGetAllByCriterion(Route route, BusType busType, int group)
        {
            var       query          = _session.QueryOver <BookingBusByDate>();
            BusByDate busByDateAlias = null;

            query = query.JoinAlias(x => x.BusByDate, () => busByDateAlias);
            Route routeAlias = null;

            query = query.JoinAlias(() => busByDateAlias.Route, () => routeAlias);
            if (route != null && route.Id > 0)
            {
                query = query.Where(() => routeAlias.Id == route.Id);
            }
            BusType busTypeAlias = null;

            query = query.JoinAlias(() => busByDateAlias.BusType, () => busTypeAlias);
            if (busType != null && busType.Id > 0)
            {
                query = query.Where(() => busTypeAlias.Id == busType.Id);
            }
            if (group > 0)
            {
                query = query.Where(() => busByDateAlias.Group == group);
            }
            return(query);
        }
Beispiel #3
0
        public IQueryOver <BookingBusByDate, BookingBusByDate> BookingBusByDateGetAllByCriterion(Booking booking, BusByDate busByDate)
        {
            var query = _session.QueryOver <BookingBusByDate>();

            if (booking != null)
            {
                query = query.Where(x => x.Booking == booking);
            }
            BusByDate busByDateAlias = null;

            query = query.JoinAlias(x => x.BusByDate, () => busByDateAlias);
            if (busByDate != null)
            {
                query = query.Where(() => busByDateAlias.Id == busByDate.Id);
            }
            return(query);
        }
Beispiel #4
0
        public void ExportWelcomeBoard(ExcelPackage excelPackage, BusByDate busByDate)
        {
            var listBookingBusByDate = TransferRequestByDateBLL.BookingBusByDateGetAllByCriterion(busByDate).Future().ToList();
            var listBooking          = listBookingBusByDate.Select(x => x.Booking).ToList();
            var shortRouteName       = StringUtil.GetFirstLetter(busByDate.Route.Name);
            var sheet = excelPackage.Workbook.Worksheets.Copy("Welcome Board", "WB" + "-"
                                                              + shortRouteName.Replace(" ", "").Replace("-", "_") + "-" + busByDate.BusType.Name
                                                              + "-G" + busByDate.Group);
            var totalRow = 6;
            var totalCol = 11;

            for (int i = 0; i < listBooking.Count; i++)
            {
                var booking      = listBooking[i];
                var listCustomer = booking.Customers;
                sheet.Cells[1, 1, totalRow, totalCol].Copy(sheet.Cells[(i + 1) * totalRow + 1, 1]);
                var currentRow = (i + 2) * totalRow;
                //chỉnh lại chiều cao của các row vừa mới copy
                sheet.Row(currentRow - 5).Height = 119.25;
                sheet.Row(currentRow - 4).Height = 42;
                sheet.Row(currentRow - 3).Height = 300.75;
                sheet.Row(currentRow - 2).Height = 30.75;
                sheet.Row(currentRow - 1).Height = 45.75;
                sheet.Row(currentRow - 0).Height = 42;
                var name = booking.CustomerNameFull.Replace("<br/>", "\r\n").ToUpper();
                sheet.Cells[currentRow - 3, 1].Value = name;
                sheet.Cells[currentRow - 1, 2].Value = busByDate.Driver_Name + " - " + NumberUtil.FormatPhoneNumber(busByDate.Driver_Phone);
                foreach (var busByDateGuide in busByDate.BusByDatesGuides)
                {
                    sheet.Cells[currentRow - 0, 2].Value += (busByDateGuide.Guide != null ? busByDateGuide.Guide.Name : "") + " - "
                                                            + (busByDateGuide.Guide != null ? NumberUtil.FormatPhoneNumber(busByDateGuide.Guide.Phone) : "") + "\r\n";
                }
                sheet.Cells[currentRow - 1, 5].Value  = booking.PickupAddress;
                sheet.Cells[currentRow - 1, 10].Value = CurrentUser.FullName;
            }
            sheet.DeleteRow(1, totalRow);
        }
Beispiel #5
0
        public void ExportTour(ExcelPackage excelPackage, BusByDate busByDate)
        {
            var listBookingBusByDate = TransferRequestByDateBLL.BookingBusByDateGetAllByCriterion(busByDate).Future().ToList();
            var listBooking          = listBookingBusByDate.Select(x => x.Booking).ToList();
            var listCustomer         = listBooking.SelectMany(x => x.Customers).ToList();
            var shortRouteName       = StringUtil.GetFirstLetter(busByDate.Route.Name);
            var sheet = excelPackage.Workbook.Worksheets.Copy("Tour Command", "TC" + "-"
                                                              + shortRouteName.Replace(" ", "").Replace("-", "_") + "-" + busByDate.BusType.Name + "-G" + busByDate.Group);

            sheet.Cells["I1"].Value = "Group " + busByDate.Group;
            sheet.Cells["E1"].Value = (busByDate.Date.HasValue ? busByDate.Date.Value.ToLongDateString() : "");
            //Điền guide vào lệnh điều tour
            var startRow         = 3;
            var currentRow       = startRow;
            var templateGuideRow = currentRow;
            var listGuide        = busByDate.BusByDatesGuides.Where(x => x.Guide != null).Select(x => x.Guide).ToList();

            sheet.InsertRow(currentRow, listGuide.Count - 1, templateGuideRow);
            FillGuide(listGuide, sheet, ref currentRow);
            //--
            //Điền driver vào lệnh điều tour
            var templateDriverRow = currentRow;
            var listBusByDate     = new List <BusByDate>();

            listBusByDate.Add(busByDate);
            sheet.InsertRow(currentRow, listBusByDate.Count - 1, templateDriverRow);
            FillDriver(listBusByDate, sheet, ref currentRow);
            //--
            //Điền opt vào lệnh điều tour
            var listGuideExpense = new List <Expense>();

            foreach (var guide in listGuide)
            {
                var guideExpense = TransferRequestByDateBLL.ExpenseGetAllByCriterion(guide, busByDate.Date, busByDate.Route)
                                   .Future().ToList().FirstOrDefault();
                if (guideExpense != null)
                {
                    listGuideExpense.Add(guideExpense);
                }
            }
            var templateOptRow = currentRow;
            //Lấy danh sách opt
            var listOpt          = listGuideExpense.Select(x => x.Operator);
            var listOpt_Distinct = listOpt.Distinct().DefaultIfEmpty(new User()).ToList();//Lấy danh sách Opt không lặp

            sheet.InsertRow(currentRow, listOpt_Distinct.Count - 1, templateOptRow);
            FillOpt(listOpt_Distinct, sheet, ref currentRow);
            //--
            //Export booking trong ngày
            currentRow = currentRow + 2;//Chuyển current row đến templaterow booking
            int templateRow = currentRow;
            int totalRow    = templateRow + listBooking.Count();
            int index       = 1;

            currentRow++;//Chuyển current row đến trước template row để bắt đầu coppyrow
            sheet.InsertRow(currentRow, listBooking.Count, templateRow);
            for (int i = 0; i < listBooking.Count; i++)
            {
                var booking = listBooking[i] as Booking;
                if (booking != null)
                {
                    var name = booking.CustomerNameFull.Replace("<br/>", "\r\n").ToUpper();
                    sheet.Cells[currentRow, 1].Value = index;
                    sheet.Cells[currentRow, 2, currentRow, 3].Merge = true;
                    sheet.Cells[currentRow, 2].Value  = name;
                    sheet.Cells[currentRow, 4].Value  = booking.Adult;
                    sheet.Cells[currentRow, 5].Value  = booking.Child;
                    sheet.Cells[currentRow, 6].Value  = booking.Baby;
                    sheet.Cells[currentRow, 7].Value  = booking.Trip.TripCode;
                    sheet.Cells[currentRow, 8].Value  = booking.PickupAddress;
                    sheet.Cells[currentRow, 9].Value  = booking.SpecialRequest;
                    sheet.Cells[currentRow, 11].Value = "OS" + booking.Id;
                    sheet.Cells[currentRow, 26].Value = name;//Work around cho cột merged name không hiển thị hết khi nội dung quá dài
                    currentRow++;
                    index++;
                }
            }
            sheet.DeleteRow(templateRow);
            sheet.Cells[totalRow, 4].Value = listBooking.Sum(x => x.Adult);
            sheet.Cells[totalRow, 5].Value = listBooking.Sum(x => x.Child);
            sheet.Cells[totalRow, 6].Value = listBooking.Sum(x => x.Baby);
            sheet.Cells["I3"].Value        = "Total number of pax: " + (listBooking.Sum(x => x.Adult) + listBooking.Sum(x => x.Child));
            //--
        }
Beispiel #6
0
        private void BusByDateCloneForRouteBackNextDay(BusByDate busByDate)
        {
            if (busByDate == null)
            {
                return;
            }
            var route = busByDate.Route;

            if (route.Way != "To")
            {
                return;
            }
            var routeBack = TransferRequestByDateBLL.RouteBackGetByRouteTo(busByDate.Route);
            var date      = busByDate.Date;
            var tomorrow  = date.HasValue ? date.Value.AddDays(1) : date;
            //Tạo bus cho chiều về vào ngày mai nếu được tạo
            BusByDate clonedBusByDateRouteBack = null;

            if (busByDate.Cloned)
            {
                clonedBusByDateRouteBack = busByDate.BusByDateRouteBackRef;
            }
            else
            {
                clonedBusByDateRouteBack = new BusByDate();
            }
            if (clonedBusByDateRouteBack == null)
            {
                return;
            }
            clonedBusByDateRouteBack.BusType = busByDate.BusType;
            clonedBusByDateRouteBack.Date    = tomorrow;
            clonedBusByDateRouteBack.Group   = busByDate.Group;
            clonedBusByDateRouteBack.Guide   = busByDate.Guide;
            clonedBusByDateRouteBack.Route   = routeBack;
            //Xóa hết các liên kết bookingbusbydate cũ của busByDateRouteBack
            var listBookingBusByDate = TransferRequestByDateBLL
                                       .BookingBusByDateGetAllByCriterion(clonedBusByDateRouteBack).Future().ToList();

            listBookingBusByDate.ForEach(x =>
            {
                TransferRequestByDateBLL.BookingBusByDateDelete(x);
            });
            //--
            TransferRequestByDateBLL.BusByDateSaveOrUpdate(clonedBusByDateRouteBack);
            busByDate.BusByDateRouteBackRef = clonedBusByDateRouteBack;
            busByDate.Cloned = true;
            TransferRequestByDateBLL.BusByDateSaveOrUpdate(busByDate);
            //Tìm các booking có chiều về vào ngày mai của bus hôm nay
            var listBookingNeedTransferBackOnTomorrow = busByDate.ListBookingBusByDate
                                                        .Select(x => x.Booking).Where(x => x.Transfer_DateBack == tomorrow).ToList();

            listBookingNeedTransferBackOnTomorrow.ForEach(booking =>
            {
                //Gắn booking chiều về vào bus chiều về
                TransferRequestByDateBLL.BookingBusByDateSaveOrUpdate(new BookingBusByDate()
                {
                    Booking   = booking,
                    BusByDate = clonedBusByDateRouteBack,
                });
                //--
            });
            //--
        }
Beispiel #7
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();
        }
 public IQueryOver <BookingBusByDate, BookingBusByDate> BookingBusByDateGetAllByCriterion(BusByDate busByDate)
 {
     return(BookingBusByDateRepository.BookingBusByDateGetAllByCriterion(null, busByDate));
 }
 public void BusByDateDelete(BusByDate busByDate)
 {
     BusByDateRepository.Delete(busByDate);
 }
 public void BusByDateSaveOrUpdate(BusByDate busByDate)
 {
     BusByDateRepository.SaveOrUpdate(busByDate);
 }