예제 #1
0
        public static void ParseJson(string filepath, GenerateForm genForm,
                                     CheckBoxAction checkBoxAction, TextFieldAction textFieldAction)
        {
            using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(filepath, true))
            {
                IDictionary <String, BookmarkStart> bookmarkMap = new Dictionary <String, BookmarkStart>();
                foreach (BookmarkStart bookmarkStart in wordprocessingDocument.MainDocumentPart.RootElement.Descendants <BookmarkStart>())
                {
                    bookmarkMap[bookmarkStart.Name] = bookmarkStart;
                }

                foreach (BookmarkStart bookmarkStart in bookmarkMap.Values)
                {
                    Run bookmarkFieldCode = bookmarkStart.NextSibling <Run>();
                    if (bookmarkFieldCode != null)
                    {
                        FieldCode fcode = bookmarkFieldCode.GetFirstChild <FieldCode>();
                        if (fcode != null && FormTypes.isFormType(fcode.Text))
                        {
                            if (FormTypes.FormCheckBox.Is(fcode.Text))
                            {
                                Run           checkboxRun   = bookmarkStart.PreviousSibling <Run>();
                                FieldChar     fieldChar     = checkboxRun?.GetFirstChild <FieldChar>();
                                FormFieldData formFieldData = fieldChar?.GetFirstChild <FormFieldData>();
                                CheckBox      checkbox      = formFieldData?.GetFirstChild <CheckBox>();
                                //Note: docs say Checked should appear however type is DefaultCheckBoxFormFieldState
                                //Checked checkboxChecked =  checkbox?.GetFirstChild<Checked>();
                                DefaultCheckBoxFormFieldState checkboxChecked = checkbox?.GetFirstChild <DefaultCheckBoxFormFieldState>();
                                if (checkboxChecked != null)
                                {
                                    PrintVerbose("" + (bool)checkboxChecked.Val);
                                    checkBoxAction(genForm, bookmarkStart.Name, checkboxChecked);
                                }
                            }
                            else if (FormTypes.FormText.Is(fcode.Text))
                            {
                                while (bookmarkFieldCode.NextSibling <Run>() != null)
                                {
                                    Text bookmarkText = bookmarkFieldCode.GetFirstChild <Text>();
                                    if (bookmarkText != null)
                                    {
                                        PrintVerbose(bookmarkText.Text);
                                        textFieldAction(genForm, bookmarkStart.Name, bookmarkText);
                                    }
                                    bookmarkFieldCode = bookmarkFieldCode.NextSibling <Run>();
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
 private void UpdateGroupingModeList(GroupingAttribute attrib, CheckBoxAction action)
 {
     if (action == CheckBoxAction.Checked)
     {
         _grouppingAttributes.Add(attrib);
     }
     else
     {
         _grouppingAttributes.Remove(attrib);
         SelectedGroupAttrib = _grouppingAttributes.First();
     }
     NotifyPropertyChanged("ResultGrouppingModesList");
 }
예제 #3
0
        public static void fillJson(string filepath, GenerateForm genForm)
        {
            CheckBoxAction checkBoxFill = (GenerateForm genForm, string key,
                                           DefaultCheckBoxFormFieldState checkboxChecked) => {
                checkboxChecked.Val = genForm.checkboxMap[key];
            };
            TextFieldAction textFieldFill =
                (GenerateForm genForm, string key, Text bookmarkText) => {
                bookmarkText.Text = genForm.stringMap[key];
            };

            ParseJson(filepath, genForm, checkBoxFill, textFieldFill);
        }
예제 #4
0
        public static void GenerateJson(string filepath, GenerateForm genForm)
        {
            CheckBoxAction checkBoxGen = (GenerateForm genForm, string key,
                                          DefaultCheckBoxFormFieldState checkboxChecked) => {
                genForm.checkboxMap[key] = (bool)checkboxChecked.Val;
            };
            TextFieldAction textFieldGen =
                (GenerateForm genForm, string key, Text bookmarkText) => {
                genForm.stringMap[key] = bookmarkText.Text;
            };

            ParseJson(filepath, genForm, checkBoxGen, textFieldGen);
        }