/// <summary> /// 将字符串转换成数据 /// </summary> /// <param name="value">数据</param> public void SetData(string value) { string[] lines = value.Split(dataLineSplit, StringSplitOptions.RemoveEmptyEntries); foreach (string line in lines) { string[] datas = line.Split(dataValueSplit, StringSplitOptions.RemoveEmptyEntries); if (datas.Length == 2) { switch (datas[0]) { case "id": int.TryParse(datas[1].Trim(), out id); break; case "name": name = datas[1].Trim(); break; case "time": int.TryParse(datas[1].Trim(), out time); break; case "level": int.TryParse(datas[1].Trim(), out level); break; case "synthesisType": try { synthesisType = (EnumSynthesisType)Enum.Parse(typeof(EnumSynthesisType), datas[1].Trim()); } catch { } break; case "synthesisItem": try { synthesisItem = (EnumSynthesisItem)Enum.Parse(typeof(EnumSynthesisItem), datas[1].Trim()); } catch { } break; case "inputStruct": int[][] arrayValues = GetNextStringSplit(datas[1].Trim()); inputStruct = new SynthesisItemStruct[arrayValues.GetLength(0)]; for (int i = 0; i < inputStruct.Length; i++) { inputStruct[i] = new SynthesisItemStruct(); inputStruct[i].SetData(datas[1].Substring(arrayValues[i][0], arrayValues[i][1])); } break; case "outputStruct": outputStruct = new SynthesisItemStruct(); outputStruct.SetData(datas[1].Trim()); break; } } } }
/// <summary> /// 添加节点 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 添加节点ToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode selectNode = TreeView_Main.SelectedNode; if (selectNode != null) { Stack <TreeNode> treeNodeStack = new Stack <TreeNode>(); Action <TreeNode> selectParentAction = null; selectParentAction = (thisNode) => { treeNodeStack.Push(thisNode); if (thisNode.Parent != null) { selectParentAction(thisNode.Parent); } }; selectParentAction(selectNode); if (treeNodeStack.Count >= 2) { TreeNode synthesisTypeNode = treeNodeStack.Pop(); TreeNode synthesisItemNode = treeNodeStack.Pop(); EnumSynthesisType synthesisType = (EnumSynthesisType)Enum.Parse(typeof(EnumSynthesisType), synthesisTypeNode.Tag.ToString()); EnumSynthesisItem synthesisItem = (EnumSynthesisItem)Enum.Parse(typeof(EnumSynthesisItem), synthesisItemNode.Tag.ToString()); int id = startID++; SynthesisDataStruct synthesisDataStruct = new SynthesisDataStruct(); synthesisDataStruct.id = id; synthesisDataStruct.name = ""; synthesisDataStruct.time = 1; synthesisDataStruct.synthesisType = synthesisType; synthesisDataStruct.synthesisItem = synthesisItem; synthesisDataStruct.inputStruct = new SynthesisDataStruct.SynthesisItemStruct[0]; synthesisDataAnalysis.AddSynthesisDataStruct(synthesisDataStruct); TreeNode treeNode = new TreeNode(); treeNode.Name = id.ToString(); treeNode.Tag = synthesisDataStruct; treeNode.Text = synthesisDataStruct.ToStringSimple(); synthesisItemNode.Nodes.Add(treeNode); } } }