Example #1
0
        private SIEEFieldlist GetFieldlistFromUI()
        {
            TextBox           tb;
            DataGridView      dgv;
            SIEEFieldlist     fl = new SIEEFieldlist(schema);
            SIEETableFieldRow tfr;

            foreach (SIEEField f in fl)
            {
                Control c = tb_dict[f.Name];
                if (c is TextBox)
                {
                    tb      = (TextBox)c;
                    f.Value = tb.Text;
                    continue;
                }
                // else c is DataGridView
                dgv = (DataGridView)c;
                SIEETableField tf    = (SIEETableField)f;
                DataTable      table = gridToTableMap[dgv];
                foreach (DataRow row in table.Rows)
                {
                    tfr = new SIEETableFieldRow();
                    foreach (DataColumn col in table.Columns)
                    {
                        tfr[col.ColumnName] = row[col] is DBNull ? "" : (string)row[col];
                    }
                    tf.AddRow(tfr);
                }
            }
            return(fl);
        }
 public SIEETableField(SIEETableField tf) : base(tf)
 {
     Columns = new SIEEFieldlist();
     foreach (SIEEField f in tf.Columns)
     {
         Columns.Add(new SIEEField(f));
     }
 }
        public void MakeFieldnamesOCCCompliant()
        {
            foreach (SIEEField field in this)
            {
                field.Name = ConvertToLegalOCCFieldname(field.Name);
            }

            MakeFieldNamesUnique(this);
            foreach (SIEEField field in this)
            {
                if (field is SIEETableField)
                {
                    SIEETableField tablefield = (SIEETableField)field;
                    SIEEFieldlist  columns    = tablefield.Columns;
                    foreach (SIEEField f1 in columns)
                    {
                        f1.Name = ConvertToLegalOCCFieldname(f1.Name);
                    }
                    MakeFieldNamesUnique(columns);
                    tablefield.Columns = columns;
                }
            }
        }
Example #4
0
        public void t02_SerializeSchemaToXML()
        {
            SIEEFieldlist s1 = new SIEEFieldlist();

            s1.Add(new SIEEField("1", "ex1", "value1"));
            s1.Add(new SIEEField("2", "ex2", "value2"));
            s1.Add(new SIEEField("3", "ex3", "value3"));

            SIEEFieldlist s2 = new SIEEFieldlist();

            s2.Add(new SIEEField("1.1", "ex1.1", "value1.1"));
            s2.Add(new SIEEField("1.2", "ex1.2", "value1.2"));

            s1.Add(new SIEETableField("4", "ex4", "value4", s2));

            string ser = Serializer.SerializeToXmlString(s1, System.Text.Encoding.Unicode);

            SIEEFieldlist deser = (SIEEFieldlist)Serializer.DeserializeFromXmlString(ser, typeof(SIEEFieldlist), System.Text.Encoding.Unicode);

            SIEEField f1 = deser.GetFieldByName("1");

            Assert.AreEqual("value1", f1.Value);
            SIEEField f2 = deser.GetFieldByName("2");

            Assert.AreEqual("2", f2.Name);
            SIEEField f3 = deser.GetFieldByName("3");

            Assert.AreEqual("ex3", f3.ExternalId);

            SIEETableField f4 = deser.GetFieldByName("4") as SIEETableField;

            Assert.AreEqual("ex4", f4.ExternalId);

            SIEEField f5 = f4.Columns[0];

            Assert.AreEqual("value1.1", f5.Value);
        }
Example #5
0
        public void t08_SIEESerializer()
        {
            // Create fieldlist
            SIEEFieldlist fieldlist = new SIEEFieldlist();

            fieldlist.Add(new SIEEField {
                Name = "Field_1", ExternalId = "Ext_1"
            });
            fieldlist.Add(new SIEEField {
                Name = "Field_2", ExternalId = "Ext_2"
            });
            SIEETableField tf = new SIEETableField {
                Name = "Table", ExternalId = "Ext_Table"
            };

            tf.Columns.Add(new SIEEField {
                Name = "TabField_1", ExternalId = "TabExt_1"
            });
            tf.Columns.Add(new SIEEField {
                Name = "TabField_2", ExternalId = "TabExt_2"
            });
            fieldlist.Add(tf);

            // Serialize
            string s1 = SIEESerializer.ObjectToString(fieldlist);
            // Deserialize
            SIEEFieldlist f1 = (SIEEFieldlist)SIEESerializer.StringToObject(s1);
            // Serialize the newly created field list
            string s2 = SIEESerializer.ObjectToString(f1);

            // final compare
            string txt1 = fieldlist.ToString(data: false);
            string txt2 = f1.ToString(data: false);

            Assert.AreEqual(s1, s2);
        }
Example #6
0
        private void addFields(SIEEFieldlist fl)
        {
            Label        l;
            TextBox      tb;
            DataGridView dgv;
            DataTable    table;
            int          ypos       = 0;
            const int    labelwidth = 300;
            int          labelheight;
            int          entryheight;
            int          gridheight;
            int          cnt = 0;

            tb_dict.Clear();

            foreach (SIEEField f in fl)
            {
                l           = new Label();
                l.Location  = new System.Drawing.Point(0, ypos);
                l.Name      = "label_" + f.Name;
                labelheight = l.Size.Height;
                l.Size      = new System.Drawing.Size(labelwidth, labelheight);
                l.TabIndex  = cnt;
                l.Text      = f.Name;
                this.panel.Controls.Add(l);

                if (!(f is SIEETableField))
                {
                    tb          = new TextBox();
                    tb.Location = new System.Drawing.Point(labelwidth + 30, ypos);
                    tb.Name     = f.Name;
                    entryheight = tb.Size.Height > labelheight ? tb.Size.Height : labelheight;
                    tb.Size     = new System.Drawing.Size(panel.Size.Width - (labelwidth + 30), entryheight);
                    tb.TabIndex = cnt;
                    this.panel.Controls.Add(tb);
                    tb_dict.Add(f.Name, tb);
                    tb.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left;
                    ypos     += entryheight;
                }
                else
                {
                    SIEETableField tf = (SIEETableField)f;
                    dgv                 = new DataGridView();
                    dgv.Location        = new System.Drawing.Point(labelwidth + 30, ypos);
                    dgv.Name            = tf.Name;
                    gridheight          = dgv.Size.Height;
                    dgv.Size            = new System.Drawing.Size(panel.Size.Width - (labelwidth + 30), gridheight);
                    dgv.TabIndex        = cnt;
                    dgv.Font            = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    table               = new DataTable();
                    gridToTableMap[dgv] = table;
                    dgv.DataSource      = table;
                    foreach (SIEEField col in tf.Columns)
                    {
                        table.Columns.Add(col.Name);
                    }
                    this.panel.Controls.Add(dgv);
                    tb_dict.Add(f.Name, dgv);
                    dgv.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left;
                    //dgv.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.Fill);
                    ypos += 10 + gridheight;
                }
                cnt++;
            }
        }
        /// This is the core function that copies the field values from an OCC datapool document into an SIEEFieldlist.
        /// Input is a fieldlist as derived from the Schema. This means it contains all Schema fields. In the document
        /// there may (a) be additional fields and (b) the might be no field connected to a given Schema field.
        /// Additional fields are simply ingnored. Fields in the fieldlist that have no correspondence in the document
        /// are left unchanged. That means, if the field has a value that that is passed to the export. Normally schema
        /// fields should have "null" assigned to the Value property of a fields. The SIEEExport function needs to
        /// handle this case.
        private SIEEDocument documentToFieldlist(SIEEFieldlist fieldlist, Document doc, string batchId, string profile)
        {
            CustomExportDestinationField edf;
            CustomExportDestinationTable edt;

            foreach (Field dataPoolField in doc.Fields)
            {
                if (dataPoolField is LookupList)
                {
                    foreach (Field dataPoolSubfield in dataPoolField.Fields)
                    {
                        setFieldValue(fieldlist, dataPoolSubfield);
                    }
                    continue;
                }
                if (dataPoolField is Table)
                {
                    edt = this.writerSettings.FieldsMapper.GetExternalTable((Table)dataPoolField);
                    if (edt == null)
                    {
                        continue;
                    }
                    SIEETableField tf = (SIEETableField)fieldlist.GetFieldByName(edt.Name);
                    if (tf == null)
                    {
                        continue;
                    }
                    FieldCollection rows = ((Table)dataPoolField).Rows;
                    for (int i = 0; i != rows.Count; i++)
                    {
                        TableRow          r      = (TableRow)rows[i];
                        SIEETableFieldRow tf_row = new SIEETableFieldRow();
                        foreach (Field col in r.Columns)
                        {
                            edf = this.writerSettings.FieldsMapper.GetExternalTableCell(((Table)dataPoolField), col);
                            if (edf == null)
                            {
                                continue;
                            }

                            if (tf.ColumnExists(edf.Name))
                            {
                                tf_row.Add(edf.Name, col.Value);
                            }
                        }
                        tf.AddRow(tf_row);
                    }
                    continue;
                }
                // regular field
                setFieldValue(fieldlist, dataPoolField);
            }

            SIEEFieldlist auxFields = new SIEEFieldlist();

            foreach (Field dataPoolField in doc.Fields)
            {
                if (!(dataPoolField is LookupList) && !(dataPoolField is Table))
                {
                    auxFields.Add(new SIEEField(dataPoolField.Name, null, dataPoolField.Value));
                }
            }

            SourceInstance[] si = doc.GetInputSourceInstances();
            Annotation       a  = doc.Annotations["exportName"];

            SIEEDocument document = new SIEEDocument()
            {
                Fieldlist     = fieldlist,
                AuxFields     = auxFields,
                PDFFileName   = doc.GetExportPdfSource().Url,
                InputFileName = si.Length > 0 ? doc.GetInputSourceInstances()[0].Id : "",
                BatchId       = batchId,
                ScriptingName = a?.Value,
                Profile       = profile,
            };

            return(document);
        }