Esempio n. 1
0
        private TextBox CreateTextInputBlock2(FormEntry item)
        {
            TextBox tb = new TextBox()
            {
                Margin = new Thickness(5, 8, 0, 5)
            };
            var bc = new BrushConverter();

            tb.Foreground = (Brush)bc.ConvertFrom("#FF2D72BC");
            //  MyData myDataObject = new MyData(DateTime.Now);
            if (item.type == 1)
            {
            }
            if (item.type == 2)
            {
                Binding myBinding = new Binding();
                myBinding.Source = item;
                myBinding.Path   = new PropertyPath("Var1");
                myBinding.Mode   = BindingMode.TwoWay;
                myBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                BindingOperations.SetBinding(tb, TextBox.TextProperty, myBinding);
                myBinding.Path = new PropertyPath("Var2");
            }
            return(tb);
        }
Esempio n. 2
0
        public static void HandleType1(FormEntry item, bool bEditMode)
        {
            int   row = 0;
            Label lb;

            if (bEditMode)
            {
                rootGrid.Children.Add(CreateTextInputBlock(item.label1, row, 0));
            }
            else
            {
                lb = CreateLabel(row, 0, "enter text here");
                rootGrid.Children.Add(lb);
            }
            CheckBox cb = CreateCheckBox(row, 1, item.checkbox1);

            cb.HorizontalAlignment = HorizontalAlignment.Right;
            rootGrid.Children.Add(cb);
            cb = CreateCheckBox(row, 2, item.checkbox2);
            cb.HorizontalAlignment = HorizontalAlignment.Left;
            rootGrid.Children.Add(cb);
            row += 1;
            lb   = CreateLabel(row, 0, item.label2);
            rootGrid.Children.Add(lb);
            rootGrid.Children.Add(CreateTextInputBlock(item.textbox1, row, 0));
            row += 1;
        }
        public List <FormEntry> GetFormEntries(string formName)
        {
            List <FormEntry> entries    = new List <FormEntry>();
            BizFormInfo      formObject = BizFormInfoProvider.GetBizFormInfo(formName, SiteContext.CurrentSiteID);

            if (formObject == null)
            {
                throw new InvalidOperationException("The requested checkin form does not exist.");
            }
            // Gets the class name of the form
            DataClassInfo formClass = DataClassInfoProvider.GetDataClassInfo(formObject.FormClassID);
            string        className = formClass.ClassName;

            // Loads the form's data
            ObjectQuery <BizFormItem> data = BizFormItemProvider.GetItems(className);

            // Checks whether the form contains any records
            if (!DataHelper.DataSourceIsEmpty(data))
            {
                // Loops through the form's data records
                foreach (BizFormItem item in data)
                {
                    FormEntry entry = new FormEntry();
                    entry.ID = item.ItemID;

                    foreach (var columnName in item.ColumnNames)
                    {
                        entry.FormValues.Add(columnName.ToLower(), item.GetStringValue(columnName, ""));
                    }
                    entries.Add(entry);
                }
            }
            return(entries);
        }
Esempio n. 4
0
        public async Task ProcessAsync(ACFormProcessor processor, FormEntry formEntry)
        {
            string submissionSnapshot = await StringifySubmission(formEntry);

            await SaveArchiveRecord(formEntry, submissionSnapshot);
            await ArchiveFormAsPDF(formEntry, submissionSnapshot);
        }
Esempio n. 5
0
        private void MainWindow_KeyDown(object sender, KeyEventArgs e)
        {
            if (bEntryMode || e.Key != Key.Delete)
            {
                return;
            }

            Button but = sender as Button;

            if (selectedItem == null)
            {
                MessageBox.Show("please select a line first", "Form error");
                return;
            }
            using (var db = new EditorDb())
            {
                FormEntry item = selectedBlock.questions.Where(i => i.linenum == selectedItem.linenum).SingleOrDefault();
                selectedBlock.questions.Remove(selectedItem);
                db.Entry(selectedItem).State = System.Data.Entity.EntityState.Deleted;
                for (int line = selectedItem.linenum + 1; line <= lines.Count; line++)
                {
                    item                 = selectedBlock.questions.Where(i => i.linenum == line).SingleOrDefault();
                    item.linenum         = item.linenum - 1;
                    db.Entry(item).State = System.Data.Entity.EntityState.Modified;   //EF change tracking not working
                }
                db.SaveChanges();
                //   MessageBox.Show(string.Format("Line {0} removed", formRowSelected));
                Refresh();
            }
        }
Esempio n. 6
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var form = controllerContext.HttpContext.Request.Form;

            var result = new FormEntry
            {
                ControlValues = new Dictionary<string, string>()
            };

            var aux = form.Get(FormSettings.FORM_ID_NAME);
            int formId;
            var validFormId = int.TryParse(aux, out formId);

            if (validFormId)
            {
                result.FormId = formId;

                foreach (var key in form.AllKeys.Where(k => k.StartsWith(FormSettings.COLUMN_PREFIX)))
                {
                    var values = form.GetValues(key).Select(v => v.Replace(FormSettings.SELECTED_VALUES_SEPARATOR.ToString(), string.Empty));
                    var value = string.Join(FormSettings.SELECTED_VALUES_SEPARATOR.ToString(), values) ;

                    result.ControlValues.Add(key, value);
                }
            }

            return result;
        }
Esempio n. 7
0
        public IList<string> AddEntry(FormEntry formEntryDto)
        {
            formEntryDto.EntryDate = DateTime.Now;
            formEntryDto.Ip = HttpContext.Current.Request.GetClientIpAddress();

            var form = _h5FormsContext.Forms.Single(f => f.Id == formEntryDto.FormId);
            var formDto = Mapper.Map<Entities.Form.Form, Form>(form);
            var result = default(IList<string>);

            formDto.SetValues(formEntryDto);

            #region Validation

            result = formDto.BasicValidation();

            if (result.Count > 0)
                return result;

            result = formDto.UniqueValidation(_h5FormsContext.IsUniqueEntry);

            if (result.Count > 0)
                return result;

            var formEntry = Mapper.Map<FormEntry, Entities.Form.FormEntry>(formEntryDto);

            #endregion

            _h5FormsContext.AddEntry(formEntry);

            return result;
        }
        public static void SubmitForm(string firstName, string lastName, string email, string phone, string company, string message, string ipAddress, Guid userId, string formName)
        {
            Dictionary <string, string> inputs = new Dictionary <string, string>();

            inputs.Add("FirstName", firstName);
            inputs.Add("LastName", lastName);
            inputs.Add("Email", email);
            inputs.Add("PhoneNumber", phone);
            inputs.Add("Company", company);
            inputs.Add("Message", message);

            FormsManager manager = FormsManager.GetManager();
            var          form    = manager.GetFormByName(formName);
            FormEntry    entry   = manager.CreateFormEntry(form.EntriesTypeName);

            foreach (var item in inputs)
            {
                entry.SetValue(item.Key, item.Value);
            }

            entry.IpAddress = ipAddress;
            entry.UserId    = userId;

            if (AppSettings.CurrentSettings.Multilingual)
            {
                entry.Language = System.Globalization.CultureInfo.CurrentUICulture.Name;
            }

            entry.ReferralCode = (manager.Provider.GetNextReferralCode(entry.GetType().ToString())).ToString();
            entry.SubmittedOn  = System.DateTime.UtcNow;

            manager.SaveChanges();
        }
Esempio n. 9
0
        private void Tb_LostFocus2(object sender, RoutedEventArgs e)
        {
            //if textbox is the last in the stackpanel then action is done so remove
            TextBox   tb    = sender as TextBox;
            FormEntry entry = tb.Tag as FormEntry;

            //if (entry.var2Type == 1)
            //{
            //    int weight;
            //    bool bFailed = false;
            //    if (!Int32.TryParse(tb.Text, out weight))
            //        bFailed = true;

            //    if (weight < 10 || weight > 85)
            //        bFailed = true;
            //    if (bFailed)
            //    {
            //        MessageBox.Show("invalid weight");
            //        return ;
            //    }
            //}
            Debug.WriteLine(string.Format("Tb_LostFocus2 {0} {1} ", tb.Tag, tb.Text));
            var sp    = VisualTreeHelperExtensions.FindAncestor <StackPanel>(tb);
            var grid  = VisualTreeHelperExtensions.FindAncestor <Grid>(sp);
            int index = sp.Children.IndexOf(tb);

            if (index + 1 == sp.Children.Count)
            {
                removeline(entry);

                //  CheckForFinish(block);
            }
            //  rootGrid.Children.Remove(sptest);
        }
Esempio n. 10
0
        public void TestDeleteFormEntry_ShouldDeleteCorrectEntry()
        {
            var       id = Guid.NewGuid().ToString();
            const int expectedEntriesCount = 1;
            var       entryModel           = new FormEntry()
            {
                Id          = id,
                SenderName  = "ivan",
                SenderEmail = "*****@*****.**",
                MessageBody = "super"
            };

            this._context.Add(entryModel);
            this._context.SaveChanges();

            var ActualCountOfEntries = this._context.FormEntries.Count();

            Assert.Equal(expectedEntriesCount, ActualCountOfEntries);

            this._formEntryService.DeleteFormEntry(id);

            var expectedNull = this._context.FormEntries.FirstOrDefault(x => x.Id == id);

            Assert.Null(expectedNull);
        }
Esempio n. 11
0
        public void TestGetAllEntries_ShouldReturnAllEntries()
        {
            var entryModel = new FormEntry()
            {
                SenderName  = "ivan",
                SenderEmail = "*****@*****.**",
                MessageBody = "super"
            };

            var entryModel2 = new FormEntry()
            {
                SenderName  = "petko",
                SenderEmail = "*****@*****.**",
                MessageBody = "perfect"
            };

            this._context.FormEntries.Add(entryModel);
            this._context.FormEntries.Add(entryModel2);

            this._context.SaveChanges();

            var listOfEntriesActual = this._formEntryService.GetAll();
            var countOfJob          = this._context.FormEntries.Count();

            Assert.Equal(listOfEntriesActual.Count(), countOfJob);
        }
Esempio n. 12
0
        void removeline(FormEntry item)
        {
            itemResponse response = new itemResponse()
            {
                Name     = selectedBlock.Name,
                linenum  = item.linenum,
                start    = startBlock,
                userName = ((App)Application.Current).activeUser.Name,
                type     = item.type,
                var1     = item.Var1,
                var2     = item.Var2,
                var3     = item.Var3
            };

            FindType(item, typeof(Button));
            FindType(item, typeof(StackPanel));
            buts.ForEach(b => rootGrid.Children.Remove(b));
            stacks.ForEach(s => rootGrid.Children.Remove(s));
            selectedBlock.CurrentItem = item.linenum;
            responses.Add(response);

            using (var db = new EditorDb())
            {
                // db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                db.Responses.Add(response);
                db.SaveChanges();
            }
            lines.Remove(item);
            itemNumber = -1;
            CheckForFinish(selectedBlock);
        }
Esempio n. 13
0
 public async Task ProcessAsync(ACPreFillProcessor processor, FormEntry formEntry)
 {
     _logger.LogWarning(
         "NullPreFillProcessor triggered for entry {formEntry}. Expected processor was [{processorType}]. Check for correct registration in ProcessorExtensions.cs",
         formEntry.Id,
         processor.ProcessorType.ToString());
     await Task.CompletedTask;
 }
Esempio n. 14
0
        void HandleType1(FormEntry item)
        {
            StackPanel sp = CreateStackPanel(row, 1);

            sp.Tag = item;
            TextBlock tb1 = new TextBlock();

            tb1.Width  = 400;
            tb1.Height = 30;
            tb1.Text   = item.label1;
            if (item.label1.Length > 80)
            {
                tb1.Height       = 60;
                tb1.TextWrapping = TextWrapping.Wrap;
            }
            sp.Children.Add(tb1);
            CheckBox cb1 = CreateCheckBox1(item);

            if (item.checkbox1State)
            {
                cb1.IsChecked = true;
            }
            sp.Children.Add(cb1);
            CheckBox cb = CreateCheckBox2(item);

            if (item.checkbox2State)
            {
                cb.IsChecked = true;
            }
            sp.Children.Add(cb);

            row += 1;
            if (item.label2 == null || item.label2 == string.Empty)
            {
                return;
            }

            StackPanel sp2 = CreateStackPanel(row, 1);

            sp2.Tag = item;
            sp2.Children.Add(CreateLabel(item.label2, item.isBold));
            TextBox tb = new TextBox()
            {
                Width = 60, Height = 30
            };

            tb.Tag = cb1;
            tb.GotKeyboardFocus += Tb_GotKeyboardFocus;
            tb.LostFocus        += Tb_LostFocus;
            tb.KeyDown          += Tb_KeyDown;
            Binding myBinding = setBinding();

            myBinding.Source = item;
            myBinding.Path   = new PropertyPath("Var1");
            BindingOperations.SetBinding(tb, TextBox.TextProperty, myBinding);
            sp2.Children.Add(tb);
            row += 1;
        }
Esempio n. 15
0
        private async Task ArchiveFormAsPDF(FormEntry formEntry, string stringPayload)
        {
            var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json");
            var response    = await _httpClient.PostAsync("api/render/acforms/pdf", httpContent);

            response.EnsureSuccessStatusCode();
            _logger.LogInformation("PDF rendered successfully for FormEntry {formEntry}. Saving...", formEntry.Id);
            await _attachmentService.SaveAttachmentAsync(formEntry.Id, "form.pdf", await response.Content.ReadAsStreamAsync());
        }
Esempio n. 16
0
        private async Task SaveArchiveRecord(FormEntry formEntry, string submissionSnapshot)
        {
            _logger.LogInformation("Archiving submission for FormEntry {formEntry}", formEntry.Id);
            await _db.AddAsync(new FormEntryArchive(formEntry, submissionSnapshot));

            await _db.SaveChangesAsync();

            _logger.LogInformation("Archived submission for FormEntry {formEntry} successfully", formEntry.Id);
        }
Esempio n. 17
0
        //user clicked in tetbox 2
        private void Tb_PreviewMouseLeftButtonDownTB2(object sender, MouseButtonEventArgs e)
        {
            TextBox   tb    = sender as TextBox;
            FormEntry entry = tb.Tag as FormEntry;

            if (entry.var2Type == (int)vartype.time)
            {
                tb.Text = DateTime.Now.ToShortTimeString();
            }
        }
Esempio n. 18
0
        public void SetValues(FormEntry formEntry)
        {
            foreach (var column in formEntry.ControlValues)
            {
                var controlId = int.Parse(column.Key.Replace(FormSettings.COLUMN_PREFIX,string.Empty));
                var control = Controls.Single(c => c.Id == controlId) as ValueControl;

                control.SetValue(column.Value);
            }
        }
Esempio n. 19
0
        private void Tb_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            TextBox    tb   = sender as TextBox;
            StackPanel sp   = tb.Parent as StackPanel;
            FormEntry  item = sp.Tag as FormEntry;

            if (item.var1Type == (int)vartype.time)
            {
                tb.Text = DateTime.Now.ToShortTimeString();
            }
        }
Esempio n. 20
0
        public void CreateOrUpdateFormData(FormEntry formEntry)
        {
            _sitecoreFormsDb.FormEntries.AddOrUpdate(formEntry);
            _sitecoreFormsDb.SaveChanges();

            foreach (FieldData fieldData in formEntry.FieldDatas)
            {
                _sitecoreFormsDb.FieldDatas.AddOrUpdate(fieldData);
            }
            _sitecoreFormsDb.SaveChanges();
        }
Esempio n. 21
0
        private static async Task <string> StringifySubmission(FormEntry formEntry)
        {
            var questionnaire = QuestionnaireExtensions.QuestionnaireValueMapper(formEntry, false);

            // the data snapshot and PDF will record EST...the database will still record the archive record as UTC
            questionnaire.SubmissionDate = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(formEntry.SubmissionDate.GetValueOrDefault(), "Eastern Standard Time");
            var stringPayload = await Task.Run(() => JsonSerializer.Serialize(questionnaire, new JsonSerializerOptions {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            }));

            return(stringPayload);
        }
Esempio n. 22
0
        public async Task <Guid> StartNewFormAsync(FormAccessLevel accessLevel, string key, PreFillLookupCriteria criteria)
        {
            var form = await _db.Forms.FirstOrDefaultAsync(f => f.AccessLevel == accessLevel && f.Key == key);

            if (form is null)
            {
                throw new Exception("No matching form");
            }

            var entry = new FormEntry
            {
                FormKey         = form.Key,
                PrefillCriteria = criteria,
                Status          = FormStatus.Open,
            };

            var preFillProcessors = await _db.PreFillProcessors.Where(p => p.FormKey == key).ToArrayAsync();

            foreach (var processor in preFillProcessors)
            {
                await _preFillProcessor.ProcessFormAsync(processor, entry);
            }

            if (form.Key == "ocif")
            {
                //var ocif = new FormOCIF
                //{
                //    Id = entry.Id,
                //    Data = entry.Data,
                //};

                //await _db.AddAsync(ocif);

                var ocif = new OCIF
                {
                    ID       = entry.Id,
                    JSONData = entry.Data
                };

                await _uiPathDb.AddAsync(ocif);

                await _uiPathDb.SaveChangesAsync();
            }

            await _db.AddAsync(entry);

            await _db.SaveChangesAsync();

            return(entry.Id);
        }
Esempio n. 23
0
        private void Tb_MouseLeftButtonDownTB1(object sender, MouseButtonEventArgs e)
        {
            TextBox   tb    = sender as TextBox;
            FormEntry entry = tb.Tag as FormEntry;

            if (entry.var1Type == (int)vartype.time)
            {
                tb.Text = DateTime.Now.ToShortTimeString();
            }
            else if (entry.var1Type == (int)vartype.dayweek)
            {
                tb.Text = DateTime.Now.DayOfWeek.ToString();
            }
        }
Esempio n. 24
0
        public void CreateFormEntry(FormEntryInputViewModel model)
        {
            var entry = new FormEntry
            {
                SenderName  = model.SenderName,
                SenderEmail = model.SenderEmail,
                PhoneNumber = model.PhoneNumber,
                MessageBody = model.Message,
                CreatedOn   = DateTime.UtcNow
            };

            this.context.FormEntries.Add(entry);
            this.context.SaveChanges();
        }
        public ActionResult Test(FormEntry formEntry)
        {
            ModelState.Clear();

            var result = _formAdmin.AddEntry(formEntry);
            var form = _formAdmin.GetForm(formEntry.FormId);

            foreach (var message in result)
            {
                ModelState.AddModelError(string.Empty, message);
                form.SetValues(formEntry);
            }

            return View(form);
        }
Esempio n. 26
0
        private CheckBox CreateCheckBox2(FormEntry item)
        {
            CheckBox cb = new CheckBox();

            cb.Tag      = item;
            cb.Click   += Cb_Click2;
            cb.Margin   = new Thickness(5);
            cb.Height   = 22;
            cb.MinWidth = 50;


            cb.Content = item.checkbox2;

            return(cb);
        }
Esempio n. 27
0
        private void but_Click(object sender, RoutedEventArgs e)
        {
            Button but = sender as Button;

            selectedItem = but.Tag as FormEntry;

            FindType(selectedItem, typeof(Button));
            FindType(selectedItem, typeof(StackPanel));
            //   StackPanel lb = GetGridElement(rootGrid, (int)but.Tag, 1) as StackPanel;
            stacks[0].Background = new SolidColorBrush(Colors.DarkGray);
            if (oldSelectedRow != null)
            {
                oldSelectedRow.Background = oldSelectedBrush;
            }
            oldSelectedRow = stacks[0];
        }
Esempio n. 28
0
        void FindType(FormEntry item, Type type)
        {
            if (type.Name == "Button")
            {
                buts.Clear();
            }
            else
            {
                stacks.Clear();
            }
            int childrenCount = VisualTreeHelper.GetChildrenCount(rootGrid);

            for (int i = 0; i < childrenCount; i++)
            {
                var child = VisualTreeHelper.GetChild(rootGrid, i);
                // If the child is not of the request child type child
                if (type.Name == "Button")
                {
                    if (child as Button != null)
                    {
                        Button but = child as Button;
                        if (but.Tag != null)
                        {
                            FormEntry entry = but.Tag as FormEntry;
                            if (entry == item)
                            {
                                buts.Add(but);
                            }
                        }
                        continue;
                    }
                }

                if (child as StackPanel != null)
                {
                    StackPanel st = child as StackPanel;
                    if (st.Tag != null)
                    {
                        FormEntry entry = (st.Tag) as FormEntry;
                        if (entry == item)
                        {
                            stacks.Add(st);
                        }
                    }
                }
            }
        }
Esempio n. 29
0
        private void CreateControlsUsingObjects()
        {
            FormEntry olditem = null;

            //    rootGrid = LayoutRoot;


            rootGrid.Margin = new Thickness(10.0);

            for (int i = 0; i < lines.Count * 2; i++)
            {
                rootGrid.RowDefinitions.Add(CreateRowDefinition());
            }
            foreach (FormEntry item in lines)
            {
                itemNumber++;
                int displayRow = row;
                //if (olditem != null &&    olditem.type != 3)
                //    displayRow++;
                if (item.type != 3)
                {
                    Button but = CreateButton(item, displayRow, 0);
                    rootGrid.Children.Add(but);
                }
                //   Label lb = CreateLabel(row, 0, string.Format("{0}", item.linenum ));

                switch (item.type)
                {
                case 1:
                    HandleType1(item);
                    break;

                case 2:
                    HandleType2(item);
                    break;

                case 3:
                    HandleType3(item);
                    break;
                }
            }


            //      rootGrid.Measure(new Size(600, 600));
            //      rootGrid.Arrange(new Rect(new Size(600, 600)));
            //       LayoutRoot.Children.Add(rootGrid);
        }
Esempio n. 30
0
        //check 1 can only be YES or Done
        private void Cb_Click1(object sender, RoutedEventArgs e)
        {
            CheckBox cb      = sender as CheckBox;
            bool     bDelete = false;

            FormEntry entry = cb.Tag as FormEntry;

            if (cb.Content as String == "Done")
            {
                bDelete = true;

                entry.checkbox1State = true;
            }
            else if (cb.Content as String == "Yes")    //no second input field
            {
                //if the next sibling in visual tree of checkbox parent (stackpanel) is a button then the
                //checkbox does not have an associated input that must be filled in. in this case delete also
                entry.checkbox1State = true;
                var sp    = VisualTreeHelperExtensions.FindAncestor <StackPanel>(cb);
                var grid  = VisualTreeHelperExtensions.FindAncestor <Grid>(sp);
                int index = grid.Children.IndexOf(sp);
                //check if this is last entry
                if (index == grid.Children.Count - 1)
                {
                    bDelete = true;
                }
                else
                {
                    Button but = grid.Children[index + 1] as Button;
                    if (but != null)
                    {
                        bDelete = true;
                    }
                }
            }

            if (bDelete)
            {
                removeline(entry);
                //   CheckForFinish(block);
                //buts.ForEach(b => rootGrid.Children.Remove(b));
                //stacks.ForEach(s => rootGrid.Children.Remove(s));
                //buts.Clear();
                //stacks.Clear();
            }
        }
Esempio n. 31
0
        public TextEditRow(FormViewer formViewer, FormField field) : base(formViewer, field)
        {
            _header = new FormFieldHeader(field.Label);

            _editor = new FormEntry()
            {
                Text      = field.Value,
                IsEnabled = field.IsUserEditable,
            };

            if (Device.RuntimePlatform == Device.Android)
            {
                _editor.HeightRequest = 40;
            }


            _editor.IsPassword = field.FieldType == FieldTypes.Password.ToString();

            _editor.TextChanged += _editor_TextChanged;

            FieldTypes fieldType;

            if (Enum.TryParse <FieldTypes>(field.FieldType, out fieldType))
            {
                switch (FieldType)
                {
                case FieldTypes.Key:
                    _editor.Keyboard = Keyboard.Plain;
                    break;

                case FieldTypes.Decimal:
                case FieldTypes.Integer:
                    _editor.Keyboard = Keyboard.Numeric;
                    _editor.HorizontalTextAlignment = TextAlignment.End;
                    break;
                }

                _validationMessage = new FormFieldValidationMessage(field.RequiredMessage);

                Children.Add(_header);
                Children.Add(_editor);
                Children.Add(_validationMessage);
                Margin = RowMargin;
            }
        }
Esempio n. 32
0
        private FormEntry GetPriorFormEntry()
        {
            FormEntry entry = null;

            if (_sfTrackingCookie != null)
            {
                entry = GetFormEntryByUserId(Guid.Parse(_sfTrackingCookie.Value));
            }

            Guid userId = ClaimsManager.GetCurrentUserId();

            if (entry == null && userId != Guid.Empty)
            {
                entry = GetFormEntryByUserId(userId);
            }

            return(entry);
        }
Esempio n. 33
0
        private Button CreateButton(FormEntry item, int row, int column)
        {
            Button but = new Button()
            {
                Content = item.linenum, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(5, 8, 0, 5)
            };

            but.Height    = 25;
            but.Focusable = false;
            but.Width     = 35;
            but.Click    += but_Click;
            but.Tag       = item;
            //  tb.Visibility = Visibility.Hidden;
            Grid.SetColumn(but, column);
            Grid.SetRow(but, row);
            Selectors.Add(but);
            return(but);
        }
Esempio n. 34
0
        private void MigrateFormData(Guid formId)
        {
            var formDataRecords = _dataProvider.GetFormDataRecords(formId);

            var fieldValueTypeCollection = GetFieldValueTypeCollection(formId);

            foreach (FormData formDataRecord in formDataRecords)
            {
                // Delete existing field data records in Sitecore Forms destination db
                _sitecoreFormsDbRepository.DeleteFieldDataByFormRecordId(formDataRecord.Id);

                // Get Field Data records data from forms data provider
                var fieldDataRecords = _dataProvider.GetFieldDataRecords(formDataRecord.Id);

                if (fieldDataRecords == null || !fieldDataRecords.Any())
                {
                    continue;
                }

                // Convert the source field data records
                List <FieldData> fieldDataFormsRecords = fieldDataRecords.Select(data => ConvertFieldData(data, fieldValueTypeCollection)).ToList();

                FormEntry formEntry = new FormEntry()
                {
                    Id = formDataRecord.Id,
                    FormDefinitionId = formDataRecord.FormItemId,
                    Created          = formDataRecord.TimeStamp,
                    ContactId        = null,
                    IsRedacted       = false,
                    FieldDatas       = fieldDataFormsRecords
                };

                _sitecoreFormsDbRepository.CreateOrUpdateFormData(formEntry);

                // Migrate file upload storage records, if any
                foreach (FieldData fieldDataFormsRecord in fieldDataFormsRecords)
                {
                    if (fieldDataFormsRecord.ValueType.Contains("Sitecore.ExperienceForms.Data.Entities.StoredFileInfo"))
                    {
                        MigrateFileUploadMediaItem(fieldDataFormsRecord);
                    }
                }
            }
        }
        protected override void InitializeControls(GenericContainer container)
        {
            _currentSiteId = SystemManager.CurrentContext.CurrentSite.Id;
            _sfTrackingCookie = HttpContext.Current.Request.Cookies["sf-trckngckie"];

            switch (ExtendedFormType)
            {
                case "conditional":
                    _isConditionalForm = true;
                    break;
                case "progressive":
                    _isProgressiveForm = true;
                    break;
            }

            if (_isProgressiveForm)
            {
                _isProgressiveForm = true;
                _priorFormEntry = GetPriorFormEntry();
            }

            if (!this.IsLicensed)
            {
                this.ErrorsPanel.Visible = true;
                ControlCollection controls = this.ErrorsPanel.Controls;
                Label label = new Label()
                {
                    Text = Res.Get<FormsResources>().ModuleNotLicensed
                };

                controls.Add(label);
                return;
            }

            if (this.FormData != null)
            {
                bool flag = true;
                CultureInfo currentUICulture = CultureInfo.CurrentUICulture;

                if (this.CurrentLanguage != null)
                {
                    currentUICulture = new CultureInfo(this.CurrentLanguage);
                }

                if (!this.FormData.IsPublished(currentUICulture))
                {
                    flag = false;
                }

                if (flag)
                {
                    this.RenderFormFields();
                }
            }

            if (!this.formDescriptionFound && this.IsDesignMode())
            {
                this.ErrorsPanel.Visible = true;
                ControlCollection controlCollections = this.ErrorsPanel.Controls;
                Label label1 = new Label()
                {
                    Text = Res.Get<FormsResources>().TheSpecifiedFormNoLongerExists
                };

                controlCollections.Add(label1);
            }

            HttpContextBase currentHttpContext = SystemManager.CurrentHttpContext;

            if (currentHttpContext != null && this.formDescriptionFound)
            {
                if (!currentHttpContext.Items.Contains("PageFormControls"))
                {
                    currentHttpContext.Items["PageFormControls"] = string.Empty;
                }

                currentHttpContext.Items["PageFormControls"] = string.Format("{0}Id={1},ValidationGroup={2};", (string)currentHttpContext.Items["PageFormControls"], this.FormId, this.ValidationGroup);
            }
        }
        new private void SaveFormEntry(FormDescription description)
        {
            FormsManager manager = FormsManager.GetManager();
            FormEntry userHostAddress = null;

            if (_isProgressiveForm && _priorFormEntry == null)
            {
                FieldControl keyField = this.FieldControls.Where(fc => ((IFormFieldControl)fc).MetaField.FieldName == _progressiveKeyFieldName).FirstOrDefault() as FieldControl;

                if (keyField != null && !String.IsNullOrWhiteSpace((string)keyField.Value))
                {
                    _priorFormEntry = GetPriorFormEntryByKeyField((string)keyField.Value);
                }
            }

            if (_isProgressiveForm && _priorFormEntry != null)
            {
                string entryType = String.Format("{0}.{1}", manager.Provider.FormsNamespace, this.FormData.Name);

                userHostAddress = manager.GetFormEntry(entryType, _priorFormEntry.Id);
            }
            else
            {
                userHostAddress = manager.CreateFormEntry(string.Format("{0}.{1}", manager.Provider.FormsNamespace, description.Name));
            }
            
            foreach (IFormFieldControl formFieldControl in this.FieldControls)
            {
                FieldControl fieldControl = formFieldControl as FieldControl;
                object value = fieldControl.Value;

                if (fieldControl.GetType().Name == "FormFileUpload")
                {
                    typeof(FormsControl)
                        .GetMethod("SaveFiles", BindingFlags.Static | BindingFlags.NonPublic)
                        .Invoke(null, new object[] { value as UploadedFileCollection, manager, description, userHostAddress, formFieldControl.MetaField.FieldName });
                }
                else if (!(value is List<string>))
                {
                    userHostAddress.SetValue(formFieldControl.MetaField.FieldName, value);
                }
                else
                {
                    StringArrayConverter stringArrayConverter = new StringArrayConverter();
                    object obj = stringArrayConverter.ConvertTo((value as List<string>).ToArray(), typeof(string));

                    userHostAddress.SetValue(formFieldControl.MetaField.FieldName, obj);
                }
            }
            userHostAddress.IpAddress = this.Page.Request.UserHostAddress;
            userHostAddress.SubmittedOn = DateTime.UtcNow;

            Guid userId = ClaimsManager.GetCurrentUserId();

            userHostAddress.UserId = userId == Guid.Empty ? Guid.Parse(_sfTrackingCookie.Value) : userId;

            if (userHostAddress.UserId == userId)
            {
                userHostAddress.Owner = userId;
            }

            if (SystemManager.CurrentContext.AppSettings.Multilingual)
            {
                userHostAddress.Language = CultureInfo.CurrentUICulture.Name;
            }

            FormDescription formData = this.FormData;
            formData.FormEntriesSeed = formData.FormEntriesSeed + (long)1;
            userHostAddress.ReferralCode = this.FormData.FormEntriesSeed.ToString();

            manager.SaveChanges();
        }