Beispiel #1
0
        public string ValidateField(BF_FORM.FieldInfo FieldInfo, string val, string rowKey, int DB_ID, string TABLE_NAME, List <BF_FORM.FieldInfo> FieldList)
        {
            string message = "";

            if (string.IsNullOrWhiteSpace(val) && FieldInfo.IS_NOT_NULL == 1)//验证必填字段
            {
                return("对不起!" + FieldInfo.CN_NAME + "字段不能为空。");
            }
            //唯一性约束
            if (string.IsNullOrWhiteSpace(val) == false && FieldInfo.IS_UNIQUE == 1)
            {
                List <object> paramList = new List <object>();
                paramList.Add(val);
                string sql = "SELECT {0} FROM {1} WHERE {0} = ?";
                if (string.IsNullOrWhiteSpace(rowKey) == false)
                {
                    string strWhere = GetKeyWhere(FieldList, rowKey, ref paramList, true);
                    sql += " AND " + strWhere;
                }
                sql = string.Format(sql, FieldInfo.EN_NAME, TABLE_NAME);

                DataTable dt = BF_DATABASE.Instance.ExecuteSelectSQL(DB_ID, sql, paramList, 0);
                if (dt != null && dt.Rows.Count > 0)
                {
                    return("对不起!" + FieldInfo.CN_NAME + "字段不能重复。因为您违反了唯一性约束!");
                }
            }
            return(message);
        }
Beispiel #2
0
        private string GetTrea(BF_FORM.FieldInfo fieldData)
        {
            if (fieldData == null)
            {
                return("");
            }
            #region 组装数据集
            DataTable opData = SelectItem(fieldData);
            var       obj    = new List <object>();
            if (opData != null && opData.Rows.Count > 0)
            {
                foreach (DataRow dr in opData.Rows)
                {
                    obj.Add(
                        new
                    {
                        id   = dr["v"] == null || dr["v"].ToString().Trim() == "" ? "" : dr["v"].ToString(),
                        name = dr["k"] == null || dr["k"].ToString().Trim() == "" ? "" : dr["k"].ToString(),
                        pId  = dr["p"] == null || dr["p"].ToString().Trim() == "" ? "0" : dr["p"].ToString()
                    });
                }
            }
            JsonSerializerSettings _jsonSerializerSettings = new JsonSerializerSettings();
            string TreeVal = JsonConvert.SerializeObject(obj, _jsonSerializerSettings);
            #endregion

            //生成字符串
            string opHtml = "<script>$(function(){var zNodes" + fieldData.EN_NAME + " = JSON.parse('" + TreeVal + "');$.comboztree('{id}',{ztreenode: zNodes" + fieldData.EN_NAME + "});});</script>";//添加支撑JS
            return(opHtml);
        }
Beispiel #3
0
        private string GetCheck(BF_FORM.FieldInfo fieldData, string value)
        {
            DataTable opData = SelectItem(fieldData);
            //生成字符串
            string opHtml = "";

            string[] vals = value.Split(',');
            bool     isCk = false;//是否选中

            if (opData == null || opData.Rows.Count <= 0)
            {
                return("");
            }
            foreach (DataRow item in opData.Rows)
            {
                isCk = false;//是否选中
                foreach (string val in vals)
                {
                    if (item["v"] != null && val == item["v"].ToString().Trim())
                    {
                        isCk = true;
                        break;
                    }
                }
                opHtml += "<input type =\"checkbox\" value=\"" + item["v"] + "\" name=\"" + fieldData.EN_NAME + "\" lay-skin=\"primary\" title=\"" + item["k"] + "\" " + (isCk ? "checked=\"\"" : "") + ">";
            }

            return(opHtml);
        }
Beispiel #4
0
        private string GetSelectOption(BF_FORM.FieldInfo fieldData, string value)
        {
            DataTable opData = SelectItem(fieldData);

            if (opData == null || opData.Rows.Count <= 0)
            {
                return("");
            }
            //生成字符串
            string opHtml = "";

            foreach (DataRow item in opData.Rows)
            {
                opHtml += "<option value=\"" + item["v"] + "\"" + (item["v"].ToString() == value ? " selected=\"selected\"" : "") + ">" + item["k"] + "</option>";
            }
            return(opHtml);
        }
Beispiel #5
0
        private DataTable SelectItem(BF_FORM.FieldInfo fieldData)
        {
            if (fieldData == null)
            {
                return(null);
            }

            DataTable opData = new DataTable();

            switch (fieldData.SELECT_INPUT_TYPE)
            {
            case (int)FormSelectType.枚举值:
                opData.Columns.Add("k");
                opData.Columns.Add("v");
                if (fieldData.INPUT_TYPE == (int)FormInputType.拉树选择)
                {
                    opData.Columns.Add("p");
                }
                List <SelectEnumOption> op = fieldData.SELECT_ENUM_OPTIONS;
                if (op != null && op.Count > 0)
                {
                    foreach (SelectEnumOption item in op)
                    {
                        DataRow row = opData.NewRow();
                        row["k"] = GetReadParam(item.NAME);
                        row["v"] = GetReadParam(item.VALUE);
                        if (fieldData.INPUT_TYPE == (int)FormInputType.拉树选择)
                        {
                            row["p"] = (string.IsNullOrWhiteSpace(item.PID) ? "0" : item.PID);
                        }
                        opData.Rows.Add(row);
                    }
                }
                break;

            case (int)FormSelectType.表查询:
                string pidField = "";
                if (fieldData.INPUT_TYPE == (int)FormInputType.拉树选择)
                {
                    pidField = "," + fieldData.SELECT_QUERY_INFO.PID_FIELD + " p ";
                }
                string strField = fieldData.SELECT_QUERY_INFO.NAME_FIELD + " k," + fieldData.SELECT_QUERY_INFO.VALUE_FIELD + " v" + pidField; //需要查询的字段
                string strWhere = fieldData.SELECT_QUERY_INFO.WHERE;
                strWhere = GetReadParam(strWhere);                                                                                            //得到SQL
                opData   = GetData(fieldData.SELECT_QUERY_INFO.DB_ID, fieldData.SELECT_QUERY_INFO.TABLE_NAME, strField, strWhere);
                break;

            case (int)FormSelectType.SQL语句:
                if (string.IsNullOrWhiteSpace(fieldData.SQL) == false)
                {
                    string[] info = fieldData.SQL.Split('◎');
                    if (info.Length < 2 || string.IsNullOrWhiteSpace(info[0]) || string.IsNullOrWhiteSpace(info[1]))
                    {
                        return(null);
                    }
                    try
                    {
                        string strSql = GetReadParam(info[1]);    //得到SQL
                        opData = BF_DATABASE.Instance.ExecuteSelectSQL(Convert.ToInt32(info[0]), strSql, null, 0, 1);
                    }
                    catch (Exception ex)
                    {
                        BLog.Write(BLog.LogLevel.ERROR, "保存SQL模式时,出现未知错误:" + ex.ToString());
                        return(null);
                    }
                }
                break;
            }
            return(opData);
        }
Beispiel #6
0
        public string GetControllerHtml(BF_FORM.FieldInfo fieldData, DataRow row)
        {
            if (fieldData == null)
            {
                return("");
            }
            #region 控件模板
            string inputHtml    = "<input type=\"text\" id=\"{id}\" name=\"{name}\" lay-filter=\"{别名}\" value=\"{value}\" lay-verify=\"{验证}\" placeholder=\"{提示}\" autocomplete=\"off\" class=\"layui-input\" {只读}>";
            string dataHtml     = "<input type=\"text\" id=\"{id}\" name=\"{name}\" lay-filter=\"{别名}\" value=\"{value}\" lay-verify=\"datetime\" placeholder=\"yyyy-MM-dd HH:mm:ss\" autocomplete=\"off\" class=\"layui-input\" {只读}>";
            string checkHtml    = "<input type=\"checkbox\" id=\"{id}\" name=\"{name}\" lay-filter=\"{别名}\" value=\"{value}\" title=\"{提示}\" {选中} {只读}>";
            string textareaHtml = "<textarea id=\"{id}\" name=\"{name}\" lay-filter=\"{别名}\" placeholder=\"{提示}\" lay-verify=\"{验证}\" class=\"layui-textarea\" {只读}>{内容}</textarea>";
            string selectHtml   = "<select lay-search id=\"{id}\"  name=\"{name}\" lay-filter=\"{别名}\" lay-verify=\"{验证}\" {只读}>{选项}</select>";
            string checkboxHtml = "<span {只读}>{选项}</span>";
            string treeHtml     = "<input type=\"text\" id=\"{id}\" name=\"{name}\" value=\"{value}\" {只读}>";
            #endregion

            string strHtml = "";
            string value   = "";
            string enName  = fieldData.EN_NAME;//验证字段的默认值
            if (row != null && row[enName] != null)
            {
                value = row[enName].ToString().Trim();
            }
            else
            {
                //添加默认值
                if (string.IsNullOrWhiteSpace(fieldData.DEFAULT) == false)
                {
                    value = fieldData.DEFAULT;
                    #region 处理函数
                    int s = value.IndexOf("@{");
                    int e = value.IndexOf("}");
                    if (s == 0 && e == value.Length - 1)
                    {
                        value = BF_FORM.Instance.GetReadParam(value); //得到参数值
                    }
                    #endregion
                }
            }

            switch (fieldData.INPUT_TYPE)
            {
            case (int)Enums.FormInputType.拉单选框:
                string opHtml = GetSelectOption(fieldData, value);
                strHtml = selectHtml.Replace("{选项}", opHtml);
                break;

            case (int)Enums.FormInputType.单个复选框:
                if (value == "1" || value.ToLower() == "true")
                {
                    checkHtml = checkHtml.Replace("{选中}", "checked");
                }
                else
                {
                    checkHtml = checkHtml.Replace("{选中}", "");
                }
                checkHtml = checkHtml.Replace("{提示}", fieldData.CN_NAME).Replace("{value}", (value == "" ? "0" : value));    //这个地方设默认值为0可能存在争议
                strHtml   = checkHtml;
                break;

            case (int)Enums.FormInputType.多个复选框:
                opHtml = GetCheck(fieldData, value);
                if (opHtml != null && opHtml != "")
                {
                    strHtml = checkboxHtml.Replace("{选项}", opHtml);
                }
                break;

            case (int)Enums.FormInputType.多行文字框:
                strHtml = textareaHtml.Replace("{内容}", value);
                break;

            case (int)Enums.FormInputType.日期文字框:
                if (value != null && value != "")
                {
                    value = Convert.ToDateTime(value).ToString("yyyy-MM-dd HH:mm:ss");
                }
                strHtml = dataHtml.Replace("{value}", value);
                break;

            case (int)Enums.FormInputType.普通文字框:
                strHtml = inputHtml.Replace("{value}", value);
                if (fieldData.FIELD_DATA_TYPE == (int)Enums.FieldDataType.数值)    //如果是数值性的就用数值型的文本
                {
                    strHtml = strHtml.Replace("type=\"text\"", "type=\"number\"");
                }
                break;

            case (int)Enums.FormInputType.拉树选择:
                strHtml  = treeHtml.Replace("{value}", value);
                strHtml += GetTrea(fieldData);
                break;

            default:
                strHtml = inputHtml.Replace("{value}", value);
                break;
            }
            strHtml = strHtml.Replace("{id}", enName).Replace("{name}", enName);
            strHtml = strHtml.Replace("{name}", enName).Replace("{别名}", enName);
            strHtml = strHtml.Replace("{提示}", "请输入" + fieldData.CN_NAME).Replace("{别名}", enName);
            strHtml = strHtml.Replace("{验证}", (fieldData.IS_NOT_NULL == 1 ? "required" : ""));
            #region 加入编辑时只读标签
            if (row != null && fieldData.IS_READONLY == 1)//是否为编辑时的只读字段
            {
                strHtml = strHtml.Replace("{只读}", "readonly=\"readonly\"");
            }
            else
            {
                strHtml = strHtml.Replace("{只读}", "");
            }
            #endregion

            return(strHtml);
        }