async Task LoadQuestionData()
        {
            var media = await new DbService().FindMedia(_currentQuestion.Question_Ref, StateService.CurrentAddress.UPRN);

            tbImage.Visibility = media != null ? Visibility.Visible : Visibility.Collapsed;

            var options1 = await new DbService().GetFirstLevelOptions(_currentQuestion.Question_Ref);

            _currentAnswer = await new DbService().FindAnswer(_currentQuestion.Question_Ref, StateService.CurrentAddress.UPRN);

            if (_currentAnswer != null)
            {
                tbComment.Text = _currentAnswer.COMMENT;
            }
            else
            {
                tbComment.Text = "";
            }

            options1.Insert(0, new Option {
                DisplayText = "Answer required", Identity = "0"
            });
            cmb1.ItemsSource = options1;

            if (_currentAnswer != null)
            {
                var o1 = options1.FirstOrDefault(x => x.OptionId == _currentAnswer.OptionID);

                if (o1 != null)
                {
                    cmb1.SelectedItem = o1;
                }
            }

            if (options1.Any() && cmb1.SelectedItem == null)
            {
                cmb1.SelectedIndex = 0;
            }

            if (options1.Count > 1)
            {
                cmb1Panel.Visibility       = Visibility.Visible;
                tb1ForCmb1Panel.Visibility = Visibility.Collapsed;
                tb1ForCmb1.Text            = "";
            }
            else
            {
                if (_currentAnswer != null)
                {
                    tb1ForCmb1.Text = _currentAnswer.Freetext ?? "";
                }
                else
                {
                    tb1ForCmb1.Text = "";
                }

                tb1ForCmb1Panel.Visibility = Visibility.Visible;
                tb1ForCmb1.BorderThickness = new Thickness(3);
                tb1ForCmb1.BorderBrush     = new SolidColorBrush(Color.FromArgb(255, 100, 160, 200));
                cmb1Panel.Visibility       = Visibility.Collapsed;
            }

            cmb2.IsEnabled = true;

            tbQuestionRef.Text     = string.Format("{0} {1}", _currentQuestion.Main_Element, _currentQuestion.Unit);
            tbQuestionHeading.Text = _currentQuestion.Question_Heading;

            tbCurrentQNmber.Text = (_questions.IndexOf(_currentQuestion) + 1).ToString();
            tbQuestionCount.Text = _questions.Count.ToString();


            foreach (StackPanel child in panelTextBoxes.Children)
            {
                var tb = child.Children[1] as TextBox;
                tb.KeyUp -= tb_KeyUp;
            }

            panelTextBoxes.Children.Clear();
            if (_currentQuestion.Apply_2nd_Question == "YES")
            {
                panel2.Visibility = Visibility.Visible;


                tbComment.Visibility      = Visibility.Visible;
                tbQuestionNum.Visibility  = Visibility.Visible;
                panelTextBoxes.Visibility = Visibility.Visible;

                var options2 = await new DbService().GetSecondLevelOptions(_currentQuestion.Question_Ref);



                if (options2.Any())
                {
                    options2.Insert(0, new Option {
                        DisplayText = "Answer required", Identity = "0"
                    });
                    cmb2.ItemsSource = options2;

                    cmb2.Visibility = Visibility.Visible;

                    if (_currentAnswer != null)
                    {
                        var o2 = options2.FirstOrDefault(x => x.OptionId == _currentAnswer.OptionID2ndry);

                        if (o2 != null)
                        {
                            cmb2.SelectedItem = o2;
                        }
                    }

                    if (options2.Any() && cmb2.SelectedItem == null)
                    {
                        cmb2.SelectedIndex = 0;
                    }
                }
                else
                {
                    cmb2.Visibility = Visibility.Collapsed;
                }

                var address = StateService.CurrentAddress;

                // var surveyTypes = await new DbService().FindSurveyType(address.Type);

                var qRef = "*";
                if (_currentQuestion.SurveyType.Contains("HHSRS") || _currentQuestion.SurveyType.Contains("RDSAP"))
                {
                    qRef = _currentQuestion.Question_Ref;
                }

                var survelemMaps = await new DbService().GetSurvelemMaps(qRef);


                foreach (var survelemMap in survelemMaps)
                {
                    var p = new StackPanel()
                    {
                        Width = 200
                    };
                    var b = new TextBlock()
                    {
                        Text = survelemMap.Question_Heading
                    };
                    var tb = new TextBox()
                    {
                        Tag = survelemMap.SqName, Width = 180
                    };


                    b.Margin           = new Thickness(25, 0, 0, -8);
                    b.Foreground       = new SolidColorBrush(Color.FromArgb(255, 219, 70, 154));
                    b.FontWeight       = FontWeights.Bold;
                    tb.BorderThickness = new Thickness(3);
                    tb.BorderBrush     = new SolidColorBrush(Color.FromArgb(255, 100, 160, 200));

                    InputScope     numberScope     = new InputScope();
                    InputScopeName numberScopeName = new InputScopeName();
                    numberScopeName.NameValue = InputScopeNameValue.CurrencyAmountAndSymbol;
                    numberScope.Names.Add(numberScopeName);

                    InputScope     textScope     = new InputScope();
                    InputScopeName textScopeName = new InputScopeName();
                    textScopeName.NameValue = InputScopeNameValue.AlphanumericFullWidth;
                    textScope.Names.Add(textScopeName);

                    if (survelemMap.SqName.ToLower().StartsWith("sqn"))
                    {
                        tb.InputScope = numberScope;
                    }
                    else if (survelemMap.SqName.ToLower().StartsWith("sqt"))
                    {
                        tb.InputScope = textScope;
                    }

                    var props = typeof(Survelem).GetProperties();

                    if (_currentAnswer != null)
                    {
                        var value = props.First(x => x.Name == survelemMap.SqName).GetValue(_currentAnswer);
                        if (value != null)
                        {
                            tb.Text = value.ToString();
                        }
                        if (cmb1.SelectedIndex != 0)
                        {
                            var selectedO = cmb1.SelectedItem as Option;
                            tb.IsEnabled = !selectedO.Disable2nd;
                        }
                    }

                    p.Children.Add(b);
                    p.Children.Add(tb);

                    tb.KeyUp += tb_KeyUp;

                    panelTextBoxes.Children.Add(p);
                }
            }
            else
            {
                panel2.Visibility = Visibility.Collapsed;
                cmb2.Visibility   = Visibility.Collapsed;

                tbComment.Visibility      = Visibility.Collapsed;
                tbQuestionNum.Visibility  = Visibility.Collapsed;
                panelTextBoxes.Visibility = Visibility.Collapsed;
            }
        }
        async Task <bool> SaveData()
        {
            if (tb1ForCmb1Panel.Visibility == Visibility.Visible && string.IsNullOrEmpty(tb1ForCmb1.Text))
            {
                return(false);
            }

            if (cmb1.Items.Count > 1 && cmb1.SelectedIndex <= 0)
            {
                return(false);
            }

            foreach (StackPanel child in panelTextBoxes.Children)
            {
                var item = child.Children[1] as TextBox;

                if (item != null && string.IsNullOrEmpty(item.Text) && item.IsEnabled)
                {
                    MessageBox.Show("Please answer all questions");
                    return(false);
                }
            }

            if (_currentAnswer == null)
            {
                _currentAnswer = new Survelem()
                {
                    UPRN              = StateService.CurrentAddress.UPRN,
                    DateOfSurvey      = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"),
                    id                = Guid.NewGuid().ToString(),
                    Question_Ref      = _currentQuestion.Question_Ref,
                    BuildingType      = StateService.CurrentAddress.Type,
                    CustomerID        = _currentQuestion.CustomerID,
                    CustomerSurveyID  = _currentQuestion.CustomerSurveyID,
                    IsCreatedOnClient = true
                };
            }

            if (!string.IsNullOrEmpty(tb1ForCmb1.Text))
            {
                _currentAnswer.Freetext = tb1ForCmb1.Text;
            }

            _currentAnswer.COMMENT = tbComment.Text;

            var o1 = (Option)cmb1.SelectedItem;

            // o1.Choose = true;

            if (o1.ConfirmationRequired && !_confirmations.Contains(o1.Identity))
            {
                _confirmations.Add(o1.Identity);
                var mb = MessageBox.Show(string.Format("Are you sure you want to select {0}?", o1.Text), "Warning", MessageBoxButton.OKCancel);
                if (mb == MessageBoxResult.Cancel)
                {
                    return(false);
                }
            }

            _currentAnswer.OptionID = o1.OptionId;


            if (cmb2.Items.Count > 1 && cmb2.IsEnabled)
            {
                if (cmb2.SelectedIndex <= 0 && cmb2.IsEnabled)
                {
                    return(false);
                }

                var o2 = cmb2.SelectedItem as Option;

                if (o2.ConfirmationRequired && !_confirmations.Contains(o1.Identity))
                {
                    _confirmations.Add(o2.Identity);
                    var mb = MessageBox.Show(string.Format("Are you sure you want to select {0}?", o2.Text), "Warning", MessageBoxButton.OKCancel);
                    if (mb == MessageBoxResult.Cancel)
                    {
                        return(false);
                    }
                }
                //o2.Choose = true;

                _currentAnswer.OptionID2ndry = o2.OptionId;
                // await new DbService().Save(o2, ESyncStatus.NotSynced);
            }


            if (_currentQuestion.Apply_2nd_Question == "YES" && panelTextBoxes.Children.Any())
            {
                foreach (StackPanel child in panelTextBoxes.Children)
                {
                    var item = child.Children[1] as TextBox;

                    if (item == null)
                    {
                        continue;
                    }

                    var name = item.Tag.ToString();

                    var props = typeof(Survelem).GetProperties();

                    var prop = props.FirstOrDefault(x => x.Name == name);

                    if (prop == null)
                    {
                        throw  new Exception("Not found property: " + name);
                    }

                    if (item.IsEnabled)
                    {
                        prop.SetValue(_currentAnswer, item.Text);
                    }
                    else
                    {
                        prop.SetValue(_currentAnswer, "");
                    }
                }
            }
            // await new DbService().Save(o1, ESyncStatus.NotSynced);


            _currentAnswer.Identity = _currentAnswer.id;

            await new DbService().Save(_currentAnswer, ESyncStatus.NotSynced);

            QuestionStatus questionStatus = await new DbService().FindQuestionStatus(_currentQuestion.Question_Ref, StateService.CurrentAddress.UPRN);

            if (questionStatus == null)
            {
                questionStatus = new QuestionStatus()
                {
                    Identity = Guid.NewGuid().ToString(), QuestionRef = _currentQuestion.Question_Ref, UPRN = StateService.CurrentAddress.UPRN
                };
            }
            questionStatus.Completed = true;

            await new DbService().Save(questionStatus);


            var address = StateService.CurrentAddress;

            address.HasStartedToSurveyed = true;
            await new DbService().Save(address, ESyncStatus.NotSynced);

            return(true);
        }
示例#3
0
        async Task <bool> SaveData()
        {
            if (tb1ForCmb1Panel.Visibility == Visibility.Visible && string.IsNullOrEmpty(tb1ForCmb1.Text) && dt1ForCmb1.Value == null)
            {
                return(false);
            }

            if (cmb1.Items.Count > 1 && cmb1.SelectedIndex <= 0)
            {
                return(false);
            }

            if (_currentQuestion.NeedToHaveMedia)
            {
                var media = await new DbService().FindMedia(_currentQuestion.Question_Ref, StateService.CurrentAddress.UPRN);

                if (media == null)
                {
                    MessageBox.Show("This question requires to take a photo. Please take a photo to go to the next question.");
                    return(false);
                }
            }

            foreach (StackPanel child in panelTextBoxes.Children)
            {
                var item = child.Children[1] as TextBox;

                if (item != null && string.IsNullOrEmpty(item.Text) && item.IsEnabled)
                {
                    MessageBox.Show("Please answer all questions");
                    return(false);
                }
            }

            if (!string.IsNullOrEmpty(tb1ForCmb1.Text) && !_shownRangeWarning)
            {
                if (!string.IsNullOrEmpty(_currentQuestion.LookAtRange) && _currentQuestion.LookAtRange.ToLower() == "true")
                {
                    double value = 0;

                    if (!double.TryParse(tb1ForCmb1.Text, out value))
                    {
                        _shownRangeWarning = true;
                        MessageBox.Show("Value should be numeric");
                        return(false);
                    }


                    if (!string.IsNullOrEmpty(_currentQuestion.AnswerRangeFrom))
                    {
                        var low = double.Parse(_currentQuestion.AnswerRangeFrom);
                        if (value < low)
                        {
                            _shownRangeWarning = true;
                            MessageBox.Show(_currentQuestion.AnswerRangeTextF ?? "AnswerRangeTextF");
                            return(false);
                        }
                    }
                    if (!string.IsNullOrEmpty(_currentQuestion.AnswerRangeTo))
                    {
                        var top = double.Parse(_currentQuestion.AnswerRangeTo);
                        if (value > top)
                        {
                            _shownRangeWarning = true;
                            MessageBox.Show(_currentQuestion.AnswerRangeTextT ?? "AnswerRangeTextT");
                            return(false);
                        }
                    }
                }
            }

            if (_currentAnswer == null)
            {
                _currentAnswer = new Survelem()
                {
                    UPRN         = StateService.CurrentAddress.UPRN,
                    DateOfSurvey = DateTime.Now.ToString(Constants.DateTimeFormat),

                    Question_Ref      = _currentQuestion.Question_Ref,
                    BuildingType      = StateService.CurrentAddress.Type,
                    CustomerID        = _currentQuestion.CustomerID,
                    CustomerSurveyID  = _currentQuestion.CustomerSurveyID,
                    IsCreatedOnClient = true,
                };
            }

            if (!string.IsNullOrEmpty(tb1ForCmb1.Text))
            {
                _currentAnswer.Freetext = tb1ForCmb1.Text;
            }
            else if (dt1ForCmb1.Value != null)
            {
                _currentAnswer.Freetext = dt1ForCmb1.Value.Value.ToString(Constants.DateTimeFormat, CultureInfo.InvariantCulture);
            }
            _currentAnswer.COMMENT = tbComment.Text;

            var o1 = (Option)cmb1.SelectedItem;

            // o1.Choose = true;

            if (o1.ConfirmationRequired && !_confirmations.Contains(o1.Id.ToString()))
            {
                _confirmations.Add(o1.Id.ToString());
                var mb = MessageBox.Show(string.Format("Are you sure you want to select {0}?", o1.Text), "Warning", MessageBoxButton.OKCancel);
                if (mb == MessageBoxResult.Cancel)
                {
                    return(false);
                }
            }

            if (o1.NeedToHaveMedia)
            {
                var media = await new DbService().FindMedia(_currentQuestion.Question_Ref, StateService.CurrentAddress.UPRN);

                if (media == null)
                {
                    MessageBox.Show("This answer requires to take a photo. Please take a photo to go to the next question.");
                    return(false);
                }
            }

            _currentAnswer.OptionID = o1.Id != Guid.Empty ? (Guid?)o1.Id : null;


            if (cmb2.Items.Count > 1 && cmb2.IsEnabled)
            {
                if (cmb2.SelectedIndex <= 0 && cmb2.IsEnabled)
                {
                    return(false);
                }

                var o2 = cmb2.SelectedItem as Option;

                if (o2.ConfirmationRequired && !_confirmations.Contains(o1.Id.ToString()))
                {
                    _confirmations.Add(o2.Id.ToString());
                    var mb = MessageBox.Show(string.Format("Are you sure you want to select {0}?", o2.Text), "Warning", MessageBoxButton.OKCancel);
                    if (mb == MessageBoxResult.Cancel)
                    {
                        return(false);
                    }
                }

                if (o2.NeedToHaveMedia)
                {
                    var media = await new DbService().FindMedia(_currentQuestion.Question_Ref, StateService.CurrentAddress.UPRN);

                    if (media == null)
                    {
                        MessageBox.Show("Please make a photo");
                        return(false);
                    }
                }

                //o2.Choose = true;

                _currentAnswer.OptionID2ndry = o2.Id != Guid.Empty ? (Guid?)o2.Id : null;
                // await new DbService().Save(o2, ESyncStatus.NotSynced);
            }


            if (_currentQuestion.Apply_2nd_Question == "YES" && panelTextBoxes.Children.Any())
            {
                foreach (StackPanel child in panelTextBoxes.Children)
                {
                    var item = child.Children[1] as TextBox;

                    if (item == null)
                    {
                        continue;
                    }

                    var name = item.Tag.ToString();


                    var props = typeof(Survelem).GetProperties();

                    var prop = props.FirstOrDefault(x => x.Name == name);

                    if (prop == null)
                    {
                        throw new Exception("Not found property: " + name);
                    }

                    if (item.IsEnabled)
                    {
                        prop.SetValue(_currentAnswer, item.Text);
                    }
                    else
                    {
                        prop.SetValue(_currentAnswer, "");
                    }
                }
            }

            if (!StateService.IsQA)
            {
                await new DbService().Save(_currentAnswer, ESyncStatus.NotSynced);
            }

            var address = StateService.CurrentAddress;

            if (!address.HasStartedToSurveyed)
            {
                address.HasStartedToSurveyed = true;
                if (!StateService.IsQA)
                {
                    await new DbService().Save(address, ESyncStatus.NotSynced);
                }
            }

            return(true);
        }
示例#4
0
        async Task LoadQuestionData()
        {
            _shownRangeWarning = false;

            tb1ForCmb1.InputScope = new InputScope();

            var media = await new DbService().FindMedia(_currentQuestion.Question_Ref, StateService.CurrentAddress.UPRN);

            tbImage.Visibility = media != null ? Visibility.Visible : Visibility.Collapsed;

            var options1 = await new DbService().GetFirstLevelOptions(_currentQuestion.Question_Ref, StateService.CurrentCustomer.CustomerSurveyID);

            _currentAnswer = await new DbService().FindAnswer(_currentQuestion.Question_Ref, StateService.CurrentAddress.UPRN);

            if (_currentAnswer != null)
            {
                tbComment.Text = _currentAnswer.COMMENT ?? "";
            }
            else
            {
                tbComment.Text = "";
            }

            options1.Insert(0, new Option {
                DisplayText = "Answer required", Id = Guid.Empty
            });
            cmb1.ItemsSource = options1;

            if (_currentAnswer != null)
            {
                var o1 = options1.FirstOrDefault(x => x.Id == _currentAnswer.OptionID);

                if (o1 != null)
                {
                    cmb1.SelectedItem = o1;
                }
            }

            if (options1.Any() && cmb1.SelectedItem == null)
            {
                cmb1.SelectedIndex = 0;
            }

            if (options1.Count > 1)
            {
                cmb1Panel.Visibility       = Visibility.Visible;
                tb1ForCmb1Panel.Visibility = Visibility.Collapsed;
                tb1ForCmb1.Text            = "";
            }
            else
            {
                tb1ForCmb1Panel.Visibility = Visibility.Visible;
                if (_currentQuestion.isDate)
                {
                    dt1ForCmb1.Visibility = Visibility.Visible;

                    tb1ForCmb1.Visibility = Visibility.Collapsed;
                }
                else
                {
                    dt1ForCmb1.Visibility = Visibility.Collapsed;

                    tb1ForCmb1.Visibility = Visibility.Visible;
                }

                if (_currentAnswer != null)
                {
                    if (_currentQuestion.isDate)
                    {
                        tb1ForCmb1.Text = "";
                        if (!string.IsNullOrEmpty(_currentAnswer.Freetext))
                        {
                            DateTime date;

                            if (DateTime.TryParseExact(_currentAnswer.Freetext, Constants.DateTimeFormat, CultureInfo.CurrentUICulture, DateTimeStyles.None, out date))
                            {
                                dt1ForCmb1.Value = date;
                            }
                            else
                            {
                                dt1ForCmb1.Value = null;
                            }
                        }
                    }
                    else
                    {
                        dt1ForCmb1.Value = null;
                        tb1ForCmb1.Text  = _currentAnswer.Freetext ?? "";
                    }
                }

                else
                {
                    tb1ForCmb1.Text  = "";
                    dt1ForCmb1.Value = null;
                }

                if (!string.IsNullOrEmpty(_currentQuestion.LookAtRange) &&
                    _currentQuestion.LookAtRange.ToLower() == "true")
                {
                    InputScope     numberScope     = new InputScope();
                    InputScopeName numberScopeName = new InputScopeName();
                    numberScopeName.NameValue = InputScopeNameValue.NumberFullWidth;
                    numberScope.Names.Add(numberScopeName);

                    tb1ForCmb1.InputScope = numberScope;
                }

                tb1ForCmb1Panel.Visibility = Visibility.Visible;
                tb1ForCmb1.BorderThickness = new Thickness(3);
                tb1ForCmb1.BorderBrush     = new SolidColorBrush(Color.FromArgb(255, 100, 160, 200));
                cmb1Panel.Visibility       = Visibility.Collapsed;
            }

            cmb2.IsEnabled = true;

            tbQuestionRef.Text     = string.Format("{0} {1}", _currentQuestion.Main_Element, _currentQuestion.Unit);
            tbQuestionHeading.Text = _currentQuestion.Question_Heading;

            tbCurrentQNmber.Text = (_questions.IndexOf(_currentQuestion) + 1).ToString();
            tbQuestionCount.Text = _questions.Count.ToString();


            foreach (StackPanel child in panelTextBoxes.Children)
            {
                var tb = child.Children[1] as TextBox;
                tb.KeyUp -= tb_KeyUp;
            }

            panelTextBoxes.Children.Clear();
            if (_currentQuestion.Apply_2nd_Question == "YES")
            {
                panel2.Visibility = Visibility.Visible;


                tbComment.Visibility      = Visibility.Visible;
                tbQuestionNum.Visibility  = Visibility.Visible;
                panelTextBoxes.Visibility = Visibility.Visible;

                var options2 = await new DbService().GetSecondLevelOptions(_currentQuestion.Question_Ref, StateService.CurrentCustomer.CustomerSurveyID);



                if (options2.Any())
                {
                    options2.Insert(0, new Option {
                        DisplayText = "Answer required", Id = Guid.Empty
                    });
                    cmb2.ItemsSource = options2;

                    cmb2.Visibility = Visibility.Visible;

                    if (_currentAnswer != null)
                    {
                        var o2 = options2.FirstOrDefault(x => x.Id == _currentAnswer.OptionID2ndry);

                        if (o2 != null)
                        {
                            cmb2.SelectedItem = o2;
                        }
                    }

                    if (options2.Any() && cmb2.SelectedItem == null)
                    {
                        cmb2.SelectedIndex = 0;
                    }
                }
                else
                {
                    cmb2.Visibility = Visibility.Collapsed;
                }

                var address = StateService.CurrentAddress;

                // var surveyTypes = await new DbService().FindSurveyType(address.Type);

                //todo: Ulas disabled to deafult qRef to be *, and now sending actual Question_Ref of the current question to GetSurvelMaps method. We need to check if this effects anywhere else.

                //var qRef = "*";

                //todo: Ulas commented out the following if clause in order to enable secondary questions for HHRSRS and RDSAP. Need to check and see if this causes any problem with the first project data. We need to check if this effects anywhere else.

                //if (_currentQuestion.SurveyType.Contains("HHSRS") || _currentQuestion.SurveyType.Contains("RDSAP"))
                //{
                //    qRef = _currentQuestion.Question_Ref;
                //}

                var survelemMaps = await new DbService().GetSurvelemMaps(_currentQuestion.Question_Ref, StateService.CurrentCustomer.CustomerSurveyID, _currentQuestion.SurveyType);


                foreach (var survelemMap in survelemMaps)
                {
                    var p = new StackPanel()
                    {
                        Width = 200
                    };
                    var b = new TextBlock()
                    {
                        Text = survelemMap.Question_Heading
                    };
                    var tb = new TextBox()
                    {
                        Tag = survelemMap.SqName, Width = 180
                    };


                    b.Margin           = new Thickness(25, 0, 0, -8);
                    b.Foreground       = new SolidColorBrush(Color.FromArgb(255, 219, 70, 154));
                    b.FontWeight       = FontWeights.Bold;
                    tb.BorderThickness = new Thickness(3);
                    tb.BorderBrush     = new SolidColorBrush(Color.FromArgb(255, 100, 160, 200));

                    InputScope     numberScope     = new InputScope();
                    InputScopeName numberScopeName = new InputScopeName();
                    numberScopeName.NameValue = InputScopeNameValue.NumberFullWidth;
                    numberScope.Names.Add(numberScopeName);

                    InputScope     textScope     = new InputScope();
                    InputScopeName textScopeName = new InputScopeName();
                    textScopeName.NameValue = InputScopeNameValue.AlphanumericFullWidth;
                    textScope.Names.Add(textScopeName);

                    if (survelemMap.SqName.ToLower().StartsWith("sqn"))
                    {
                        tb.InputScope = numberScope;
                    }
                    else if (survelemMap.SqName.ToLower().StartsWith("sqt"))
                    {
                        tb.InputScope = textScope;
                    }

                    if (_currentAnswer != null)
                    {
                        var value = _propertyInfos.First(x => x.Name == survelemMap.SqName).GetValue(_currentAnswer);
                        if (value != null)
                        {
                            tb.Text = value.ToString();
                        }
                        if (cmb1.SelectedIndex != 0)
                        {
                            var selectedO = cmb1.SelectedItem as Option;
                            tb.IsEnabled = !selectedO.Disable2nd;
                        }
                    }

                    p.Children.Add(b);
                    p.Children.Add(tb);

                    tb.KeyUp += tb_KeyUp;

                    panelTextBoxes.Children.Add(p);
                }
            }
            else
            {
                panel2.Visibility = Visibility.Collapsed;
                cmb2.Visibility   = Visibility.Collapsed;

                tbComment.Visibility      = Visibility.Collapsed;
                tbQuestionNum.Visibility  = Visibility.Collapsed;
                panelTextBoxes.Visibility = Visibility.Collapsed;
            }
        }
        private async void ApplicationBarIconButton_OnClick(object sender, EventArgs e)
        {
            var items    = lstAdresses.ItemsSource as List <Address>;
            var selected = items.Where(x => x.IsSelected).ToList();


            if (selected.Count == 0)
            {
                MessageBox.Show("No addresses selected");
                return;
            }

            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            StateService.ProgressIndicatorService.Show("Processing");


            var survelems = await new DbService().GetSurvelemsByAddressUPRN(_address.UPRN);


            List <string> notCompletedGroups = new List <string>();

            foreach (var a in selected)
            {
                bool canAdressComplete = true;
                foreach (var o in survelems)
                {
                    var q = await new DbService().FindQuestion(o.Question_Ref);

                    if (q != null)
                    {
                        if (q.ExcludeFromClone)
                        {
                            canAdressComplete = false;
                            notCompletedGroups.Add(q.Main_Element);
                            continue;
                        }
                    }
                    else
                    {
                        Debug.WriteLine("Not found question: " + o.Question_Ref);
                    }
                    var n = new Survelem()
                    {
                        id = Guid.NewGuid().ToString(), IsCreatedOnClient = true
                    };
                    n.BuildingType     = o.BuildingType;
                    n.COMMENT          = o.COMMENT;
                    n.CustomerID       = o.CustomerID;
                    n.CustomerSurveyID = o.CustomerSurveyID;
                    n.DateOfSurvey     = o.DateOfSurvey;
                    n.Freetext         = o.Freetext;
                    n.OptionID         = o.OptionID;
                    n.OptionID2ndry    = o.OptionID2ndry;
                    n.Question_Ref     = o.Question_Ref;
                    n.SpotPriceFF      = o.SpotPriceFF;


                    n.SqN1  = o.SqN1;
                    n.SqN10 = o.SqN10;
                    n.SqN11 = o.SqN11;
                    n.SqN12 = o.SqN12;
                    n.SqN13 = o.SqN13;
                    n.SqN14 = o.SqN14;
                    n.SqN15 = o.SqN15;
                    n.SqN2  = o.SqN2;
                    n.SqN3  = o.SqN3;
                    n.SqN4  = o.SqN4;
                    n.SqN5  = o.SqN5;
                    n.SqN6  = o.SqN6;
                    n.SqN7  = o.SqN7;
                    n.SqN8  = o.SqN8;
                    n.SqN9  = o.SqN9;

                    n.SqT1  = o.SqT1;
                    n.SqT10 = o.SqT10;
                    n.SqT11 = o.SqT11;
                    n.SqT12 = o.SqT12;
                    n.SqT13 = o.SqT13;
                    n.SqT14 = o.SqT14;
                    n.SqT15 = o.SqT15;
                    n.SqT2  = o.SqT2;
                    n.SqT3  = o.SqT3;
                    n.SqT4  = o.SqT4;
                    n.SqT5  = o.SqT5;
                    n.SqT6  = o.SqT6;
                    n.SqT7  = o.SqT7;
                    n.SqT8  = o.SqT8;
                    n.SqT9  = o.SqT9;


                    n.Identity = n.id;
                    n.UPRN     = a.UPRN;

                    await new DbService().Save(n, ESyncStatus.NotSynced);

                    if (q != null && !notCompletedGroups.Contains(q.Main_Element))
                    {
                        new ApplicationSettingsService().SetSetting(a.UPRN + "." + q.Main_Element, true);
                    }
                }

                if (canAdressComplete)
                {
                    a.Complete = true;
                }

                a.CopiedFrom = _address.UPRN;

                await new DbService().Save(a, ESyncStatus.NotSynced);
            }



            StateService.ProgressIndicatorService.Hide();
            IsBusy = false;

            MessageBox.Show("Addresses copied");

            ExNavigationService.GoBack();
        }
示例#6
0
        private async void ApplicationBarIconButton_OnClick(object sender, EventArgs e)
        {
            var items    = lstAdresses.ItemsSource as List <Address>;
            var selected = items.Where(x => x.IsSelected).ToList();


            if (selected.Count == 0)
            {
                MessageBox.Show("No addresses selected");
                return;
            }

            if (IsBusy || StateService.IsQA)
            {
                return;
            }

            IsBusy = true;

            StateService.ProgressIndicatorService.Show("Processing");


            var survelems = await new DbService().GetSurvelemsByAddressUPRN(_address.UPRN);


            List <string> notCompletedGroups = new List <string>();

            foreach (var a in selected)
            {
                bool canAdressComplete = true;
                var  count             = 0;
                foreach (var o in survelems)
                {
                    var q = await new DbService().FindQuestion(o.Question_Ref, o.CustomerSurveyID);

                    if (q != null)
                    {
                        if (q.ExcludeFromClone)
                        {
                            canAdressComplete = false;
                            notCompletedGroups.Add(q.Main_Element);
                            Debug.WriteLine("Exclude from clone is true for Question_Ref: " + o.Question_Ref);
                            continue;
                        }
                    }
                    else
                    {
                        Debug.WriteLine("Not found question: " + o.Question_Ref);
                    }


                    var existingAnswer = await new DbService().FindAnswer(o.Question_Ref, a.UPRN);

                    if (existingAnswer != null)
                    {
                        //WE skip answers that already exists 01.05.2015
                        continue;
                    }

                    count++;

                    var n = new Survelem()
                    {
                        IsCreatedOnClient = true
                    };

                    n.BuildingType = o.BuildingType;
                    //n.COMMENT = o.COMMENT; //
                    n.CustomerID       = o.CustomerID;
                    n.CustomerSurveyID = o.CustomerSurveyID;
                    n.DateOfSurvey     = DateTime.Now.ToString(Constants.DateTimeFormat);
                    n.Freetext         = o.Freetext;
                    n.OptionID         = o.OptionID;
                    n.OptionID2ndry    = o.OptionID2ndry;
                    n.Question_Ref     = o.Question_Ref;
                    n.UPRN             = a.UPRN;
                    n.SqT1             = o.SqT1;
                    n.SqT2             = o.SqT2;
                    n.SqT3             = o.SqT3;
                    n.SqT4             = o.SqT4;
                    n.SqT5             = o.SqT5;
                    n.SqT6             = o.SqT6;
                    n.SqT7             = o.SqT7;
                    n.SqT8             = o.SqT8;
                    n.SqT9             = o.SqT9;
                    n.SqT10            = o.SqT10;
                    n.SqT11            = o.SqT11;
                    n.SqT12            = o.SqT12;
                    n.SqT13            = o.SqT13;
                    n.SqT14            = o.SqT14;
                    n.SqT15            = o.SqT15;

                    n.SqN1  = o.SqN1;
                    n.SqN2  = o.SqN2;
                    n.SqN3  = o.SqN3;
                    n.SqN4  = o.SqN4;
                    n.SqN5  = o.SqN5;
                    n.SqN6  = o.SqN6;
                    n.SqN7  = o.SqN7;
                    n.SqN8  = o.SqN8;
                    n.SqN9  = o.SqN9;
                    n.SqN10 = o.SqN10;
                    n.SqN11 = o.SqN11;
                    n.SqN12 = o.SqN12;
                    n.SqN13 = o.SqN13;
                    n.SqN14 = o.SqN14;
                    n.SqN15 = o.SqN15;


                    await new DbService().Save(n, ESyncStatus.NotSynced);
                    Debug.WriteLine("Copied question: " + o.Question_Ref);
                }


                var groups = await new DbService().GetAddressQuestionGroups(_address.Id);

                foreach (var g in groups)
                {
                    if (!notCompletedGroups.Contains(g.Group))
                    {
                        var newGroup = new AddressQuestionGroupStatus()
                        {
                            AddressId   = a.Id,
                            Group       = g.Group,
                            IsCompleted = true
                        };
                        await new DbService().Save(newGroup, ESyncStatus.NotSynced);
                    }
                }

                var oldStatus = await new DbService().FindAddressStatus(_address.Id);

                var status = new AddressStatus()
                {
                    IsCreatedOnClient = true
                };
                status.AddressId               = a.Id;
                status.IsCompleted             = canAdressComplete;
                status.CompletedQuestionsCount = oldStatus.CompletedQuestionsCount;


                await new DbService().Save(status, ESyncStatus.NotSynced);
                a.CopiedFrom    = _address.UPRN;
                a.IsCompleted   = canAdressComplete;
                a.IsLoadToPhone = canAdressComplete;
                await new DbService().Save(a, ESyncStatus.NotSynced);
            }



            StateService.ProgressIndicatorService.Hide();
            IsBusy = false;

            MessageBox.Show("Addresses copied");

            ExNavigationService.GoBack();
        }