Ejemplo n.º 1
0
        public ActionResult Edit(Ticket tk, FormCollection collection)
        {
            tk.CustomerId = CustomerBusiness.SelectIdbyName(collection["SearchCustomer"]);
            IFormatProvider iFP = new System.Globalization.CultureInfo("vi-VN", true);

            tk.StartTime = DateTime.Parse(collection["StartTime"], iFP);
            tk.EndTime   = DateTime.Parse(collection["EndTime"], iFP);

            tk.MotorbikePlate = collection["SearchPlate"];
            tk.TypeId         = Int64.Parse(collection["ticketType"]);
            tk.CustomerId     = CustomerBusiness.SelectIdbyName(collection["Customer.FullName"]);
            TicketBusiness.Update(tk);
            ViewBag.ticketType = new SelectList(TicketTypeBusiness.ListTicketTypes(), "Id", "Description", tk.TypeId);
            return(PartialView("Edit", tk));
        }
        public string UpdateTicket(TTicket tticket, string userId)
        {
            try
            {
                using (ThanhVanTranSysEntities context = new ThanhVanTranSysEntities())
                {
                    DateTime departTime    = DateTime.Parse(tticket.DepartTime);
                    var      existedTicket = context.Tickets.FirstOrDefault(t => t.bus_id == tticket.BusId &&
                                                                            t.departure_time == departTime &&
                                                                            t.seat_number == tticket.SeatNo &&
                                                                            t.seat_class == tticket.SeatType &&
                                                                            t.tour_id == tticket.TourId);

                    if (existedTicket == null || (existedTicket != null && existedTicket.status == Constants.TicketStatus.Cancel.ToString()))
                    {
                        return(Constants.SERVER_ERROR_CODE_SINGLE_DATA_NOT_SYNC + " Vé đã bị xóa!");
                    }
                }

                if (CheckUserPermission(userId, tticket.UserId) == false)
                {
                    return(Constants.Messages.MSG_TICKET_INSUFFICIENT_PERMISSION);
                }

                TicketBusiness business  = new TicketBusiness();
                Ticket         ticket    = ThriftUtil.ConvertToEntityObject(tticket) as Ticket;
                string         resultMsg = business.Update(ticket);

                //notify to the others client station
                //BroadcastToClient(ClientAction.UpdateTicket,ticket);

                return(resultMsg);
            }
            catch (Exception exc)
            {
                ServerLogger.logError("[UpdateTicket]", exc);
                return(exc.Message);
            }
        }
        public override bool HandleSaveTask()
        {
            bool isSuccess = false;

            try
            {
                string errorMsg = string.Empty;
                errorMsg = ValidateData();
                var confirmView = new TicketPaymentView();
                var tickets     = new List <Ticket>();

                if (string.IsNullOrEmpty(errorMsg))
                {
                    if (_isUpdating == false)
                    {
                        foreach (var seatNo in _selectedSeatNumbers)
                        {
                            tickets.Add(CreateUpdateTicket(seatNo: seatNo));
                        }

                        if (tickets.Count > 1)
                        {
                            int index = 1;
                            tickets.ForEach(x =>
                            {
                                x.id += index.ToString("D2");
                                index++;
                            });
                        }

                        confirmView.ConfirmTickets = tickets;
                        //confirmView.SellTicket = new TicketPaymentView.SellTicketDelegate(SellTicket);
                        confirmView.ShowDialog();
                        if (confirmView.DialogResult == System.Windows.Forms.DialogResult.OK ||
                            confirmView.DialogResult == System.Windows.Forms.DialogResult.Yes)
                        {
                            foreach (var ticket in tickets)
                            {
                                errorMsg = _ticketBusiness.Insert(ticket);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        var ticket = CreateUpdateTicket(_ticketBusiness.Get(lblTicketId.Text));
                        errorMsg = _ticketBusiness.Update(ticket);
                    }
                }

                // print receipt
                if (string.IsNullOrEmpty(errorMsg) && confirmView.DialogResult == System.Windows.Forms.DialogResult.Yes)
                {
                    var tour = _tourBusiness.Get(_tourId);
                    var bus  = _busBusiness.Get(_busId);

                    Exporter <EntityObject> exporter = new Exporter <EntityObject>(Constants.PRINT_TICKET_RECIEPT, tickets, new List <EntityObject>()
                    {
                        tour
                    }, new List <EntityObject>()
                    {
                        bus
                    });
                    exporter.Run();
                }

                // output result
                if (string.IsNullOrEmpty(errorMsg))
                {
                    ShowInformationMessage(_isUpdating ? Constants.Messages.MSG_TICKET_UPDATE_TICKET_SUCCESS_MSG : Constants.Messages.MSG_TICKET_INSERT_TICKET_SUCCESS_MSG);
                    isSuccess = true;

                    LoadSeatMapData();
                    ChangeStatusControl(false);
                }
                else
                {
                    ShowErrorMessageBox(errorMsg);
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                AppLogger.logError(this.ToString(), Constants.Messages.MSG_TICKET_UPDATE_TICKET_EXCEPTION_MSG, ex);
                ShowErrorMessageBox(Constants.Messages.MSG_TICKET_UPDATE_TICKET_FAIL_MSG);
            }

            return(isSuccess);
        }