public List <TTicket> SyncTicket()
        {
            try
            {
                IEnumerable <TicketHistory> changedTicketId;

                using (ThanhVanTranSysEntities context = new ThanhVanTranSysEntities())
                    using (TicketBusiness business = new TicketBusiness())
                    {
                        changedTicketId = context.TicketHistories
                                          .Where(i => i.changed_date.Year == DateTime.Now.Year && i.changed_date.Month == DateTime.Now.Month && i.changed_date.Day == DateTime.Now.Day)
                                          .OrderBy(i => i.ticket_id).ThenBy(i => i.changed_date);

                        //insert/update records
                        var tickets = (from t in business.GetAll()
                                       join th in changedTicketId on t.id equals th.ticket_id
                                       where t.departure_time >= DateTime.Now
                                       select ThriftUtil.ConvertToTTicket(t, th.action == Constants.DELETE_ACTION)).ToList();

                        //deleted records
                        tickets.AddRange((from th in changedTicketId
                                          where th.action == Constants.DELETE_ACTION
                                          select new TTicket
                        {
                            TicketId = th.ticket_id,
                            BusId = string.Empty,
                            CusIdNo = string.Empty,
                            CusName = string.Empty,
                            CusPhone = string.Empty,
                            DepartTime = DateTime.Now.ToString(),
                            IsDeleted = true,
                            SeatNo = 0,
                            SeatType = string.Empty,
                            Status = string.Empty,
                            TicketPrice = 0,
                            TourId = string.Empty,
                            UserId = string.Empty
                        }));

                        return(tickets);
                    }
            }
            catch (Exception exc)
            {
                ServerLogger.logError("[LoadTicket]", exc);
                return(new List <TTicket>());
            }
        }
 public List <TTicket> LoadTicket()
 {
     try
     {
         using (TicketBusiness business = new TicketBusiness())
         {
             return(business.GetAll().ToList()
                    .Where(i => i.departure_time >= DateTime.Now)
                    .Select(i => ThriftUtil.ConvertToTTicket(i)).ToList());
         }
     }
     catch (Exception exc)
     {
         ServerLogger.logError("[LoadTicket]", exc);
         return(new List <TTicket>());
     }
 }
        private void SearchTicket()
        {
            ClearAll();
            string busId  = this.cbBus.SelectedValue.ToString();
            string tourId = this.cbTour.SelectedValue.ToString();

            _tickets = _ticketBusiness.GetAll().Where(t => t.bus_id.Equals(busId) &&
                                                      t.tour_id.Equals(tourId) &&
                                                      t.status.Equals(Constants.TicketStatus.Closed.ToString()) == false &&
                                                      t.departure_time.Year == this.dtpDepature.Value.Year &&
                                                      t.departure_time.Month == this.dtpDepature.Value.Month &&
                                                      t.departure_time.Day == this.dtpDepature.Value.Day).OrderBy(i => i.seat_class).ThenBy(i => i.seat_number).ToList();
            dgvTicketsList.DataSource = _tickets;

            _totalRevenue            = _tickets.Sum(i => i.cost);
            tbTotalPayment.Text      = CurrencyUtil.ToString(_totalRevenue);
            tbIncludeAdjustment.Text = CurrencyUtil.ToString(_totalRevenue);
            tbRealAmount.Text        = "0";
            lblPaymentChange.Text    = "0";
        }
        public override void HandlePrint()
        {
            try
            {
                var tour    = _tourBusiness.Get(_tourId);
                var bus     = _busBusiness.Get(_busId);
                var tickets = _ticketBusiness.GetAll(_busId, _tourId, Constants.TicketStatus.Paid, _departureTime);

                Exporter <EntityObject> exporter = new Exporter <EntityObject>(Constants.PRINT_BUS_TICKETS, tickets, new List <EntityObject>()
                {
                    tour
                }, new List <EntityObject>()
                {
                    bus
                });
                exporter.Run();
            }
            catch (Exception ex)
            {
                AppLogger.logError(this.ToString(), Constants.Messages.MSG_TICKET_PRINT_TICKET_EXCEPTION_MSG, ex);
                ShowErrorMessageBox(Constants.Messages.MSG_TICKET_PRINT_TICKET_FAIL_MSG);
            }
        }