public DataSet Import(string path, StandardDef standard) { try { string domainName = Path.GetFileNameWithoutExtension(path); DomainDef domain = standard.DomainContainer.Find(x => x.Code == domainName | x.LangStr == 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 = standard.GetDGObjectDefByName(sheetName); DataTable dt = ReadSheet(wb.GetSheet(sheetName), objectDef); if (dt != null) { ds.Tables.Add(dt); } } return(ds); } catch (Exception) { System.Windows.MessageBox.Show("Check if the Standard adapt to data"); return(null); } }
private void GenerateNodes(Tunnel tunnel, StandardDef Standard) { List <TreeNode> nodes = new List <TreeNode>(); int index = 0; foreach (Stage stage in tunnel.Stages) { TreeNode stageTreeNode = new TreeNode() { NodeID = index++, Level = 1, Context = stage.LangStr, isExpanded = true }; foreach (Category category in stage.Categories) { TreeNode categoryTreeNode = new TreeNode() { NodeID = index++, Level = 2, Context = category.LangStr, isExpanded = true }; foreach (string obj in category.objList) { DGObjectDef dGObject = Standard.GetDGObjectDefByCode(obj); TreeNode objTreeNode = new TreeNode() { NodeID = index++, Level = 3, Context = dGObject.LangStr }; categoryTreeNode.ChildNodes.Add(objTreeNode); } stageTreeNode.ChildNodes.Add(categoryTreeNode); } nodes.Add(stageTreeNode); } TreeNodes = nodes; }
IWorkbook ReadWorkbook(string path) { try { this.standardDef = new StandardDef { 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); throw e; } return(null); }
public void Data2DataBase(DataSet dataSet, StandardDef standard) { try { foreach (DataTable table in dataSet.Tables) { DGObjectDef dGObject = standard.GetDGObjectDefByName(table.TableName); string typeName = "iS3_DataManager.ObjectModels." + dGObject.Code; Type type = Type.GetType(typeName); var properties = type.GetProperties(); int count = properties.Length; foreach (DataRow row in table.Rows) { object[] project = new object[35]; int index = 0; foreach (PropertyMeta meta in dGObject.PropertyContainer) { project[index++] = row[meta.LangStr]; } var instance = Activator.CreateInstance(type, project); } } } catch (Exception x) { throw x; } }
/// <summary> /// just for test /// </summary> /// <returns></returns> public StandardDef GetSample() { //定义隧道数据标准和地质域 StandardDef dsDef = new StandardDef() { 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 bool Export(StandardDef dataStandard, string path = null) { try { string json = JsonConvert.SerializeObject(dataStandard); if (path == null) { DirectoryInfo localPath = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory); path = localPath.Parent.Parent.FullName + "\\Standard\\" + dataStandard.Code + ".json"; } FileInfo fInfo = new FileInfo(path); fInfo.Attributes = FileAttributes.Normal; FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(fs, Encoding.UTF8); sw.Write(json); sw.Flush(); sw.Close(); fs.Close(); // Set the IsReadOnly property. fInfo.Attributes = fInfo.Attributes | FileAttributes.ReadOnly | FileAttributes.Hidden; return(true); } catch (Exception) { return(false); } }
public DataSet Import(string path, StandardDef standard) { //try //{ string domainName = Path.GetFileNameWithoutExtension(path); // StageDef domain = standard.StageContainer.Find(x => x.Code == domainName | x.LangStr == domainName); DataSet ds = new DataSet() { DataSetName = domainName }; try { IWorkbook wb = ReadWorkbook(path); List <string> sheetNames = GetSheetNames(wb); //sheetNames equal to objectName foreach (string sheetName in sheetNames) { DGObjectDef objectDef = standard.GetDGObjectDefByName(sheetName); DataTable dt = ReadSheet(wb.GetSheet(sheetName), objectDef); if (dt != null) { ds.Tables.Add(dt); } } return(ds); } catch (Exception ex) { return(null); } }
public List <DataSet> Import(List <string> paths, StandardDef standard) { List <DataSet> dataSetContainer = new List <DataSet>(); foreach (string path in paths) { dataSetContainer.Add(Import(path, standard)); } return(dataSetContainer); }
void LoadStandard() { try { IDSImporter importer = new StandardImport_Exl(); LYTunnelStandard = importer.Import("LYTunnel"); } catch (Exception e) { MessageBox.Show(e.Message); } }
public TreeViewData(Tunnel tunnel, StandardDef Standard) { if (Standard.Code == "Geology") { GenerateNodes(tunnel, Standard); } else { GenerateNodes(Standard); } treeNodes = TreeNodes; }
public void GenerateClass(StandardDef standardDef) { //try //{ this.standard = standardDef; foreach (DomainDef domain in standardDef.DomainContainer) { GenerateClass(domain); } //} //catch (Exception e) //{ // System.Windows.MessageBox.Show(e.ToString()); //} }
private void Filter2Standard(Category category, ref StandardDef standardDef, StandardDef dataStandard) { DomainDef domain = new DomainDef() { Code = category.CategoryName, LangStr = category.LangStr }; foreach (string obj in category.objList) { DGObjectDef objectDef = dataStandard.GetDGObjectDefByCode(obj); domain.DGObjectContainer.Add(objectDef); } standardDef.DomainContainer.Add(domain); }
public void GenerateClass(StandardDef standardDef) { try { this.standard = standardDef; foreach (StageDef domain in standardDef.StageContainer) { GenerateClass(domain); } } catch (Exception e) { System.Windows.MessageBox.Show(e.ToString()); } }
public List <DataSet> Import(StandardDef 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); }
/// <summary> /// /// </summary> /// <param name="path"></param> /// <returns></returns> public StandardDef ReadJson(string path) { if (path != null) { FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); StreamReader streamReader = new StreamReader(fs, Encoding.UTF8); string json = streamReader.ReadToEnd(); fs.Close(); streamReader.Close(); StandardDef standard = JsonConvert.DeserializeObject <StandardDef>(json); return(standard); } else { return(null); } }
/// <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(StandardDef standard, string path = null) { this.standard = standard; this.path = path ?? this.path; try { foreach (StageDef domain in standard.StageContainer) { this.domain = domain; Export(); } } catch (Exception e) { System.Windows.MessageBox.Show(e.Message); return(false); } return(true); }
public bool Export(StandardDef standard, string path = null) { this.standard = standard; if (path == null) { } else { this.path = path; } bool succeed = Export(); if (succeed) { System.Windows.MessageBox.Show("The Exl templete generated successfully at Destop!"); } else { System.Windows.MessageBox.Show("Someting getting wrong during generating,Please try again!"); } return(succeed); }
private void GenerateNodes(StandardDef standardDef) { List <TreeNode> nodes = new List <TreeNode>(); int index = 0; if (standardDef == null) { return; } foreach (StageDef domain in standardDef.StageContainer) { TreeNode stageTreeNode = new TreeNode() { NodeID = index++, Level = 1, Code = domain.Code, Context = domain.LangStr, isExpanded = true, isSelected = false }; foreach (DGObjectDef dG in domain.DGObjectContainer) { TreeNode categoryTreeNode = new TreeNode() { NodeID = index++, Level = 2, Code = dG.Code, Context = dG.LangStr, Parent = domain.Code, isExpanded = false, isSelected = false }; stageTreeNode.ChildNodes.Add(categoryTreeNode); } nodes.Add(stageTreeNode); } TreeNodes = nodes; }
private void GenerateNodes(StandardDef standardDef) { List <TreeNode> nodes = new List <TreeNode>(); int index = 0; foreach (DomainDef domain in standardDef.DomainContainer) { TreeNode stageTreeNode = new TreeNode() { NodeID = index++, Level = 1, Context = domain.LangStr, isExpanded = true }; foreach (DGObjectDef dG in domain.DGObjectContainer) { TreeNode categoryTreeNode = new TreeNode() { NodeID = index++, Level = 2, Context = dG.LangStr, isExpanded = true }; stageTreeNode.ChildNodes.Add(categoryTreeNode); } nodes.Add(stageTreeNode); } TreeNodes = nodes; }
public StandardDef LoadAllStandard(List <string> standardNameList) { if (standardNameList.Count < 1) { standardNameList = new List <string>(); standardNameList.Add("Geology"); standardNameList.Add("Structure"); standardNameList.Add("Environment"); } StandardDef tmpStandard = new StandardDef() { Code = "Standard", Description = "StandardforAll", LangStr = "数据标准" }; foreach (string standardName in standardNameList) { foreach (StageDef stage in GetStandard(standardName).StageContainer) { tmpStandard.StageContainer.Add(stage); } } return(tmpStandard); }
public DataChecker(DataTable table, StandardDef standard) { dataTable = table; standardDef = standard; }
/// <summary> /// generate New DateStandard by filter conditon /// </summary> /// <param name="dataStandard">Common DataStand with all items in it </param> /// <param name="tunnelType">tunnel type in Chinese </param> /// <param name="constructionStage"></param> /// <param name="categoryName"></param> /// <returns></returns> public StandardDef Filter(StandardDef dataStandard, string tunnelType = null, string constructionStage = null, string categoryName = null) { try { if (tunnelType != null) { Tunnel tunnel = Tunnels.Find(x => x.LangStr == tunnelType); StandardDef newStandard = new StandardDef() { Code = tunnel.TunnelType, LangStr = tunnel.LangStr }; if (constructionStage != null) { Stage stage = tunnel.Stages.Find(x => x.LangStr == constructionStage); if (categoryName != null) { Category category = stage.Categories.Find(x => x.LangStr == categoryName); Filter2Standard(category, ref newStandard, dataStandard); } else { foreach (var item in stage.Categories) { Filter2Standard(item, ref newStandard, dataStandard); } } return(newStandard); } else { foreach (Stage stage in tunnel.Stages) { foreach (Category category in stage.Categories) { Filter2Standard(category, ref newStandard, dataStandard); } } return(newStandard); } } else { StandardDef newStandard = new StandardDef() { Code = dataStandard.Code, LangStr = dataStandard.LangStr }; foreach (Tunnel tunnel in Tunnels) { foreach (Stage stage in tunnel.Stages) { foreach (Category category in stage.Categories) { Filter2Standard(category, ref newStandard, dataStandard); } } } return(newStandard); } } catch (Exception e) { throw e; } }
public DataChecker(DataSet set, StandardDef standard) { dataSet = set; standardDef = standard; }
public TreeViewData(StandardDef Standard) { GenerateNodes(Standard); treeNodes = TreeNodes; }
public DataLoader(StandardDef standard) { this.standard = standard; }