コード例 #1
0
 public void ClearValue()
 {
     NullCheckBox.Checked = false;
     ValidControl.SetError(errPositionControl, "");
     ValueControl.Text = "";
     if (ValueControl is ComboBox ComboControl)
     {
         ComboControl.SelectedIndex = -1;
     }
     else if (ValueControl is CheckBox CheckBox)
     {
         CheckBox.Checked = false;
     }
 }
コード例 #2
0
 private void NullCheckBox_CheckedChanged(object sender, EventArgs e)
 {
     ValueControl.Enabled = !NullCheckBox.Checked || !JColumn.IsNullable;
     ValidControl.SetError(errPositionControl, "");
 }
コード例 #3
0
 private void TextControl_TextChanged(object sender, EventArgs e)
 {
     ValidControl.SetError(errPositionControl, "");
 }
コード例 #4
0
        public bool CheckValid(int lineIndex)
        {
            ValidControl.SetError(errPositionControl, "");

            //確認Null
            if (JColumn.IsNullable && NullCheckBox.Checked)
            {
                return(true);
            }
            else if (!JColumn.IsNullable && NullCheckBox.Checked)
            {
                ValidControl.SetError(NullCheckBox, string.Format(Res.JE_VAL_NOT_NULLABLE));
                return(false);
            }

            //確定型態符合
            if (ValueControl is Label)
            {
                return(true);
            }
            else if (ValueControl is TextBox)
            {
                if (!ChangeTextToString(ValueControl.Text).TryParseJType(JColumn.Type, out parsedValue))
                {
                    ValidControl.SetError(errPositionControl, string.Format(Res.JE_VAL_INVALID_CAST, ValueControl.Text));
                    return(false);
                }
            }
            else if (ValueControl is CheckBox)
            {
                if (!(ValueControl as CheckBox).Checked.TryParseJType(JColumn.Type, out parsedValue))
                {
                    ValidControl.SetError(errPositionControl, string.Format(Res.JE_VAL_INVALID_CAST, ValueControl.Text));
                    return(false);
                }
            }
            else if (ValueControl is ComboBox) //確認Choice 正確
            {
                if ((ValueControl as ComboBox).SelectedIndex == -1 || !(ValueControl as ComboBox).SelectedItem.TryParseJType(JColumn.Type, out parsedValue))
                {
                    ValidControl.SetError(errPositionControl, string.Format(Res.JE_VAL_CHOICE_VALUE_NOT_EXIST, (ValueControl as ComboBox).SelectedItem ?? Const.NullString));
                    return(false);
                }
            }

            //確認Regex正確
            if (JColumn.Type == JType.String)
            {
                if (!string.IsNullOrEmpty(JColumn.RegularExpression))
                {
                    if (!Regex.IsMatch(ChangeTextToString(ValueControl.Text), JColumn.RegularExpression))
                    {
                        ValidControl.SetError(errPositionControl, string.Format(Res.JE_VAL_REGEX_IS_NOT_MATCH, ValueControl.Text));
                        return(false);
                    }
                }
            }

            //確認MinMax正確
            if (JColumn.Type.IsNumber() || JColumn.Type.IsDateTime())
            {
                if (!string.IsNullOrEmpty(JColumn.MinValue) && parsedValue.CompareTo(JColumn.MinValue.ParseJType(JColumn.Type), JColumn.Type) == -1)
                {
                    ValidControl.SetError(errPositionControl, string.Format(Res.JE_VAL_LESS_THEN_MIN_VALUE, ValueControl.Text, JColumn.MinValue));
                    return(false);
                }
                if (!string.IsNullOrEmpty(JColumn.MaxValue) && parsedValue.CompareTo(JColumn.MaxValue.ParseJType(JColumn.Type), JColumn.Type) == 1)
                {
                    ValidControl.SetError(errPositionControl, string.Format(Res.JE_VAL_GREATER_THEN_MAX_VALUE, ValueControl.Text, JColumn.MaxValue));
                    return(false);
                }
            }

            //確認MaxLength正確
            if (JColumn.MaxLength != 0)
            {
                if (parsedValue.ToString().Length > JColumn.MaxLength)
                {
                    ValidControl.SetError(errPositionControl, string.Format(Res.JE_VAL_TEXT_MAXIMUM_LENGTH_OVER, JColumn.MaxLength));
                    return(false);
                }
            }

            //確認唯一值
            if (JColumn.IsUnique)
            {
                int columnIndex = JTable.Columns.IndexOf(JColumn);
                for (int i = 0; i < JTable.Count; i++)
                {
                    if (i != lineIndex && parsedValue == JTable[i][columnIndex])
                    {
                        ValidControl.SetError(errPositionControl, string.Format(Res.JE_VAL_VALUE_IS_NOT_UNIQUE, parsedValue));
                        return(false);
                    }
                }
            }

            //跳過Key檢查

            //外部驗證 - FK驗證 跳過
            //if (JColumn.FKTable != null && JColumn.FKColumn != null)
            //{
            //    //有錯表示有欄位錯誤
            //    JTable jt = Var.Tables.Find(m => m.Name == JColumn.FKTable);
            //    int columnIndex = jt.Columns.FindIndex(m => m.Name == JColumn.FKColumn);
            //    //結束

            //    if (!jt.Loaded)
            //        if (!MainForm.LoadOrScanJsonFile(jt))
            //            return false;

            //    if (!jt.Lines.Exists(m => ChangeStringToText(m.Values[columnIndex].ToString(jt.Columns[columnIndex].Type)) == ValueControl.Text))
            //    {
            //        ValidControl.SetError(errPositionControl, string.Format(Res.JE_VAL_FK_VALUE_NOT_FOUND, ValueControl.Text));
            //        return false;
            //    }
            //}
            return(true);
        }
コード例 #5
0
 private void ComboControl_SelectedIndexChanged(object sender, EventArgs e)
 {
     ValidControl.SetError(errPositionControl, "");
 }