/// <summary> /// 为Recipe添加一个配置项 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btAddItem_Click(object sender, EventArgs e) { FormXCfgItemEdit fmGenItem = new FormXCfgItemEdit(); fmGenItem.SetItemAllowedTypes(new Type[] { typeof(int), typeof(double), typeof(string), typeof(bool), typeof(PointF), typeof(List <int>), typeof(List <double>), typeof(List <string>), typeof(List <bool>), typeof(List <PointF>) }); if (DialogResult.OK == fmGenItem.ShowDialog()) { string[] allItemNames = _recipe.AllItemNames(); if (null != allItemNames && allItemNames.Contains(fmGenItem.GetItemName())) { MessageBox.Show("添加数据项失败,已包含数据项:" + fmGenItem.GetItemName()); return; } _recipe.AddItem(fmGenItem.GetItemName(), fmGenItem.GetItemValue()); UcJFParamEdit pe = new UcJFParamEdit(); //if (fmGenItem.GetItemType().IsPrimitive) pe.Height = 23; pe.Width = 500; pe.IsHelpVisible = false; pe.SetParamDesribe(JFParamDescribe.Create(fmGenItem.GetItemName(), fmGenItem.GetItemType(), JFValueLimit.NonLimit, null)); //pe.SetParamType(fmGenItem.GetItemType()); pe.SetParamValue(fmGenItem.GetItemValue()); pe.IsValueReadOnly = false; //添加后状态为可编辑 tableLayoutPanel1.Controls.Add(pe); Button btDel = new Button(); btDel.Text = "删除"; btDel.Tag = fmGenItem.GetItemName(); btDel.Click += OnDelButtonClick; tableLayoutPanel1.Controls.Add(btDel); _lstItems.Add(pe); _lstDeleteItemButtons.Add(btDel); } }
private void btAddItem_Click(object sender, EventArgs e) { if (null == _station) { return; } if (tabControlCF1.SelectedIndex < 0) { MessageBox.Show("请在右侧Tab栏选择数据项类别!"); return; } FormXCfgItemEdit fmAddItem = new FormXCfgItemEdit(); fmAddItem.SetItemAllowedTypes(AllowAddTypes.ToArray()); if (DialogResult.OK == fmAddItem.ShowDialog()) { string itemName = fmAddItem.GetItemName(); if (_station.Config.ContainsItem(itemName)) { MessageBox.Show("已包含同名配置项,不能重复添加"); return; } string itemTag = tabControlCF1.SelectedTab.Text; object itemVal = fmAddItem.GetItemValue(); _station.Config.AddItem(itemName, itemVal, itemTag); _station.Config.Save(); UpdateCurrPage(true); } }