public ucModelFieldAdd(int index, IDataFile db) { if (index != 0 && index % 2 == 0) { BackColor = Color.Gray; } string[] models = db.GetListDB(); #region [ === UI === ] txt_Name = new TextBoxCustom() { Left = 4, Top = _top, Width = 80, Name = "name" + index.ToString(), WaterMark = "Name ...", BorderStyle = BorderStyle.FixedSingle, TextAlign = HorizontalAlignment.Center }; cbo_Type = new ComboBox() { Left = 88, Top = _top, Width = 60, Name = "type" + index.ToString(), DropDownStyle = ComboBoxStyle.DropDownList, }; chk_Auto = new CheckBox() { Left = 164, Top = _top, Width = 22, Name = "auto" + index.ToString() }; for (int k = 0; k < dbType.Types.Length; k++) { cbo_Type.Items.Add(dbType.Types[k]); } cbo_Type.SelectedIndex = 0; cbo_Kit = new ComboBox() { Left = 192, Top = _top, Width = 80, Name = "kit" + index.ToString(), DropDownStyle = ComboBoxStyle.DropDownList, }; foreach (ControlKit kit in Kits) { cbo_Kit.Items.Add(new ComboboxItem() { Text = kit.ToString().ToUpper(), Value = ((int)kit) }); } cbo_Kit.SelectedIndex = 0; cbo_LinkType = new ComboBox() { Left = 276, Top = _top, Width = 84, Name = "link_type" + index.ToString(), DropDownStyle = ComboBoxStyle.DropDownList }; foreach (JoinType ti in JoinTypes) { cbo_LinkType.Items.Add(new ComboboxItem() { Text = ti.ToString().ToUpper(), Value = ((int)ti) }); } cbo_LinkType.SelectedIndex = 0; txt_ValueDefault = new TextBoxCustom() { Left = 363, Top = _top, Width = 200, Name = "value_default" + index.ToString(), WaterMark = "Default value: v1|v2|...", BorderStyle = BorderStyle.FixedSingle }; cbo_LinkModel = new ComboBox() { Visible = false, Left = 363, Top = _top, Width = 100, Name = "link_model" + index.ToString(), DropDownStyle = ComboBoxStyle.DropDownList, }; cbo_LinkField = new ComboBox() { Visible = false, Left = 465, Top = _top, Width = 100, Name = "link_field" + index.ToString(), DropDownStyle = ComboBoxStyle.DropDownList, }; cbo_LinkModel.Items.Add(new ComboboxItem() { Text = "", Value = "" }); for (int k = 0; k < models.Length; k++) { cbo_LinkModel.Items.Add(new ComboboxItem() { Text = models[k].ToUpper(), Value = models[k] }); } cbo_LinkModel.SelectedIndex = 0; txt_Caption = new TextBoxCustom() { Left = 568, Top = _top, Width = 100, Name = "caption" + index.ToString(), WaterMark = "Caption title ...", BorderStyle = BorderStyle.FixedSingle, TextAlign = HorizontalAlignment.Center }; chk_Index = new CheckBox() { Left = 684, Top = _top, Width = 20, Name = "index" + index.ToString(), Checked = false }; chk_Null = new CheckBox() { Left = 720, Top = _top, Width = 15, Name = "null" + index.ToString(), Checked = true }; /////////////////////////////////////////////////////////////////////////////////////////////// btn_Ext = new Button() { Text = "+", Left = 744, Top = _top, Width = 20 }; int hiBox = 30; txt_CaptionShort = new TextBoxCustom() { Left = 4, Top = _top + 30, Width = 100, Name = "caption_short" + index.ToString(), WaterMark = "Caption short ...", BorderStyle = BorderStyle.FixedSingle }; txt_Des = new TextBoxCustom() { Left = 112, Top = _top + 30, Width = 150, Name = "des" + index.ToString(), WaterMark = "Description ...", BorderStyle = BorderStyle.FixedSingle, TextAlign = HorizontalAlignment.Center }; chk_MobiShow = new CheckBox() { Left = 268, Top = _top + 30, Name = "mobi" + index.ToString(), Text = "Show Mobi", Width = 90, Checked = true }; chk_TabletShow = new CheckBox() { Left = 358, Top = _top + 30, Name = "tablet" + index.ToString(), Text = "Show Tablet", Width = 100, Checked = true }; chk_Duplicate = new CheckBox() { Left = 460, Top = _top + 30, Name = "duplicate" + index.ToString(), Text = "Duplicate", Width = 100, Checked = true }; chk_Encrypt = new CheckBox() { Left = 560, Top = _top + 30, Name = "encrypt" + index.ToString(), Text = "Encrypt", Width = 100, Checked = false }; btn_Remove = new Button() { Text = "Remove", Left = 704, Top = _top + 30, Width = 60 }; btn_Remove.Click += (se, ev) => remove_Field(index); btn_Ext.Click += (se, ev) => { if (btn_Ext.Text == "-") { btn_Ext.Text = "+"; this.Height = this.Height - hiBox; } else { btn_Ext.Text = "-"; this.Height = this.Height + hiBox; } }; this.Controls.AddRange(new Control[] { txt_Name, cbo_Type, chk_Auto, cbo_Kit, cbo_LinkType, txt_ValueDefault, cbo_LinkModel, cbo_LinkField, txt_Caption, chk_Index, chk_Null, btn_Ext, txt_CaptionShort, txt_Des, chk_MobiShow, chk_TabletShow, chk_Duplicate, chk_Encrypt, btn_Remove }); #endregion /////////////////////////////////////////////////////////////////////////////////////////////// #region [ === EVENT === ] cbo_LinkModel.Visible = false; cbo_LinkField.Visible = false; int ijt = JoinTypes.FindIndex(x => x == JoinType.DEF_VALUE); cbo_LinkType.SelectedIndex = ijt; cbo_Type.SelectedIndexChanged += (se, ev) => { string type = dbType.Types[cbo_Type.SelectedIndex]; if (type == typeof(Boolean).Name) { chk_Auto.Checked = false; chk_Auto.Visible = false; int iKit = Kits.FindIndex(x => x == ControlKit.CHECK); cbo_Kit.SelectedIndex = iKit; cbo_Kit.Enabled = false; cbo_LinkType.Visible = false; return; } else { chk_Auto.Visible = true; cbo_Kit.Enabled = true; cbo_Kit.SelectedIndex = 0; cbo_LinkType.Visible = true; return; } if (type == typeof(DateTime).Name) { int iKit = Kits.FindIndex(x => x == ControlKit.TEXT_DATETIME); cbo_Kit.SelectedIndex = iKit; cbo_Kit.Enabled = false; return; } else { cbo_Kit.Enabled = true; cbo_Kit.SelectedIndex = 0; return; } }; cbo_Kit.SelectedIndexChanged += (se, ev) => kit_Change(); cbo_LinkType.SelectedIndexChanged += (se, ev) => { JoinType ji = JoinTypes[cbo_LinkType.SelectedIndex]; switch (ji) { case JoinType.NONE: cbo_LinkType.SelectedIndex = 1; break; case JoinType.DEF_VALUE: txt_ValueDefault.Visible = true; cbo_LinkModel.Visible = false; cbo_LinkField.Visible = false; break; case JoinType.JOIN_MODEL: txt_ValueDefault.Visible = false; cbo_LinkModel.Visible = true; cbo_LinkField.Visible = true; break; } }; cbo_LinkModel.SelectedIndexChanged += (se, ev) => { cbo_LinkField.Items.Clear(); if (cbo_LinkModel.SelectedIndex > 0) { string m = models[cbo_LinkModel.SelectedIndex - 1]; if (!string.IsNullOrEmpty(m)) { var fs = db.GetFields(m).ToArray(); if (fs.Length > 0) { for (int k = 0; k < fs.Length; k++) { cbo_LinkField.Items.Add(new ComboboxItem() { Text = fs[k].Name.ToUpper() + " - " + fs[k].Type.Name, Value = fs[k].Name }); } cbo_LinkField.SelectedIndex = 0; } } } }; chk_Auto.CheckedChanged += (se, ev) => { kit_Change(); if (chk_Auto.Checked) { // FIELD KEY AUTO chk_Null.Checked = false; chk_Null.Visible = false; cbo_Kit.Visible = false; cbo_LinkType.Visible = false; txt_ValueDefault.Visible = false; cbo_LinkModel.Visible = false; cbo_LinkField.Visible = false; } else { // FIELD DATA chk_Null.Visible = true; cbo_Kit.Visible = true; cbo_LinkType.Visible = true; txt_ValueDefault.Visible = true; } }; #endregion /////////////////////////////////////////////////////////////////////////////////////////////// }
//private void form_RemoveAt(FlowLayoutPanel boi_Filter, int index) //{ // if (index == countField) // form_Remove(boi_Filter); // else // { // listIndexRemove.Add(index); // foreach (Control c in boi_Filter.Controls) // { // if (c.Name == "uc" + index.ToString()) // { // c.Visible = false; // break; // } // } // } //} //private void form_Remove(FlowLayoutPanel boi_Filter) //{ // int id = countField; // countField--; // if (countField == -1) return; // foreach (Control c in boi_Filter.Controls) // if (c.Name == "uc" + id.ToString()) // { // boi_Filter.Controls.Remove(c); // 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.ToUpper().Trim(); if (MessageBox.Show("Are you sure update model [" + dbName + "] ?", "Update Model", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) != DialogResult.Yes) { return; } bool exist = db.ExistModel(dbName); if (exist) { MessageBox.Show("Model Name exist. Please choose other name."); return; } var li = new List <FieldInfo>(); int index = 1; foreach (Control c in boi_Filter.Controls) { var o = new FieldInfo(); int ki = 0; foreach (Control fi in c.Controls) { #region 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.TYPE_NAME = (fi as ComboBox).Items[ix].ToString(); } else if (fi.Name == "auto" + index.ToString()) { o.IS_KEY_AUTO = (fi as CheckBox).Checked; } else if (fi.Name == "kit" + index.ToString()) { #region if (o.IS_KEY_AUTO) { 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.IS_KEY_AUTO) { continue; } o.JOIN_TYPE = JoinType.NONE; object ct = (fi as ComboBox).SelectedItem; if (ct != null) { try { o.JOIN_TYPE = (JoinType)((int)(ct as ComboboxItem).Value); } catch { } } } else if (fi.Name == "value_default" + index.ToString()) { if (o.IS_KEY_AUTO) { continue; } string vd = (fi as TextBox).Text; o.VALUE_DEFAULT = vd == null ? new string[] { } : vd.Split('|'); } else if (fi.Name == "link_model" + index.ToString()) { if (o.IS_KEY_AUTO) { continue; } object ct = (fi as ComboBox).SelectedItem; if (ct != null) { o.JOIN_MODEL = (ct as ComboboxItem).Value as string; } } else if (fi.Name == "link_field" + index.ToString()) { if (o.IS_KEY_AUTO) { continue; } object ct = (fi as ComboBox).SelectedItem; if (ct != null) { o.JOIN_FIELD = (ct as ComboboxItem).Value as string; } } else if (fi.Name == "link_view" + index.ToString()) { if (o.IS_KEY_AUTO) { continue; } object ct = (fi as ComboBox).SelectedItem; if (ct != null) { o.JOIN_VIEW = (ct as ComboboxItem).Value as string; } } else if (fi.Name == "index" + index.ToString()) { o.IS_INDEX = (fi as CheckBox).Checked; } else if (fi.Name == "null" + index.ToString()) { o.IS_ALLOW_NULL = (fi as CheckBox).Checked; if (o.IS_KEY_AUTO || o.IS_INDEX) { o.IS_ALLOW_NULL = false; } } else if (fi.Name == "caption" + index.ToString()) { o.CAPTION = (fi as TextBox).Text; } else if (fi.Name == "caption_short" + index.ToString()) { o.CAPTION_SHORT = (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.IS_NOT_DUPLICATE = (fi as CheckBox).Checked; } else if (fi.Name == "encrypt" + index.ToString()) { o.IS_ENCRYPT = (fi as CheckBox).Checked; } else if (fi.Name == "order_edit" + index.ToString()) { int _vi = 0; if (int.TryParse((fi as TextBox).Text, out _vi)) { o.ORDER_EDIT = _vi; } } else if (fi.Name == "order_view" + index.ToString()) { int _vi = 0; if (int.TryParse((fi as TextBox).Text, out _vi)) { o.ORDER_VIEW = _vi; } } else if (fi.Name == "func_edit" + index.ToString()) { o.FUNC_EDIT = fi.Text == dbFunc.title_FUNC_VALIDATE_ON_FORM ? "": fi.Text; } else if (fi.Name == "func_before_update" + index.ToString()) { o.FUNC_BEFORE_UPDATE = fi.Text == dbFunc.title_FUNC_BEFORE_ADD_OR_UPDATE ? "" : fi.Text; } else if (fi.Name == "key_url" + index.ToString()) { o.ORDER_KEY_URL = string.IsNullOrEmpty(fi.Text) ? 0 : int.Parse(fi.Text); } else if (fi.Name == "show_in_grid" + index.ToString()) { o.ONLY_SHOW_IN_DETAIL = (fi as CheckBox).Checked; } else if (fi.Name == "full_text_search" + index.ToString()) { o.IS_FULL_TEXT_SEARCH = (fi as CheckBox).Checked; } else if (fi.Name == "key_for_sync" + index.ToString()) { o.IS_KEY_SYNC_EDIT = (fi as CheckBox).Checked; } else if (fi.Name == "field_change" + index.ToString()) { try { o.FieldChange = string.IsNullOrEmpty(fi.Text) ? dbFieldChange.NONE : (dbFieldChange)int.Parse(fi.Text); } catch { } } ki++; #endregion }//end for fields if (!string.IsNullOrEmpty(o.NAME) && o.Type != null) { #region switch (o.KIT) { case ControlKit.RADIO: o.JOIN_TYPE = JoinType.DEF_VALUE; if (o.VALUE_DEFAULT == null || o.VALUE_DEFAULT.Length == 0 || (o.VALUE_DEFAULT.Length == 1 && o.VALUE_DEFAULT[0] == "")) { MessageBox.Show("Please input field [ " + o.NAME + " ] attributed [ Value Default ]"); return; } break; case ControlKit.SELECT: if (o.JOIN_TYPE == JoinType.DEF_VALUE && (o.VALUE_DEFAULT == null || o.VALUE_DEFAULT.Length == 0 || (o.VALUE_DEFAULT.Length == 1 && o.VALUE_DEFAULT[0] == ""))) { MessageBox.Show("Please input field [ " + o.NAME + " ] attributed [ Value Default ]"); return; } if (o.JOIN_TYPE == JoinType.JOIN_MODEL && (string.IsNullOrEmpty(o.JOIN_MODEL) || string.IsNullOrEmpty(o.JOIN_FIELD))) { MessageBox.Show("Please input field [ " + o.NAME + " ] attributed [ JOIN MODEL - JOIN FIELD ]"); return; } break; case ControlKit.LOOKUP: if (o.JOIN_TYPE == JoinType.JOIN_MODEL && (string.IsNullOrEmpty(o.JOIN_MODEL) || string.IsNullOrEmpty(o.JOIN_FIELD))) { MessageBox.Show("Please input field [ " + o.NAME + " ] attributed [ JOIN MODEL - JOIN FIELD ]"); return; } break; } if (o.JOIN_TYPE == JoinType.JOIN_MODEL && !string.IsNullOrEmpty(o.JOIN_MODEL) && !string.IsNullOrEmpty(o.JOIN_FIELD)) { string[] types = db.GetFields(o.JOIN_MODEL).Where(x => x.NAME == o.JOIN_FIELD).Select(x => x.TYPE_NAME).ToArray(); if (types.Length > 0) { o.TYPE_NAME = types[0]; } } if (o.JOIN_TYPE == JoinType.DEF_VALUE && o.VALUE_DEFAULT != null && o.VALUE_DEFAULT.Length >= 1 && o.VALUE_DEFAULT[0] != "") { o.TYPE_NAME = typeof(Int32).Name; } #endregion if (o.FieldChange != dbFieldChange.REMOVE) { li.Add(o); } } else { MessageBox.Show("Please input fields: name, type, caption."); c.Focus(); return; } index++; }//end for controls if (li.Count > 0) { DB_MODEL m = new DB_MODEL() { NAME = dbName.Replace(" ", "_").Trim().ToUpper(), FIELDS = li.ToArray(), }; if (OnSubmit != null) { OnSubmit(m); } } else { MessageBox.Show("Please input fields: name, type, caption."); } }
private void joinModel_Change() { if (isFirstLoad) { var fs = db.GetFields(Field.JOIN_MODEL).ToArray(); if (fs.Length > 0) { cbo_LinkField.Items.Clear(); cbo_LinkView.Items.Clear(); for (int k = 0; k < fs.Length; k++) { cbo_LinkField.Items.Add(new ComboboxItem() { Text = fs[k].NAME.ToUpper() + " - " + fs[k].Type.Name, Value = fs[k].NAME }); cbo_LinkView.Items.Add(new ComboboxItem() { Text = fs[k].NAME.ToUpper() + " - " + fs[k].Type.Name, Value = fs[k].NAME }); } } int k2 = fs.FindIndex(x => x.NAME == Field.JOIN_FIELD); cbo_LinkField.SelectedIndex = k2; int k3 = fs.FindIndex(x => x.NAME == Field.JOIN_VIEW); cbo_LinkView.SelectedIndex = k3; isFirstLoad = false; } else { if (cbo_LinkModel.SelectedIndex > 0) { string m = DbName[cbo_LinkModel.SelectedIndex - 1]; if (!string.IsNullOrEmpty(m)) { var fs = db.GetFields(m).ToArray(); if (fs.Length > 0) { string typeCurrent = cbo_Type.Text; int indexJoinFieldDefault = fs.FindIndex(x => x.TYPE_NAME == typeCurrent); if (indexJoinFieldDefault == -1) { MessageBox.Show("Data type JOIN FIELD not match type of Field. Please choose other model."); return; } else { cbo_LinkField.Items.Clear(); cbo_LinkView.Items.Clear(); for (int k = 0; k < fs.Length; k++) { cbo_LinkField.Items.Add(new ComboboxItem() { Text = fs[k].NAME.ToUpper() + " - " + fs[k].Type.Name, Value = fs[k].NAME }); cbo_LinkView.Items.Add(new ComboboxItem() { Text = fs[k].NAME.ToUpper() + " - " + fs[k].Type.Name, Value = fs[k].NAME }); } cbo_LinkField.SelectedIndex = indexJoinFieldDefault; cbo_LinkView.SelectedIndex = 0; } } } } } }
public ucModelFieldAdd(int index, IDataFile db) { if (index != 0 && index % 2 == 0) { BackColor = Color.Gray; } string[] models = db.GetListDB(); #region [ === UI === ] ////////////////////////////////////////////////////////////////////// // LINE 1: txt_Name = new TextBoxCustom() { Left = 4, Top = _topLine1, Width = 80, Name = "name" + index.ToString(), WaterMark = "Name ...", BorderStyle = BorderStyle.FixedSingle, TextAlign = HorizontalAlignment.Center }; cbo_Type = new ComboBox() { Left = 88, Top = _topLine1, Width = 60, Name = "type" + index.ToString(), DropDownStyle = ComboBoxStyle.DropDownList, }; chk_Auto = new CheckBox() { Left = 164, Top = _topLine1, Width = 22, Name = "auto" + index.ToString() }; for (int k = 0; k < dbType.Types.Length; k++) { cbo_Type.Items.Add(dbType.Types[k]); } cbo_Type.SelectedIndex = 0; cbo_Kit = new ComboBox() { Left = 192, Top = _topLine1, Width = 80, Name = "kit" + index.ToString(), DropDownStyle = ComboBoxStyle.DropDownList, }; foreach (ControlKit kit in Kits) { cbo_Kit.Items.Add(new ComboboxItem() { Text = kit.ToString().ToUpper(), Value = ((int)kit) }); } cbo_Kit.SelectedIndex = 0; cbo_LinkType = new ComboBox() { Left = 276, Top = _topLine1, Width = 84, Name = "link_type" + index.ToString(), DropDownStyle = ComboBoxStyle.DropDownList }; foreach (JoinType ti in JoinTypes) { cbo_LinkType.Items.Add(new ComboboxItem() { Text = ti.ToString().ToUpper(), Value = ((int)ti) }); } cbo_LinkType.SelectedIndex = 0; txt_ValueDefault = new TextBoxCustom() { Left = 363, Top = _topLine1, Width = 307, Name = "value_default" + index.ToString(), WaterMark = "Default value: v1|v2|...", BorderStyle = BorderStyle.FixedSingle }; cbo_LinkModel = new ComboBox() { Visible = false, Left = 363, Top = _topLine1, Width = 100, Name = "link_model" + index.ToString(), DropDownStyle = ComboBoxStyle.DropDownList, }; cbo_LinkField = new ComboBox() { Visible = false, Left = 465, Top = _topLine1, Width = 100, Name = "link_field" + index.ToString(), DropDownStyle = ComboBoxStyle.DropDownList, }; cbo_LinkModel.Items.Add(new ComboboxItem() { Text = "", Value = "" }); for (int k = 0; k < models.Length; k++) { cbo_LinkModel.Items.Add(new ComboboxItem() { Text = models[k].ToUpper(), Value = models[k] }); } cbo_LinkModel.SelectedIndex = 0; cbo_LinkView = new ComboBox() { Visible = false, Left = 568, Top = _topLine1, Width = 100, Name = "link_view" + index.ToString(), DropDownStyle = ComboBoxStyle.DropDownList, }; chk_Index = new CheckBox() { Left = 684, Top = _topLine1, Width = 20, Name = "index" + index.ToString(), Checked = false }; chk_Null = new CheckBox() { Left = 720, Top = _topLine1, Width = 15, Name = "null" + index.ToString(), Checked = true }; ////////////////////////////////////////////////////////////////////// // LINE 2: txt_Caption = new ucTextBoxH(100) { Left = 4, Top = _topLine2, Name = "caption" + index.ToString(), Title = "Caption" }; txt_CaptionShort = new ucTextBoxH(100) { Left = 112, Top = _topLine2, Name = "caption_short" + index.ToString(), Title = "Caption short" }; txt_Des = new ucTextBoxH(130) { Left = 216, Top = _topLine2, Name = "des" + index.ToString(), Title = "Description" }; chk_MobiShow = new CheckBox() { Left = 358, Top = _topLine1 + 30, Name = "mobi" + index.ToString(), Text = "Show Mobi", Width = 80, Checked = true }; chk_TabletShow = new CheckBox() { Left = 440, Top = _topLine1 + 30, Name = "tablet" + index.ToString(), Text = "Show Tablet", Width = 90, Checked = true }; chk_Duplicate = new CheckBox() { Left = 530, Top = _topLine1 + 30, Name = "duplicate" + index.ToString(), Text = "Duplicate", Width = 75, Checked = true }; chk_Encrypt = new CheckBox() { Left = 607, Top = _topLine1 + 30, Name = "encrypt" + index.ToString(), Text = "Encrypt", Width = 66, Checked = false }; txt_FieldChange = new TextBox() { Visible = false, Name = "field_change" + index.ToString(), Text = ((int)dbFieldChange.ADD).ToString() }; btn_Ext = new Button() { Text = "+", Left = 744, Top = _topLine1, Width = 20, BackColor = SystemColors.Control }; btn_Remove = new Button() { Text = "Remove", Left = 704, Top = _topLine1 + 30, Width = 60, BackColor = SystemColors.Control }; btn_Remove.Click += (se, ev) => remove_Field(txt_FieldChange); btn_Ext.Click += (se, ev) => { if (btn_Ext.Text == "-") { btn_Ext.Text = "+"; this.Height = this.Height - hiBox; } else { btn_Ext.Text = "-"; this.Height = this.Height + hiBox; } }; ////////////////////////////////////////////////////////////////////// // LINE 3: txt_OrderByEdit = new ucTextBoxH(100) { Left = 4, Top = _topLine3, Name = "order_edit" + index.ToString(), Text = "99", Title = "Order on form", TextAlign = HorizontalAlignment.Center, OnlyInputNumber0To9 = true }; txt_OrderByView = new ucTextBoxH(100) { Left = 112, Top = _topLine3, Name = "order_view" + index.ToString(), Text = "99", Title = "Order on grid", TextAlign = HorizontalAlignment.Center, OnlyInputNumber0To9 = true }; //txt_Des = new TextBoxCustom() { Left = 216, Top = _top + 30, Width = 130, Name = "des" + index.ToString(), WaterMark = "Description ...", BorderStyle = BorderStyle.FixedSingle, TextAlign = HorizontalAlignment.Center }; ////////////////////////////////////////////////////////////////// cbo_FuncValidate = new CustomComboBox() { Left = 358, Top = _topLine3, Width = 300, Name = "func_edit" + index.ToString(), Text = dbFunc.title_FUNC_VALIDATE_ON_FORM, }; string[] afunc = dbFunc.GetFuncValidate(); int index_VALIDATE_EMPTY = afunc.FindIndex(x => x == dbFunc.VALIDATE_EMPTY); CheckedListBox list_FuncValidate = new CheckedListBox() { BorderStyle = BorderStyle.None, Width = 300, }; foreach (string fi in afunc) { list_FuncValidate.Items.Add(new ComboboxItem() { Text = fi, Value = fi }); } if (index_VALIDATE_EMPTY != -1) { list_FuncValidate.SetItemChecked(index_VALIDATE_EMPTY, true); cbo_FuncValidate.Text = dbFunc.VALIDATE_EMPTY; } cbo_FuncValidate.KeyPress += (se, ev) => { ev.Handled = true; }; cbo_FuncValidate.DropDownControl = list_FuncValidate; //cbo_FuncValidate.DropDownWidth = 200; cbo_FuncValidate.DropDown += (se, ev) => { }; cbo_FuncValidate.DropDownClosed += (se, ev) => { }; list_FuncValidate.ItemCheck += (se, ev) => { List <string> li = new List <string>(); foreach (var o in list_FuncValidate.CheckedItems) { li.Add(o.ToString()); } string it = afunc[ev.Index]; CheckState val = ev.NewValue; if (val == CheckState.Checked) { li.Add(it); } else { li.Remove(it); } if (li.Count > 2) { cbo_FuncValidate.Text = "(" + li.Count.ToString() + ") Func validate on form"; } else { cbo_FuncValidate.Text = string.Join(",", li.Distinct().ToArray()); } }; ////////////////////////////////////////////////////////////////////// // LINE 4 cbo_FuncBeforeUpdate = new CustomComboBox() { Left = 358, Top = _topLine4, Width = 300, Name = "func_before_update" + index.ToString(), Text = dbFunc.title_FUNC_BEFORE_ADD_OR_UPDATE, }; string[] afuncUpdate = dbFunc.GetFuncBeforeAddOrUpdate(); CheckedListBox list_FuncUpdate = new CheckedListBox() { BorderStyle = BorderStyle.None, Width = 300, }; foreach (string fi in afuncUpdate) { list_FuncUpdate.Items.Add(new ComboboxItem() { Text = fi, Value = fi }); } cbo_FuncBeforeUpdate.KeyPress += (se, ev) => { ev.Handled = true; }; cbo_FuncBeforeUpdate.DropDownControl = list_FuncUpdate; //cbo_FuncBeforeUpdate.DropDownWidth = 200; cbo_FuncBeforeUpdate.DropDown += (se, ev) => { }; cbo_FuncBeforeUpdate.DropDownClosed += (se, ev) => { }; list_FuncUpdate.ItemCheck += (se, ev) => { List <string> li = new List <string>(); foreach (var o in list_FuncUpdate.CheckedItems) { li.Add(o.ToString()); } string it = afuncUpdate[ev.Index]; CheckState val = ev.NewValue; if (val == CheckState.Checked) { li.Add(it); } else { li.Remove(it); } if (li.Count > 2) { list_FuncUpdate.Text = "(" + li.Count.ToString() + ") Func validate on form"; } else { cbo_FuncBeforeUpdate.Text = string.Join(",", li.Distinct().ToArray()); } }; txt_KeyUri = new ucTextBoxH(100) { Left = 4, Top = _topLine4, Name = "key_url" + index.ToString(), Title = "Position key url", TextAlign = HorizontalAlignment.Center, OnlyInputNumber0To9 = true }; ////////////////////////////////////////////////////////////////////// // LINE 5 chk_ShowInGrid = new CheckBox() { Text = "Show only query detail", Left = 4, Top = _topLine5, Name = "show_in_grid" + index.ToString(), Width = 150, }; chk_IsFullTextSearch = new CheckBox() { Text = "Is full text search", Left = 160, Top = _topLine5, Name = "full_text_search" + index.ToString(), Width = 120, }; chk_IsKeySync = new CheckBox() { Text = "Is key for sync or edit", Left = 320, Top = _topLine5, Name = "key_for_sync" + index.ToString(), Width = 150, }; ////////////////////////////////////////////////////////////////// this.Controls.AddRange(new Control[] { txt_Name, cbo_Type, chk_Auto, cbo_Kit, cbo_LinkType, txt_ValueDefault, cbo_LinkModel, cbo_LinkField, cbo_LinkView, chk_Index, chk_Null, btn_Ext, txt_Caption, txt_CaptionShort, txt_Des, chk_MobiShow, chk_TabletShow, chk_Duplicate, chk_Encrypt, txt_OrderByView, txt_OrderByEdit, cbo_FuncValidate, cbo_FuncBeforeUpdate, txt_KeyUri, btn_Remove, txt_FieldChange, chk_ShowInGrid, chk_IsFullTextSearch, chk_IsKeySync }); #endregion /////////////////////////////////////////////////////////////////////////////////////////////// #region [ === EVENT === ] cbo_LinkModel.Visible = false; cbo_LinkField.Visible = false; cbo_LinkView.Visible = false; int ijt = JoinTypes.FindIndex(x => x == JoinType.DEF_VALUE); cbo_LinkType.SelectedIndex = ijt; cbo_Type.SelectedIndexChanged += (se, ev) => { string type = dbType.Types[cbo_Type.SelectedIndex]; if (type == typeof(Boolean).Name) { chk_Auto.Checked = false; chk_Auto.Visible = false; int iKit = Kits.FindIndex(x => x == ControlKit.CHECK); cbo_Kit.SelectedIndex = iKit; cbo_Kit.Enabled = false; cbo_LinkType.Visible = false; //return; } else { chk_Auto.Visible = true; cbo_Kit.Enabled = true; cbo_Kit.SelectedIndex = 0; cbo_LinkType.Visible = true; //return; } if (type == typeof(DateTime).Name) { int iKit = Kits.FindIndex(x => x == ControlKit.TEXT_DATETIME); cbo_Kit.SelectedIndex = iKit; cbo_Kit.Enabled = false; //return; } else { cbo_Kit.Enabled = true; cbo_Kit.SelectedIndex = 0; //return; } }; cbo_Kit.SelectedIndexChanged += (se, ev) => kit_Change(); cbo_LinkType.SelectedIndexChanged += (se, ev) => { JoinType ji = JoinTypes[cbo_LinkType.SelectedIndex]; switch (ji) { case JoinType.NONE: cbo_LinkType.SelectedIndex = 1; break; case JoinType.DEF_VALUE: txt_ValueDefault.Visible = true; cbo_LinkModel.Visible = false; cbo_LinkField.Visible = false; cbo_LinkView.Visible = false; break; case JoinType.JOIN_MODEL: txt_ValueDefault.Visible = false; cbo_LinkModel.Visible = true; cbo_LinkField.Visible = true; cbo_LinkView.Visible = true; ControlKit kit = Kits[cbo_Kit.SelectedIndex]; if (kit != ControlKit.SELECT && kit != ControlKit.LOOKUP) { int _ix = Kits.FindIndex(x => x == ControlKit.SELECT); if (_ix != -1) { cbo_Kit.SelectedIndex = _ix; } } break; } }; cbo_LinkModel.SelectedIndexChanged += (se, ev) => { cbo_LinkField.Items.Clear(); cbo_LinkView.Items.Clear(); if (cbo_LinkModel.SelectedIndex > 0) { string m = models[cbo_LinkModel.SelectedIndex - 1]; if (!string.IsNullOrEmpty(m)) { var fs = db.GetFields(m).ToArray(); if (fs.Length > 0) { for (int k = 0; k < fs.Length; k++) { cbo_LinkField.Items.Add(new ComboboxItem() { Text = fs[k].NAME.ToUpper() + " - " + fs[k].Type.Name, Value = fs[k].NAME }); cbo_LinkView.Items.Add(new ComboboxItem() { Text = fs[k].NAME.ToUpper() + " - " + fs[k].Type.Name, Value = fs[k].NAME }); } cbo_LinkField.SelectedIndex = 0; cbo_LinkView.SelectedIndex = 0; } } } }; chk_Auto.CheckedChanged += (se, ev) => { kit_Change(); if (chk_Auto.Checked) { // FIELD KEY AUTO chk_Null.Checked = false; chk_Null.Visible = false; cbo_Kit.Visible = false; cbo_LinkType.Visible = false; txt_ValueDefault.Visible = false; cbo_LinkModel.Visible = false; cbo_LinkField.Visible = false; cbo_LinkView.Visible = false; } else { // FIELD DATA chk_Null.Visible = true; cbo_Kit.Visible = true; cbo_LinkType.Visible = true; txt_ValueDefault.Visible = true; } }; #endregion /////////////////////////////////////////////////////////////////////////////////////////////// }
public FormModelEdit(IDataFile _db) { db = _db; var fields = db.GetFields("Test"); FlowLayoutPanel boi_Filter = new FlowLayoutPanel() { Dock = DockStyle.Fill, Height = (((fields.Length / 3) + 0) * 25), AutoScroll = false, Padding = new Padding(0), BackColor = Color.WhiteSmoke }; boi_Filter.FlowDirection = FlowDirection.LeftToRight; boi_Filter.MouseDown += FormMove_MouseDown; Label lbl_Name = new Label() { Text = "Name", AutoSize = false, Width = 80, BackColor = Color.Gray, ForeColor = Color.Black, TextAlign = ContentAlignment.MiddleCenter }; Label lbl_Type = new Label() { Text = "Type", AutoSize = false, Width = 80, BackColor = Color.Gray, ForeColor = Color.Black, TextAlign = ContentAlignment.MiddleCenter }; Label lbl_Caption = new Label() { Text = "Caption", AutoSize = false, Width = 80, BackColor = Color.Gray, ForeColor = Color.Black, TextAlign = ContentAlignment.MiddleCenter }; boi_Filter.Controls.AddRange(new Control[] { lbl_Name, lbl_Type, lbl_Caption, }); StringBuilder wh_Contain = new StringBuilder(); for (int k = 0; k < fields.Length; k++) { var dp = fields[k]; wh_Contain.Append(dp.Name + (dp.Type.Name == "String" ? string.Empty : ".ToString()") + ".Contains(@0) "); if (k < fields.Length - 1) { wh_Contain.Append(" || "); } TextBox lbl = new TextBox() { Name = "lbl" + k.ToString(), Text = dp.Name, Width = 80, BorderStyle = BorderStyle.FixedSingle, TextAlign = HorizontalAlignment.Center }; ComboBox cbo = new ComboBox() { Name = "cbo" + k.ToString(), Width = 80, DropDownStyle = ComboBoxStyle.DropDownList, }; //if (dp.Type.Name == "String") // for (int ki = 0; ki < OpString.Length; ki++) cbo.Items.Add(OpString[ki]); //else // for (int ki = 0; ki < OpNumber.Length; ki++) cbo.Items.Add(OpNumber[ki]); //cbo.SelectedIndexChanged += (se, ev) => //{ //}; //cbo.DataSource = dp.Type.Name == "String" ? OpString : OpNumber; TextBox txt = new TextBox() { Name = "txt" + k.ToString(), Width = 80, BorderStyle = BorderStyle.FixedSingle, TextAlign = HorizontalAlignment.Center }; boi_Filter.Controls.AddRange(new Control[] { lbl, cbo, txt, }); if (k != 0 && k % 3 == 0) { Label sp = new Label() { Text = "", AutoSize = false, Width = App.Width, Height = 1, }; boi_Filter.Controls.Add(sp); } }//end for fields Panel boi_Footer = new Panel() { Dock = DockStyle.Bottom, Height = 25 }; Button btn_Add = new Button() { Dock = DockStyle.Right, Text = "ADD", BackColor = Color.WhiteSmoke, Width = 60, TextAlign = ContentAlignment.MiddleCenter }; Button btn_Remove = new Button() { Dock = DockStyle.Right, Text = "REMOVE", BackColor = Color.WhiteSmoke, Width = 70, TextAlign = ContentAlignment.MiddleCenter }; Button btn_Submit = new Button() { Dock = DockStyle.Right, Text = "SUBMIT", BackColor = Color.WhiteSmoke, Width = 60, TextAlign = ContentAlignment.MiddleCenter }; Button btn_Close = new Button() { Dock = DockStyle.Right, Text = "CLOSE", BackColor = Color.WhiteSmoke, Width = 60, TextAlign = ContentAlignment.MiddleCenter }; boi_Footer.Controls.AddRange(new Control[] { btn_Add, btn_Remove, btn_Submit, btn_Close }); this.Controls.AddRange(new Control[] { boi_Filter, boi_Footer, }); boi_Filter.BringToFront(); btn_Submit.Focus(); btn_Close.Click += (se, ev) => { this.Close(); }; btn_Submit.Click += (se, ev) => { }; new Thread(() => { this.Width = 270; }).Start(); }
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."); } }