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(); }
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); }
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(); }