void CalulateMileage() { if (!doCalculate || string.IsNullOrWhiteSpace(txtFromAdd.Text) || string.IsNullOrWhiteSpace(txtToAdd.Text) || txtFromAdd.Text == EMPTYADDRESS || txtToAdd.Text == EMPTYADDRESS) { return; } double distance = 0d; distance = GoogleMaps.GetDistance(txtFromAdd.Text, txtToAdd.Text, (bool)chkAvdFerr.IsChecked); double dist = distance; if (!txtMonHrs.IsReadOnly && journalline.Day1 > 0) { txtMonHrs.EditValue = dist; } if (!txtTueHrs.IsReadOnly && journalline.Day2 > 0) { txtTueHrs.EditValue = dist; } if (!txtWedHrs.IsReadOnly && journalline.Day3 > 0) { txtWedHrs.EditValue = dist; } if (!txtThuHrs.IsReadOnly && journalline.Day4 > 0) { txtThuHrs.EditValue = dist; } if (!txtFriHrs.IsReadOnly && journalline.Day5 > 0) { txtFriHrs.EditValue = dist; } if (!txtSatHrs.IsReadOnly && journalline.Day6 > 0) { txtSatHrs.EditValue = dist; } if (!txtSunHrs.IsReadOnly && journalline.Day7 > 0) { txtSunHrs.EditValue = dist; } CalculateTotal(); }
private void TopCallWorkersFrm_Load(object sender, EventArgs e) { if (Call == null) { return; } //show which call this is callLbl.Text = Call.ToString(); //get the service user for this call ServiceUser serviceuser = Call.ServiceUser; ////this is the list of workers to add to the list List <TopWorkersViewModel> workersToAdd = new List <TopWorkersViewModel>(); //Get infor for every active worker foreach (Worker worker in WorkerManager.Instance.ActiveWorkers) { //first lets get distance double miles = -1; if (worker.LongLatCoords != null && worker.LongLatCoords.HasLongLat) { try { miles = GoogleMaps.GetDistance(worker.LongLatCoords, serviceuser.LongLatCoords, "M"); } catch (Exception ex) { } } //now whether they are a keyworker bool isKeyWorker = serviceuser.KeyWorkers.Contains(worker); //no Image img = null; if (isKeyWorker) { img = Cura.Properties.Resources.key; } //now get the time unassigned int minutes_unassinged = worker.Unassigned_Mins_ForWeek(StartDate); //ignore people without any of this information! if (minutes_unassinged == 0 && !isKeyWorker && miles < 0) { continue; } workersToAdd.Add( new TopWorkersViewModel() { worker = worker, distance_miles = miles, isKeyWorker = isKeyWorker, image = img, mins_workingtime_unassigned = minutes_unassinged } ); } IEnumerable <TopWorkersViewModel> res = workersToAdd.OrderByDescending(w => w.isKeyWorker).ThenBy(w => w.distance_miles).ThenByDescending(w => w.mins_workingtime_unassigned).Take(10); int index = 1; foreach (TopWorkersViewModel model in res) { model.index = index++; } ////hours remaining listView1.SetObjects(res); ////distance ////get the closest remaining who aren't key workers //Dictionary<Worker, double> WorkerMiles = new Dictionary<Worker, double>(); //if (serviceuser.LongLatCoords != null && serviceuser.LongLatCoords.HasLongLat) //{ // foreach (Worker worker in WorkerManager.Instance.Workers.Where(w => !serviceuser.KeyWorkers.Contains(w))) // { // if (worker.LongLatCoords == null || !worker.LongLatCoords.HasLongLat) // continue ; // double miles = GoogleMaps.GetDistance(worker.LongLatCoords, serviceuser.LongLatCoords, "M"); // WorkerMiles.Add(worker, miles); // } //} ////FIRST DO THE KEYWORKERS //foreach (Worker worker in serviceuser.KeyWorkers) //{ // if (remaining == 0) // break; // double miles = -1; // if (worker.LongLatCoords != null && worker.LongLatCoords.HasLongLat) // { // try // { // miles = GoogleMaps.GetDistance(worker.LongLatCoords, serviceuser.LongLatCoords, "M"); // }catch(Exception ex){} // } // workersToAdd.Add(new TopWorkersViewModel() { worker = worker, distance_miles = miles, isKeyWorker = true, image = ImageGenerator.Instance.GenerateWorkerImage(ImageGenerator.WorkerImageGen.Key), mins_workingtime_unassigned = worker.Unassigned_Mins_ForWeek(StartDate) }); // remaining -= 1; //} ////NOW DO THE PEOPLE THAT ARE CLOSEST BUT NOT KEY WORKERS // foreach(KeyValuePair<Worker, double> pair in WorkerMiles) //{ // if (remaining == 0) // break; // workersToAdd.Add(new TopWorkersViewModel() { worker = pair.Key, distance_miles = pair.Value, isKeyWorker = false, mins_workingtime_unassigned = pair.Key.Unassigned_Mins_ForWeek(StartDate) }); // remaining -= 1; //} //IEnumerable<Worker> list1 = WorkerManager.Instance.Workers; //list1.OrderByDescending(w => w.Unassigned_Mins_ForWeek(StartDate)); // foreach (Worker worker in list1) // { // if (remaining == 0) // break; // workersToAdd.Add(new TopWorkersViewModel() { worker = worker, isKeyWorker = false, mins_workingtime_unassigned = worker.Unassigned_Mins_ForWeek(StartDate) }); // remaining -= 1; // } // workersToAdd.OrderBy(w => w.isKeyWorker).ThenBy(w => w.distance_miles).ThenBy(w => w.mins_workingtime_unassigned); ////hours remaining //listView1.SetObjects(workersToAdd); }