public static Dictionary <string, string> TranslateDictionary(Scripting.Dictionary dictionary)
        {
            Dictionary <string, string> output = new Dictionary <string, string>();

            foreach (object kvPair in dictionary)
            {
                string key   = kvPair.ToString();
                string value = dictionary.get_Item(kvPair.ToString()).ToString();
                output.Add(key, value);
            }
            return(output);
        }
 public Scripting.Dictionary passDictionary2VBA(string callName)
 {
     Scripting.Dictionary dict = new Scripting.Dictionary();
     dict.Add("Apples", new DataTransferObject()
     {
         Id = callName
     });
     dict.Add("Oranges", new DataTransferObject()
     {
         Id = callName
     });
     return(dict);
 }
Example #3
0
 // function will be called from the callback function, when there is requested new data from the report generator
 // report generator needds more data --> call registered callback function in the vba script --> vba callback function calls the function "AddAdditionalData"
 public void AddAdditionalData(Scripting.Dictionary additionalData, int index)
 {
     if (m_additionalData.ContainsKey(index))
     {
         m_additionalData[index].Add(new Dictionary <string, string>(ConversionFunctions.TranslateDictionary(additionalData)));
     }
     else
     {
         m_additionalData.Add(index, new List <Dictionary <string, string> >()
         {
             new Dictionary <string, string>(ConversionFunctions.TranslateDictionary(additionalData))
         });
     }
 }
Example #4
0
        // function will be called by the vba script to add a new row of the TableDescriptionTable
        public void AddDescriptionTableEntry(string worksheetName, Scripting.Dictionary descriptionTableEntry)
        {
            Dictionary <string, string> descriptionEntry      = ConversionFunctions.TranslateDictionary(descriptionTableEntry);
            TableDescriptionTableEntry  reportDescriptionData = new TableDescriptionTableEntry();

            reportDescriptionData.FromDictionary(descriptionEntry);
            if (m_tableDescriptionTable.ContainsKey(worksheetName))
            {
                m_tableDescriptionTable[worksheetName].Add(reportDescriptionData);
            }
            else
            {
                m_tableDescriptionTable.Add(worksheetName, new TableDescriptionTable());
                m_tableDescriptionTable[worksheetName].Add(reportDescriptionData);
            }
        }
Example #5
0
        /// <summary>
        /// Binds a DataSource (ArrayList, Hashtable, NameValueCollection) to an IGuiListControl.
        /// Will also bind any other object that implements IEnumerable and has properties
        /// named "ItemName" and "ItemValue".
        /// </summary>
        /// <param name="control">The control to populate data in.</param>
        /// <param name="dataSource">The data source object.</param>
        public static void BindDataToListControl(IGuiListControl control, object dataSource)
        {
            control.Clear();

            if (dataSource is Hashtable)
            {
                Hashtable source = dataSource as Hashtable;

                foreach (string key in source.Keys)
                {
                    control[key] = source[key].ToString();
                }
            }
            else if (dataSource is NameValueCollection)
            {
                NameValueCollection source = dataSource as NameValueCollection;

                foreach (string key in source.Keys)
                {
                    control[key] = source[key];
                }
            }
            else if (dataSource is ArrayList)
            {
                ArrayList source = dataSource as ArrayList;

                for (int i = 0; i < source.Count; i++)
                {
                    control[i.ToString()] = source[i].ToString();
                }
            }
            else if (dataSource is string[])
            {
                string[] source = dataSource as string[];

                for (int i = 0; i < source.Length; i++)
                {
                    control[i.ToString()] = source[i];
                }
            }
            else if (dataSource is object[])
            {
                object[] source = dataSource as object[];

                for (int i = 0; i < source.Length; i++)
                {
                    control[i.ToString()] = source[i].ToString();
                }
            }
            else if (dataSource is IDictionary)
            {
                IDictionary dictionary = dataSource as IDictionary;
                foreach (object key in dictionary.Keys)
                {
                    control[key.ToString()] = dictionary[key].ToString();
                }
            }
            else if (dataSource is Scripting.Dictionary)
            {
                Scripting.Dictionary dictionary = dataSource as Scripting.Dictionary;
                Array items = dictionary.Items() as Array;
                Array keys  = dictionary.Keys() as Array;
                for (int i = 0; i < keys.Length; i++)
                {
                    control[keys.GetValue(i).ToString()] = items.GetValue(i).ToString();
                }
            }
            else if (dataSource is IEnumerable)
            {
                IEnumerable collection = dataSource as IEnumerable;

                PropertyInfo pinfoName, pinfoValue;
                string       name, val;
                foreach (object item in collection)
                {
                    pinfoName  = item.GetType().GetProperty("ItemValue");
                    pinfoValue = item.GetType().GetProperty("ItemName");

                    if ((pinfoName != null) && (pinfoValue != null))
                    {
                        name = pinfoName.GetGetMethod().Invoke(item, null) as String;
                        val  = pinfoValue.GetGetMethod().Invoke(item, null) as String;

                        control.Items[val] = name;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
Example #6
0
 // function will be called by the vba script to set the actual data from the current data record
 public void SetReportData(Scripting.Dictionary reportData)
 {
     m_reportData = ConversionFunctions.TranslateDictionary(reportData);
 }
        //public string[] iColumns()
        //{
        //    return;
        //}
        public Scripting.Dictionary replaceKey(Hashtable dbHasTable, Scripting.Dictionary iParameters)
        {
            Scripting.Dictionary tmpDic = new Scripting.Dictionary();
            object[] lKeys = (object[])iParameters.Keys();
            object[] lItems = (object[])iParameters.Items();
            for (int i = 0; i < iParameters.Count; i++)
            {
                if (dbHasTable.ContainsKey((string)lKeys[i]))
                {
                    lKeys[i] = dbHasTable[lKeys[i]];
                }
            }

            for (int j = 0; j < iParameters.Count; j++)
            {
                tmpDic.Add(lKeys[j],lItems[j]);
            }
            return tmpDic;
        }
        public void InsertData(string iTableName, Scripting.Dictionary iParameters)
        {
            DBMap dbmap = new DBMap();
            dbmap.initMap("dbmap.txt");
            Scripting.Dictionary dic2 = new Scripting.Dictionary();
            dic2 = replaceKey(dbmap.dbHasTable, iParameters);

            object[] lKeys = (object[])dic2.Keys();
            List<string> list_Columns = new List<string>();
            string tmp;
            for (int i = 0; i < dic2.Count; i++)
            {
                tmp = ((string)lKeys[i]).Split('@')[1];
                list_Columns.Add(tmp);
                tmp = null;
            }

            Insert(iTableName, list_Columns, dic2);
        }