private void ClearOldBookingBusByDate(IList <BusByDate> listBusByDate)
 {
     foreach (var busByDate in listBusByDate)
     {
         var listBookingBusByDate = TransferRequestByDateBLL
                                    .BookingBusByDateGetAllByCriterion(busByDate).Future().ToList();
         listBookingBusByDate.ForEach(x =>
         {
             TransferRequestByDateBLL.BookingBusByDateDelete(x);
         });
     }
 }
        public string TableRowColorGetByGroup(Booking booking, Route route)
        {
            var bookingBusByDate = TransferRequestByDateBLL.BookingBusByDateGetAllByCriterion(booking).Future()
                                   .ToList().Where(x => x.BusByDate.Route.Id == route.Id).ToList().FirstOrDefault();
            var group = 0;

            if (bookingBusByDate != null && bookingBusByDate.Id > 0)
            {
                group = bookingBusByDate.BusByDate.Group;
            }
            if (group > 0)
            {
                return("");
            }
            return("custom-warning");
        }
Ejemplo n.º 3
0
        public bool BusTypeCheckBookingHaveNoGroup(BusType busType, Route route, DateTime?date)
        {
            var haveBookingNoGroup = false;
            var listBooking        = TransferRequestByDateBLL.BookingGetAllByCriterionTransfer(busType, route, date)
                                     .Future().ToList();

            listBooking.ForEach(booking =>
            {
                var listBookingBusByDate = TransferRequestByDateBLL.BookingBusByDateGetAllByCriterion(booking)
                                           .Future().ToList().Where(x => x.BusByDate.Route.Id == route.Id).ToList();
                if (listBookingBusByDate.Count == 0)
                {
                    haveBookingNoGroup = true;
                    return;
                }
            });
            return(haveBookingNoGroup);
        }
 protected void rptTransportBookingStandard_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
     {
         var booking       = (Booking)e.Item.DataItem;
         var ddlGroup      = (DropDownList)e.Item.FindControl("ddlGroup");
         var listBusByDate = TransferRequestByDateBLL.BusByDateGetAllByCriterion(Date, BusType, Route, Way).Future().ToList();
         var listGroup     = listBusByDate.Select(x => x.Group).Distinct().OrderBy(x => x).ToList();
         listGroup.ForEach(feGroup =>
         {
             ddlGroup.Items.Add(new ListItem(BusType.Name[0].ToString().ToUpper() + feGroup.ToString(), feGroup.ToString()));
         });
         var bookingBusByDate = TransferRequestByDateBLL.BookingBusByDateGetAllByCriterion(booking).Future()
                                .ToList().Where(x => x.BusByDate.Route.Id == Route.Id).ToList().FirstOrDefault();
         var group = "0";
         if (bookingBusByDate != null && bookingBusByDate.Id > 0)
         {
             group = bookingBusByDate.BusByDate.Group.ToString();
         }
         ddlGroup.SelectedValue = group;
     }
 }
 protected void rptTransportBooking_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
     {
         var booking       = (Booking)e.Item.DataItem;
         var busType       = (BusType)((RepeaterItem)e.Item.Parent.Parent).DataItem;
         var route         = (Route)((RepeaterItem)e.Item.Parent.Parent.Parent.Parent).DataItem;
         var ddlGroup      = (DropDownList)e.Item.FindControl("ddlGroup");
         var listBusByDate = TransferRequestByDateBLL.BusByDateGetAllByCriterion(Date, busType, route, route.Way)
                             .Future().ToList();
         var listGroup = listBusByDate.Select(x => x.Group).Distinct().OrderBy(x => x).ToList();
         listGroup.ForEach(noOfGroup =>
         {
             ddlGroup.Items.Add(new ListItem(busType.Name[0].ToString().ToUpper() + noOfGroup.ToString()
                                             , noOfGroup.ToString()));
         });
         var bookingBusByDate = TransferRequestByDateBLL.BookingBusByDateGetAllByCriterion(booking).Future()
                                .ToList().Where(x => x.BusByDate.Route.Id == route.Id).ToList().FirstOrDefault();
         var group = "--";
         if (bookingBusByDate != null && bookingBusByDate.Id > 0)
         {
             group = bookingBusByDate.BusByDate.Group.ToString();
         }
         ddlGroup.SelectedValue = group;
         var lblGroup = (Label)e.Item.FindControl("lblGroup");
         if (bookingBusByDate != null &&
             bookingBusByDate.BusByDate != null &&
             bookingBusByDate.BusByDate.BusType != null)
         {
             lblGroup.Text = bookingBusByDate.BusByDate.BusType.Name.First().ToString().ToUpper() + group;
         }
         else
         {
             lblGroup.Text = group;
         }
     }
 }
Ejemplo n.º 6
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);
        }
 public void SaveGroup(Repeater repeater)
 {
     foreach (RepeaterItem repeaterItemBooking in repeater.Items)
     {
         var bookingId    = ((HiddenField)repeaterItemBooking.FindControl("hidBookingId")).Value;
         var bookingIdInt = -1;
         try
         {
             bookingIdInt = Int32.Parse(bookingId);
         }
         catch { }
         var booking = TransferRequestByDateBLL.BookingGetById(bookingIdInt);
         if (booking == null || booking.Id <= 0)
         {
             ShowErrors("Booking doesn't exist. Please try again");
             return;
         }
         var ddlGroup = (DropDownList)repeaterItemBooking.FindControl("ddlGroup");
         var group    = -1;
         try
         {
             group = Int32.Parse(ddlGroup.SelectedValue);
         }
         catch { }
         var listBusByDate = new List <BusByDate>();
         if (group != -1)
         {
             listBusByDate = TransferRequestByDateBLL.BusByDateGetAllByCriterion(Date, BusType, Route, Way, group)
                             .Future().ToList();
         }
         var listBookingBusByDate = TransferRequestByDateBLL.BookingBusByDateGetAllByCriterion(booking)
                                    .Future().ToList()
                                    .Where(x => x.BusByDate.BusType.Id == BusType.Id)
                                    .Where(x => x.BusByDate.Route.Id == Route.Id && x.BusByDate.Route.Way == Way)
                                    .ToList();
         if (listBookingBusByDate == null)
         {
             listBookingBusByDate = new List <BookingBusByDate>();
         }
         for (int i = 0; i < listBusByDate.Count; i++)
         {
             var busByDate        = listBusByDate[i];
             var bookingBusByDate = new BookingBusByDate();
             bookingBusByDate.Booking   = booking;
             bookingBusByDate.BusByDate = busByDate;
             var addMore = true;
             for (int j = i; j < listBookingBusByDate.Count; j++)
             {
                 bookingBusByDate           = listBookingBusByDate[j];
                 bookingBusByDate.Booking   = booking;
                 bookingBusByDate.BusByDate = busByDate;
                 TransferRequestByDateBLL.BookingBusByDateSaveOrUpdate(bookingBusByDate);
                 addMore = false;
             }
             if (addMore)
             {
                 TransferRequestByDateBLL.BookingBusByDateSaveOrUpdate(bookingBusByDate);
             }
         }
         var numberOfBookingBusByDateUnnecessary = listBookingBusByDate.Count - listBusByDate.Count;
         if (numberOfBookingBusByDateUnnecessary > 0)
         {
             for (int i = 0; i < numberOfBookingBusByDateUnnecessary; i++)
             {
                 var bookingBusByDate = listBookingBusByDate.OrderByDescending(x => x.Id).ToList()[i];
                 TransferRequestByDateBLL.BookingBusByDateDelete(bookingBusByDate);
             }
         }
     }
 }
Ejemplo n.º 8
0
        public string TransferRequestDTOGetByCriterion(string d, string bti, string ri)
        {
            DateTime?date = null;

            try
            {
                date = DateTime.ParseExact(d, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            catch { }
            var busTypeId = -1;

            try
            {
                busTypeId = Int32.Parse(bti);
            }
            catch { }
            var listBusType = TransferRequestByDateBLL.BusTypeGetAllById(busTypeId).Future().ToList();
            var routeId     = -1;

            try
            {
                routeId = Int32.Parse(ri);
            }
            catch { }
            var listRoute    = TransferRequestByDateBLL.RouteGetAllById(routeId).Future().ToList();
            var listRouteDTO = new List <RouteDTO>();

            foreach (var route in listRoute)
            {
                var listBusTypeDTO = new List <BusTypeDTO>();
                var routeDTO       = new RouteDTO()
                {
                    Id   = route.Id,
                    Name = route.Name,
                    Way  = route.Way,
                };
                foreach (var busType in listBusType)
                {
                    var busTypeDTO = new BusTypeDTO()
                    {
                        Id   = busType.Id,
                        Name = busType.Name,
                        HaveBookingNoGroup = BusTypeCheckBookingHaveNoGroup(busType, route, date),
                        HaveNoBooking      = false,
                    };
                    var listBusByDateDTO = new List <BusByDateDTO>();
                    var listBusByDate    = TransferRequestByDateBLL.BusByDateGetAllByCriterion(date, busType, route, route.Way)
                                           .OrderBy(y => y.Group).Asc.Future().ToList();
                    listBusByDate.ForEach(busByDate =>
                    {
                        var listBookingBusByDate = TransferRequestByDateBLL.BookingBusByDateGetAllByCriterion(busByDate).Future().ToList();
                        var listBooking          = listBookingBusByDate.Select(x => x.Booking).Distinct().ToList();
                        int?supplierId           = null;
                        if (busByDate.Supplier != null)
                        {
                            supplierId = busByDate.Supplier.Id;
                        }
                        var busByDateDTO = new BusByDateDTO()
                        {
                            Id           = busByDate.Id,
                            Group        = busByDate.Group,
                            Driver_Name  = busByDate.Driver_Name,
                            Driver_Phone = busByDate.Driver_Phone,
                            Adult        = listBooking.Select(x => x.Adult).Sum(),
                            Child        = listBooking.Select(x => x.Child).Sum(),
                            Baby         = listBooking.Select(x => x.Baby).Sum(),
                            SupplierId   = supplierId,
                            RouteName    = busByDate.Route != null ? busByDate.Route.Name : "",
                            BusTypeName  = busByDate.BusType != null ? busByDate.BusType.Name : "",
                        };
                        foreach (var busByDateGuide in busByDate.BusByDatesGuides)
                        {
                            var guide         = busByDateGuide.Guide;
                            GuideDTO guideDTO = null;
                            if (guide != null && guide.Id > 0)
                            {
                                guideDTO = new GuideDTO()
                                {
                                    Id    = guide.Id,
                                    Name  = guide.Name,
                                    Phone = guide.Phone,
                                };
                            }
                            var busByDateGuideDTO = new BusByDateGuideDTO()
                            {
                                BusByDateDTO = busByDateDTO,
                                GuideDTO     = guideDTO
                            };
                            busByDateDTO.BusByDatesGuidesDTO.Add(busByDateGuideDTO);
                        }
                        listBusByDateDTO.Add(busByDateDTO);
                    });
                    busTypeDTO.ListBusByDateDTO = listBusByDateDTO;
                    listBusTypeDTO.Add(busTypeDTO);
                }
                routeDTO.ListBusTypeDTO = listBusTypeDTO;
                listRouteDTO.Add(routeDTO);
            }
            var transferRequestDTO = new TransferRequestDTO();

            transferRequestDTO.ListRouteDTO = listRouteDTO;
            Dispose();
            return(JsonConvert.SerializeObject(transferRequestDTO));
        }
Ejemplo n.º 9
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));
            //--
        }
Ejemplo n.º 10
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,
                });
                //--
            });
            //--
        }