Example #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Lebi_Table model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into " + TableName + " (");
            strSql.Append(LB.DataAccess.DB.BaseUtilsInstance.ColName("char_length") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("defaultval") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("isidentity") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("isnullable") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("ispk") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("name") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("numeric_length") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("numeric_scale") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("parentid") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("parentname") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("remark") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("type") + ")");
            strSql.Append(" values (");
            strSql.Append("@char_length,@defaultval,@isidentity,@isnullable,@ispk,@name,@numeric_length,@numeric_scale,@parentid,@parentname,@remark,@type);select @@identity;");
            SqlParameter[] parameters =
            {
                new SqlParameter("@char_length",    model.char_length),
                new SqlParameter("@defaultval",     model.defaultval),
                new SqlParameter("@isidentity",     model.isidentity),
                new SqlParameter("@isnullable",     model.isnullable),
                new SqlParameter("@ispk",           model.ispk),
                new SqlParameter("@name",           model.name),
                new SqlParameter("@numeric_length", model.numeric_length),
                new SqlParameter("@numeric_scale",  model.numeric_scale),
                new SqlParameter("@parentid",       model.parentid),
                new SqlParameter("@parentname",     model.parentname),
                new SqlParameter("@remark",         model.remark),
                new SqlParameter("@type",           model.type)
            };

            object obj = LB.DataAccess.DB.Instance.TextExecute(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(1);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Example #2
0
        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public Lebi_Table ReaderBind(IDataReader dataReader)
        {
            Lebi_Table model = new Lebi_Table();
            object     ojb;

            ojb = dataReader["id"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.id = Convert.ToInt32(ojb);
            }
            ojb = dataReader["char_length"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.char_length = Convert.ToInt32(ojb);
            }
            model.defaultval = dataReader["defaultval"].ToString();
            ojb = dataReader["isidentity"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.isidentity = Convert.ToInt32(ojb);
            }
            ojb = dataReader["isnullable"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.isnullable = Convert.ToInt32(ojb);
            }
            ojb = dataReader["ispk"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ispk = Convert.ToInt32(ojb);
            }
            model.name = dataReader["name"].ToString();
            ojb        = dataReader["numeric_length"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.numeric_length = Convert.ToInt32(ojb);
            }
            ojb = dataReader["numeric_scale"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.numeric_scale = Convert.ToInt32(ojb);
            }
            ojb = dataReader["parentid"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.parentid = Convert.ToInt32(ojb);
            }
            model.parentname = dataReader["parentname"].ToString();
            model.remark     = dataReader["remark"].ToString();
            model.type       = dataReader["type"].ToString();
            return(model);
        }
Example #3
0
 /// <summary>
 /// 安全方式绑定对象表单
 /// </summary>
 public Lebi_Table SafeBindForm(Lebi_Table model)
 {
     if (HttpContext.Current.Request["char_length"] != null)
     {
         model.char_length = LB.Tools.RequestTool.RequestInt("char_length", 0);
     }
     if (HttpContext.Current.Request["defaultval"] != null)
     {
         model.defaultval = LB.Tools.RequestTool.RequestSafeString("defaultval");
     }
     if (HttpContext.Current.Request["isidentity"] != null)
     {
         model.isidentity = LB.Tools.RequestTool.RequestInt("isidentity", 0);
     }
     if (HttpContext.Current.Request["isnullable"] != null)
     {
         model.isnullable = LB.Tools.RequestTool.RequestInt("isnullable", 0);
     }
     if (HttpContext.Current.Request["ispk"] != null)
     {
         model.ispk = LB.Tools.RequestTool.RequestInt("ispk", 0);
     }
     if (HttpContext.Current.Request["name"] != null)
     {
         model.name = LB.Tools.RequestTool.RequestSafeString("name");
     }
     if (HttpContext.Current.Request["numeric_length"] != null)
     {
         model.numeric_length = LB.Tools.RequestTool.RequestInt("numeric_length", 0);
     }
     if (HttpContext.Current.Request["numeric_scale"] != null)
     {
         model.numeric_scale = LB.Tools.RequestTool.RequestInt("numeric_scale", 0);
     }
     if (HttpContext.Current.Request["parentid"] != null)
     {
         model.parentid = LB.Tools.RequestTool.RequestInt("parentid", 0);
     }
     if (HttpContext.Current.Request["parentname"] != null)
     {
         model.parentname = LB.Tools.RequestTool.RequestSafeString("parentname");
     }
     if (HttpContext.Current.Request["remark"] != null)
     {
         model.remark = LB.Tools.RequestTool.RequestSafeString("remark");
     }
     if (HttpContext.Current.Request["type"] != null)
     {
         model.type = LB.Tools.RequestTool.RequestSafeString("type");
     }
     return(model);
 }
Example #4
0
        /// <summary>
        /// 得到一个对象实体 by where条件
        /// </summary>
        public Lebi_Table GetModel(string strWhere, int seconds = 0)
        {
            if (strWhere.IndexOf("lbsql{") > 0)
            {
                SQLPara para = new SQLPara(strWhere, "", "");
                return(GetModel(para, seconds));
            }
            string strTableName = TableName;
            string strFieldShow = "*";
            string cachekey     = "";
            string cachestr     = "";

            if (BaseUtils.BaseUtilsInstance.MemcacheInstance != null && seconds > 0)
            {
                cachestr = "select * " + TableName + " where " + strWhere + "|" + seconds;
                cachekey = LB.Tools.Utils.MD5(cachestr);
                var obj = LB.DataAccess.DB.Instance.GetMemchche(cachekey);
                if (obj != null)
                {
                    return(obj as Lebi_Table);
                }
            }
            Lebi_Table model = null;

            using (IDataReader dataReader = LB.DataAccess.DB.Instance.TextExecuteReaderOne(strTableName, strFieldShow, strWhere, null))
            {
                if (dataReader == null)
                {
                    return(null);
                }
                while (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                    if (cachekey != "")
                    {
                        LB.DataAccess.DB.Instance.SetMemchche(cachekey, model, "Lebi_Table", model.id, cachestr, seconds);
                    }
                    return(model);
                }
            }
            return(null);
        }
Example #5
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Lebi_Table model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + TableName + " set ");
            List <string> cols = new List <string>();

            if (("," + model.UpdateCols + ",").IndexOf(",char_length,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("char_length") + "= @char_length");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",defaultval,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("defaultval") + "= @defaultval");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",isidentity,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("isidentity") + "= @isidentity");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",isnullable,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("isnullable") + "= @isnullable");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",ispk,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("ispk") + "= @ispk");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",name,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("name") + "= @name");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",numeric_length,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("numeric_length") + "= @numeric_length");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",numeric_scale,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("numeric_scale") + "= @numeric_scale");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",parentid,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("parentid") + "= @parentid");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",parentname,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("parentname") + "= @parentname");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",remark,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("remark") + "= @remark");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",type,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("type") + "= @type");
            }
            strSql.Append(string.Join(",", cols));
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id",             model.id),
                new SqlParameter("@char_length",    model.char_length),
                new SqlParameter("@defaultval",     model.defaultval),
                new SqlParameter("@isidentity",     model.isidentity),
                new SqlParameter("@isnullable",     model.isnullable),
                new SqlParameter("@ispk",           model.ispk),
                new SqlParameter("@name",           model.name),
                new SqlParameter("@numeric_length", model.numeric_length),
                new SqlParameter("@numeric_scale",  model.numeric_scale),
                new SqlParameter("@parentid",       model.parentid),
                new SqlParameter("@parentname",     model.parentname),
                new SqlParameter("@remark",         model.remark),
                new SqlParameter("@type",           model.type)
            };
            LB.DataAccess.DB.Instance.TextExecuteNonQuery(strSql.ToString().Replace(", where id=@id", " where id=@id"), parameters);
        }
Example #6
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public static void Update(Lebi_Table model)
 {
     D_Lebi_Table.Instance.Update(model);
 }
Example #7
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public static int Add(Lebi_Table model)
 {
     return(D_Lebi_Table.Instance.Add(model));
 }
Example #8
0
 /// <summary>
 /// 安全方式绑定表单数据
 /// </summary>
 public static Lebi_Table SafeBindForm(Lebi_Table model)
 {
     return(D_Lebi_Table.Instance.SafeBindForm(model));
 }