public string insertFieldValue(fieldValues newFieldValue) { string ret; //newFieldValue.FieldValueId = getNewId("fieldValues"); ret = fieldValueL.Insert(newFieldValue); return(ret); }
//protected string deleteDataTable(DataTable dt) //{ // string ret = ""; // string tableName = DataTableName(dt); // return ret; //} public string ImportDataTableSaveas(DataTable dt , string saveAsNewTablename = "", bool append = false) { string ret = ""; Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " ImportDataTableSaveas 1"); if (saveAsNewTablename == "") { saveAsNewTablename = DataTableName(dt); } // import datatable save as new table // if new table existed, append false to overwrite // delete target table if (!append) { Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " ImportDataTableSaveas 2b"); dbBig.deleteTag(saveAsNewTablename); Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " ImportDataTableSaveas 2"); dbBig.deleteTable(saveAsNewTablename); } Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " ImportDataTableSaveas 3"); // write to tables tables tbl = new tables(); tbl.tableName = saveAsNewTablename; Guid tableId; ret = dbBig.insertTable(tbl, out tableId, saveAsNewTablename); Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " ImportDataTableSaveas 4"); // write to fields List <string> colNames = DataTableColumnNames(dt); List <string> colTypes = DataTableColumnTypes(dt); Dictionary <string, Guid> name2id = new Dictionary <string, Guid>(); for (int i = 0; i < colNames.Count && i < colTypes.Count; i++) { fields fld = new fields(); fld.fieldName = colNames[i]; fld.fieldDesc = colTypes[i]; fld.tableId = tableId; fld.defaultOrder = i + 1; Guid fieldId = Guid.Empty; ret = dbBig.insertField(fld, out fieldId, saveAsNewTablename); name2id.Add(fld.fieldName, fieldId); //Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " ImportDataTableSaveas 5 i="+i); } Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " ImportDataTableSaveas 6"); List <Dictionary <string, string> > dtCells = DataTableCellValue(dt); int j = 0; foreach (Dictionary <string, string> rowCols in dtCells) { // write to rows Guid rowId = Guid.Empty; rows rw = new rows(); rw.tableId = tableId; ret = dbBig.insertRow(rw, out rowId, saveAsNewTablename); if (++j % 10000 == 0) { Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + $" ImportDataTableSaveas 7 [{j}/{dtCells.Count}]"); } // write to field values foreach (KeyValuePair <string, string> pair in rowCols) { fieldValues fv = new fieldValues(); fv.rowId = rowId; fv.fieldId = name2id[pair.Key]; fv.fieldValue = pair.Value; ret = dbBig.insertFieldValue(fv); } } Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " ImportDataTableSaveas 8 end"); return(ret); }