/// <summary> ///加载需要导入的数据。/ /// </summary> /// <param name="parent"></param> /// <param name="buiObj"></param> /// <param name="xmlFileName"></param> /// <param name="importFile"></param> /// <returns></returns> public DataSet LoadImportData(IWin32Window parent, MB.WinBase.IFace.IClientRule buiObj, string xmlFileName, string importFile) { try { MB.WinBase.IFace.IForm iForm = parent as MB.WinBase.IFace.IForm; if (iForm != null) { _ClientRuleObject = iForm.ClientRuleObject; } var colPropertys = MB.WinBase.LayoutXmlConfigHelper.Instance.GetColumnPropertys(xmlFileName); var editCols = MB.WinBase.LayoutXmlConfigHelper.Instance.GetColumnEdits(colPropertys, xmlFileName); DataSet dsData = createNULLDataByFieldPropertys(colPropertys); if (importFile.EndsWith(".txt")) { MB.WinEIDrive.Import.TxtImport txtImport = new MB.WinEIDrive.Import.TxtImport(dsData, importFile); ImportEngine helper = new ImportEngine(editCols, grdCtlMain, txtImport); helper.Commit(); } else { if (ExistsRegedit() > 0) { MB.WinEIDrive.Import.OfficeXlsImport xlsImport = new WinEIDrive.Import.OfficeXlsImport(dsData, importFile); ImportEngine helper = new ImportEngine(editCols, grdCtlMain, xlsImport); helper.Commit(); } else { MB.WinEIDrive.Import.XlsImport xlsImport = new MB.WinEIDrive.Import.XlsImport(dsData, importFile); ImportEngine helper = new ImportEngine(editCols, grdCtlMain, xlsImport); helper.Commit(); } } //移除空行数据 MB.Util.DataValidated.Instance.RemoveNULLRowData(dsData); _ColPropertys = colPropertys; _EditCols = editCols; _CurrentImportData = dsData; _XmlFileName = xmlFileName; return(_CurrentImportData); } catch (MB.Util.APPException aEx) { throw aEx; } catch (Exception ex) { throw new MB.Util.APPException("数据导入处理有误。", MB.Util.APPMessageType.SysFileInfo, ex); } }
//数据导入处理相关... private void dataImport() { string file = MB.WinBase.ShareLib.Instance.SelectedFile("Excel 文件 (*.xls)|*.xls"); if (string.IsNullOrEmpty(file)) { return; } DataSet dsData = new DataSet(); dsData.Tables.Add(_DtSource.Clone()); foreach (DataColumn dc in dsData.Tables[0].Columns) { var eCol = getGridColumnByFieldName(gridViewMain, dc.ColumnName); if (eCol == null) { continue; } dc.Caption = eCol.Caption; } MB.WinEIDrive.Import.XlsImport xlsImport = new MB.WinEIDrive.Import.XlsImport(dsData, file); ImportEngine helper = new ImportEngine(_EditCols, grdCtlMain, xlsImport); helper.Commit(); //移除空行数据 MB.Util.DataValidated.Instance.RemoveNULLRowData(dsData); var arg = new QuickInputDataImportEventArgs(_DtSource, dsData); OnBeforeDataImport(arg); if (!arg.Handled) { dataImportByOveride(dsData); } }