private void OpenFile(string fileName) { try { gridView1.Columns.Clear(); bindingSource1.DataSource = null; //先把数据读取到表中 DataTable data = TextFileToDataTable.ReadTextFile(fileName, "Bill", "\t"); this.tHeaderColumns = new string[] { "货位编号", "货位描述", "所属货区" }; //查看其它字段是否符合模板定义 if (!IsColumnExist(data)) { return; } //绑定到界面 tHeader = data; //先添加一列执行结果,记录导入成功、略过等信息 tHeader.Columns.Add("导入结果", typeof(string)); bindingSource1.DataSource = data; gridView1.ViewCaption = string.Format("文件:{0}", fileName); } catch (Exception ex) { MsgBox.Err(ex.Message); } }
// Return sql data types: public static string[,] SQLDataTypesBasedOnTextFile(string pathtocsv, Int32 norowsreview, char sep) { // "c:\\PathToFile\\data.csv" DataTable dt = TextFileToDataTable.CsvToDataTableToEstimateSepAndDataTypes(pathtocsv, norowsreview, sep); string[,] sqldatatype_array = new string[2, dt.Columns.Count]; return(EstimateDataTypes(sqldatatype_array, dt)); }
private void OpenFile(string fileName) { dsASN.Clear(); if (tOriginal != null) { tOriginal.Rows.Clear(); } using (new WaitDialogForm("请稍等...", "正在读取数据")) { //tOriginal = NPOIHandler.ExcelToDataTable(excelFile, 0, 1); //Nodes.Util.ExcelPrinter.ExcelAccess excel = new Nodes.Util.ExcelPrinter.ExcelAccess(); //excel.Open(excelFile); //tOriginal = excel.ExcelToDataTableCore(1, 2); //excel.Close(); try { tOriginal = TextFileToDataTable.ReadTextFile(fileName, "SO", "\t"); bindingSource1.DataSource = null; if (IsHeaderColumnExist(tOriginal)) { bindingSource1.DataSource = tOriginal; gridView1.ViewCaption = string.Format("文件:{0}", fileName); SplitDataTable(tOriginal); } else { gridControl2.DataSource = null; } } catch (Exception ex) { MsgBox.Err(ex.Message); } } }
private void OpenFile(string fileName) { //原来为Excel文件,现在变成了文本文件,所以下面的函数不再使用 //使用NPOI方法 //tOriginal = NPOIHandler.ExcelToDataTable(excelFile, 0, 1); //使用Excel.interop //Nodes.Util.ExcelPrinter.ExcelAccess excel = new Nodes.Util.ExcelPrinter.ExcelAccess(); //excel.Open(excelFile); //tOriginal = excel.ExcelToDataTableCore(1, 2); //excel.Close(); try { gridView1.Columns.Clear(); gridView2.Columns.Clear(); bindingSource1.DataSource = null; gridControl2.DataSource = null; //先把数据读取到表中 DataTable data = TextFileToDataTable.ReadTextFile(fileName, "Bill", "\t"); //查看数据文件是到货通知单还是销货单(销货单文本文件格式包含好几种单据类型,既有出库也有入库的单据; //到货通知单文件只包含到货通知单) //区分文件类型方式是到货通知单单据编号是DocEntry,销货单是DocEntry1 if (data.Columns.Contains("DocEntry")) { this.BillNOColumnName = "DocEntry"; this.IsAsnFile = true; this.tHeaderColumns = new string[] { "DocEntry", "Object", "CardCode", "CardName", "Warehouse", "DocDate", "Comments", "Reporter", "RprtName", "NumAtCard", "BaseType", "BaseEntry", "BaseLine" }; this.tDetailColumns = new string[] { "DocEntry", "LineNum", "ItemCode", "Dscription", "Quantity", "SupplierNum", "EffectDate", "NumAtCardLine", "Fonumber" }; } else if (data.Columns.Contains("DocEntry1")) { this.BillNOColumnName = "DocEntry1"; this.IsAsnFile = false; this.tHeaderColumns = new string[] { "DocEntry1", "Object", "SlpCode1", "CardCode1", "CardName1", "NumAtCard1", "QCNumber", "shcompany", "consignee", "shtel", "shaddress", "WhsCode1", "Warehouse", "DocDate1", "BaseType1", "BaseEntry1", "BaseLine1", "Comments1", "DHLnumber", "USER", "CARDBZ", "Deliveryrequire" }; this.tDetailColumns = new string[] { "DocEntry1", "LineNum1", "ItemCode1", "Dscription1", "Brand", "Quantity1", "PriceAfVAT", "DistNumber1", "ExpDate1", "SaleContNo", "Fonumber" }; } else { throw new Exception("文件格式错误,无法解析。"); } //查看其它字段是否符合模板定义 if (!IsColumnExist(data)) { return; } //根据文件类型初始化表结构 InitTable(); //绑定到界面 tOriginal = data; bindingSource1.DataSource = data; gridView1.ViewCaption = string.Format("文件:{0}", fileName); //将原始表分割为表头和明细,显示到下面的表格中 SplitDataTable(data); } catch (Exception ex) { MsgBox.Err(ex.Message); } }