示例#1
0
        public MainClientForm(ClientApplicationForm parent, User user) : this()
        {
            _parent     = parent;
            _user       = user;
            label1.Text = $"Welcome, {_user.Name}!";

            try
            {
                ParkingSession active = _parent._parkingManager.GetSessionByCarPlateNumber(_user.CarPlateNumber);
                textBox1.Text = active.ToString();
            }
            catch (ArgumentException ex)
            {
                textBox1.Text = "There are no active parking sesssions!";
            }


            string sessions = _parent._parkingManager.GetCompletedSessionsByCarPlateNumber(_user.CarPlateNumber);

            if (sessions == "")
            {
                textBox2.Text = "There are no passed parking sessions!";
            }
            else
            {
                textBox2.Text = sessions;
            }
        }
 private void CompleteSession(ParkingSession session, DateTime currentDt)
 {
     session.ExitDt = currentDt;
     activeSessions.Remove(session);
     pastSessions.Add(session);
     SaveData();
 }
示例#3
0
        public void CheckIfParkingAvailableForBookedPlace()
        {
            var booking = new ParkingSession {
                StartTime = DateTime.MaxValue, IsBooking = true, Place = _plc
            };

            _plc.Booked = true;
            _plc.Bookings.Add(booking);
            _session.DeclaredDurationInHours = 4;
            Assert.True(_parkingManager.IsEmmediateParkingAllowed());
        }
示例#4
0
        void CreateDataTable(string tableName)
        {
            DataTable dt = new DataTable(tableName);

            DataColumn[] columns = new DataColumn[8] {
                new DataColumn("ID", typeof(int)), new DataColumn("EntryDt", typeof(string)),
                new DataColumn("PaymentDt", typeof(string)), new DataColumn("ExitDt", typeof(string)),
                new DataColumn("Total Payment", typeof(decimal)), new DataColumn("CarPalteNumber", typeof(string)),
                new DataColumn("TicketNumber", typeof(int)), new DataColumn("UserID", typeof(int))
            };

            dt.Columns.AddRange(columns);

            if (tableName == "Active")
            {
                for (int i = 0; i < _pm.ActiveSessions.Count; i++)
                {
                    DataRow        dr   = dt.NewRow();
                    ParkingSession temp = _pm.ActiveSessions[i];
                    dr[0] = i;
                    dr[1] = temp.EntryDt == null ? "-" : temp.EntryDt.ToString();
                    dr[2] = temp.PaymentDt == null ? "-" : temp.PaymentDt.ToString();
                    dr[3] = temp.ExitDt == null ? "-" : temp.ExitDt.ToString();
                    dr[4] = temp.TotalPayment == null ? 0 : temp.TotalPayment;
                    dr[5] = temp.CarPlateNumber;
                    dr[6] = temp.TicketNumber;
                    dr[7] = temp.UserId;

                    dt.Rows.Add(dr);
                }
                _activeDt = dt;
            }
            else if (tableName == "Passed")
            {
                for (int i = 0; i < _pm.PastSessions.Count; i++)
                {
                    DataRow        dr   = dt.NewRow();
                    ParkingSession temp = _pm.PastSessions[i];
                    dr[0] = i;
                    dr[1] = temp.EntryDt == null ? "-" : temp.EntryDt.ToString();
                    dr[2] = temp.PaymentDt == null ? "-" : temp.PaymentDt.ToString();
                    dr[3] = temp.ExitDt == null ? "-" : temp.ExitDt.ToString();
                    dr[4] = temp.TotalPayment == null ? 0 : temp.TotalPayment;
                    dr[5] = temp.CarPlateNumber;
                    dr[6] = temp.TicketNumber;
                    dr[7] = temp.UserId;

                    dt.Rows.Add(dr);
                }
                _passedDt = dt;
            }
        }
示例#5
0
        private async void StartParking()
        {
            ResponseModel response = await _pk.EnterParking();

            _currentSession = (ParkingSession)response.Data;

            CarPlateNumber = _currentSession.CarPlateNumber;
            EntryDate      = _currentSession.EntryDt;

            EnterEnabled = false;
            PayEnabled   = true;
            RenewEnabled = true;
        }
示例#6
0
 public ParkingManagerShould()
 {
     _session = new ParkingSession {
         StartTime = DateTime.Now
     };
     _plc = new Place
     {
         Row          = 1,
         Column       = 2,
         IsParkingLot = true,
         Bookings     = new List <ParkingSession>()
     };
     _parkingManager = new ParkingManager(_plc, _session);
 }
        public bool TryLeaveParkingByCarPlateNumber(string carPlateNumber, out ParkingSession session)
        {
            session = activeSessions.FirstOrDefault(s => s.CarPlateNumber == carPlateNumber);
            if (session == null)
            {
                return(false);
            }

            var currentDt = DateTime.Now;

            if (session.PaymentDt != null)
            {
                if ((currentDt - session.PaymentDt.Value).TotalMinutes <= freeLeavePeriod)
                {
                    CompleteSession(session, currentDt);
                    return(true);
                }
                else
                {
                    session = null;
                    return(false);
                }
            }
            else
            {
                // No payment, within free leave period -> allow exit
                if ((currentDt - session.EntryDt).TotalMinutes <= freeLeavePeriod)
                {
                    session.TotalPayment = 0;
                    CompleteSession(session, currentDt);
                    return(true);
                }
                else
                {
                    // The session has no connected customer
                    if (session.User == null)
                    {
                        session = null;
                        return(false);
                    }
                    else
                    {
                        session.TotalPayment = GetCost((currentDt - session.EntryDt).TotalMinutes - freeLeavePeriod);
                        session.PaymentDt    = currentDt;
                        CompleteSession(session, currentDt);
                        return(true);
                    }
                }
            }
        }
        public ActiveSession(ParkingManager parking)
        {
            _park = parking;
            InitializeComponent();
            ParkingSession thisses = _park.ShowActive(_park.ActivePhoneNumber);

            if (thisses != null)
            {
                CurrentSessionText.Text = $"Start time: {thisses.EntryDt}\nNeed to pay: {_park.GetRemainingCost(thisses.TicketNumber)}";
            }
            else
            {
                CurrentSessionText.Text = "There is no active session";
            }
        }
示例#9
0
        public async Task <ResponseModel> TryLeaveParking(int ticketNumber, ParkingSession session)
        {
            // bool
            CheckJwt();
            UriBuilder ub   = new UriBuilder(rootUrl + "/api/parking/tryleaveparking");
            string     json = JsonConvert.SerializeObject(new
            {
                CarPlateNumber = session.CarPlateNumber,
                TicketId       = ticketNumber
            });
            var data = new StringContent(json, Encoding.UTF8, "application/json");
            HttpResponseMessage response = await client.PostAsync(ub.Uri, data);

            string resultString = await response.Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <ResponseModel>(resultString));
        }
        public SessionsWindow(User user, ListRepository listRepository)
        {
            InitializeComponent();
            authorizedUser = user;
            listRepository.AppData();

            ParkingSession activeSession = listRepository.ActiveSessionForUser(authorizedUser, listRepository.ActiveSessions);

            if (activeSession != null)
            {
                List <ParkingSession> activeSessions = new List <ParkingSession>();
                activeSessions.Add(activeSession);
                currentSessionData.ItemsSource = activeSessions;
            }
            completedSessionsData.ItemsSource = listRepository.GetSessionsList(authorizedUser, listRepository.CompletedSessions);
            tariffData.ItemsSource            = listRepository.GetTariffs();
        }
示例#11
0
        // Перевести вGoogleBingif the user has closed the
        // application it is necessary to download data from the
        // active sessionif the user has closed the application it is
        // necessary to download data from the active session
        private async void LoadActiveIfExists()
        {
            ResponseModel response1 = await _pk.GetActiveSessionForUser();

            _currentSession = (ParkingSession)response1.Data;

            if (_currentSession != null)
            {
                EnterEnabled   = false;
                CarPlateNumber = _currentSession.CarPlateNumber;
                EntryDate      = _currentSession.EntryDt;
                PayEnabled     = true;
                RenewEnabled   = true;
                ResponseModel response2 = await _pk.GetRemainingCost(_currentSession.TicketNumber);

                Cost = (decimal)response2.Data;
            }
        }
示例#12
0
        private void button1_Click(object sender, EventArgs e)
        {
            decimal?profit = 0;

            DateTime from = dateTimePicker1.Value;
            DateTime to   = dateTimePicker2.Value;

            for (int i = 0; i < _pm.PastSessions.Count; i++)
            {
                ParkingSession temp = _pm.PastSessions[i];

                if (temp.EntryDt > from && temp.ExitDt < to)
                {
                    profit += temp.TotalPayment;
                }
            }

            label10.Text = "Profit: " + profit.ToString();
        }
示例#13
0
        public ClientApplicationForm()
        {
            InitializeComponent();
            _parkingManager = new ParkingManager();

            Users = _parkingManager.users;

            foreach (var user in Users)
            {
                _parkingManager.EnterParking(user.CarPlateNumber);
            }

            ParkingSession parkingSession = new ParkingSession();

            if (Users[0] != null)
            {
                _parkingManager.TryLeaveParkingByCarPlateNumber(Users[0].CarPlateNumber, out parkingSession);
            }
        }
        public bool TryLeaveParkingWithTicket(int ticketNumber, out ParkingSession session)
        {
            session = GetSessionByTicketNumber(ticketNumber);

            var currentDt = DateTime.Now;  // Getting the current datetime only once

            var diff = (currentDt - (session.PaymentDt ?? session.EntryDt)).TotalMinutes;

            if (diff <= freeLeavePeriod)
            {
                session.TotalPayment = 0;
                CompleteSession(session, currentDt);
                return(true);
            }
            else
            {
                session = null;
                return(false);
            }
        }
        public ParkingSession EnterParking(string carPlateNumber)
        {
            if (activeSessions.Count >= parkingCapacity || activeSessions.Any(s => s.CarPlateNumber == carPlateNumber))
            {
                return(null);
            }

            var session = new ParkingSession
            {
                CarPlateNumber = carPlateNumber,
                EntryDt        = DateTime.Now,
                TicketNumber   = nextTicketNumber++,
                User           = users.FirstOrDefault(u => u.CarPlateNumber == carPlateNumber)
            };

            session.UserId = session.User?.Id;

            activeSessions.Add(session);
            SaveData();
            return(session);
        }
示例#16
0
        public void CheckIfParkingAllowedForBookedLotUntilBooking(int ok, int tooLong)
        {
            var booking1 = new ParkingSession {
                StartTime = DateTime.Now.AddHours(4), IsBooking = true, Place = _plc
            };
            var booking2 = new ParkingSession {
                StartTime = DateTime.Now.AddHours(6), IsBooking = true, Place = _plc
            };

            _plc.Booked = true;
            _plc.Bookings.Add(booking2);
            _plc.Bookings.Add(booking1);

            _session.DeclaredDurationInHours = ok;

            Assert.True(_parkingManager.IsParkingAllowedUntilBooking());

            _session.DeclaredDurationInHours = tooLong;

            Assert.False(_parkingManager.IsParkingAllowedUntilBooking());
        }
示例#17
0
        private async void TryToLeave()
        {
            bool          leaveResult;
            ResponseModel response;

            if (_payed)
            {
                response = await _pk.TryLeaveParking(_currentSession.TicketNumber, _currentSession);

                leaveResult = response.Succeded;
            }
            else
            {
                response = await _pk.TryLeaveParkingByCarPlateNumber(CarPlateNumber, _currentSession);

                leaveResult = response.Succeded;
            }

            if (leaveResult)
            {
                _currentSession = null;
                EntryDate       = default;
                Cost            = 0;
                _payed          = false;

                EnterEnabled = true;
                PayEnabled   = false;
                LeaveEnabled = false;
                RenewEnabled = false;
            }
            else
            {
                if (!issueWindow.IsVisible)
                {
                    issueWindow.SetText("You can not leave the parking now");
                    issueWindow.ShowDialog();
                }
            }
        }
示例#18
0
 public ParkingManager(Place lot, ParkingSession session)
 {
     _lot     = lot;
     _session = session;
 }