Пример #1
0
        public static IList <Route> GetRoutesForWarrant(TravelWarrant travelWarrant)
        {
            if (travelWarrant == null)
            {
                throw new ArgumentNullException("travelWarrant", "Atr travelWarrant must not be null");
            }
            IList <Route> routes = new List <Route>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(DbProps.GetCs(), "GetRoutesForWarrant", travelWarrant.IDWarrant))
            {
                while (reader.Read())
                {
                    routes.Add(new Route
                    {
                        IDRoute    = (int)reader["IDRoute"],
                        WarrantID  = (int)reader["WarrantID"],
                        DateStart  = DateTime.Parse(reader["DateFrom"].ToString()),
                        DateEnd    = DateTime.Parse(reader["DateTo"].ToString()),
                        CoordA     = reader["CoordA"].ToString(),
                        CoordB     = reader["CoordB"].ToString(),
                        DistanceKm = (int)reader["DistanceInKm"],
                        AvgSpeed   = (int)reader["AvgV"],
                        FuelSpent  = (int)reader["FuelSpent"]
                    });
                }
            }
            return(routes);
        }
        //protected bool ValidateProduct(TWEditVM modelToValidate)
        //{
        //    TravelWarrant travelWarrant = context.TravelWarrant.Find(modelToValidate.TravelWarrantId);
        //    if(modelToValidate.Status.ToString() == "Completed"
        //        && travelWarrant.Status.ToString() == "Recorded")
        //    {
        //        validationDictionary.AddError("Status", "Cannot be completed");
        //    }
        //    return validationDictionary.IsValid;
        //}

        public bool createTravelWarrant(TWCreateVM model)
        {
            TravelWarrant travelWarrant = new TravelWarrant
            {
                CarId              = model.CarId,
                DriverId           = model.DriverId,
                StartLocation      = model.StartLocation,
                EndLocation        = model.EndLocation,
                StartTime          = model.StartTime,
                EndTime            = model.EndTime,
                NumberOfPassengers = model.NumberOfPassengers,
                Status             = Status.Recorded,
            };

            foreach (var item in context.TravelWarrant)
            {
                if (item.CarId == travelWarrant.CarId &&
                    (item.Status.ToString() == "Recorded" ||
                     item.Status.ToString() == "Confirmed") &&
                    (travelWarrant.StartTime >= item.StartTime &&
                     travelWarrant.StartTime <= item.EndTime) ||
                    (travelWarrant.EndTime >= item.StartTime &&
                     travelWarrant.EndTime <= item.EndTime)
                    )
                {
                    return(false);
                }
            }
            context.TravelWarrant.Add(travelWarrant);
            context.SaveChanges();
            return(true);
        }
        public IActionResult Edit(TWEditVM model)
        {
            //if (!travelWarrantService.editTravelWarrant(model))
            //    return View(model);
            //return RedirectToAction("Index");
            if (ModelState.IsValid)
            {
                TravelWarrant travelWarrant = context.TravelWarrant.Find(model.TravelWarrantId);
                if (travelWarrant == null)
                {
                    Response.StatusCode = 404;
                    return(View("TravelWarrantNotFound", model.TravelWarrantId));
                }
                if (model.Status.ToString() == "Recorded" &&
                    travelWarrant.Status.ToString() == "Confirmed")
                {
                    TempData["message"] = "Nalog se ne moze vratiti na pocetno stanje";
                    model.Status        = travelWarrant.Status;

                    return(RedirectToAction("Edit", model));
                }
                if (model.Status.ToString() == "Completed" &&
                    travelWarrant.Status.ToString() == "Recorded")
                {
                    TempData["message"] = "Nalog nije moguce kompletirati prije nego li je prihvacen";
                    model.Status        = travelWarrant.Status;

                    return(RedirectToAction("Edit", model));
                }
                travelWarrant.Status = model.Status;
                context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Пример #4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            var t = new TravelWarrant(((Driver)cbDrivers.SelectedItem).Id, ((Vehicle)cbVehicle.SelectedItem).IDVehicle, TravelWarrantStateEnum.OPEN);;

            Ishod1.SaveWarrant(t);
            setData();
            setWidgets();
        }
Пример #5
0
 public RouteForm(TravelWarrant travelWarrant)
 {
     InitializeComponent();
     tw     = travelWarrant;
     routes = Ishod4.GetRoutesForWarrant(tw);
     initData(routes);
     initWidgets();
 }
Пример #6
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int           item = dgWarrants.SelectedCells[0].RowIndex;
            TravelWarrant tw   = warrants[item];

            Ishod1.DeleteWarrant(tw.IDWarrant);
            setData();
            setWidgets();
        }
Пример #7
0
        public TravelWarrantPanel(TravelWarrant travelWarrant)
        {
            InitializeComponent();

            travelWarrantsSqlRepository = new TravelWarrantsSqlRepository();

            this.travelWarrant = travelWarrant;

            SetTravelWarrantValues();
        }
Пример #8
0
        private void LoadDataToWindow(TravelWarrant travelWarrant)
        {
            // Travel Warrant

            LblIdTravelWarrant.Text   = travelWarrant.Id.ToString();
            LblStatus.Text            = travelWarrant.WarrantStatus;
            LblDateTravelWarrant.Text = travelWarrant.DateIssued.ToShortDateString();
            LblTimeTravelWarrant.Text = travelWarrant.TimeIssued.ToString();

            // Driver

            Driver driver = driversSqlRepository.ReadById(travelWarrant.DriverId);

            LblIdDriver.Text             = driver.Id.ToString();
            LblFirstName.Text            = driver.FirstName;
            LblLastName.Text             = driver.LastName;
            LblPhoneNumber.Text          = driver.PhoneNumber;
            LblDriversLicenceNumber.Text = driver.DriversLicenceNumber;

            // Vehicle

            Vehicle vehicle = vehiclesSqlRepository.ReadById(travelWarrant.VehicleId);

            LblIdVehicle.Text         = vehicle.Id.ToString();
            LblMake.Text              = vehicle.Make;
            LblModel.Text             = vehicle.Model;
            LblYearOfManufacture.Text = vehicle.YearOfManufacture.ToString();
            LblInitialMileage.Text    = vehicle.InitialMileage.ToString();
            LblAvailability.Text      = vehicle.Available == true ? "Available" : "Not available";

            // Fuel Cost

            FuelCost fuelCost = fuelCostsSqlRepository.ReadById(travelWarrant.FuelCostId);

            LblIdFuelCost.Text   = fuelCost.Id.ToString();
            LblDateIssuedFc.Text = fuelCost.DateIssued.ToShortDateString();
            LblTimeIssuedFc.Text = fuelCost.TimeIssued.ToString();
            LblPosition.Text     = fuelCost.Position;
            LblAmount.Text       = fuelCost.Amount.ToString();
            LblPrice.Text        = fuelCost.Price.ToString();

            // Travel Route

            TravelRoute travelRoute = travelRoutesSqlRepository.ReadById(travelWarrant.TravelRouteId);

            LblIdTravelRoute.Text      = travelRoute.Id.ToString();
            LblDateIssuedTr.Text       = travelRoute.DateIssued.ToShortDateString();
            LblTimeIssuedTr.Text       = travelRoute.TimeIssued.ToString();
            LblOrigin.Text             = travelRoute.Origin;
            LblDestination.Text        = travelRoute.Destination;
            LblKilometersTraveled.Text = travelRoute.KilometersTraveled.ToString();
            LblAverageSpeed.Text       = travelRoute.AverageSpeed.ToString();
            LblSpentFuel.Text          = travelRoute.SpentFuel.ToString();
        }
Пример #9
0
        public ShowTravelWarrantWindow(TravelWarrant travelWarrant)
        {
            InitializeComponent();

            driversSqlRepository      = new DriversSqlRepository();
            vehiclesSqlRepository     = new VehiclesSqlRepository();
            fuelCostsSqlRepository    = new FuelCostsSqlRepository();
            travelRoutesSqlRepository = new TravelRoutesSqlRepository();

            LoadDataToWindow(travelWarrant);
        }
        public EditTravelWarrantWindow(TravelWarrant travelWarrant)
        {
            InitializeComponent();

            driversSqlRepository        = new DriversSqlRepository();
            vehiclesSqlRepository       = new VehiclesSqlRepository();
            fuelCostsSqlRepository      = new FuelCostsSqlRepository();
            travelRoutesSqlRepository   = new TravelRoutesSqlRepository();
            travelWarrantsSqlRepository = new TravelWarrantsSqlRepository();

            this.travelWarrant = travelWarrant;

            LoadTravelWarrantToWindow(travelWarrant);
        }
Пример #11
0
        private void ReadTravelWarrants(string filePath)
        {
            XmlReader xmlReader = XmlReader.Create(filePath);

            xmlReader.ReadToFollowing("TravelWarrant");

            do
            {
                xmlReader.MoveToFirstAttribute();
                int id = int.Parse(xmlReader.Value);

                xmlReader.ReadToFollowing("WarrantStatus");
                string warrantStatus = xmlReader.ReadElementContentAsString();

                xmlReader.ReadToFollowing("DateIssued");
                DateTime dateIssued = DateTime.Parse(xmlReader.ReadElementContentAsString());

                xmlReader.ReadToFollowing("TimeIssued");
                TimeSpan timeIssued = TimeSpan.Parse(xmlReader.ReadElementContentAsString());

                xmlReader.ReadToFollowing("DriverId");
                int driverId = xmlReader.ReadElementContentAsInt();

                xmlReader.ReadToFollowing("VehicleId");
                int vehicleId = xmlReader.ReadElementContentAsInt();

                xmlReader.ReadToFollowing("TravelRouteId");
                int travelRouteId = xmlReader.ReadElementContentAsInt();

                xmlReader.ReadToFollowing("FuelCostId");
                int fuelCostId = xmlReader.ReadElementContentAsInt();

                TravelWarrant travelWarrant = new TravelWarrant()
                {
                    Id            = id,
                    WarrantStatus = warrantStatus,
                    DateIssued    = dateIssued,
                    TimeIssued    = timeIssued,
                    DriverId      = driverId,
                    VehicleId     = vehicleId,
                    FuelCostId    = fuelCostId,
                    TravelRouteId = travelRouteId
                };

                travelWarrantsSqlRepository.Restore(travelWarrant);
            } while (xmlReader.ReadToFollowing("TravelWarrant"));

            xmlReader.Close();
        }
Пример #12
0
        public static int SaveWarrant(TravelWarrant tv)
        {
            int v = 0;

            using (SqlConnection conn = new SqlConnection(DbProps.GetCs()))
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SaveWarrant";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@driverid", tv.DriverID);
                    cmd.Parameters.AddWithValue("@vehicleid", tv.VehicleID);
                    cmd.Parameters.AddWithValue("@warrantstateid", tv.WarrantStateID);
                    v = cmd.ExecuteNonQuery();
                }
            }
            return(v);
        }
        public bool editTravelWarrant(TWEditVM model)
        {
            //if (!ValidateProduct(model))
            //    return false;

            // Database logic
            try
            {
                TravelWarrant travelWarrant = context.TravelWarrant.Find(model.TravelWarrantId);

                travelWarrant.Status = model.Status;
                context.SaveChanges();
            }
            catch
            {
                return(false);
            }
            return(true);
        }
 private void LoadTravelWarrantToWindow(TravelWarrant travelWarrant)
 {
     CbStatus.Text = travelWarrant.WarrantStatus;
     TbDate.Text   = travelWarrant.DateIssued.ToShortDateString();
     TbTime.Text   = travelWarrant.TimeIssued.ToString();
 }
        private void UpdateTravelWarrant()
        {
            if (CbStatus.Text != string.Empty && TbDate.Text != string.Empty && TbTime.Text != string.Empty && CbDrivers.Text != string.Empty && CbVehicles.Text != string.Empty)
            {
                if (DateTime.TryParse(TbDate.Text, out DateTime date) && (TimeSpan.TryParse(TbTime.Text, out TimeSpan time)))
                {
                    if ((Regex.IsMatch(TbDate.Text, @"\d\d/\d\d/\d\d\d\d") || Regex.IsMatch(TbDate.Text, @"\d/\d\d/\d\d\d\d")) && Regex.IsMatch(TbTime.Text, @"\d\d:\d\d:\d\d"))
                    {
                        int driverId      = int.Parse(CbDrivers.Text.Substring(0, CbDrivers.Text.IndexOf(' ')));
                        int vehicleId     = int.Parse(CbVehicles.Text.Substring(0, CbVehicles.Text.IndexOf(' ')));
                        int fuelCostId    = 0;
                        int travelRouteId = 0;

                        foreach (FuelCostPanel fuelCostPanel in SpFuelCosts.Children)
                        {
                            if (fuelCostPanel.RbFcSelect.IsChecked == true)
                            {
                                fuelCostId = int.Parse(fuelCostPanel.LblId.Text);
                            }
                        }

                        foreach (TravelRoutePanel travelRoutePanel in SpTravelRoutes.Children)
                        {
                            if (travelRoutePanel.RbTrSelect.IsChecked == true)
                            {
                                travelRouteId = int.Parse(travelRoutePanel.LblId.Text);
                            }
                        }

                        TravelWarrant updatedTravelWarrant = new TravelWarrant
                        {
                            Id            = travelWarrant.Id,
                            WarrantStatus = CbStatus.Text,
                            DateIssued    = date,
                            TimeIssued    = time,
                            DriverId      = driverId,
                            VehicleId     = vehicleId,
                            FuelCostId    = fuelCostId,
                            TravelRouteId = travelRouteId
                        };

                        int oldVehicleId = travelWarrant.VehicleId;
                        vehiclesSqlRepository.UpdateVehicleAvailability(oldVehicleId, true);

                        vehiclesSqlRepository.UpdateVehicleAvailability(vehicleId, false);

                        bool success = travelWarrantsSqlRepository.Update(updatedTravelWarrant);

                        if (success)
                        {
                            MessageBox.Show("Success");
                            Close();
                        }
                        else
                        {
                            MessageBox.Show("Fail");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Date format must be: \"MM/dd/yyyy\"\nTime format must be: \"HH:MM:ss\"");
                    }
                }
                else
                {
                    MessageBox.Show("Date format must be: \"MM/dd/yyyy\"\nTime format must be: \"HH:MM:ss\"");
                }
            }
            else
            {
                MessageBox.Show("All input fields are required");
            }
        }
Пример #16
0
 private void dgWarrants_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     lblWarrantID.Text           = warrants[e.RowIndex].IDWarrant.ToString();
     clicked                     = warrants[e.RowIndex];
     cbWarrantState.SelectedItem = clicked.WarrantState;
 }