Ejemplo n.º 1
0
        public void BusByDateExportAll(string ri, string bti, string d)
        {
            var routeId = -1;

            try
            {
                routeId = Int32.Parse(ri);
            }
            catch { }
            var route     = TransferRequestByDateBLL.RouteGetById(routeId);
            var busTypeId = -1;

            try
            {
                busTypeId = Int32.Parse(bti);
            }
            catch { }
            var      busType = TransferRequestByDateBLL.BusTypeGetById(busTypeId);
            DateTime?date    = null;

            try
            {
                date = DateTime.ParseExact(d, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            catch { }
            var listBusByDate = TransferRequestByDateBLL.BusByDateGetAllByCriterion(date, busType, route, "All")
                                .Future().ToList().OrderBy(x => x.Route.Id).ThenBy(x => x.Id);

            using (var memoryStream = new MemoryStream())
            {
                using (var excelPackage = new ExcelPackage(new FileInfo(Server.MapPath("/Modules/Sails/Admin/ExportTemplates/TourCommandAndWelcomeBoard.xlsx"))))
                {
                    foreach (var busByDate in listBusByDate)
                    {
                        ExportTour(excelPackage, busByDate);
                        ExportWelcomeBoard(excelPackage, busByDate);
                    }
                    excelPackage.Workbook.Worksheets.Delete("Welcome Board");
                    excelPackage.Workbook.Worksheets.Delete("Tour Command");
                    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();
        }
Ejemplo n.º 2
0
        private int getGroupForNewBusByDate()
        {
            var groupNeed        = 1;
            var listBusByDateDTO = TransferRequestByDateBLL.BusByDateGetAllByCriterion(Date, BusType, Route, Way).Future().ToList()
                                   .OrderBy(x => x.Group).ToList();

            listBusByDateDTO = listBusByDateDTO.GroupBy(x => x.Group).Select(y => y.FirstOrDefault()).ToList();
            for (var i = 0; i < listBusByDateDTO.Count(); i++)
            {
                var groupExist = listBusByDateDTO[i].Group;
                if (groupNeed == groupExist)
                {
                    groupNeed++;
                }
                else
                {
                    break;
                }
            }
            return(groupNeed);
        }
 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;
         }
     }
 }
 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);
             }
         }
     }
 }
 protected void btnSave_Click(object sender, EventArgs e)
 {
     foreach (RepeaterItem repeaterItemRouteByWay in rptRouteByWay.Items)
     {
         var routeId    = ((HiddenField)repeaterItemRouteByWay.FindControl("hidRouteId")).Value;
         var routeIdInt = -1;
         try
         {
             routeIdInt = Int32.Parse(routeId);
         }
         catch { }
         var route = TransferRequestByDateBLL.RouteGetById(routeIdInt);
         if (route == null || route.Id <= 0)
         {
             ShowErrors("Route doesn't exist. Please try again");
             return;
         }
         var rptBusType = (Repeater)repeaterItemRouteByWay.FindControl("rptBusType");
         foreach (RepeaterItem repeaterItemBusType in rptBusType.Items)
         {
             var busTypeId    = ((HiddenField)repeaterItemBusType.FindControl("hidBusTypeId")).Value;
             var busTypeIdInt = -1;
             try
             {
                 busTypeIdInt = Int32.Parse(busTypeId);
             }
             catch { }
             var busType = TransferRequestByDateBLL.BusTypeGetById(busTypeIdInt);
             if (route == null || route.Id <= 0)
             {
                 ShowErrors("Bus type doesn't exist. Please try again");
                 return;
             }
             var rptTransportBooking = (Repeater)repeaterItemBusType.FindControl("rptTransportBooking");
             //Xóa hết các liên kết BookingBusByDate cũ
             var listBusByDate = TransferRequestByDateBLL.BusByDateGetAllByCriterion(Date, busType, route, route.Way)
                                 .Future().ToList();
             ClearOldBookingBusByDate(listBusByDate);
             //--
             foreach (RepeaterItem repeaterItemBooking in rptTransportBooking.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 { }
                 //Tạo các liên kết BookingBusByDate mới
                 if (group != -1)
                 {
                     var busByDate = TransferRequestByDateBLL.BusByDateGetAllByCriterion(Date, busType, route, route.Way, group)
                                     .Future().ToList().FirstOrDefault();
                     var bookingBusByDate = new BookingBusByDate()
                     {
                         Booking   = booking,
                         BusByDate = busByDate,
                     };
                     TransferRequestByDateBLL.BookingBusByDateSaveOrUpdate(bookingBusByDate);
                 }
                 //--
             }
         }
     }
     ShowSuccess("Saved successfully");
     Session["Redirect"] = true;
     Response.Redirect(Request.RawUrl);
 }
Ejemplo n.º 7
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));
        }