[Quantproject-developers] QuantProject/b1_ADT ExtendedDataTable.cs,1.5,1.6
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2004-08-22 16:51:21
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18983/b1_ADT Modified Files: ExtendedDataTable.cs Log Message: Added static method to the class in order to retrieve a HashTable containing common values from two given columns in two given dataTables (method has to be tested) Index: ExtendedDataTable.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/ExtendedDataTable.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ExtendedDataTable.cs 11 Aug 2004 21:33:10 -0000 1.5 --- ExtendedDataTable.cs 22 Aug 2004 16:51:09 -0000 1.6 *************** *** 1,7 **** --- 1,9 ---- using System; + using System.Collections; using System.Data; using System.Windows.Forms; + namespace QuantProject.ADT { *************** *** 94,97 **** --- 96,165 ---- } + /// <summary> + /// Get an array of float corresponding to the ratio between columnA and columnB + /// </summary> + public static float[] GetArrayOfFloatFromRatioOfColumns(DataTable table, + string columnAName, string columnBName) + { + int numRows = table.Rows.Count; + float[] arrayOfFloat = new float[numRows]; + int index = 0; + try + { + for(; index!= numRows; index++) + { + arrayOfFloat[index] = (float) table.Rows[index][columnAName] / + (float) table.Rows[index][columnBName]; + } + + } + catch(Exception ex) + { + MessageBox.Show(ex.ToString()); + index = numRows; + } + return arrayOfFloat; + + } + + /// <summary> + /// It returns a hashtable containing the common values in two + /// columns of two given Data tables (the two columns must contain unique values!) + /// </summary> + /// <param name="firstDataTable">The first table that contains the first column</param> + /// <param name="secondDataTable">The second table that contains the second column</param> + /// <param name="indexOfColumnOfFirstTable">The index of the first column in the first table</param> + /// <param name="indexOfColumnOfSecondTable">The index of the second column in the second table</param> + public static Hashtable GetCommonValues(DataTable firstDataTable, DataTable secondDataTable, + int indexOfColumnOfFirstTable, + int indexOfColumnOfSecondTable) + { + + Hashtable hashTable = new Hashtable(); + + string columnNameTable1 = firstDataTable.Columns[indexOfColumnOfFirstTable].ColumnName; + string columnNameTable2 = firstDataTable.Columns[indexOfColumnOfSecondTable].ColumnName; + DataRow[] orderedRowsTable1 = firstDataTable.Select(columnNameTable1 + "!=' '", "DESC"); + DataRow[] orderedRowsTable2 = secondDataTable.Select(columnNameTable2 + "!=' '", "DESC"); + int j = 0; + for(int i=0; i != orderedRowsTable1.Length; i++) + { + for(; j != orderedRowsTable2.Length; j++) + { + int currentIndex = j; + object object1 = orderedRowsTable1[i][indexOfColumnOfFirstTable]; + object object2 = orderedRowsTable2[i][indexOfColumnOfSecondTable]; + if( object1 == object2 ) + { + hashTable.Add(object1, object2); + j = currentIndex; + } + } + } + return hashTable; + + } + + } } |