public DataSet Import(string path, DataStandardDef standard) { try { string domainName = Path.GetFileNameWithoutExtension(path); DomainDef domain = standard.DomainContainer.Find(x => x.Code == domainName); DataSet ds = new DataSet(domainName); IWorkbook wb = ReadWorkbook(path); List <string> sheetNames = GetSheetNames(wb); //sheetNames equal to objectName foreach (string sheetName in sheetNames) { DGObjectDef objectDef = domain.DGObjectContainer.Find(x => x.Code == sheetName); DataTable dt = ReadSheet(wb.GetSheet(sheetName), objectDef); ds.Tables.Add(dt); } return(ds); } catch (Exception) { return(null); } }
/// <summary> /// just for test /// </summary> /// <returns></returns> public DataStandardDef GetSample() { //定义隧道数据标准和地质域 DataStandardDef dsDef = new DataStandardDef() { Code = "TunnelStandard", Description = "This a Tunnel DataStandard", }; DomainDef ddDef = new DomainDef() { Code = "Geology", Desciption = "This a Geology Domain", }; dsDef.DomainContainer.Add(ddDef); //定义地质域内的数据结构 DGObjectDef dgDef = new DGObjectDef() { Code = "Borehole", Desctiption = "This a Borehole DGObject" }; ddDef.DGObjectContainer.Add(dgDef); //定义钻孔中的属性内容 dgDef.PropertyContainer.Add(new PropertyMeta("ID", "Int", null, "这是编号字段", "['zh':'编号','en':'ID']", IsKey: true, regularExpression: @"\d")); dgDef.PropertyContainer.Add(new PropertyMeta("BoreholeID", "string", null, "这是钻孔编号", "['zh':'钻孔编号','en':'BoreholeID']", true, regularExpression: @"")); dgDef.PropertyContainer.Add(new PropertyMeta("BoreholeTime", "dateTime", null, "这是钻孔时间", "['zh':'钻孔时间','en':'BoreholeTime']", true)); dgDef.PropertyContainer.Add(new PropertyMeta("BoreholeDepth", "double", "m", "这是钻孔深度", "['zh':'钻孔深度','en':'BoreholeDepth']", true)); return(dsDef); }
public void Data2DB(DataSet dataSet, DataStandardDef standardDef) { try { string domainName = dataSet.DataSetName; DomainDef domain = standardDef.DomainContainer.Find(x => x.Code == domainName); if (domain != null) { // get current assembly(程序集) //Assembly assembly = Assembly.GetExecutingAssembly(); //create Entity for specific domain //dynamic db = assembly.CreateInstance("iS3_DataManager.DataManager." + domainName + "DB_EF"); GeologyDB_EF db = new GeologyDB_EF(); foreach (DataTable table in dataSet.Tables) { DGObjectDef objectDef = domain.DGObjectContainer.Find(x => x.Code == table.TableName); Insert(db, objectDef, table); } } System.Windows.MessageBox.Show("数据导入成功"); } catch (Exception e) { System.Windows.MessageBox.Show(e.Message); } }
IWorkbook ReadWorkbook(string path) { try { var fullPath = Directory.GetFiles(path, "*.xlsx"); if (fullPath.Equals(null)) { fullPath = Directory.GetFiles(path, "*.xls"); } path = fullPath.Length == 0 ? (AppDomain.CurrentDomain.BaseDirectory + @"Standard\RockTunnel.xlsx") : fullPath[0]; this.standardDef = new DataStandardDef { Code = Path.GetFileNameWithoutExtension(path) }; FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); if (path.IndexOf(".xlsx") > 0) // for excel version over 2007 { return(new XSSFWorkbook(fs)); } else if (path.IndexOf(".xls") > 0) //for excel version 97-03 { return(new HSSFWorkbook(fs)); } } catch (Exception e) { System.Windows.MessageBox.Show(e.Message); return(null); } return(null); }
/// <summary> /// /// </summary> /// <param name="path"></param> /// <returns></returns> public DataStandardDef readJson(string path) { var fullPath = Directory.GetFiles(path, "*.txt"); if (!(fullPath[0] == null)) { FileStream fs = new FileStream(fullPath[0], FileMode.Open, FileAccess.Read); int n = (int)fs.Length; byte[] b = new byte[n]; int r = fs.Read(b, 0, n); string json = Encoding.Default.GetString(b, 0, n); DataStandardDef standard = JsonConvert.DeserializeObject <DataStandardDef>(json); return(standard); } else { // if (true) { int a, b; a = 1; b = 1; a = b; return(null); } } }
public bool Export(DataStandardDef standard, string path = null) { this.standard = standard; if (path == null) { } else { this.path = path; } return(Export()); }
public bool CreatTable(DataStandardDef standardDef) { SqlConnection connection = new SqlConnection(connectionString); foreach (DomainDef domain in standardDef.DomainContainer) { foreach (DGObjectDef item in domain.DGObjectContainer) { string sql_create = "CREATE TABLE " + item.Code + "("; } } return(false); }
public void GenerateClass(DataStandardDef standardDef) { try { foreach (DomainDef domain in standardDef.DomainContainer) { GenerateClass(domain); } } catch (Exception e) { System.Windows.MessageBox.Show(e.ToString()); } }
public List <DataSet> Import(DataStandardDef standard) { List <DataSet> domainContainer = null; OpenFileDialog ofd = new OpenFileDialog { Multiselect = true }; if (ofd.ShowDialog() == true) { foreach (string path in ofd.FileNames) { domainContainer.Add(Import(path, standard)); } } return(domainContainer); }
public void Data2DB(DataSet ds, DataStandardDef standardDef) { try { string domainName = ds.DataSetName; DomainDef domain = standardDef.DomainContainer.Find(x => x.Code == domainName); if (domain != null) { foreach (DataTable table in ds.Tables) { DGObjectDef objectDef = domain.DGObjectContainer.Find(x => x.Code == table.TableName); Insert(objectDef, table); } System.Windows.MessageBox.Show("数据导入成功"); } } catch (Exception e) { System.Windows.MessageBox.Show(e.ToString()); } }
public bool Export(DataStandardDef dataStandard, string path = null) { try { string json = JsonConvert.SerializeObject(dataStandard); if (path == null) { path = AppDomain.CurrentDomain.BaseDirectory + "Standard\\" + dataStandard.Code + ".json"; } FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.Write(json); sw.Flush(); sw.Close(); fs.Close(); return(true); } catch (Exception) { return(false); } }
/// <summary> /// export standard to excel for data input /// </summary> /// <param name="standard"></param> /// <param name="path">the path where excel will generate at</param> /// <returns></returns> public bool Export(DataStandardDef standard, string path = null) { this.standard = standard; if (path != null) { this.path = path; } try { foreach (DomainDef domain in standard.DomainContainer) { this.domain = domain; Export(); } } catch (Exception e) { System.Windows.MessageBox.Show(e.Message); return(false); } return(true); }
private void MainWindow_Loaded(object sender, RoutedEventArgs e) { //step1: find the aim object def string aimDGObjectType = "Borehole"; //load standard IDSImporter importer = new StandardImport_Exl(); DataStandardDef standard = importer.Import(null); //StandardLoader loader = new StandardLoader(); //DataStandardDef standard = loader.getStandard(null); // excel templete for data input IDataExporter dexporter = new DataExporter_Excel(); dexporter.Export(standard); //generate data model according standard(write cs file ,need to be added manually) //ClassGenerator classGenerator = new ClassGenerator(); //classGenerator.GenerateClass(standard); ////IDSExporter dsexporter = new Exporter_For_JSON();//export data standard //DGObjectDef aimDGObjectDef = standard.getDGObjectDefByCode(aimDGObjectType); //Import Data from excel IDataImporter dimporter = new DataImporter_Excel(); string path = @"C:\Users\litao\Desktop\Geology.xls"; DataSet ds = dimporter.Import(path, standard); DataChecker checker = new DataChecker(ds, standard); checker.Check(); //store data to database IDataBaseManager dataManager = new DataBaseManager_EF(); dataManager.Data2DB(ds, standard); //step8 : exporter the data }
private void MainWindow_Loaded(object sender, RoutedEventArgs e) { //step1 : find the aim object def string aimDGObjectType = "Borehole"; StandardLoader loader = new StandardLoader();//get standard from local json file in debug catagory //IDSImporter idsImporter = null; //DataStandardDef def = idsImporter.Import(null); DataStandardDef standard = loader.getStandard(); IDSExporter exporter = new Exporter_For_JSON(); exporter.Export(standard, AppDomain.CurrentDomain.BaseDirectory);//输出 DGObjectDef aimDGObjectDef = standard.getDGObjectDefByCode(aimDGObjectType); //step2 : create a instance of dataSchema for data importer DataSchema dataSchema = new DataSchema(); //step3 : choose the type of data source and convert to the commonDataFormat dataSchema.dataFormatConverter = null; CommonDataFormat rawCDF = dataSchema.dataFormatConverter.Convert(null); //setp4 : choose the mapping rule between the commonDataFormat and aimDGObjectDef dataSchema.dataPropertyMapping = new CommonPropertyMapping(); CommonDataFormat mappingCDF = dataSchema.dataPropertyMapping.Mapping(rawCDF); //step5 : verify the data dataSchema.dataVerification = new CommonDataVerification(); CommonDataFormat verificationCDF = dataSchema.dataVerification.Verification(mappingCDF); //step6 : set the data access frequency, such as one time access, access at a time, realtime access ,push access //------- //setp7 : save the data //step8 : exporter the data }
public bool Export(DataStandardDef dataStandard, string path) { return(true); }
public DataChecker(DataSet set, DataStandardDef standard) { dataSet = set; standardDef = standard; }
public DataChecker(DataTable table, DataStandardDef standard) { dataTable = table; standardDef = standard; }
public string write2Json(DataStandardDef dataStandard, string path) { string json = JsonConvert.SerializeObject(dataStandard); return(json); }
public bool Export(DataStandardDef dataStandard, string path) { return(write2Json(dataStandard, path).Equals(null)); }