private async Task FirstWrite() { try { if (_settingsService.UserLineSettings != _settingsService.MachineLineSettings) { await _dialogService.ShowDialog("You can work only in your line.", "Warning", "OK"); return; } var currentTime = await _jobDataService.GetServerDateTime(); var machine = await _masiniService.GetMachineAsync(_settingsService.MachineIdSettings); var jobId = _settingsService.JobIdSettings; var job = await _jobDataService.GetJob(jobId); job.FirstWrite = currentTime; Models.MasiniForUpdate machineToUpdate = new Models.MasiniForUpdate() { Id = machine.Id, Occupied = false, Active = true }; await _masiniService.UpdateMachineActivity(machineToUpdate, machineToUpdate.Id); await _jobDataService.UpdateJob(jobId, job); await _navigationService.NavigateToAsync <JobViewModel>(); } catch (Exception e) { await _dialogService.ShowDialog(e.Message, "Exception:" + e.InnerException, "OK"); } }
//private async Task UpdateJobFirstWrite(DateTime firstClick) //{ // try // { // if (Counter == 1) // { // var jobId = _settingsService.JobIdSettings; // var job = await _jobService.GetJob(jobId); // job.FirstWrite = firstClick; // await _jobService.UpdateJob(jobId, job); // } // } // catch (Exception e) // { // Console.WriteLine(e); // throw; // } //} private async Task UpdateJobLastWrite(bool isStop) { try { var job = await _jobService.GetJob(_settingsService.JobIdSettings); var machine = await _masiniService.GetMachineAsync(_settingsService.MachineIdSettings); var lastWrite = await _jobService.GetLastClickForJob(_settingsService.JobIdSettings); var currentTime = await _jobService.GetServerDateTime(); DateTime initialdate = DateTime.ParseExact("11/11/2011 00:00:00", "dd/MM/yyyy hh:mm:ss", null); if (lastWrite == initialdate) { job.LastWrite = currentTime; job.Closed = currentTime; } else if (DateTime.Parse(_settingsService.UserLoginDateSettings).Day != currentTime.Day) { job.LastWrite = lastWrite; job.Closed = lastWrite; } else { job.LastWrite = lastWrite; job.Closed = currentTime; } await _jobService.UpdateJob(job.Id.ToString(), job); //await AddEfficiencyForJob(job); if (machine.Active && isStop) { MasiniForUpdate machineToUpdate = new MasiniForUpdate() { Id = machine.Id, Occupied = false, Active = false }; await _masiniService.UpdateMachineActivity(machineToUpdate, machineToUpdate.Id); } _settingsService.JobIdSettings = null; _settingsService.JobNormSettings = null; _settingsService.CounterSettings = null; _settingsService.OneClickWorthSettings = null; _settingsService.IsNormCalculatedSettings = null; _settingsService.TotalEfficiencySettings = null; _settingsService.SelectedPhaseSettings = null; _settingsService.LastClickSetting = null; // MessagingCenter.Send(this, "disconnectFromBT"); await _navigationService.NavigateToAsync <HomeViewModel>(); } catch (Exception e) { await _dialogService.ShowDialog(e.Message, "Exception:UpdateJobLastWrite" + e, "OK"); } }
private async void MachineWithBarCode(string id) { IsBusy = true; if (_connectionService.IsConnected) { if (!string.IsNullOrWhiteSpace(_settingsService.UserNameSetting)) { var machine = await _machineService.GetMachineAsync(id); if (machine.Occupied) { await _navigationService.NavigateToAsync <MainViewModel>(); await _dialogService.ShowDialog( $"Two persons can't be logged on one machine at the same time!", "Machine is occupied!", "OK"); } else { if (machine.Linie.Contains(_settingsService.UserLineSettings)) { try { // we store the Id to know if the user is already logged in to the application _settingsService.MachineIdSettings = id; _settingsService.MachineCodeSettings = machine.CodMasina; _settingsService.MachineNameSettings = machine.Descriere; _settingsService.MachineLineSettings = machine.Linie; IsBusy = false; int.TryParse(id, out var machineId); MasiniForUpdate machineToUpdate = new MasiniForUpdate { Id = machineId, Occupied = true, Active = true, }; await _machineService.UpdateMachineActivity(machineToUpdate, machineId); await _navigationService.NavigateToAsync <MainViewModel>(); } catch (Exception e) { await _dialogService.ShowDialog(e.ToString(), "Exception", "OK"); } } else { await _navigationService.NavigateToAsync <MainViewModel>(); await _dialogService.ShowDialog( $"You selected wrong line. Scanned machine belong to {machine.Linie} and your selected line by manager is {_settingsService.UserLineSettings}. " + "Please contact your superior!", "Wrong line!", "OK"); } } } else { await _navigationService.NavigateToAsync <LoginViewModel>(); await _dialogService.ShowDialog( "First try to sing in, then you can scan the machine.", "Wrong barcode!", "OK"); } } else { await _navigationService.NavigateToAsync <MainViewModel>(); await _dialogService.ShowDialog( "Connection problem please try again later.", "Internet connection problem", "OK"); } }