예제 #1
0
        public override async Task InitializeAsync(object data)
        {
            var currentDate = await _jobService.GetServerDateTime();

            //var currentDate = DateTime.Now.AddDays(1);
            var isLoggedFromYesterday = await IsCurrentUserLoggedFromYesterday();

            if (isLoggedFromYesterday)
            {
                return;
            }
            ////   MessagingCenter.Send(this, "connectToBT", _settingsService.MachineCodeSettings);
            await ShiftControl(currentDate.Hour);

            //if (DateTime.Parse(_settingsService.UserLoginDateSettings).Day == 0) _settingsService.TotalPiecesSettings = "0" ;
            //if (DateTime.Parse(_settingsService.UserLoginDateSettings).Day != currentDate.Day)
            //{ _settingsService.TotalPiecesSettings = "0"; }
            FillLocalJobData();
            var normHour   = _settingsService.JobNormSettings.ToInteger();
            var clickWorth = _settingsService.OneClickWorthSettings.ToInteger();

            if (clickWorth != 1)
            {
                if (_settingsService.IsNormCalculatedSettings.Equals("true"))
                {
                    Norm = normHour.ToString();
                }
                else
                {
                    Norm = (normHour / clickWorth).ToString();
                    _settingsService.JobNormSettings          = Norm;
                    _settingsService.IsNormCalculatedSettings = "true";
                }
            }
        }
예제 #2
0
        public override async Task InitializeAsync(object data)
        {
            //var isLoggedFromYesterday = await IsCurrentUserLoggedFromYesterday();
            //if (isLoggedFromYesterday) return;
            try
            {
                var currentDate = await _jobDataService.GetServerDateTime();

                //var currentDate = DateTime.Now.AddDays(1);
                if (DateTime.Parse(_settingsService.UserLoginDateSettings).Day == 0)
                {
                    _settingsService.TotalPiecesSettings = "0";
                }
                if (DateTime.Parse(_settingsService.UserLoginDateSettings).Day != currentDate.Day)
                {
                    _settingsService.TotalPiecesSettings = "0";
                }
                if (_settingsService.JobIdSettings != string.Empty)
                {
                    if (_settingsService.MachineNameSettings == "MANICHINO" || _settingsService.MachineNameSettings == "Manichino")
                    {
                        await _navigationService.NavigateToAsync <ManichinoViewModel>();

                        return;
                    }
                    await _navigationService.NavigateToAsync <JobViewModel>();

                    return;
                }

                await FetchData();
            }
            catch (HttpRequestExceptionEx e)
            {
                await _dialogService.ShowDialog(e.HttpCode.ToString(), "InitializeAsync", "OK");
            }
            catch (Exception)
            {
                //ignore
            }
        }
예제 #3
0
        private async Task FirstWrite()
        {
            try
            {
                var dialog = _dialogService.ShowProgressDialog("Please wait...");
                dialog.Show();
                var currentTime = await _jobDataService.GetServerDateTime();

                var jobId = _settingsService.JobIdSettings;
                var job   = await _jobDataService.GetJob(jobId);

                job.FirstWrite = currentTime;
                await _jobDataService.UpdateJob(jobId, job);

                dialog.Hide();
                await _navigationService.NavigateToAsync <ManichinoViewModel>();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
예제 #4
0
        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");
            }
        }
예제 #5
0
        private async void OnPauseJobAcceptCommand(object obj)
        {
            try
            {
                if (_pause1Switch)
                {
                    PauseType = "Pause 1";
                }
                else if (_pause2Switch)
                {
                    PauseType = "Pause 2";
                }
                else if (_wcSwitch)
                {
                    PauseType = "WC";
                }
                else if (_technicalProblemsSwitch)
                {
                    PauseType = "Technical Problem";
                }
                else if (_otherSwitch)
                {
                    PauseType = "Other";
                }
                else
                {
                    await _dialogService.ShowDialog("Please select pause type", "Information", "OK");

                    return;
                }
                _pause = new Pause
                {
                    Type        = PauseType,
                    StartPause  = await _jobService.GetServerDateTime(),
                    RealizareID = Convert.ToInt32(_settingsService.JobIdSettings)
                };
                await WaitAndExecute(100, StartStopwatch);
            }
            catch (HttpRequestExceptionEx e)
            {
                await _dialogService.ShowDialog(e.Message, "HttpRequestExceptionEx:OnPauseJobAcceptCommand", "OK");
            }
            catch (Exception)
            {
                //ignore
            }
        }
예제 #6
0
        //private async Task DeviceInfo()
        //{
        //    try
        //    {
        //        var device = new Models.Device
        //        {
        //            SN = CrossDeviceInfo.Current.Id,
        //            Type = CrossDeviceInfo.Current.Idiom.ToString(),
        //            Model = CrossDeviceInfo.Current.Model,
        //            Platform = CrossDeviceInfo.Current.Platform.ToString(),
        //            Version = CrossDeviceInfo.Current.VersionNumber.ToString()
        //        };

        //        var deviceEntity = await _deviceDataService.AddDevice(device);

        //        if (deviceEntity.DeviceID != 0)
        //        {
        //            _settingsService.DeviceIdSettings = deviceEntity.DeviceID.ToString();
        //        }
        //        else
        //        {
        //            var deviceFromDatabase = await _deviceDataService.GetDeviceWithSN(device.SN);
        //            _settingsService.DeviceIdSettings = deviceFromDatabase.DeviceID.ToString();
        //        }

        //    }
        //    catch (HttpRequestExceptionEx)
        //    {

        //    }

        //}
        private async void LoginWithBarcode(string username, string password)
        {
            if (string.IsNullOrWhiteSpace(_settingsService.UserNameSetting))
            {
                IsBusy = true;
                var dialog = _dialogService.ShowProgressDialog("Logging in... ");
                dialog.Show();
                if (_connectionService.IsConnected)
                {
                    try
                    {
                        AuthenticationResponse authenticationResponse =
                            await _authenticationService.Authenticate(username, password);

                        if (authenticationResponse.IsAuthenticated)
                        {
                            var timeWhenUserLogged = await _jobDataService.GetServerDateTime();

                            // we store the Id to know if the user is already logged in to the application
                            _settingsService.UserIdSetting   = authenticationResponse.User.Id.ToString();
                            _settingsService.UserNameSetting = authenticationResponse.User.Angajat;
                            var strSector = string.Empty;
                            var idSector  = authenticationResponse.User.IdSector;
                            if (idSector == 1)
                            {
                                strSector = "Confection";
                            }
                            else if (idSector == 2)
                            {
                                strSector = "Stiro";
                            }
                            else if (idSector == 6)
                            {
                                strSector = "Ramendo";
                            }
                            else if (idSector == 7)
                            {
                                strSector = "Tessitura";
                            }
                            else if (idSector == 8)
                            {
                                strSector = "Sartoria";
                            }
                            _settingsService.UserSectorSettings    = strSector;
                            _settingsService.UserLineSettings      = authenticationResponse.User.Linie;
                            _settingsService.UserLoginDateSettings = timeWhenUserLogged.ToString();
                            IsBusy = false;
                            var user = authenticationResponse.User;
                            user.Active         = true;
                            user.LastTimeLogged = timeWhenUserLogged;
                            await _userService.UpdateUserActivity(user.Id.ToString(), user);

                            //await DeviceInfo();
                            await _navigationService.NavigateToAsync <MainViewModel>();
                        }
                        dialog.Hide();
                    }
                    catch (HttpRequestExceptionEx e)
                    {
                        dialog.Hide();
                        await _navigationService.NavigateToAsync <LoginViewModel>();

                        await _dialogService.ShowDialog(
                            $"This username/password combination isn't known. HTTP Code: {e.HttpCode} Error Message: {e.Message}",
                            "Error logging you in",
                            "OK");
                    }
                    catch (Exception exception)
                    {
                        dialog.Hide();
                        await _navigationService.NavigateToAsync <LoginViewModel>();

                        await _dialogService.ShowDialog(
                            $"Unknown error occured: {exception.Message}",
                            "Error logging you in",
                            "OK");
                    }
                }
                else
                {
                    dialog.Hide();
                    await _navigationService.NavigateToAsync <LoginViewModel>();

                    await _dialogService.ShowDialog(
                        "Connection problem please try again later.",
                        "Internet connection problem",
                        "OK");
                }
            }
            else
            {
                await _navigationService.NavigateToAsync <MainViewModel>();

                await _dialogService.ShowDialog(
                    $"User already logged in with name {_settingsService.UserNameSetting}, please logout to change user account",
                    "User logged", "OK");
            }
        }
예제 #7
0
        //private async Task DeviceInfo()
        //{
        //    try
        //    {
        //        var device = new Models.Device
        //        {
        //            SN =  CrossDeviceInfo.Current.Id,
        //            Type = CrossDeviceInfo.Current.Idiom.ToString(),
        //            Model = CrossDeviceInfo.Current.Model,
        //            Platform = CrossDeviceInfo.Current.Platform.ToString(),
        //            Version = CrossDeviceInfo.Current.VersionNumber.ToString()
        //        };

        //    var deviceEntity =  await _deviceDataService.AddDevice(device);

        //    if (deviceEntity.DeviceID != 0)
        //    {
        //        _settingsService.DeviceIdSettings = deviceEntity.DeviceID.ToString();
        //    }
        //    else
        //    {
        //        var deviceFromDatabase = await _deviceDataService.GetDeviceWithSN(device.SN);
        //        if (deviceFromDatabase !=null)
        //        {
        //            _settingsService.DeviceIdSettings = deviceFromDatabase.DeviceID.ToString();
        //        }
        //    }

        //    }
        //    catch (HttpRequestExceptionEx)
        //    {

        //    }

        //}
        private async void OnLogin(object obj)
        {
            IsBusy = true;
            var dialog = _dialogService.ShowProgressDialog("Logging in... ");

            dialog.Show();
            if (await _connectionService.CheckConnection())
            {
                try
                {
                    var authenticationResponse = await _authenticationService.Authenticate(UserName, Password);

                    if (authenticationResponse.IsAuthenticated)
                    {
                        var timeWhenUserLogged = await _jobDataSevice.GetServerDateTime();

                        // we store the Id to know if the user is already logged in to the application
                        _settingsService.UserIdSetting   = authenticationResponse.User.Id.ToString();
                        _settingsService.UserNameSetting = authenticationResponse.User.Angajat;
                        var strSector = string.Empty;
                        var idSector  = authenticationResponse.User.IdSector;
                        if (idSector == 1)
                        {
                            strSector = "Confection";
                        }
                        else if (idSector == 2)
                        {
                            strSector = "Stiro";
                        }
                        else if (idSector == 6)
                        {
                            strSector = "Ramendo";
                        }
                        else if (idSector == 7)
                        {
                            strSector = "Tessitura";
                        }
                        else if (idSector == 8)
                        {
                            strSector = "Sartoria";
                        }
                        _settingsService.UserSectorSettings    = strSector;
                        _settingsService.UserLineSettings      = authenticationResponse.User.Linie;
                        _settingsService.UserLoginDateSettings = timeWhenUserLogged.ToString();
                        var user = authenticationResponse.User;
                        user.Active         = true;
                        user.LastTimeLogged = timeWhenUserLogged;
                        await _userDataService.UpdateUserActivity(user.Id.ToString(), user);

                        //      await DeviceInfo();
                        await _navigationService.NavigateToAsync <MainViewModel>();

                        dialog.Hide();
                        IsBusy = false;
                    }
                }
                catch (HttpRequestExceptionEx exception)
                {
                    dialog.Hide();
                    await _dialogService.ShowDialog(exception.Message, "Http request error", "OK");
                }
                catch (Exception exception)
                {
                    dialog.Hide();
                    await _dialogService.ShowDialog(exception.Message, "Http request error", "OK");

                    // ignored
                }
            }
            else
            {
                dialog.Hide();
                await _dialogService.ShowDialog(
                    "Connection problem please try again later.",
                    "Internet connection problem",
                    "OK");
            }
        }