Ejemplo n.º 1
0
        public void GetHoursParked_ShouldBeTwo()
        {
            DateTime    now = DateTime.UtcNow;
            ParkingSlip sut = new ParkingSlip(now.AddHours(-2));

            sut.SetExitDateTime(now);
            Assert.That(sut.GetHoursParked(), Is.EqualTo(2));
        }
Ejemplo n.º 2
0
        public void SetExitDateTime_ShouldBeExpirationDateSet()
        {
            DateTime    now = DateTime.UtcNow;
            ParkingSlip sut = new ParkingSlip(now.AddHours(-1));

            sut.SetExitDateTime(now);
            Assert.That(sut.GetExitDateTime(), Is.EqualTo(now));
        }
Ejemplo n.º 3
0
        public void CalculateParkingFee_ShouldBeZero()
        {
            List <IParkingSpace> parkingSpaces = new List <IParkingSpace>();

            parkingSpaces.Add(new ParkingSpace());
            parkingSpaces.Add(new ParkingSpace());
            parkingSpaces.Add(new ParkingSpace());
            List <IParkingFee> parkingFees = new List <IParkingFee>();

            parkingFees.Add(new ParkingFee(2, 4, 5));
            IParkingLot sut         = new ParkingLot(parkingSpaces, parkingFees);
            ParkingSlip parkingSlip = new ParkingSlip(DateTime.UtcNow.AddHours(-1));

            parkingSlip.SetExitDateTime(DateTime.UtcNow);
            Assert.That(sut.CalculateParkingFee(parkingSlip).GetCost(), Is.EqualTo(0));
        }
Ejemplo n.º 4
0
        public void CalculateParkingFee_ShouldBeFifteen()
        {
            List <IParkingSpace> parkingSpaces = new List <IParkingSpace>();

            parkingSpaces.Add(new ParkingSpace());
            parkingSpaces.Add(new ParkingSpace());
            parkingSpaces.Add(new ParkingSpace());
            List <IParkingFee> parkingFees = new List <IParkingFee>();

            parkingFees.Add(new ParkingFee(0, 2, 5));
            parkingFees.Add(new ParkingFee(2, 10, 10));
            parkingFees.Add(new ParkingFee(10, Double.MaxValue, 15));
            IParkingLot sut         = new ParkingLot(parkingSpaces, parkingFees);
            ParkingSlip parkingSlip = new ParkingSlip(DateTime.UtcNow.AddHours(-15));

            parkingSlip.SetExitDateTime(DateTime.UtcNow);
            Assert.That(sut.CalculateParkingFee(parkingSlip).GetCost(), Is.EqualTo(15));
        }
        public HttpResponseMessage GetParkingFee(string parkingLotId, string parkingSlipId)
        {
            /*
             * Normally we would query a database for the parkingLotId and parkingSlipId then call CalculateParkingFee() on them.
             * But in the interest of time, I set up some test data showing the JSON output of various parking slips with different lengths of time.
             */

            // Get parking fee
            // Build parking spaces list
            List <IParkingSpace> parkingSpaces = new List <IParkingSpace>();

            parkingSpaces.Add(new ParkingSpace());
            parkingSpaces.Add(new ParkingSpace());
            parkingSpaces.Add(new ParkingSpace());
            // Build parking fee structure
            List <IParkingFee> parkingFees = new List <IParkingFee>();

            parkingFees.Add(new ParkingFee(0, 2, 5));
            parkingFees.Add(new ParkingFee(2, 10, 10));
            parkingFees.Add(new ParkingFee(10, Double.MaxValue, 15));
            // Create parking lot
            ParkingLot parkingLot = new ParkingLot(parkingSpaces, parkingFees);
            // Build a list of fees
            List <double> myParkingFees = new List <double>();
            DateTime      now           = DateTime.UtcNow;
            // Create parking slips with various start times and add to the list
            IParkingSlip parkingSlip = new ParkingSlip(now.AddHours(-1));

            parkingSlip.SetExitDateTime(now);
            myParkingFees.Add(parkingLot.CalculateParkingFee(parkingSlip).GetCost());
            parkingSlip = new ParkingSlip(now.AddHours(-5));
            parkingSlip.SetExitDateTime(now);
            myParkingFees.Add(parkingLot.CalculateParkingFee(parkingSlip).GetCost());
            parkingSlip = new ParkingSlip(now.AddHours(-25));
            parkingSlip.SetExitDateTime(now);
            myParkingFees.Add(parkingLot.CalculateParkingFee(parkingSlip).GetCost());

            // Create http response (application/json)
            HttpResponseMessage response = Request.CreateResponse <Object>(System.Net.HttpStatusCode.OK, myParkingFees, "application/json");

            // Return http response
            return(response);
        }
Ejemplo n.º 6
0
 private void ExecutePrint(object obj)
 {
     try
     {
         using (SqlConnection conn = new SqlConnection(GlobalClass.TConnectionString))
         {
             var pin = conn.Query <ParkingIn>(string.Format("SELECT * FROM ParkingInDetails WHERE PID = (SELECT MAX(PID) FROM ParkingInDetails WHERE FYID = {0}) AND FYID = {0}", GlobalClass.FYID)).First();
             pin.VType = _VehicleTypeList.FirstOrDefault(x => x.VTypeID == pin.VehicleType);
             var pslip = new ParkingSlip {
                 PIN = pin, CompanyName = GlobalClass.CompanyName, CompanyAddress = GlobalClass.CompanyAddress
             };
             pslip.Print();
             GlobalClass.SetUserActivityLog("Entrance", "Re-Print", WorkDetail: "PID : " + pin.PID);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(GlobalClass.GetRootException(ex).Message, "Entrance", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Ejemplo n.º 7
0
        private void ExecuteSave(object obj)
        {
            try
            {
                if (obj is VehicleType)
                {
                    Parking.VType       = obj as VehicleType;
                    Parking.VehicleType = Parking.VType.VTypeID;
                }
                if (GlobalClass.EnablePlateNo)
                {
                    if (string.IsNullOrEmpty(Parking.VType.PlateNo))
                    {
                        if (MessageBox.Show("Vehicle Plate No is not entered. Do you want to continue?", MessageBoxCaption, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
                        {
                            return;
                        }
                    }
                    Parking.PlateNo = Parking.VType.PlateNo;
                }
                DateTime ServerTime = nepDate.GetServerTime();
                Parking.InDate = ServerTime.Date;
                Parking.InMiti = nepDate.CBSDate(Parking.InDate);
                Parking.InTime = ServerTime.ToString("hh:mm:ss tt");
                using (SqlConnection Conn = new SqlConnection(GlobalClass.TConnectionString))
                {
                    Conn.Open();
                    if (!string.IsNullOrEmpty(Parking.PlateNo) && Conn.ExecuteScalar <int>("SELECT COUNT(*) FROM ParkingInDetails PID LEFT JOIN ParkingOutDetails POD ON PID.PID = POD.PID AND PID.FYID = POD.FYID WHERE PID.PlateNo = @PlateNo AND POD.PID IS NULL", Parking) > 0)
                    {
                        MessageBox.Show("Vehicle plate no is already in parking", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return;
                    }
                    using (SqlTransaction tran = Conn.BeginTransaction())
                    {
                        //Parking.PID = conn.ExecuteScalar<int>("SELECT CurNo FROM tblSequence WHERE VNAME = 'PID' AND FYID = " + GlobalClass.FYID, transaction: tran);
                        Parking.PID = Convert.ToInt32(GetInvoiceNo("PID", tran));

                        while (Conn.ExecuteScalar <int>("SELECT COUNT (*) FROM ParkingInDetails WHERE PID = @PID AND FYID = @FYID", new { PID = Parking.PID, FYID = GlobalClass.FYID }, tran) > 0)
                        {
                            Conn.Execute("UPDATE tblSequence SET CurNo = CurNo + 1 WHERE VNAME = 'PID' AND FYID = " + GlobalClass.FYID, transaction: tran);
                            Parking.PID = Conn.ExecuteScalar <int>("SELECT CurNo FROM tblSequence WHERE VNAME = 'PID' AND FYID = " + GlobalClass.FYID, transaction: tran);
                        }
                        Parking.Barcode = BarCode(tran);
                        if (Parking.Save(tran))
                        {
                            Conn.Execute("UPDATE tblSequence SET CurNo = CurNo + 1 WHERE VNAME = 'PID' AND FYID = " + GlobalClass.FYID, transaction: tran);
                            GlobalClass.SetUserActivityLog(tran, "Entrance", "New", WorkDetail: "PID : " + Parking.PID);
                            var pslip = new ParkingSlip {
                                PIN = Parking, CompanyName = GlobalClass.CompanyName, CompanyAddress = GlobalClass.CompanyAddress
                            };
                            pslip.Print();
                            tran.Commit();

                            MessageBox.Show("Entrance Success." + Environment.NewLine + "Barcode : " + Parking.Barcode + Environment.NewLine + "In Time : " + Parking.InMiti + " " + Parking.InTime, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Information);
                            Parking.VType.PlateNo = string.Empty;
                            ExecuteUndo(null);
                        }
                        else
                        {
                            MessageBox.Show("Entrance failed.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Number + " : " + ex.Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 8
0
        public void GetHoursParked_ShouldBeThrowsExceptionInvalidDate()
        {
            ParkingSlip sut = new ParkingSlip(DateTime.UtcNow.AddHours(-2));

            Assert.Throws <Exception>(() => sut.GetHoursParked());
        }
Ejemplo n.º 9
0
        public void SetExitDateTime_ShouldBeThrowsExceptionInvalidDate()
        {
            ParkingSlip sut = new ParkingSlip(DateTime.UtcNow.AddHours(-1));

            Assert.Throws <ArgumentException>(() => sut.SetExitDateTime(DateTime.MinValue));
        }