//import datatable public void btnImportData_Click(object sender, EventArgs e) { DataTable dataDT = new DataTable("Imported Data"); VBCommon.IO.ImportExport import = new VBCommon.IO.ImportExport(); if ((dataDT = import.Input) == null) { return; } //check for unique records or blanks string errcolname = string.Empty; int errndx = 0; if (!recordIndexUnique(dataDT, out errndx)) { MessageBox.Show("Unable to import datasets with non-unique record identifiers.\n" + "Fix your datatable by assuring unique record identifier values\n" + "in the 1st column and try importing again.\n\n" + "Record Identifier values cannot be blank or duplicated;\nencountered " + "error near row " + errndx.ToString(), "Import Data Error - Cannot Import This Dataset", MessageBoxButtons.OK); return; } //check for spaces string offendingCol = string.Empty; if (datasetHasSpacesinColNmaes(dataDT, out offendingCol)) { MessageBox.Show("Cannot import datasets with spaces in column names.\nEdit your dataset and re-import.\n" + "First offending column encountered = " + offendingCol, "Import Data Error - Column names have spaces.", MessageBoxButtons.OK); return; } dsControl1.DT = dataDT.Copy(); //enable validation_click //init in case they've re-imported dsControl1.dgv.DataSource = null; dsControl1.dgv.DataSource = dsControl1.DT; //set extendedProperties on columns for (int c = 0; c < dsControl1.DT.Columns.Count; c++) { dsControl1.DT.Columns[c].ExtendedProperties[VBCommon.Globals.MAINEFFECT] = true; if (c == 0) { dsControl1.DT.Columns[c].ExtendedProperties[VBCommon.Globals.DATETIMESTAMP] = true; dsControl1.dgv.Columns[c].ReadOnly = true; //cannot edit this puppy..... editable makes it breakable } if (c == 1) { dsControl1.DT.Columns[c].ExtendedProperties[VBCommon.Globals.DEPENDENTVAR] = true; } dsControl1.dgv.Columns[c].SortMode = DataGridViewColumnSortMode.NotSortable; dsControl1.dgv.Columns[c].DefaultCellStyle.ForeColor = Color.Black; } //initialize rows to all enabled for imported table //(builds dictionary of keys, <string>datetime and values <bool>enabled/disabled row) dsControl1.DTRI = VBCommon.Metadata.dtRowInformation.getdtRI(dsControl1.DT, true); //initialize cols to all enabled for imported table //(builds dictionary of keys, <string>datetime and values <bool>enabled/disabled col) dsControl1.DTCI = VBCommon.Metadata.dtColumnInformation.getdtCI(dsControl1.DT, true); //init the utilities dsControl1.Utils = new VBCommon.Metadata.Utilities(); dsControl1.TableUtils = new VBCommon.Metadata.Utilities.TableUtils(dsControl1.DT); dsControl1.GridUtils = new VBCommon.Metadata.Utilities.GridUtils(dsControl1.dgv); //default col 1 as response dsControl1.SelectedColIndex = 1; dsControl1.ResponseVarColIndex = 1; dsControl1.ResponseVarColName = dsControl1.DT.Columns[1].Caption; dsControl1.GridUtils.setResponseVarCol(dsControl1.dgv, dsControl1.SelectedColIndex, dsControl1.SelectedColIndex); dsControl1.GridUtils.setViewOnGrid(dsControl1.dgv); //initial info for the list FileInfo fi = new FileInfo(import.getFileImportedName); dsControl1.FileName = fi.Name; dsControl1.showListInfo(dsControl1.FileName, dsControl1.DT); dsControl1.dgv.Enabled = false; boolInitialPass = true; boolValidated = false; }
//import datatable public void btnImportData_Click(object sender, EventArgs e) { DataTable dataDT = new DataTable("Imported Data"); VBCommon.IO.ImportExport import = new VBCommon.IO.ImportExport(); if ((dataDT = import.Input) == null) return; //check for unique records or blanks string errcolname = string.Empty; int errndx = 0; if (!recordIndexUnique(dataDT, out errndx)) { MessageBox.Show("Unable to import datasets with non-unique record identifiers.\n" + "Fix your datatable by assuring unique record identifier values\n" + "in the 1st column and try importing again.\n\n" + "Record Identifier values cannot be blank or duplicated;\nencountered " + "error near row " + errndx.ToString(), "Import Data Error - Cannot Import This Dataset", MessageBoxButtons.OK); return; } //check for spaces string offendingCol = string.Empty; if (datasetHasSpacesinColNmaes(dataDT, out offendingCol)) { MessageBox.Show("Cannot import datasets with spaces in column names.\nEdit your dataset and re-import.\n" + "First offending column encountered = " + offendingCol, "Import Data Error - Column names have spaces.", MessageBoxButtons.OK); return; } dsControl1.DT = dataDT.Copy(); //enable validation_click //init in case they've re-imported dsControl1.dgv.DataSource = null; dsControl1.dgv.DataSource = dsControl1.DT; //set extendedProperties on columns for (int c = 0; c < dsControl1.DT.Columns.Count; c++) { dsControl1.DT.Columns[c].ExtendedProperties[VBCommon.Globals.MAINEFFECT] = true; if (c == 0) { dsControl1.DT.Columns[c].ExtendedProperties[VBCommon.Globals.DATETIMESTAMP] = true; dsControl1.dgv.Columns[c].ReadOnly = true; //cannot edit this puppy..... editable makes it breakable } if (c == 1) dsControl1.DT.Columns[c].ExtendedProperties[VBCommon.Globals.DEPENDENTVAR] = true; dsControl1.dgv.Columns[c].SortMode = DataGridViewColumnSortMode.NotSortable; dsControl1.dgv.Columns[c].DefaultCellStyle.ForeColor = Color.Black; } //initialize rows to all enabled for imported table //(builds dictionary of keys, <string>datetime and values <bool>enabled/disabled row) dsControl1.DTRI = VBCommon.Metadata.dtRowInformation.getdtRI(dsControl1.DT, true); //initialize cols to all enabled for imported table //(builds dictionary of keys, <string>datetime and values <bool>enabled/disabled col) dsControl1.DTCI = VBCommon.Metadata.dtColumnInformation.getdtCI(dsControl1.DT, true); //init the utilities dsControl1.Utils = new VBCommon.Metadata.Utilities(); dsControl1.TableUtils = new VBCommon.Metadata.Utilities.TableUtils(dsControl1.DT); dsControl1.GridUtils = new VBCommon.Metadata.Utilities.GridUtils(dsControl1.dgv); //default col 1 as response dsControl1.SelectedColIndex = 1; dsControl1.ResponseVarColIndex = 1; dsControl1.ResponseVarColName = dsControl1.DT.Columns[1].Caption; dsControl1.GridUtils.setResponseVarCol(dsControl1.dgv, dsControl1.SelectedColIndex,dsControl1.SelectedColIndex); dsControl1.GridUtils.setViewOnGrid(dsControl1.dgv); //initial info for the list FileInfo fi = new FileInfo(import.getFileImportedName); dsControl1.FileName = fi.Name; dsControl1.showListInfo(dsControl1.FileName, dsControl1.DT); dsControl1.dgv.Enabled = false; boolInitialPass = true; boolValidated = false; }