public ucDataItemAdd(int index, dbField field)
        {
            int wi_Name = 110, wi_Max = 630, wi_ = 200;

            _Height = Height_Min;
            _Width  = wi_ + wi_Name + 8;
            string caption  = string.IsNullOrEmpty(field.Caption) ? field.Name : field.Caption;
            Label  lbl_Name = new Label()
            {
                Left = 4, Top = 0, Text = caption, AutoSize = false, Width = wi_Name, ForeColor = Color.Black, TextAlign = ContentAlignment.MiddleRight
            };

            this.Controls.Add(lbl_Name);

            switch (field.Kit)
            {
            case ControlKit.LABEL:
                Label lbl = new Label()
                {
                    Left = wi_Name + 8, AutoSize = false, Width = wi_, Height = _Height - 5, BackColor = SystemColors.Control, Tag = field,
                };
                this.Controls.Add(lbl);
                break;

            case ControlKit.CHECK:
                CheckBox chk = new CheckBox()
                {
                    Left = wi_Name + 8, Top = 0, Tag = field,
                };
                this.Controls.Add(chk);
                break;

            case ControlKit.RADIO:
                RadioButton radio = new RadioButton()
                {
                    Left = wi_Name + 8, Top = 0, Tag = field,
                };
                this.Controls.Add(radio);
                break;

            case ControlKit.COLOR:
                Label lbl_Color = new Label()
                {
                    Left = wi_Name + 8, AutoSize = false, Width = 44, Height = _Height - 5, BackColor = Color.Gray, Tag = field,
                };
                this.Controls.Add(lbl_Color);
                break;

            case ControlKit.SELECT:
                ComboBox cbo = new ComboBox()
                {
                    Left = wi_Name + 8, Top = 0, Width = wi_, Height = _Height, DropDownStyle = ComboBoxStyle.DropDownList, Tag = field,
                };
                this.Controls.Add(cbo);
                break;

            case ControlKit.TEXT_PASS:
                TextBox txt_Pass = new TextBox()
                {
                    Left = wi_Name + 8, Top = 0, Width = wi_, Height = _Height, PasswordChar = '*', BorderStyle = BorderStyle.FixedSingle, Multiline = false, ScrollBars = ScrollBars.None, WordWrap = false, Tag = field,
                };
                this.Controls.Add(txt_Pass);
                break;

            case ControlKit.TEXT_DATE:
            case ControlKit.TEXT_DATETIME:
            case ControlKit.TEXT_TIME:
                DateTimePicker dt = new DateTimePicker()
                {
                    Left = wi_Name + 8, Top = 0, CustomFormat = "dd-MM-yyyy HH:mm:ss", Format = DateTimePickerFormat.Custom, Tag = field,
                };
                this.Controls.Add(dt);
                break;

            case ControlKit.TEXT_EMAIL:
                TextBox txt_Email = new TextBox()
                {
                    Left = wi_Name + 8, Top = 0, Width = wi_, Height = _Height, BorderStyle = BorderStyle.FixedSingle, Multiline = false, ScrollBars = ScrollBars.None, WordWrap = false, Tag = field,
                };
                this.Controls.Add(txt_Email);
                break;

            case ControlKit.TEXT_FILE:
                TextBox txt_File = new TextBox()
                {
                    Left = wi_Name + 8, Top = 0, Width = wi_, Height = _Height, ReadOnly = true, BorderStyle = BorderStyle.FixedSingle, Multiline = false, ScrollBars = ScrollBars.None, WordWrap = false, Tag = field,
                };
                this.Controls.Add(txt_File);
                break;

            case ControlKit.TEXTAREA:
            case ControlKit.HTML:
                _Height = Height_Max;
                _Width  = wi_Max + wi_Name + 8;
                TextBox text_area = new TextBox()
                {
                    Left = wi_Name + 8, Top = 0, Width = wi_Max, Height = _Height, BorderStyle = BorderStyle.FixedSingle, Multiline = true, ScrollBars = ScrollBars.Vertical, WordWrap = true, Tag = field,
                };
                this.Controls.Add(text_area);
                break;

            case ControlKit.LOOKUP:
                TextBox txt_Lookup = new TextBox()
                {
                    Left = wi_Name + 8, Top = 0, Width = wi_, Height = _Height, ReadOnly = true, BorderStyle = BorderStyle.FixedSingle, Multiline = false, ScrollBars = ScrollBars.None, WordWrap = false, Tag = field,
                };
                this.Controls.Add(txt_Lookup);
                break;

            default:     //case ControlKit.TEXT: break;
                TextBox txt = new TextBox()
                {
                    Left = wi_Name + 8, Top = 0, Width = wi_, Height = _Height, BorderStyle = BorderStyle.FixedSingle, Multiline = false, ScrollBars = ScrollBars.None, WordWrap = false, Tag = field,
                };
                this.Controls.Add(txt);
                break;
            }
        }
        private void form_Submit(string dbName, string dbCaption, FlowLayoutPanel boi_Filter)
        {
            //string dbName = txt_Name.Text, dbCaption = txt_Caption.Text;
            if (string.IsNullOrEmpty(dbName))
            {
                MessageBox.Show("Please input Model Name and fields: name, type, caption.");
                return;
            }

            dbName = dbName.ToLower().Trim();
            bool exist = db.ExistModel(dbName);

            if (exist)
            {
                MessageBox.Show("Model Name exist. Please choose other name.");
                return;
            }

            var li    = new List <dbField>();
            int index = 1;

            foreach (Control c in boi_Filter.Controls)
            {
                if (listIndexRemove.IndexOf(index) != -1)
                {
                    continue;
                }

                var o  = new dbField();
                int ki = 0;
                foreach (Control fi in c.Controls)
                {
                    if (fi.Name == "name" + index.ToString())
                    {
                        o.Name = (fi as TextBox).Text;
                    }
                    else if (fi.Name == "type" + index.ToString())
                    {
                        int ix = (fi as ComboBox).SelectedIndex;
                        o.TypeName = (fi as ComboBox).Items[ix].ToString();
                    }
                    else if (fi.Name == "auto" + index.ToString())
                    {
                        o.IsKeyAuto = (fi as CheckBox).Checked;
                    }
                    else if (fi.Name == "kit" + index.ToString())
                    {
                        #region

                        if (o.IsKeyAuto)
                        {
                            continue;
                        }

                        object _coltrol = (fi as ComboBox).SelectedItem;
                        if (_coltrol != null)
                        {
                            try
                            {
                                o.Kit = (ControlKit)((int)(_coltrol as ComboboxItem).Value);
                            }
                            catch { }
                        }

                        #endregion
                    }
                    else if (fi.Name == "link_type" + index.ToString())
                    {
                        if (o.IsKeyAuto)
                        {
                            continue;
                        }
                        o.JoinType = JoinType.NONE;
                        object ct = (fi as ComboBox).SelectedItem;
                        if (ct != null)
                        {
                            try
                            {
                                o.JoinType = (JoinType)((int)(ct as ComboboxItem).Value);
                            }
                            catch { }
                        }
                    }
                    else if (fi.Name == "value_default" + index.ToString())
                    {
                        if (o.IsKeyAuto)
                        {
                            continue;
                        }
                        string vd = (fi as TextBox).Text;
                        o.ValueDefault = vd == null ? new string[] { } : vd.Split('|');
                    }
                    else if (fi.Name == "link_model" + index.ToString())
                    {
                        if (o.IsKeyAuto)
                        {
                            continue;
                        }
                        object ct = (fi as ComboBox).SelectedItem;
                        if (ct != null)
                        {
                            o.JoinModel = (ct as ComboboxItem).Value as string;
                        }
                    }
                    else if (fi.Name == "link_field" + index.ToString())
                    {
                        if (o.IsKeyAuto)
                        {
                            continue;
                        }
                        object ct = (fi as ComboBox).SelectedItem;
                        if (ct != null)
                        {
                            o.JoinField = (ct as ComboboxItem).Value as string;
                        }
                    }
                    else if (fi.Name == "caption" + index.ToString())
                    {
                        o.Caption = (fi as TextBox).Text;
                    }
                    else if (fi.Name == "index" + index.ToString())
                    {
                        o.IsIndex = (fi as CheckBox).Checked;
                    }
                    else if (fi.Name == "null" + index.ToString())
                    {
                        o.IsAllowNull = (fi as CheckBox).Checked;
                        if (o.IsKeyAuto || o.IsIndex)
                        {
                            o.IsAllowNull = false;
                        }
                    }
                    else if (fi.Name == "caption_short" + index.ToString())
                    {
                        o.CaptionShort = (fi as TextBox).Text;
                    }
                    else if (fi.Name == "des" + index.ToString())
                    {
                        o.Description = (fi as TextBox).Text;
                    }
                    else if (fi.Name == "mobi" + index.ToString())
                    {
                        o.Mobi = (fi as CheckBox).Checked;
                    }
                    else if (fi.Name == "tablet" + index.ToString())
                    {
                        o.Tablet = (fi as CheckBox).Checked;
                    }
                    else if (fi.Name == "duplicate" + index.ToString())
                    {
                        o.IsDuplicate = (fi as CheckBox).Checked;
                    }
                    else if (fi.Name == "encrypt" + index.ToString())
                    {
                        o.IsEncrypt = (fi as CheckBox).Checked;
                    }

                    ki++;
                }//end for fields

                if (!string.IsNullOrEmpty(o.Name) && o.Type != null)
                {
                    switch (o.Kit)
                    {
                    case ControlKit.CHECK:
                    case ControlKit.RADIO:
                        o.JoinType = JoinType.DEF_VALUE;
                        if (o.ValueDefault == null || o.ValueDefault.Length == 0 || (o.ValueDefault.Length == 1 && o.ValueDefault[0] == ""))
                        {
                            MessageBox.Show("Please input field [ " + o.Name + " ] attributed [ Value Default ]");
                            return;
                        }
                        break;

                    case ControlKit.SELECT:
                        if (o.JoinType == JoinType.DEF_VALUE && (o.ValueDefault == null || o.ValueDefault.Length == 0 || (o.ValueDefault.Length == 1 && o.ValueDefault[0] == "")))
                        {
                            MessageBox.Show("Please input field [ " + o.Name + " ] attributed [ Value Default ]");
                            return;
                        }
                        if (o.JoinType == JoinType.JOIN_MODEL && (string.IsNullOrEmpty(o.JoinModel) || string.IsNullOrEmpty(o.JoinField)))
                        {
                            MessageBox.Show("Please input field [ " + o.Name + " ] attributed [ JOIN MODEL - JOIN FIELD ]");
                            return;
                        }
                        break;

                    case ControlKit.LOOKUP:
                        if (o.JoinType == JoinType.JOIN_MODEL && (string.IsNullOrEmpty(o.JoinModel) || string.IsNullOrEmpty(o.JoinField)))
                        {
                            MessageBox.Show("Please input field [ " + o.Name + " ] attributed [ JOIN MODEL - JOIN FIELD ]");
                            return;
                        }
                        break;
                    }

                    if (o.JoinType == JoinType.JOIN_MODEL && !string.IsNullOrEmpty(o.JoinModel) && !string.IsNullOrEmpty(o.JoinField))
                    {
                        string[] types = db.GetFields(o.JoinModel).Where(x => x.Name == o.JoinField).Select(x => x.TypeName).ToArray();
                        if (types.Length > 0)
                        {
                            o.TypeName = types[0];
                        }
                    }

                    if (o.JoinType == JoinType.DEF_VALUE && o.ValueDefault != null)
                    {
                        o.TypeName = typeof(Int32).Name;
                    }

                    li.Add(o);
                }
                else
                {
                    MessageBox.Show("Please input fields: name, type, caption.");
                    c.Focus();
                    return;
                }

                index++;
            }//end for controls
            if (li.Count > 0)
            {
                dbModel m = new dbModel()
                {
                    Name   = dbName.Replace(" ", "_").Trim().ToUpper(),
                    Fields = li.ToArray(),
                };
                //if (OnSubmit != null) OnSubmit(m);
                generalApiController(dbName, li);
            }
            else
            {
                MessageBox.Show("Please input fields: name, type, caption.");
            }
        }