Exemplo n.º 1
0
        public List <VehicleDetails> DisplayDetails(DateTime startDate, DateTime endDate)
        {
            List <VehicleDetails> l = new List <VehicleDetails>();

            try
            {
                SqlCommand cmd = new SqlCommand("select * from VehicleDetails where DateofRegistration between @s and @e", SqlCon);
                cmd.Parameters.AddWithValue("@s", startDate);
                cmd.Parameters.AddWithValue("@e", endDate);
                SqlDataReader  R  = cmd.ExecuteReader();
                VehicleDetails vc = null;
                while (R.Read())
                {
                    vc                    = new VehicleDetails();
                    vc.VehicleNo          = R[0].ToString();
                    vc.Brand              = R[1].ToString();
                    vc.DateofManufacture  = DateTime.Parse(R[2].ToString());
                    vc.DateofRegistration = DateTime.Parse(R[3].ToString());
                    vc.VehicleType        = R[4].ToString();
                    vc.VehicleBuyer       = R[5].ToString();
                    vc.Cost               = int.Parse(R[6].ToString());
                    vc.Registrationcost   = float.Parse(R[7].ToString());
                    l.Add(vc);
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                SqlCon.Close();
            }
            return(l);
        }
Exemplo n.º 2
0
 public void AddVehicle(VehicleDetails detail)
 {
     try
     {
         SqlCommand cmd = new SqlCommand("insert into VehicleDetails values(@vn,@br,@dm,@dr,@vt,@vb,@c,@rc)", SqlCon);
         cmd.Parameters.AddWithValue("@vn", detail.VehicleNo);
         cmd.Parameters.AddWithValue("@br", detail.Brand);
         cmd.Parameters.AddWithValue("@dm", detail.DateofManufacture);
         cmd.Parameters.AddWithValue("@dr", detail.DateofRegistration);
         cmd.Parameters.AddWithValue("@vt", detail.VehicleType);
         cmd.Parameters.AddWithValue("@vb", detail.VehicleBuyer);
         cmd.Parameters.AddWithValue("@c", detail.Cost);
         CalculateCost(detail);
         cmd.Parameters.AddWithValue("@rc", detail.Registrationcost);
         cmd.ExecuteNonQuery();
     }
     catch (SqlException E)
     {
         Console.WriteLine(E.Message);
     }
     finally
     {
         SqlCon.Close();
     }
 }
Exemplo n.º 3
0
        public void CalculateCost(VehicleDetails detail)
        {
            int age = (int)(detail.DateofRegistration.Subtract(detail.DateofManufacture).TotalDays / 365);

            if (detail.VehicleType == "2 Wheeler")
            {
                if (detail.VehicleBuyer == "New")
                {
                    detail.Registrationcost = 12 * detail.Cost / 100;
                }
                else if (detail.VehicleBuyer == "old" && age < 15)
                {
                    if (age >= 5)
                    {
                        detail.Registrationcost = 8 * detail.Cost / 100;
                    }
                    else if (age >= 3 && age < 5)
                    {
                        detail.Registrationcost = 9 * detail.Cost / 100;
                    }
                    else
                    {
                        detail.Registrationcost = 10 * detail.Cost / 100;
                    }
                }
                else
                {
                    Console.WriteLine("Given Vehicle cannot be registered as it is more than  15  year");
                }
            }
            else
            {
                if (detail.VehicleBuyer == "New")
                {
                    detail.Registrationcost = 14 * detail.Cost / 100;
                }
                else if (age < 15 && detail.VehicleBuyer == "Old")
                {
                    if (age >= 5)
                    {
                        detail.Registrationcost = 9 * detail.Cost / 100;
                    }
                    else if (age >= 3 && age < 5)
                    {
                        detail.Registrationcost = (float)10.5 * detail.Cost / 100;
                    }
                    else
                    {
                        detail.Registrationcost = (float)12.50 * detail.Cost / 100;
                    }
                }
                else
                {
                    Console.WriteLine("Given Vehicle cannot be registered as it is more than  15  year");
                }
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            VehicleDetails    detail = new VehicleDetails();
            Vehicle_Validator vd     = new Vehicle_Validator();
            VehicleRegister   vr     = new VehicleRegister();

            Console.WriteLine("enter choice 1.adddetails 2.display details");
            int ch = int.Parse(Console.ReadLine());

            switch (ch)
            {
            case 1:
                Console.WriteLine("Enter Vehicle Details");
                Console.WriteLine("Enter VehicleNo");
                String vnum = Console.ReadLine();

                while (vd.ValidateVehicle(vnum) != null)
                {
                    Console.WriteLine(vd.ValidateVehicle(vnum));
                    Console.WriteLine("Enter VehicleNo");
                    vnum = Console.ReadLine();
                }
                detail.VehicleNo = vnum;
                Console.WriteLine("Enter Brand");
                String bnd = Console.ReadLine();
                detail.Brand = bnd;
                Console.WriteLine("Enter Date of Manufacture");
                DateTime dof = DateTime.ParseExact(Console.ReadLine(), "dd-MMM-yyyy", CultureInfo.InvariantCulture);
                detail.DateofManufacture = dof;
                Console.WriteLine("Enter Date of Registration");
                DateTime dor = DateTime.ParseExact(Console.ReadLine(), "dd-MMM-yyyy", CultureInfo.InvariantCulture);
                detail.DateofRegistration = dor;
                Console.WriteLine("Enter VehicleType:");
                string vet = Console.ReadLine();
                detail.VehicleType = vet;
                Console.WriteLine("Enter Vehicle Buyer:");
                String vbuyer = Console.ReadLine();
                detail.VehicleBuyer = vbuyer;
                Console.WriteLine("Vehicle Cost");
                int co = int.Parse(Console.ReadLine());
                detail.Cost = co;
                Console.WriteLine("Confirm the details Y/N?");
                String n = Console.ReadLine();
                if (n == "Y")
                {
                    vr.AddVehicle(detail);
                    Console.WriteLine("Enter VehicleNo:" + detail.VehicleNo);

                    Console.WriteLine("Enter Brand:\t" + detail.Brand);
                    Console.WriteLine("Enter Date of Manufacture:\t" + detail.DateofManufacture.ToString("dd-MMM-yyyy"));
                    Console.WriteLine("Enter Date of Registration:" + detail.DateofRegistration.ToString("dd-MMM-yyyy"));
                    Console.WriteLine("Enter VehicleType:" + detail.VehicleType);
                    Console.WriteLine("Enter Vehicle Buyer:" + detail.VehicleBuyer);
                    Console.WriteLine("Vehicle Cost" + detail.Cost);
                    Console.WriteLine("Registration Cost" + detail.Registrationcost);

                    int age = (int)(detail.DateofRegistration.Subtract(detail.DateofManufacture).TotalDays / 365);
                    if (age < 15)
                    {
                        Console.WriteLine("Vehicle life" + age);
                    }
                }
                else
                {
                    System.Environment.Exit(0);
                }
                break;

            case 2:
                Console.WriteLine("enter startdate and enddate");
                DateTime startDate       = DateTime.ParseExact(Console.ReadLine(), "dd-MMM-yyyy", CultureInfo.InvariantCulture);
                DateTime endDate         = DateTime.ParseExact(Console.ReadLine(), "dd-MMM-yyyy", CultureInfo.InvariantCulture);
                List <VehicleDetails> l1 = vr.DisplayDetails(startDate, endDate);
                for (int i = 0; i < l1.Count; i++)
                {
                    Console.WriteLine(l1[i].VehicleNo + "" + l1[i].Brand + "" + l1[i].DateofManufacture.ToString("dd-MMM-yyyy") + " " + l1[i].DateofRegistration.ToString("dd-MMM-yyyy") + " " + l1[i].VehicleType + " " + l1[i].VehicleBuyer + " " + l1[i].Cost + " " + l1[i].Registrationcost);
                }
                break;
            }
            Console.Read();
        }