private void InitControl(NumericUpDown nud, Handbook handbook, string text)
 {
     try
     {
         string  defaultValue = handbook.GetDefaultValue();
         decimal min          = GetDecimal(handbook.minValue, nud.Minimum);
         decimal max          = GetDecimal(handbook.maxValue, nud.Maximum);
         decimal val          = GetDecimal(defaultValue, nud.Minimum);
         if (val < min)
         {
             val = min;
         }
         if (max < min)
         {
             max = min;
         }
         if (max < val)
         {
             max = val;
         }
         nud.Minimum       = min;
         nud.Maximum       = max;
         nud.Value         = val;
         nud.DecimalPlaces = handbook.decimalPlaces;
         nud.Text          = text;
     }
     catch (Exception ex)
     {
         Log.Exception(ex);
     }
 }
        Control AddRow(Handbook handbook, int row)
        {
            rowBinding.Add(handbook, row);
            Label label = new Label();

            label.AutoSize = true;
            label.Anchor   = AnchorStyles.Left;
            tlp.Controls.Add(label, 0, row);
            if (handbook.handbookType == HandbookType.Header)
            {
                label.Text = "" + handbook.name;
                Font font = new Font(label.Font, FontStyle.Bold);
                label.Font = font;
                return(label);
            }
            label.Text = handbook.name + ':';
            Control ctl  = null;
            string  text = handbooksInfo.ContainsKey(handbook.id)?handbooksInfo[handbook.id]:handbook.GetDefaultValue();

            switch (handbook.handbookType)
            {
            case HandbookType.Date:
            {
                DateTimePicker dp = new DateTimePicker();
                InitControl(dp, handbook, text);
                ctl = dp;
            }
            break;

            case HandbookType.Number:
                if (handbook.nullable)
                {
                    NullableNumericUserControl ucNullableNumeric = new NullableNumericUserControl();
                    InitControl(ucNullableNumeric.numericUpDown, handbook, text);
                    ucNullableNumeric.Text = text;
                    ctl = ucNullableNumeric;
                }
                else
                {
                    NumericUpDown nud = new NumericUpDown();
                    InitControl(nud, handbook, text);
                    ctl = nud;
                }
                break;

            case HandbookType.String:
                if (handbook.Items.Count > 0)
                {
                    if (handbook.IsMultiline)
                    {
                        MultilineComboUserControl uc = new MultilineComboUserControl();
                        uc.LineCount  = handbook.lineCount;
                        uc.Additive   = handbook.additive;
                        uc.DataSource = handbook.Items;
                        ctl           = uc;
                    }
                    else
                    {
                        ComboBox cb = new ComboBox();
                        cb.Items.AddRange(handbook.Items.ToArray());
                        cb.SelectedItem = text;
                        ctl             = cb;
                    }
                }
                else
                {
                    TextBox tb = new TextBox();
                    if (handbook.IsMultiline)
                    {
                        tb.Multiline = true;
                        tb.Height   *= handbook.lineCount;
                    }
                    ctl = tb;
                }
                ctl.Text = text;
                break;

            default:
                ctl.Text = text;
                break;
            }
            if (ctl != null)
            {
                ctl.Width = App.GuiConfig.handbookControlWidth;
                tlp.Controls.Add(ctl, 1, row);
                binding.Add(handbook, ctl);
                return(ctl);
            }
            return(null);
        }