/// <summary> /// 添加子条件 /// </summary> /// <param name="child"></param> /// <returns></returns> public bool AddChild(Precondition child) { if (this.child.Count() >= this.childCount) { return false; } this.child.Add(child); return true; }
public object Clone() { Precondition res = new Precondition(); res.name = (string)this.name.Clone(); res.type = (string)this.type.Clone(); res.childCount = this.childCount; res.isBase = this.isBase; if (this.child != null) { List<Precondition> childs = new List<Precondition>(); foreach (var children in this.child) { childs.Add((Precondition)children.Clone()); } res.child = childs; } return res; }
/// <summary> /// 确认按钮点击 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void sureButton_Click(object sender, EventArgs e) { string error = null; if (!this.checkDatas(ref error)) { MessageBox.Show(error,"错误", MessageBoxButtons.OK); return; } if (this.editPrecondition != null)//编辑 { Precondition tmpP = new Precondition(); tmpP.name = this.editPrecondition.name; tmpP.type = this.editPrecondition.type; this.editPrecondition.name = this.nameTextBox.Text.Trim(new char[] { '\n', ' ' }); this.editPrecondition.type = this.typeTextBox.Text.Trim(new char[] { '\n', ' ' }); this.editPrecondition.childCount = (int)this.numericUpDown1.Value; this.editPrecondition.isBase = this.isBasePCheckBox.Checked; if (this.editPrecondition.childCount > 0 && !this.isBasePCheckBox.Checked) { this.editPrecondition.child = new List<Precondition>(); if (this.editPrecondition.childCount >= 1) { Precondition child1 = this.childDatas[this.child1CheckedListBox.SelectedIndex]; this.editPrecondition.child.Add(child1); } if (this.editPrecondition.childCount >= 2) { Precondition child2 = this.childDatas[this.child2CheckedListBox.SelectedIndex]; this.editPrecondition.child.Add(child2); } } List<Precondition> parms = new List<Precondition>(); parms.Add(tmpP); parms.Add(this.editPrecondition); NotificationCenter.DefaultCenter().postNotification("PreconditionUpdate", parms); } else { Precondition newP = new Precondition(); newP.name = this.nameTextBox.Text.Trim(new char[]{'\n',' '}); newP.type = this.typeTextBox.Text.Trim(new char[] { '\n', ' ' }); newP.childCount = (int)this.numericUpDown1.Value; newP.isBase = this.isBasePCheckBox.Checked; if (newP.childCount > 0 && !this.isBasePCheckBox.Checked) { newP.child = new List<Precondition>(); if (newP.childCount >= 1) { Precondition child1 = this.childDatas[this.child1CheckedListBox.SelectedIndex]; newP.child.Add(child1); } if (newP.childCount >= 2) { Precondition child2 = this.childDatas[this.child2CheckedListBox.SelectedIndex]; newP.child.Add(child2); } } this.childPreconditions.Add(newP); } if (this.m_delegate != null) { this.m_delegate.RefreshPrecondition(); } this.Close(); }
/// <summary> /// 查找子条件在条件集合的下标 /// </summary> /// <param name="child"></param> /// <returns></returns> private int findIndexByChild(Precondition child) { int ret = -1; if (this.childDatas != null && this.childDatas.Count > 0) { foreach (var item in this.childDatas) { if (item.type == child.type && item.name == child.name) { ret = this.childDatas.IndexOf(item); break; } } } return ret; }