예제 #1
0
파일: Chooser.cs 프로젝트: S031/MetaStack
        public static TKey Choose <TKey, TText>(IEnumerable <KeyValuePair <TKey, TText> > items, int selected)
        {
            WinFormItem selector = new WinFormItem("RadioGropPanel")
            {
                PresentationType = typeof(TableLayoutPanel),
                ControlTrigger   = (c, e) =>
                {
                    e.Dock = DockStyle.Fill;
                }
            };
            int i = 0;

            foreach (var item in items)
            {
                selector.Add(new WinFormItem($"P{i}")
                {
                    PresentationType = typeof(RadioButton),
                    ControlTrigger   = (cdi, ctrl) =>
                    {
                        RadioButton rb             = (ctrl as RadioButton);
                        rb.UseVisualStyleBackColor = true;
                        rb.Text        = item.Value.ToString();
                        rb.Tag         = item.Key;
                        rb.Dock        = DockStyle.Top;
                        rb.MouseClick += (c, e) => cdi
                                         .LinkedControl
                                         .FindForm()
                                         .DialogResult = System.Windows.Forms.DialogResult.OK;
                        rb.MouseMove += (c, e) => rb.Cursor = Cursors.Hand;
                        rb.TabIndex   = i;
                    }
                });
                i++;
            }

            using (WinForm cd = new BaseViewForm(selector))
            {
                cd.GetControl <RadioButton>($"P{selected}").Checked = true;
                Button btn = cd.GetControl <Button>("OK");
                cd.AcceptButton = btn;

                cd.StartPosition = FormStartPosition.CenterParent;
                if (cd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    cd.Save();
                    return((TKey)cd.Items
                           .Select(kvp => kvp.Value.LinkedControl as RadioButton)
                           .FirstOrDefault(rb => rb != null && rb.Checked).Tag);
                }
                else
                {
                    return(default);
예제 #2
0
        public DBGridParam(JMXSchema schema, DBGrid grid)
        {
            _grid = grid;
            int count = schema.Parameters.Count;
            List <WinFormItem> listItems = new List <WinFormItem>(count);

            foreach (var p in schema.Parameters)
            {
                WinFormItem item = new WinFormItem(p.ParamName)
                {
                    Caption          = p.Name,
                    DataType         = MdbTypeMap.GetType(p.DataType),
                    Width            = p.DisplayWidth,
                    DataSize         = p.Width,
                    Format           = p.Format,
                    SuperForm        = p.SuperForm,
                    SuperMethod      = p.SuperMethod,
                    ConstName        = p.ConstName,
                    PresentationType = Type.GetType(p.PresentationType),
                    Value            = p.DefaultValue
                };
                if (p.ListData.Count > 0)
                {
                    for (int i = 0; i < p.ListData.Count; i++)
                    {
                        item.Add(new WinFormItem(p.ListItems[i])
                        {
                            Caption  = p.ListItems[i],
                            DataType = item.DataType,
                            Value    = p.ListData[i]
                        });
                    }
                    item.Mask = "lock";
                }
                //!!! Добавить добавление констант в расширениях (class UserConstants.GetConst(), AddConst()
                switch (item.ConstName.ToLower())
                {
                case "bs_datecurrent":
                    item.Value = vbo.Date();
                    break;

                case "bs_datestart":
                    item.Value = rth.DateStart;
                    break;

                case "bs_datefinish":
                    item.Value = rth.DateFinish;
                    break;

                case "bs_username":
                    item.Value = PathHelper.UserName;
                    break;

                default:
                    if (item.ConstName.Left(1) == "=")
                    {
                        //!!! item.Value = Evaluator.Eval(item.ConstName.Substring(1), schema);
                    }
                    else
                    {
                        //!!!
                        //string localSetting = schema[path + "ConstName"];
                        //if (localSetting.IndexOf(vbo.chrSep) > -1)
                        //	localSetting = dbs.GetSetting(localSetting);
                        //else
                        //	localSetting = dbs.GetSetting(setPath + localSetting);
                        //if (string.IsNullOrEmpty(localSetting))
                        //	localSetting = dbs.GetSetting(schema["ObjectName"] + vbo.chrSep + "Setup" + vbo.chrSep +
                        //		schema[path + "ConstName"]);
                        //if (!string.IsNullOrEmpty(localSetting))
                        //	item.Value = localSetting;
                    }
                    break;
                }
                if (item.OriginalValue == null && _grid.ParentRow != null && !string.IsNullOrEmpty(p.FieldName))
                {
                    try
                    {
                        item.Value = _grid.ParentRow[p.FieldName];
                    }
                    finally
                    {
                        if (vbo.IsEmpty(item.Value))
                        {
                            item.Value = null;
                        }
                    }
                }
                if ((item.Visible = (vbo.IsEmpty(item.Value))) && _paramCash.ContainsKey(item.Name))
                {
                    item.Value = _paramCash[item.Name];
                }
                listItems.Add(item);
            }
            _items = listItems.ToArray();
        }
예제 #3
0
        public static object Add(this Control parent, WinFormItem winFormItem)
        {
            if (!winFormItem.Caption.IsEmpty())
            {
                Label l;
                if (winFormItem.CellAddress == WinFormItem.CellAddressDefault)
                {
                    l = parent.Add <Label>(new WinFormItem("Label_" + winFormItem.Name)
                    {
                        CellAddress = new Pair <int>(winFormItem.CellAddress.X, winFormItem.CellAddress.Y)
                    });
                    winFormItem.CellAddress = new Pair <int>(winFormItem.CellAddress.X + 1, winFormItem.CellAddress.Y);
                }
                else
                {
                    l = parent.Add <Label>(new WinFormItem("Label_" + winFormItem.Name));
                }
                l.Text = winFormItem.Caption;
            }
            if (winFormItem.PresentationType == null)
            {
                if (winFormItem.DataType == typeof(bool))
                {
                    winFormItem.PresentationType = typeof(CheckBox);
                    winFormItem.Clear();
                    winFormItem.Add(new WinFormItem("Да")
                    {
                        Value = true
                    });
                    winFormItem.Add(new WinFormItem("Нет")
                    {
                        Value = false
                    });
                    winFormItem.ControlTrigger = (i, c) =>
                    {
                        CheckBox chkBox = c as CheckBox;
                        chkBox.Text            = (bool)i.Value ? "Да" : "Нет";
                        chkBox.Checked         = (bool)i.Value;
                        chkBox.CheckedChanged += (ctrl, e) =>
                        {
                            CheckBox cb = (CheckBox)ctrl;
                            chkBox.Text = cb.Checked ? "Да" : "Нет";
                        };
                    };
                }
                else if (winFormItem.DataType == typeof(DateTime))
                {
                    winFormItem.PresentationType = typeof(DateEdit);
                }
                else if (!winFormItem.SuperForm.IsEmpty())
                {
                    winFormItem.PresentationType = typeof(TextBuX);
                }
            }
            if ((winFormItem.PresentationType == null || winFormItem.PresentationType.IsSubclassOf(typeof(ListBox))) &&
                winFormItem.Count() > 0 && winFormItem.SuperForm.IsEmpty() && IsSimpleType(winFormItem.DataType))
            {
                winFormItem.PresentationType = typeof(ComboBox);
                winFormItem.ControlTrigger   = (item, c) =>
                {
                    ComboBox cmb = c as ComboBox;
                    if (item.Mask.ToLower() == "lock")
                    {
                        cmb.DropDownStyle = ComboBoxStyle.DropDownList;
                    }
                    if (!string.IsNullOrEmpty(item.Format))
                    {
                        cmb.FormatString = item.Format;
                    }
                    cmb.Items.AddRange(item.ToArray());
                    cmb.DataSource = item.Select(wfi => wfi.Name).ToList();
                    cmb.DataBindings.Add("Text", item, "Value");

                    Type t = winFormItem.DataType;
                    if (t.IsNumeric())
                    {
                        var itemWithData = winFormItem.FirstOrDefault(d => d.Value.Equals(winFormItem.Value));
                        if (itemWithData != null)
                        {
                            cmb.Text = itemWithData.Caption;
                        }
                    }
                };
            }
            else if ((winFormItem.PresentationType == typeof(RadioGroup) && winFormItem.Count() > 0 &&
                      winFormItem.SuperForm.IsEmpty() && IsSimpleType(winFormItem.DataType)))
            {
                winFormItem.ControlTrigger = (i, c) =>
                {
                    RadioGroup rg = c as RadioGroup;
                    rg.Items.AddRange(i.Select(item => item.Name).ToArray());
                    if (rg.Items.Count > 2)
                    {
                        rg.Height = Math.Max(rg.Height, rg.Items.Count * rg.Font.Height * 2);
                    }
                    else
                    {
                        rg.Height = rg.Font.Height * 5;
                    }

                    if (winFormItem.Value != null)
                    {
                        rg.Text = winFormItem.Value.ToString();
                    }
                };
            }
            else if (winFormItem.PresentationType == null)
            {
                winFormItem.PresentationType = typeof(TextBox);
            }
            return(AddInternal(parent, winFormItem));
        }