Example #1
0
 /// <summary>
 /// Copy fields values into matching dest_form fields
 /// </summary>
 /// <param name="dest_form">Destination form</param>
 /// <param name="field_ids">Fields set</param>
 public void CopyTo(TemplateForm dest_form, params string[] field_ids)
 {
     foreach (string field_id in field_ids)
     {
         dest_form[field_id].Value = this[field_id].Value;
     }
 }
Example #2
0
        /// <summary>
        /// Form based costructor
        /// </summary>
        /// <param name="form">Form reference</param>
        public TemplatePager(TemplateForm form)
            : this()
        {
            _tfMasterForm = form;

            // Add the first page
            AddPage();
        }
Example #3
0
        /// <summary>
        /// Constructor file based.
        /// </summary>
        /// <param name="template_file">Master form file</param>
        public TemplatePager(string template_file)
            : this()
        {
            _tfMasterForm = TemplateForm.Read(template_file);

            // Add the first page
            AddPage();
        }
Example #4
0
        /// <summary>
        /// Add new page to internal page set copying it from master form
        /// </summary>
        public TemplateForm AddPage()
        {
            if (_tfMasterForm == null)
            {
                throw new Exception("Master page not initialized");
            }

            TemplateForm _newForm = new TemplateForm(_tfMasterForm);

            _lstPageForms.Add(_newForm);

            _nCurrentPageIndex = _lstPageForms.Count - 1;

            return(_newForm);
        }
Example #5
0
        private void btnSearchTemplate_Click(object sender, EventArgs e)
        {
            if (System.IO.Path.GetExtension(dlgTemplate.FileName).ToLower() != ".xml")
            {
                dlgTemplate.FileName = "";
            }

            dlgTemplate.Title           = "Select XML template file";
            dlgTemplate.CheckFileExists = true;
            dlgTemplate.OverwritePrompt = false;
            dlgTemplate.FilterIndex     = 2;

            DialogResult _drResult = dlgTemplate.ShowDialog();

            if (_drResult != DialogResult.OK)
            {
                return;
            }

            if (!File.Exists(dlgTemplate.FileName))
            {
                return;
            }

            try
            {
                AddMessage("Loading template: " + dlgTemplate.FileName);

                txtTemplatePath.Text = dlgTemplate.FileName;
                _tfTemplate          = TemplateForm.Read(dlgTemplate.FileName);
                txtFormPath.Text     = _tfTemplate.FormPath;

                foreach (TemplateFieldsGroup group in _tfTemplate.Groups)
                {
                    cbGroupIdx.Items.Add(group.Name);
                }

                if (cbGroupIdx.Items.Count != 0)
                {
                    cbGroupIdx.SelectedIndex = 0;
                }
            }
            catch (Exception ex)
            {
                AddMessage("EXCEPTION:" + ex.Message);
                AddMessage("STACKTRACE:" + ex.StackTrace);
            }
        }
Example #6
0
        public static TemplateForm Read(string template_path)
        {
            if (!File.Exists(template_path))
            {
                return(null);
            }

            XmlSerializer _xsSerializer = new XmlSerializer(typeof(TemplateForm));

            TemplateForm _tfNewTemplate = null;

            using (FileStream _srReader = new FileStream(template_path, FileMode.Open))
            {
                _tfNewTemplate = (TemplateForm)_xsSerializer.Deserialize(_srReader);
            }

            return(_tfNewTemplate);
        }
Example #7
0
        public static TemplateForm Create(string name_value, string form_path)
        {
            if (!File.Exists(form_path))
            {
                return(null);
            }

            TemplateForm _tfNewTemplate = new TemplateForm(name_value);

            _tfNewTemplate._sFormFile = form_path;

            if (_tfNewTemplate._bAutoImportFields)
            {
                _tfNewTemplate.import_fields();
            }

            return(_tfNewTemplate);
        }
Example #8
0
        /// <summary>
        /// Create a template from a provided PDF form path.
        /// The new template will be automatically bind to the 'generating' form.
        /// Fields will be imported accordingly to the settings auto_import_fields parameter.
        /// </summary>
        /// <param name="name_value">Id of the new template</param>
        /// <param name="form_path">PDF form path</param>
        /// <param name="auto_import_fields">Auto import fields from pdf form (default true)</param>
        /// <returns>New template</returns>
        public static TemplateForm Create(string name_value, string form_path, bool auto_import_fields = true)
        {
            if (!File.Exists(form_path))
            {
                return(null);
            }

            TemplateForm _tfNewTemplate = new TemplateForm(name_value);

            _tfNewTemplate._sFormFile = System.IO.Path.GetFileName(form_path);

            if (auto_import_fields)
            {
                _tfNewTemplate.import_fields();
            }

            return(_tfNewTemplate);
        }
Example #9
0
        /// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="form">Original template form</param>
        public TemplateForm(TemplateForm form)
            : this()
        {
            this._sBaseDir      = form._sBaseDir;
            this._sBaseFilename = form._sBaseFilename;
            this._sFormFile     = form._sFormFile;
            this._sId           = form._sId;
            this._sTemplateFile = form._sTemplateFile;

            foreach (TemplateField field in form._lstFields)
            {
                this._lstFields.Add(new TemplateField(field));
            }

            foreach (TemplateFieldsGroup group in form._lstGroups)
            {
                this._lstGroups.Add(new TemplateFieldsGroup(group));
            }
        }
Example #10
0
        /// <summary>
        /// Fill set of grouped fields
        /// </summary>
        /// <param name="group_name">Group name/id</param>
        /// <param name="values">Values</param>
        /// <seealso cref="FieldsExpansion"/>
        /// <returns>True if new page have been created false otherwise</returns>
        public bool FillSet(string group_name, bool format, params object[] values)
        {
            TemplateForm _tfCurrentPage = _lstPageForms[_nCurrentPageIndex];

            if (_tfCurrentPage == null)
            {
                throw (new KeyNotFoundException("Page not found"));
            }

            bool _result = _tfCurrentPage.FillSet(group_name, format, values);

            // If the FillSet require a new page we add new page and reiterate the FillSet
            if (_result)
            {
                _tfCurrentPage = AddPage();
                _result        = _tfCurrentPage.FillSet(group_name, format, values);

                return(true);
            }

            return(false);
        }