Esempio n. 1
0
        }//doTableValuesMatch()

        public void fillTableWithArbitraryData(string TableName, Dictionary <string, List <string> > FillData, List <Int32> PksList = null)
        {
            CswTableUpdate CswTableUpdate = _CswNbtSchemaModTrnsctn.makeCswTableUpdate("fillTableWtithArbitraryData_update", TableName);
            DataTable      DataTable      = CswTableUpdate.getTable();

            Int32 MaxFillDataRows = 0;

            foreach (List <string> CurrentList in FillData.Values)
            {
                if (CurrentList.Count > MaxFillDataRows)
                {
                    MaxFillDataRows = CurrentList.Count;
                }
            }

            foreach (string CurrentColumnName in FillData.Keys)
            {
                if (false == DataTable.Columns.Contains(CurrentColumnName))
                {
                    throw (new CswDniException("Value-fill column " + CurrentColumnName + " does not exist in table " + TableName));
                }
            }//iterate lists to get max row count

            Int32 MaxRowsToAdd = MaxFillDataRows - DataTable.Rows.Count; //if we need to add the rows, we do so

            for (int idx = DataTable.Rows.Count; idx < MaxRowsToAdd; idx++)
            {
                DataRow DataRow = DataTable.NewRow();
                DataTable.Rows.Add(DataRow);

                if (null != PksList)
                {
                    PksList.Add(CswConvert.ToInt32(DataRow[_CswNbtSchemaModTrnsctn.getPrimeKeyColName(TableName)]));
                }
            }//iterate max rows to prime the tables

            foreach (string CurrentColumn in FillData.Keys)
            {
                List <string> CurrentValueList = FillData[CurrentColumn];
                for (int idx = 0; idx < CurrentValueList.Count; idx++)
                {
                    DataTable.Rows[idx][CurrentColumn] = CurrentValueList[idx];
                } //iterate value list for current column
            }     //iterate fill data to to populate table

            CswTableUpdate.update(DataTable);
        }//fillTableWithArbitraryData()