Пример #1
0
 /// <summary>
 /// 获取输入面板数据至模型
 /// </summary>
 private void InputToModel(TemplateFillModel model)
 {
     foreach (Control control in pInput.Controls)
     {
         if (control is TextBox)
         {
             if (control.Tag is ElementType)
             {
                 var tag = (ElementType)control.Tag;
                 if (control.Text.Trim() == "")
                 {
                     model.ElementData.Remove(tag);
                 }
                 else
                 {
                     if (model.ElementData.ContainsKey(tag))
                     {
                         model.ElementData[tag] = control.Text;
                     }
                     else
                     {
                         model.ElementData.Add(tag, control.Text);
                     }
                 }
             }
             else if (control.Tag is string)
             {
                 model.Name = control.Text;
             }
         }
     }
 }
Пример #2
0
 /// <summary>
 /// 获取模型数据至输入面板
 /// </summary>
 private void ModelToInput(TemplateFillModel model)
 {
     pInput.Controls.Find(FillNameString, false)[0].Text = model.Name;
     foreach (var i in model.ElementData)
     {
         Control[] control = pInput.Controls.Find(i.Key.ToString(), false);
         if (control.Length >= 1)
         {
             control[0].Text = i.Value;
         }
     }
 }
Пример #3
0
        /// <summary>
        /// 设置状态
        /// </summary>
        private void SetState(string text)
        {
            switch (text)
            {
            case StateText.新建:
                lbList.SelectedIndex = -1;
                ClearInput();
                break;

            case StateText.克隆:
                lbList.SelectedIndex = -1;
                break;

            case StateText.编辑:
                ClearInput();
                ModelToInput(Core.Program.Config.TemplateFillList[lbList.SelectedIndex]);
                goto case "编辑_状态文本";

            case StateText.编辑_已保存:
                TemplateFillModel model = null;
                if (lbList.SelectedIndex == -1)
                {
                    model = new TemplateFillModel();
                    Core.Program.Config.TemplateFillList.Add(model);
                }
                else
                {
                    model = Core.Program.Config.TemplateFillList[lbList.SelectedIndex];
                }
                InputToModel(model);
                Core.Program.Config.TemplateFillList.Sort();
                Core.Program.SaveConfig();
                RefreshList();
                goto case "编辑_状态文本";

            case "编辑_状态文本":
                text = $"{text} [{lbList.SelectedIndex}] {Core.Program.Config.TemplateFillList[lbList.SelectedIndex].Name}";
                break;
            }
            lState.Text = text;
        }