示例#1
0
        private void OnSave(object sender, EventArgs args)
        {
            try
            {
                if (string.IsNullOrEmpty(Username.Text))
                {
                    Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("Enter username to proceed", MessageType.Regular, promptPageState), true));
                    return;
                }

                if (user.UserName.Equals(Username.Text))
                {
                    Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("The username you've entered is the same as the current one", MessageType.Regular, promptPageState), true));
                    return;
                }

                //Save configuration
                configuration.Users.Find(x => x.UserName == user.UserName).UserName = Username.Text;
                AiDataStore.SaveConfiguration(configuration);

                //Save user
                user.UserName = Username.Text;
                AiDataStore.SaveUser(user);

                //Close Popup
                promptPageState.OnResumePage(null);
                Task.Run(async() => await PopupNavigation.Instance.RemovePageAsync(this));
            }
            catch (Exception ex)
            {
                Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox(ex.Message, MessageType.Regular, promptPageState), true));
            }
        }
示例#2
0
 private void OnRefreshQuestionaires(object sender, EventArgs args)
 {
     try
     {
         _template = configuration.Questionaires.Find(q => q.Status == DCAnalytics.Statuses.Template);
         Task.Factory.StartNew(async() => {
             var response        = Synchronization.GetModifiedQuestionaire(_template.OID).Result;
             var responseContent = await response.Content.ReadAsStringAsync();
             questionaire        = JsonConvert.DeserializeObject <Questionaire>(responseContent);
         }).ContinueWith(task => {
             Device.BeginInvokeOnMainThread(() =>
             {
                 if (questionaire != null)
                 {
                     configuration.Questionaires[configuration.Questionaires.IndexOf(_template)] = questionaire;
                     AiDataStore.SaveConfiguration(configuration);
                     RefreshQuestionaires(questionaire);
                 }
                 else
                 {
                     Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("Something went wrong, please try again", MessageType.Regular, this)));
                 }
             });
         }, TaskScheduler.FromCurrentSynchronizationContext());
     }
     catch (Exception ex)
     {
         Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("Something went wrong, please try again", MessageType.Regular, this)));
     }
 }
示例#3
0
        private void OnTraineeTapped(object sender, ItemTappedEventArgs args)
        {
            try
            {
                var qItem = args.Item as QItem;
                var qn    = qns.Find(q => q.Key == qItem.ID);
                qn.IsSelected = true;

                var _training = configuration.Trainings.Find(x => x.Name == training.Name);

                var _trainee = _training.Trainees.Find(t => t.FarmerKey == qn.Key);
                if (_trainee == null)
                {
                    _trainee = new Trainee
                    {
                        Key       = Guid.NewGuid().ToString(),
                        FarmerKey = qn.Key
                    };

                    _training.Trainees.Add(_trainee);
                }

                AiDataStore.SaveConfiguration(configuration);

                Navigation.RemovePage(this);
            }
            catch (Exception ex)
            {
            }
        }
示例#4
0
        private void OnTrainerAdded(object sender, EventArgs args)
        {
            try
            {
                if (string.IsNullOrEmpty(Name.Text))
                {
                    Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("Name cannot be empty", MessageType.Regular, promptPageState)));
                }
                else
                {
                    configuration.Trainings.Find(x => x.Name == training.Name).Trainers.Add(new Trainer
                    {
                        Key  = Guid.NewGuid().ToString(),
                        Name = Name.Text
                    });

                    AiDataStore.SaveConfiguration(configuration);
                    promptPageState.OnResumePage(null);
                }
            }
            catch (Exception ex)
            {
                //DisplayAlert("Error", ex.Message);
                Debug.WriteLine($"Exception after Selection Complete:  {ex}");
            }
        }
示例#5
0
        private async Task SynchronizeQuestionaires()
        {
            try
            {
                var questionaires = configuration.Questionaires.Where(q => q.Status != DCAnalytics.Statuses.Template).ToList();
                for (int q = questionaires.Count - 1; q >= 0; q--)
                {
                    var questionaire = questionaires[q];
                    var result       = await Task.Factory.StartNew(async() => {
                        var response        = Data.Synchronization.SynchronizeQuestionaire(questionaire).Result;
                        var responseContent = await response.Content.ReadAsStringAsync();
                        return(JsonConvert.DeserializeObject <bool>(responseContent));
                    });

                    isSynchronized = !isSynchronized ? isSynchronized : result.Result;
                    if (isSynchronized)
                    {
                        configuration.Questionaires.Remove(questionaire);
                    }
                }

                AiDataStore.SaveConfiguration(configuration);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#6
0
        private async Task SynchronizeTrainings()
        {
            try
            {
                for (int t = configuration.Trainings.Count - 1; t >= 0; t--)
                {
                    var training = configuration.Trainings[t];
                    var result   = await Task.Factory.StartNew(async() => {
                        var response        = Data.Synchronization.SynchronizeTraining(training).Result;
                        var responseContent = await response.Content.ReadAsStringAsync();
                        return(JsonConvert.DeserializeObject <bool>(responseContent));
                    });

                    isSynchronized = !isSynchronized ? isSynchronized : result.Result;
                    if (isSynchronized)
                    {
                        training.Trainees.Clear();
                    }
                }

                AiDataStore.SaveConfiguration(configuration);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#7
0
        private async Task SynchronizePurchases()
        {
            try
            {
                for (int p = configuration.Purchases.Count - 1; p >= 0; p--)
                {
                    var purchase = configuration.Purchases[p];
                    var result   = await Task.Factory.StartNew(async() => {
                        var response        = Data.Synchronization.SynchronizePurchase(purchase).Result;
                        var responseContent = await response.Content.ReadAsStringAsync();
                        return(JsonConvert.DeserializeObject <bool>(responseContent));
                    });

                    isSynchronized = !isSynchronized ? isSynchronized : result.Result;
                    if (isSynchronized)
                    {
                        configuration.Purchases.Remove(purchase);
                    }
                }

                AiDataStore.SaveConfiguration(configuration);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#8
0
        private async Task SynchronizeInspections()
        {
            try
            {
                var inspections = configuration.Inspections.Where(x => !string.IsNullOrEmpty(x.FarmerKey)).ToList();
                for (int i = inspections.Count - 1; i >= 0; i--)
                {
                    var inspection = inspections[i];
                    var result     = await Task.Factory.StartNew(async() => {
                        var response        = Data.Synchronization.SynchronizeInspection(inspection).Result;
                        var responseContent = await response.Content.ReadAsStringAsync();
                        return(JsonConvert.DeserializeObject <bool>(responseContent));
                    });

                    isSynchronized = !isSynchronized ? isSynchronized : result.Result;
                    if (isSynchronized)
                    {
                        configuration.Inspections.Remove(inspection);
                    }
                }

                AiDataStore.SaveConfiguration(configuration);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#9
0
 public void OnConfirm()
 {
     try
     {
         configuration.Questionaires.Remove(configuration.Questionaires.Find(x => x.Key == Questionaire.Key));
         AiDataStore.SaveConfiguration(configuration);
         Navigation.RemovePage(this);
     }
     catch (Exception ex)
     {
     }
 }
示例#10
0
 public void OnConfirm()
 {
     try
     {
         configuration.Questionaires.Remove(configuration.Questionaires.Find(x => x.Key == questionaire.Key));
         AiDataStore.SaveConfiguration(configuration);
         Navigation.RemovePage(this);
     }
     catch (Exception ex)
     {
         Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox(ex.StackTrace, MessageType.Regular, this), true));
     }
 }
示例#11
0
        private void PurchaseItem(object sender, EventArgs args)
        {
            try
            {
                if (string.IsNullOrEmpty(stationLbl.ClassId) || string.IsNullOrEmpty(productLbl.ClassId) || string.IsNullOrEmpty(qty.Text) || string.IsNullOrEmpty(price.Text))
                {
                    Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("All fields should be filled", MessageType.Regular, this), true));
                }
                else
                {
                    if (purchase == null)
                    {
                        purchase = new Models.Purchase
                        {
                            Key             = Guid.NewGuid().ToString(),
                            Lotid           = (configuration.Purchases.Count() == 0) ? "LotId1" : "LotId" + (Convert.ToInt64(Regex.Match(configuration.Purchases.Last().Lotid, @"\d+$").Value) + 1),
                            DateOfPurchase  = DateTime.Now.Date,
                            Farmer          = questionaire.Key,
                            ConfigurationId = configuration.OID,
                            CreatedBy       = User.Key
                        }
                    }
                    ;

                    purchase.Price       = Convert.ToDecimal(price.Text);
                    purchase.Quantity    = Convert.ToDecimal(qty.Text);
                    purchase.Product     = int.Parse(productLbl.ClassId);
                    purchase.Station     = int.Parse(stationLbl.ClassId);
                    purchase.TotalAmount = Convert.ToDecimal(price.Text) * Convert.ToDecimal(qty.Text);

                    var configPurchase = configuration.Purchases.Find(x => x.Key == purchase.Key);
                    if (configPurchase == null)
                    {
                        configuration.Purchases.Add(purchase);
                    }
                    else
                    {
                        configPurchase = purchase;
                    }

                    AiDataStore.SaveConfiguration(configuration);

                    Navigation.RemovePage(this);
                }
            }
            catch (Exception ex)
            {
            }
        }
示例#12
0
        private void OnConfigurationTapped(object sender, ItemTappedEventArgs args)
        {
            try
            {
                var configuration = args.Item as Configuration;
                AiDataStore.SaveConfiguration(configuration);

                var configUser = configuration.Users.Find(u => u.OID == user.OID);

                //App.Current.MainPage = new MainPage(configUser.UserRights.FirstOrDefault().ObjectType);
                App.Current.MainPage = new MainPage();
            }
            catch (Exception ex)
            {
            }
        }
示例#13
0
        private void OnSave(object sender, EventArgs args)
        {
            try
            {
                if (string.IsNullOrEmpty(CPassword.Text) || string.IsNullOrEmpty(NPassword.Text) || string.IsNullOrEmpty(Password.Text))
                {
                    Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("Enter missing password to proceed", MessageType.Regular, promptPageState), true));
                    return;
                }

                if (user.Password.Equals(NPassword.Text))
                {
                    Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("You've entered a wrong current password", MessageType.Regular, promptPageState), true));
                    return;
                }

                if (!NPassword.Text.Equals(Password.Text))
                {
                    Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("New Password doesnot match the confirmed password", MessageType.Regular, promptPageState), true));
                    return;
                }

                //Save configuration
                configuration.Users.Find(x => x.UserName == user.UserName).Password = NPassword.Text;
                AiDataStore.SaveConfiguration(configuration);

                //Save user
                user.Password = NPassword.Text;
                AiDataStore.SaveUser(user);

                //Close Popup
                Task.Run(async() => await PopupNavigation.Instance.RemovePageAsync(this));
            }
            catch (Exception ex)
            {
                Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox(ex.Message, MessageType.Regular, promptPageState), true));
            }
        }
示例#14
0
        public void SaveQuestionaire()
        {
            try
            {
                //var status = -1;
                if (certification != null)
                {
                    certification.Status = DCAnalytics.Statuses.Partial;
                    if (certificationStatus.Equals(QuestionaireStatus.Create))
                    {
                        if (configuration.Certifications.Find(x => x.Key == certification.Key) == null)
                        {
                            configuration.Certifications.Add(certification);
                        }
                        certificationStatus = QuestionaireStatus.Modify;
                    }
                    else
                    {
                        var certificate = configuration.Certifications.Find(x => x.Key == certification.Key);
                        configuration.Certifications[configuration.Certifications.IndexOf(certificate)] = certification;
                    }
                }
                else if (FieldInspection != null)
                {
                    if (FieldInspection.Status.Equals(DCAnalytics.Statuses.New))
                    {
                        FieldInspection.Status = DCAnalytics.Statuses.Partial;
                        if (configuration.Inspections.Find(x => x.Key == FieldInspection.Key) == null)
                        {
                            configuration.Inspections.Add(FieldInspection);
                        }
                    }
                    else
                    {
                        var inspection = configuration.Inspections.Find(x => x.Key == FieldInspection.Key);
                        FieldInspection.Status = DCAnalytics.Statuses.Completed;
                        configuration.Inspections[configuration.Inspections.IndexOf(inspection)] = FieldInspection;
                    }
                }
                else
                {
                    questionaire.Status = DCAnalytics.Statuses.Partial;
                    if (_questionaireStatus.Equals(QuestionaireStatus.Create))
                    {
                        //status = _dbManager.SaveSQLiteQuestionaire(new SQLiteQuestionaire { sqliteQuestionaire = JsonConvert.SerializeObject(questionaire) });
                        if (configuration.Questionaires.Find(x => x.Key == questionaire.Key) == null)
                        {
                            configuration.Questionaires.Add(questionaire);
                        }
                    }
                    else
                    {
                        //status = _dbManager.UpdateReport(questionaire);
                        var qnr = configuration.Questionaires.Find(x => x.Key == questionaire.Key);
                        configuration.Questionaires[configuration.Questionaires.IndexOf(qnr)] = questionaire;
                    }
                }

                AiDataStore.SaveConfiguration(configuration);
            }
            catch (Exception ex)
            {
                Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox(ex.StackTrace, MessageType.Regular, this), true));
            }
        }