public ParcelsDTO GetCouriersParcels(StorePlace storePlace, int courierId) { ParcelsDTO result; try { var collection = _storePlaceService.GetCouriersParcels(storePlace, courierId); result = new ParcelsDTO { StorePlaces = collection, Status = collection.Count > 0 ? CollectionGetStatus.Success : CollectionGetStatus.Empty }; } catch { result = new ParcelsDTO { StorePlaces = null, Status = CollectionGetStatus.Failure }; } return(result); }
public bool PostParcel(StorePlace storePlace, PersonalData senderData, PersonalData receiverData, float height, float length, float width, float weight, int priority, string type) { var parcel = new Parcel { StorePlaceId = storePlace.Id, SenderData = senderData, ReceiverData = receiverData, ParcelHeight = height, ParcelWidth = width, ParcelLength = length, ParcelWeight = weight, Priority = priority, ReferenceId = 0, ParcelStatus = ParcelStatus.AtPostingPoint }; try { _parcelService.PostParcel(parcel); } catch (NothingAddedToDatabaseException e) { Console.WriteLine(e.ToString()); return(false); } return(true); }
public void ModifyStorePlace(StorePlace editStorePlace) { var storePlace = _storePlaceManager.GetByIdWithAddress(editStorePlace.Id); if (storePlace == default(StorePlace)) { throw new Exception($"Something while editing store place { editStorePlace.Id }."); } storePlace.Name = editStorePlace.Name; storePlace.Type = editStorePlace.Type; switch (editStorePlace.Type) { case 0: (storePlace as Warehouse).ManagerName = (editStorePlace as Warehouse).ManagerName; break; case 1: (storePlace as SendingPoint).WorkersCount = (editStorePlace as SendingPoint).WorkersCount; break; } storePlace.Address.City = editStorePlace.Address.City; storePlace.Address.Street = editStorePlace.Address.Street; storePlace.Address.PostCode = editStorePlace.Address.PostCode; storePlace.Address.HomeNumber = editStorePlace.Address.HomeNumber; storePlace.Address.ApartmentNumber = editStorePlace.Address.ApartmentNumber; _storePlaceManager.SaveChanges(); }
public Parcel[] GetParcelsFromStorePlaceByStatus(StorePlace storePlace, ParcelStatus status) { return(_context.Parcels.AsNoTracking() .Where(p => p.StorePlaceId == storePlace.Id && p.ParcelStatus == status) .Include(p => p.ReceiverData) .ThenInclude(p => p.PersonalAddress) .ToArray()); }
public Parcel[] GetParcelsByStorePlace(StorePlace storePlace) { var query = from e in _context.Parcels where e.StorePlaceId == storePlace.Id select e; return(query.ToArray()); }
public Parcel[] GetParcelsFromStorePlaceByStatus(StorePlace storePlace, ParcelStatus status) { Parcel[] parcels = _parcelManager.GetParcelsFromStorePlaceByStatus(storePlace, status); if (parcels.Length == 0) { throw new ParcelNotFoundInDatabaseException(storePlace); } return(parcels); }
public Parcel[] GetParcelsByStorePlaceWithAddress(StorePlace storePlace) { var query = from e in _context.Parcels where e.StorePlaceId == storePlace.Id select e; return(query.Include(e => e.ReceiverData.PersonalAddress). Include(e => e.SenderData.PersonalAddress).ToArray()); }
public List <Parcel> GetCouriersParcels(StorePlace storePlace, int courierId) { var emploee = _employeeManager.GetEmployeeById(courierId); if (emploee == null) { throw new Exception("Emploee of id " + courierId + " not found in database."); } return(_parcelManager.GetParcelsByStorePlace(storePlace).Where(parcel => parcel.CourierID == courierId).ToList()); }
public void UpdateStoreplace(StorePlace storeplace) { int result; result = _storePlaceManager.UpdateStoreplace(storeplace); if (result == 0) { throw new Exception("Databse wasn't changed"); } }
public Parcel[] GetParcelsByStorePlaceWithAddress(StorePlace storePlace) { Parcel[] parcels = _parcelManager.GetParcelsByStorePlaceWithAddress(storePlace); if (parcels.Length == 0) { throw new ParcelNotFoundInDatabaseException(storePlace); } return(parcels); }
public bool AddStoreplace(StorePlace storeplace) { try { _storePlaceService.AddStoreplace(storeplace); return(true); } catch { return(false); } }
public bool UpdateStoreplace(StorePlace storeplace) { try { _storePlaceService.ModifyStorePlace(storeplace); return(true); } catch { return(false); } }
private void StorePlaceAddEditForm_Load(object sender, EventArgs e) { if (storePlace.Type != -1) { storePlace = _storePlaceController.GetByIdWithAddress(storePlace.Id); textBoxStorePlaceName.Text = storePlace.Name; textBoxCity.Text = storePlace.Address.City; textBoxPostCode.Text = storePlace.Address.PostCode; textBoxStreet.Text = storePlace.Address.Street; textBoxHomeNumber.Text = storePlace.Address.HomeNumber; textBoxApartmentNumber.Text = storePlace.Address.ApartmentNumber.ToString(); } switch (storePlace.Type) { case -1: comboBoxStorePlaceType.Enabled = true; counterStorePlaceWorkersCount.Enabled = false; textBoxWarehouseManagerName.Enabled = false; break; case 0: var warehouse = storePlace as Warehouse; comboBoxStorePlaceType.SelectedIndex = 0; comboBoxStorePlaceType.Enabled = false; counterStorePlaceWorkersCount.Enabled = false; textBoxWarehouseManagerName.Enabled = true; if (warehouse.ManagerName != null) { textBoxWarehouseManagerName.Text = warehouse.ManagerName; } break; case 1: var sendingPoint = storePlace as SendingPoint; comboBoxStorePlaceType.SelectedIndex = 1; comboBoxStorePlaceType.Enabled = false; textBoxWarehouseManagerName.Enabled = false; counterStorePlaceWorkersCount.Enabled = true; counterStorePlaceWorkersCount.Value = sendingPoint.WorkersCount; break; } }
public Parcel[] GetParcelsByStorePlaceWithAddress(StorePlace storePlace) { Parcel[] parcels = { }; try { parcels = _parcelService.GetParcelsByStorePlaceWithAddress(storePlace); } catch (ParcelNotFoundInDatabaseException e) { Console.WriteLine(e.Message); } return(parcels); }
public Parcel[] GetParcelsFromStorePlaceByStatus(StorePlace storePlace, ParcelStatus status) { Parcel[] parcels = { }; try { parcels = _parcelService.GetParcelsFromStorePlaceByStatus(storePlace, status); } catch (ParcelNotFoundInDatabaseException e) { Console.WriteLine(e.Message); } return(parcels); }
private void CourierWindow_Load(object sender, EventArgs e) { listBox1.Enabled = true; radioButton1.Checked = false; radioButton2.Checked = false; radioButton3.Checked = false; radioButton4.Checked = false; radioButton5.Checked = false; radioButton6.Checked = false; radioButton7.Checked = false; _employee = _employeeController.GetLoggedEmployee(); if (_employee != null) { try { listBox1.Items.Clear(); if (_employee.ActiveEmployments.Where(em => em.Position.Name.Equals("Administrator")).Count() > 0) { for (int i = 0; i < _parcelController.GetAllParcels().Length; i++) { listBox1.Items.Add(_parcelController.GetAllParcels()[i].Id); } } else { _employment = _employee.ActiveEmployments[0]; _storePlace = _employment.StorePlaceId != null?_storePlaceController.GetById(_employment.StorePlaceId.GetValueOrDefault()) : null; _parcelsDTO = _storePlaceController.GetCouriersParcels(_storePlace, _employee.Id); if (_parcelsDTO.Status == CollectionGetStatus.Success) { for (int i = 0; i < _parcelsDTO.StorePlaces.Count; i++) { if (_parcelsDTO.StorePlaces[i].ParcelStatus.Equals(ParcelStatus.OnWayToTheCustomer)) { listBox1.Items.Add(_parcelsDTO.StorePlaces[i].Id); } } } } } catch (Exception exc) { MessageBox.Show(exc.Message); } } }
public ParcelNotFoundInDatabaseException(StorePlace store) : base("Parcel from store place" + store.Name + "not found in the database.\n") { }
public void setStorePlace(int place) { storePlace = _storePlaceManager.GetById(place); }
private void buttonSave_Click(object sender, EventArgs e) { StorePlace editedStorePlace = null; Address address; try { var apartmentNumber = Int32.Parse(textBoxApartmentNumber.Text); if (apartmentNumber < 0) { throw new FormatException(); } address = new Address { City = textBoxCity.Text, PostCode = textBoxPostCode.Text, Street = textBoxStreet.Text, HomeNumber = textBoxHomeNumber.Text, ApartmentNumber = apartmentNumber }; } catch (FormatException ex) { MessageBox.Show("Numer domu jest nieujemną liczbą typu całkowitego. Wprowadzono nieprawidłową wartość.", "Nieprawidłowa wartość", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } switch (comboBoxStorePlaceType.SelectedIndex) { case 0: editedStorePlace = new Warehouse() { Name = textBoxStorePlaceName.Text, Address = address, ManagerName = textBoxWarehouseManagerName.Text, Type = 0 }; break; case 1: editedStorePlace = new SendingPoint() { Name = textBoxStorePlaceName.Text, Address = address, WorkersCount = (int)counterStorePlaceWorkersCount.Value, Type = 1 }; break; } if (storePlace.Type == -1) { _storePlaceController.AddStoreplace(editedStorePlace); } else { editedStorePlace.Id = storePlace.Id; editedStorePlace.AddressId = storePlace.AddressId; editedStorePlace.Address.Id = storePlace.AddressId; _storePlaceController.UpdateStoreplace(editedStorePlace); } this.Close(); }
private void LogisticsNewRouteForm_Shown(object sender, EventArgs e) { comboBoxDriver.Items.Clear(); comboBoxVehicle.Items.Clear(); listViewWarehouseParcels.Items.Clear(); listViewVehicleParcels.Items.Clear(); // TODO: show error message when no vehicles etc. to not crash app Position courierPosition = _positionController.GetPositionByName("Kurier"); currentWarehouse = _storePlaceController.GetAllWarehouses().StorePlaces[0]; RoutesDTO routes = _routeController.GetAllRoutes(); List <Vehicle> vehiclesTemp = new List <Vehicle>(); List <Employee> couriersTemp = new List <Employee>(); vehicles = _vehicleController.GetAllVehicles(); couriers = _employeeController.GetEmployeesByPositionId(courierPosition.Id); if (routes.Routes.Count() == 0) { foreach (var vehicle in vehicles.Vehicles) { comboBoxVehicle.Items.Add(string.Format( "{0} {1} ({2})", vehicle.Brand, vehicle.Model, vehicle.Registration )); } foreach (var courier in couriers.Employees) { comboBoxDriver.Items.Add(string.Format( "{0} {1}", courier.Name, courier.Surname )); } } else { foreach (var vehicle in vehicles.Vehicles) { bool isFree = true; foreach (var route in routes.Routes) { if (isFree && route.VehicleId == vehicle.Id) { foreach (var point in route.RoutePoints) { if (point.Parcel.ParcelStatus == Model.Enums.ParcelStatus.OnWayToTheCustomer) { isFree = false; break; } } } } if (isFree) { vehiclesTemp.Add(vehicle); } } /* * foreach (var item in routes.Routes) * { * * foreach (var vehicle in vehicles.Vehicles) * { * if (vehicle.Id != item.VehicleId) * vehiclesTemp.Add(vehicle); * } * } */ if (vehiclesTemp.Count() == 0) { MessageBox.Show("Za mała ilość danych w bazie. Brak pojazdów w danym magazynie.", "Błąd bazy danych", 0, MessageBoxIcon.Error); this.Close(); } else { foreach (var vehicle in vehiclesTemp) { comboBoxVehicle.Items.Add(string.Format( "{0} {1} ({2})", vehicle.Brand, vehicle.Model, vehicle.Registration )); } } foreach (var courier in couriers.Employees) { bool isFree = true; foreach (var route in routes.Routes) { if (isFree && route.EmployeeId == courier.Id) { foreach (var point in route.RoutePoints) { if (point.Parcel.ParcelStatus == Model.Enums.ParcelStatus.OnWayToTheCustomer) { isFree = false; break; } } } } if (isFree) { couriersTemp.Add(courier); } } /* * foreach (var item in routes.Routes) * { * foreach (var courier in couriers.Employees) * { * if (courier.Id != item.EmployeeId) * couriersTemp.Add(courier); * } * } */ if (couriersTemp.Count() == 0) { MessageBox.Show("Za mała ilość danych w bazie. Brak pracowników na stanowisku kurier", "Błąd bazy danych", 0, MessageBoxIcon.Error); this.Close(); } else { foreach (var courier in couriersTemp) { comboBoxDriver.Items.Add(string.Format( "{0} {1}", courier.Name, courier.Surname )); } } } parcels = _parcelController.GetParcelsFromStorePlaceByStatus(currentWarehouse, Model.Enums.ParcelStatus.InWarehouse); if (parcels.Length == 0) { MessageBox.Show("Za mała ilość danych w bazie. Brak paczek do doręczenia", "Błąd bazy danych", 0, MessageBoxIcon.Error); this.Close(); } else { foreach (var parcel in parcels) { Address addr = parcel.ReceiverData.PersonalAddress; string addressText = string.Format("{0} {1}/{2}, {3}, {4}", addr.Street, addr.HomeNumber, addr.ApartmentNumber, addr.PostCode, addr.City); int weight = (int)parcel.ParcelWeight; int volume = (int)(parcel.ParcelLength * parcel.ParcelHeight * parcel.ParcelWidth); ListViewItem item = new ListViewItem(new string[] { "", addressText, weight.ToString(), volume.ToString() }); item.Tag = parcel.Id; if (parcel.Priority > 0) { item.BackColor = Color.LightGoldenrodYellow; } listViewWarehouseParcels.Items.Add(item); } } ReordereOrdinNumbers(listViewWarehouseParcels); UpdateWeightVolumeInfo(); }
public int AddStoreplace(StorePlace storeplace) { _context.StorePlaces.Add(storeplace); return(_context.SaveChanges()); }
public int UpdateStoreplace(StorePlace storeplace) { _context.StorePlaces.Update(storeplace); //_context.StorePlaces.Update return(_context.SaveChanges()); }