Int32 load(String fileName) { DataTable dtTemp = new DataTable(); mcontrolItems.Clear(); String printInfo = "binding control... ..."; ConsoleU.writeLine(printInfo, ConsoleU.Level.Warning); DataSet ds = new DataSet(); String fileExtension = System.IO.Path.GetExtension(fileName); if (fileExtension != ".xml" || !System.IO.File.Exists(fileName)) { ConsoleU.writeLine("this file is not xml or path error,please select again!", ConsoleU.Level.Warning); } ds.ReadXml(fileName); dtTemp = ds.Tables[gf_main.DIRCTRL]; DataSet dsEvent = new DataSet();//load xml about event DataSet dsEvent.ReadXml(fileName); if (dtTemp == null) { printInfo = "Cannot find node,please try again..."; ConsoleU.writeLine(printInfo, ConsoleU.Level.Warning); return(-1); } if (dtTemp.Rows == null) { printInfo = "Cannot find node rows,please try again..."; ConsoleU.writeLine(printInfo, ConsoleU.Level.Warning); return(-1); } foreach (DataRow row in dtTemp.Rows) { cc_control ctrl = new cc_control(); try { ctrl.Ctr_Text = row[gf_main.CTRLTEXT].ToString(); } catch (FormatException) { } try { ctrl.Ctr_X = Int32.Parse(row[gf_main.CTRLX].ToString()); } catch (FormatException) { } try { ctrl.Ctr_Y = Int32.Parse(row[gf_main.CTRLY].ToString()); } catch (FormatException) { } try { ctrl.Ctr_Width = Int32.Parse(row[gf_main.CTRLWIDTH].ToString()); } catch (FormatException) { } try { ctrl.Ctr_Height = Int32.Parse(row[gf_main.CTRLHEIGHT].ToString()); } catch (FormatException) { } try { ctrl.Ctr_Type = row[gf_main.CTRLTYPE].ToString(); } catch (FormatException) { } DataRelationCollection childRelations = dtTemp.ChildRelations;//relationship building if (childRelations.Count > 0) { DataRelation relation = childRelations[String.Format("{0}_{1}", gf_main.DIRCTRL, gf_main.DIREVENT)]; DataRow[] ruleRows = row.GetChildRows(relation); foreach (DataRow ruleRow in ruleRows) { ctrl.mevent.addEvent(ruleRow, dsEvent.Tables[gf_main.DIREVENT]);//init ion controls event } } mcontrolItems.Add(ctrl); } #if ctrlPrintf ConsoleU.writeLine(String.Format("control loaded. . {0}", ctrlCount), ConsoleU.Level.Normal); #endif return(0); }
Int32 load(String fileName) { DataTable dtTemp = new DataTable(); mcontrolItems.Clear(); String printInfo = "binding control... ..."; ConsoleU.writeLine(printInfo, ConsoleU.Level.Warning); DataSet ds = new DataSet(); String fileExtension = System.IO.Path.GetExtension(fileName); if (fileExtension != ".xml" || !System.IO.File.Exists(fileName)) { ConsoleU.writeLine("this file is not xml or path error,please select again!", ConsoleU.Level.Warning); } ds.ReadXml(fileName); dtTemp = ds.Tables[gf_main.DIRCTRL]; DataSet dsEvent = new DataSet();//load xml about event DataSet dsEvent.ReadXml(fileName); if (dtTemp == null) { printInfo = "Cannot find node,please try again..."; ConsoleU.writeLine(printInfo, ConsoleU.Level.Warning); return -1; } if (dtTemp.Rows == null) { printInfo = "Cannot find node rows,please try again..."; ConsoleU.writeLine(printInfo, ConsoleU.Level.Warning); return -1; } foreach (DataRow row in dtTemp.Rows) { cc_control ctrl = new cc_control(); try { ctrl.Ctr_Text = row[gf_main.CTRLTEXT].ToString(); } catch (FormatException) { } try { ctrl.Ctr_X = Int32.Parse(row[gf_main.CTRLX].ToString()); } catch (FormatException) { } try { ctrl.Ctr_Y = Int32.Parse(row[gf_main.CTRLY].ToString()); } catch (FormatException) { } try { ctrl.Ctr_Width = Int32.Parse(row[gf_main.CTRLWIDTH].ToString()); } catch (FormatException) { } try { ctrl.Ctr_Height = Int32.Parse(row[gf_main.CTRLHEIGHT].ToString()); } catch (FormatException) { } try { ctrl.Ctr_Type = row[gf_main.CTRLTYPE].ToString(); } catch (FormatException) { } DataRelationCollection childRelations = dtTemp.ChildRelations;//relationship building if (childRelations.Count > 0) { DataRelation relation = childRelations[String.Format("{0}_{1}", gf_main.DIRCTRL, gf_main.DIREVENT)]; DataRow[] ruleRows = row.GetChildRows(relation); foreach (DataRow ruleRow in ruleRows) { ctrl.mevent.addEvent(ruleRow, dsEvent.Tables[gf_main.DIREVENT]);//init ion controls event } } mcontrolItems.Add(ctrl); } #if ctrlPrintf ConsoleU.writeLine(String.Format("control loaded. . {0}", ctrlCount), ConsoleU.Level.Normal); #endif return 0; }