コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="infractionData"></param>
        /// <returns></returns>
        public virtual Infraction CreateInfraction(string[] infractionData)
        {
            Infraction infraction = new Infraction();

            try
            {
                if (Validate.IsValidInfraction(infractionData))
                {
                    infraction.SetCaseId(infractionData[0].Trim());
                    infraction.SetPoliceId(infractionData[1].Trim());
                    infraction.SetDate(infractionData[2].Trim());
                    infraction.SetPlace(infractionData[3].Trim());
                    infraction.SetCaseType(infractionData[4].Trim());
                }
                else
                {
                    throw new Exception("Not Valid Data");
                }
            }
            catch (IndexOutOfRangeException ex)
            {
                throw new IndexOutOfRangeException(ex.Message.ToString());
            }

            return(infraction);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            //bool k = "sdfa".Any(char.IsSymbol);

            TrafficViolationRecord v = new TrafficViolationRecord();
            TrafficViolation       trafficViolation = new TrafficViolation();

            string[] driverData     = new string[] { "", "TN5619951232345", "Ravanan", "Madhurai Main Road", "MCW", "13/07/2018", "23/07/2016" };
            string[] vehicleData    = new string[] { "", "TN23CN5353", "Murugan", "Guindy Main Road", "LMV", "Bajaj R16", "23/07/2025" };
            string[] infractionData = new string[] { "018/2018", "PC101", "06/04/2018", "Mumbai", "Drunk and drive" };

            Driver           driver            = trafficViolation.CreateDriver(driverData);
            Vehicle          vehicle           = trafficViolation.CreateVehicle(vehicleData);
            Infraction       infraction        = trafficViolation.CreateInfraction(infractionData);
            TrafficViolation trafficViolations = v.CreateTrafficViolation(driver, vehicle, infraction);

            string filePath = @"C:\Users\vinothkanth\Desktop\GovernmentOfIndia\TrafficViolence\TrafficViolationRecord.csv";

            for (int i = 0; i < 10; i++)
            {
                // v.StoreTheDataIntoCsvFile(trafficViolation, filePath);
            }

            List <string> rawTrafficViolationData = v.LoadCsvFile(filePath);

            List <string[]> listOfViolationData = v.SplitThaData(rawTrafficViolationData, '#');

            List <TrafficViolation> listOfTrafficViolation = v.CreateTrafficViolationList(listOfViolationData);


            foreach (var item in listOfTrafficViolation)
            {
                //Console.WriteLine("{0}, {1}, {2}, {3}", item.GetDriver().GetName(), item.GetVehicle().GetNumber(), item.GetInfraction().GetPoliceId(), item.GetInfraction().GetCaseType());
            }

            List <TrafficViolation> infractionOfDriver  = v.GetDriverInfractions("TN5619951232345", listOfTrafficViolation);
            List <TrafficViolation> infractionOfDriver1 = v.GetTicktedByPolice("PC101", listOfTrafficViolation);
            List <TrafficViolation> infractionOfDriver2 = v.GetVehicleCategoarieInfractions("HMV", listOfTrafficViolation);

            foreach (var item in infractionOfDriver)
            {
                // Console.WriteLine(item.GetInfraction().GetDataIntoCsvFormate());
            }

            foreach (var item in infractionOfDriver1)
            {
                //Console.WriteLine(item.GetVehicle().GetDataIntoCsvFormate());
            }

            foreach (var item in infractionOfDriver2)
            {
                Console.WriteLine("{0} - {1}", item.GetVehicle().GetDataIntoCsvFormate(), item.GetInfraction().GetDataIntoCsvFormate());
            }
            Console.ReadKey();
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="trafficViolations"></param>
        /// <returns></returns>
        public virtual List <TrafficViolation> CreateTrafficViolationList(List <string[]> trafficViolations)
        {
            List <TrafficViolation> listOfTrafficViolation = new List <TrafficViolation>();

            try
            {
                TrafficViolation trafficViolation = new TrafficViolation();
                foreach (var violation in trafficViolations)
                {
                    Infraction       infractions   = trafficViolation.CreateInfraction(SplitTheData(violation[0], ','));
                    Driver           drivers       = trafficViolation.CreateDriver(SplitTheData(violation[1], ','));
                    Vehicle          vehicles      = trafficViolation.CreateVehicle(SplitTheData(violation[2], ','));
                    TrafficViolation trafficCasess = CreateTrafficViolation(drivers, vehicles, infractions);
                    listOfTrafficViolation.Add(trafficCasess);
                }
            }
            catch (IndexOutOfRangeException ex)
            {
                throw new IndexOutOfRangeException(ex.Message.ToString());
            }

            return(listOfTrafficViolation);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="driver"></param>
        /// <param name="vehicle"></param>
        /// <param name="infraction"></param>
        /// <returns></returns>
        public virtual TrafficViolation CreateTrafficViolation(Driver driver, Vehicle vehicle, Infraction infraction)
        {
            TrafficViolation trafficViolation = new TrafficViolation();

            try
            {
                trafficViolation.SetDriver(driver);
                trafficViolation.SetVehicle(vehicle);
                trafficViolation.SetInfraction(infraction);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }

            return(trafficViolation);
        }
コード例 #5
0
 public void SetInfraction(Infraction infraction)
 {
     _infraction = infraction;
 }