Exemple #1
0
        public static DataTable RemoveDuplicates(DataTable dt, DataColumn[] keyColumns, string SavePath, string currentMapping)
        {
            int rowNdx = 0;
            var res = new List<DataTable>();
            DataTable duplicatesTable = dt.Clone();

            var qFields = string.Join(", ", keyColumns.Select(x => "it[\"" + x.ColumnName + "\"] as " + x.ColumnName.Replace(" ","") + ""));

            var q = dt.AsEnumerable()
                                .AsQueryable()
                                .GroupBy("new(" + qFields + ")", "it")
                                .Select("new (it as Data)");

            var dtemp = dt.Clone();

            foreach (dynamic d in q)
            {
               // dtemp.Rows.Add(d.Data.First().ItemArray());
                rowNdx = 0;
                foreach (var row in d.Data)
                {
                    if (rowNdx == 0)
                    {
                        dtemp.Rows.Add(row.ItemArray);
                    }
                    else
                    {
                        duplicatesTable.Rows.Add(row.ItemArray);
                    }
                    rowNdx++;
                }
            }

            string newFileName = string.Format("{0}{1}", "test", rowNdx);
            FileSaveHelper.ExportDataTable(duplicatesTable, string.Format("{0}\\{1}", SavePath, currentMapping + "_Duplicates.xlsx"));
            return dtemp;
            //while (rowNdx < tbl.Rows.Count - 1)
            //{
            //    DataRow[] dups = FindDups(tbl, rowNdx, keyColumns);

            //    if (dups.Length > 0)
            //    {
            //        foreach (DataRow dup in dups)
            //        {
            //            duplicatesTable.ImportRow(dup);
            //            tbl.Rows.Remove(dup);
            //        }
            //        tbl.Rows.Add(dups.FirstOrDefault());
            //    }
            //    else
            //    {
            //        rowNdx++;
            //    }
            //}
               // return duplicatesTable;
        }
        private DataTable UpdateFeaturesAction(DataColumn[] updateColumns, 
            object[] updateValues, DataTable historyTable)
        {
            if (!TableExists(_selName))
                throw new Exception("Error selecting update features from MapInfo layer.");

            //---------------------------------------------------------------------
            // QUERY: KI106 (Shape area and length values)
            // Should this include updates for the geom1 and geom2 columns automatically?
            //---------------------------------------------------------------------

            // update selection
            _mapInfoApp.Do(String.Format("Update {0} Set {1}", _selName,
                String.Join(",", updateColumns.Select((c, index) => String.Format("{0} = {1}",
                   GetFieldName(_hluLayerStructure.Columns[c.ColumnName].Ordinal),
                   QuoteValue(updateValues[index]))).ToArray())));

            if (!CommitChanges())
                return null;
            else
                return historyTable;
        }
Exemple #3
0
        private DataTable UpdateFeaturesAction(DataColumn[] updateColumns, 
            object[] updateValues, DataTable historyTable)
        {
            if (String.IsNullOrEmpty(_selName) || !TableExists(_selName))
                throw new Exception("Error selecting update features from MapInfo layer.");

            if (String.IsNullOrEmpty(_selName)) return null;

            // update selection
            _mapInfoApp.Do(String.Format("Update {0} Set {1}", _selName,
                String.Join(",", updateColumns.Select((c, index) => String.Format("{0} = {1}",
                   GetFieldName(_hluLayerStructure.Columns[c.ColumnName].Ordinal),
                   QuoteValue(updateValues[index]))).ToArray())));

            if (!CommitChanges())
                return null;
            else
                return historyTable;
        }
Exemple #4
0
        public string FromList(bool includeFrom, DataColumn[] targetColumns, 
            bool quoteIdentifiers, ref List<SqlFilterCondition> whereClause, out bool additionalTables)
        {
            DataTable[] colTables = targetColumns.Select(c => c.Table).Distinct().ToArray();
            var whereTables = whereClause.Select(con => con.Table).Distinct().Where(t => !colTables.Contains(t));

            int numTables = colTables.Length;
            colTables = colTables.Concat(whereTables).ToArray();
            additionalTables = colTables.Length > numTables;

            whereClause = JoinClause(colTables).Concat(whereClause).ToList();

            return FromList(includeFrom, quoteIdentifiers, colTables.Select(t => t.TableName).ToArray());
        }