Exemple #1
0
        public void InitDataTable()
        {
            this._DataTable = new ProductiveAdvantage.MasterDS.ChildKeyValueDataTable();
            this._DataTable.BeginInit();

            // fill with fields
            foreach (DictionaryEntry entry in this.Fields)
            {
                this._DataTable.AddChildKeyValueRow(entry.Key.ToString(), "", true, "", true);
            }

            // fill with names
            foreach (MasterDS.ChildKeyValueRow row in this._DataTable)
            {
                row.KeyName = DatabaseOptimizer.GetKeyName(row.Key);
            }

            this._DataTable.EndInit();
            this._DataTable.AcceptChanges();
        }
Exemple #2
0
        public void PopulateFields()
        {
            // fill hashTable
            Fields.Clear();
            Aspose.Word.Document doc;
            string filePath = this.SavedPath == "" ? this.FilePath : this.SavedPath;

            if (File.Exists(filePath) == false)
            {
                return;
            }

            using (FileStreamManager fs = new FileStreamManager(filePath, true))
            {
                fs.OpenFileStream();
                if (fs.Abort == true)
                {
                    TemplateValid = false;
                    return;
                }

                doc = null;
                try
                {
                    doc = new Aspose.Word.Document(fs.FileStream);
                }
                catch (Exception ex)
                {
                    ErrorManager.WriteTraceInfo("TemplateStruct.PopulateFields().openDocument", ex, true, String.Format("The following document failed to open...\n{0}", filePath));
                    TemplateValid = false;
                    return;
                }
            }

            using (JetTask t = new JetTask())
            {
                object str;
                foreach (DocumentProperty property in doc.CustomDocumentProperties)
                {
                    if (property.Name.StartsWith("pA_"))
                    {
                        t.CommandText = "SELECT [Default] FROM FieldNames WHERE FieldKey = '" + property.Name + "'";
                        str           = t.ExecuteScalar();
                        if (str == null)
                        {
                            str = "";
                        }

                        this.Fields.Add(property.Name, str);
                    }
                }
            }

            // sync dataTable
            if (this.DataTable != null)
            {
                Hashtable ht = new Hashtable();
                foreach (DictionaryEntry entry in this.Fields)
                {
                    ht.Add(entry.Key, entry.Value);

                    // check to see if its already in the datatable
                    if (this.DataTable != null && this.DataTable.IsInitialized)
                    {
                        if (this.DataTable.FindByKey(entry.Key.ToString()) == null)
                        {
                            this.DataTable.AddChildKeyValueRow(entry.Key.ToString(), DatabaseOptimizer.GetKeyName(entry.Key.ToString()), true, "", true);
                        }
                    }
                }

                // update visibility
                if (this.DataTable.Count > 0)
                {
                    foreach (MasterDS.ChildKeyValueRow row in DataTable)
                    {
                        row.IsVisible = ht.ContainsKey(row.Key);
                        row.KeyName   = DatabaseOptimizer.GetKeyName(row.Key);
                    }
                }
            }
        }