/// <summary> /// 添加一个Item到Other选项卡 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Other_Add_Click(object sender, EventArgs e) { if (selectNode == null || string.IsNullOrEmpty(projectFilePath)) { return; } AddOtherAttributeForm addOtherAttributeForm = new AddOtherAttributeForm(); DialogResult dr = addOtherAttributeForm.ShowDialog(); if (dr == DialogResult.OK) { AutoItemControl autoItemContorl = new AutoItemControl(); autoItemContorl.SkillAnalysisData = skillAnalysisData; TreeNode selectNode = TreeView_Skills.SelectedNode; if (selectNode != null) { try { string[] values = selectNode.Tag as string[]; autoItemContorl.Tag = values[0]; } catch { } } AutoItemControl.ItemStruct itemStruct = autoItemContorl.CreateItem(); itemStruct.Label = addOtherAttributeForm.attributeItemStruct.Label; itemStruct.Tag = addOtherAttributeForm.attributeItemStruct.Tag; itemStruct.ControlType = addOtherAttributeForm.attributeItemStruct.ControlType; itemStruct.TypeTag = addOtherAttributeForm.attributeItemStruct.TypeTag; itemStruct.IsArray = addOtherAttributeForm.attributeItemStruct.IsArray; itemStruct.ChildCount = addOtherAttributeForm.attributeItemStruct.ChildCount; itemStruct.ChildControlType = addOtherAttributeForm.attributeItemStruct.ChildControlType; autoItemContorl.Size = new Size(Panel_Other.Size.Width / 2 - 7, Panel_Other.Size.Height / 3); FlowLayoutPanel_Other.Controls.Add(autoItemContorl); autoItemContorl.UpdateItems(); autoItemContorl.IsChangedValue = true; if (skillAnalysisData != null && selectNode != null)//将本次设置的内容保存到OtherFieldSet字段中 { string[] tagValues = selectNode.Tag as string[]; if (tagValues != null && tagValues.Length > 0) { string[] oldOtherSettings = skillAnalysisData.GetValues <string>(tagValues[0], "OtherFieldSet"); if (oldOtherSettings == null) { oldOtherSettings = new string[0]; } string[] newOtherSettings = new string[oldOtherSettings.Length + 1]; Array.Copy(oldOtherSettings, newOtherSettings, oldOtherSettings.Length); string split = "***"; Func <object, string> FZFunc = (target) =>//封装[] { if (target == null) { return("[]"); } if (object.Equals(target.GetType(), typeof(Type))) { Type t = target as Type; return("[" + t.FullName + "]"); } return("[" + target.ToString() + "]"); }; string otherFieldSet = FZFunc(itemStruct.Label) + split + FZFunc(itemStruct.Tag) + split + FZFunc(itemStruct.ControlType) + split + FZFunc(itemStruct.TypeTag) + split + FZFunc(itemStruct.IsArray) + split + FZFunc(itemStruct.ChildCount) + split + FZFunc(itemStruct.ChildControlType); newOtherSettings[newOtherSettings.Length - 1] = otherFieldSet; skillAnalysisData.SetValues <string>(tagValues[0], "OtherFieldSet", newOtherSettings); } } //添加到下拉列表中 ComboBox_Other_Item.Items.Add(itemStruct.Tag); } }
/// <summary> /// 设置当前选中树节点应该显示的数据 /// </summary> private void SetSelectNodeShowData() { if (selectNode == null || string.IsNullOrEmpty(projectFilePath)) { return; } string id = selectNode.Name; FlowLayoutPanel_Other.Controls.Clear(); IEnumerable <TabPage> allTabPage = TabControl_Setting.TabPages.OfType <TabPage>(); EnumTypeComboBox[] enumTypeComboBoxs = allTabPage.Select(temp => temp.Controls.OfType <EnumTypeComboBox>()).Combine().ToArray(); foreach (EnumTypeComboBox enumTypeComboBox in enumTypeComboBoxs) { enumTypeComboBox.InitListenControl(); string fieldName = (string)enumTypeComboBox.Tag; if (!string.IsNullOrEmpty(fieldName)) { enumTypeComboBox.TextValue = skillAnalysisData.GetValue <string>(id, fieldName); } } TextBox[] textBoxs = allTabPage.Select(temp => temp.Controls.OfType <TextBox>()).Combine().ToArray(); foreach (TextBox textBox in textBoxs) { string fieldName = (string)textBox.Tag; if (!string.IsNullOrEmpty(fieldName)) { textBox.Text = skillAnalysisData.GetValue <string>(id, fieldName); } } AutoArrayControl[] autoArrayControls = allTabPage.Select(temp => temp.Controls.OfType <AutoArrayControl>()).Combine().ToArray(); foreach (AutoArrayControl autoArrayControl in autoArrayControls) { string fieldName = (string)autoArrayControl.Tag; if (!string.IsNullOrEmpty(fieldName)) { string[] getValues = skillAnalysisData.GetValues <string>(id, fieldName); string[] nowValues = autoArrayControl.TextValues; int index = 0; while (index < getValues.Length && index < nowValues.Length) { nowValues[index] = getValues[index]; index++; } autoArrayControl.TextValues = nowValues; } } TypeTextBox[] typeTextBoxs = allTabPage.Select(temp => temp.Controls.OfType <TypeTextBox>()).Combine().ToArray(); foreach (TypeTextBox typeTextBox in typeTextBoxs) { string fieldName = (string)typeTextBox.Tag; if (!string.IsNullOrEmpty(fieldName)) { typeTextBox.TextValue = skillAnalysisData.GetValue <string>(id, fieldName); } } AutoItemControl[] autoItemControls = allTabPage.Select(temp => temp.Controls.OfType <AutoItemControl>()).Combine().ToArray(); foreach (AutoItemControl autoItemControl in autoItemControls) { autoItemControl.UpdateItems(); } //处理技能属性(根据等级附加属性) AutoItemControl[] attributeSkillLevelControls = FlowLayoutPanel_Attribute.Controls.OfType <AutoItemControl>().ToArray(); foreach (AutoItemControl attributeSkillLevelControl in attributeSkillLevelControls) { attributeSkillLevelControl.SkillAnalysisData = skillAnalysisData; attributeSkillLevelControl.Tag = id; attributeSkillLevelControl.UpdateItems(true); } //处理其他属性 string[] oldOtherSettings = skillAnalysisData.GetValues <string>(id, "OtherFieldSet"); string[] otherSplit = new string[] { "***" }; ComboBox_Other_Item.Items.Clear(); Func <string, string> JCFZFunc = (target) => //解除封装 { if (target.Length < 2) { return(""); } target = target.Remove(0, 1); target = target.Remove(target.Length - 1, 1); return(target); }; foreach (string oldOtherSetting in oldOtherSettings) { string[] otherFieldSets = oldOtherSetting.Split(otherSplit, StringSplitOptions.RemoveEmptyEntries); if (otherFieldSets.Length == 7) { AutoItemControl autoItemContorl = new AutoItemControl(); autoItemContorl.SkillAnalysisData = skillAnalysisData; autoItemContorl.Tag = id; AutoItemControl.ItemStruct itemStruct = autoItemContorl.CreateItem(); itemStruct.Label = JCFZFunc(otherFieldSets[0]); itemStruct.Tag = JCFZFunc(otherFieldSets[1]); Type controlType = null; try { controlType = Type.GetType(JCFZFunc(otherFieldSets[2])); } catch { } itemStruct.ControlType = controlType; itemStruct.TypeTag = JCFZFunc(otherFieldSets[3]); bool isArray = false; try { isArray = bool.Parse(JCFZFunc(otherFieldSets[4])); } catch { } itemStruct.IsArray = isArray; int childCount = 0; try { childCount = int.Parse(JCFZFunc(otherFieldSets[5])); } catch { } itemStruct.ChildCount = childCount; itemStruct.ChildControlType = JCFZFunc(otherFieldSets[6]); autoItemContorl.Size = new Size(Panel_Other.Size.Width / 2 - 7, Panel_Other.Size.Height / 3); FlowLayoutPanel_Other.Controls.Add(autoItemContorl); autoItemContorl.UpdateItems(true); autoItemContorl.IsChangedValue = false; ComboBox_Other_Item.Items.Add(itemStruct.Tag); } } }