示例#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);
        }
        /// 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);
        }