Пример #1
0
        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public Lebi_Tab ReaderBind(IDataReader dataReader)
        {
            Lebi_Tab model = new Lebi_Tab();
            object   ojb;

            ojb = dataReader["id"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.id = Convert.ToInt32(ojb);
            }
            model.Description = dataReader["Description"].ToString();
            ojb = dataReader["Mode"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Mode = Convert.ToInt32(ojb);
            }
            ojb = dataReader["Position"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Position = Convert.ToInt32(ojb);
            }
            model.Tdes     = dataReader["Tdes"].ToString();
            model.Tdirname = dataReader["Tdirname"].ToString();
            model.Title    = dataReader["Title"].ToString();
            model.Tkey     = dataReader["Tkey"].ToString();
            model.Tname    = dataReader["Tname"].ToString();
            ojb            = dataReader["Tsort"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Tsort = Convert.ToInt32(ojb);
            }
            model.Url = dataReader["Url"].ToString();
            return(model);
        }
Пример #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Lebi_Tab model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into " + TableName + " (");
            strSql.Append(LB.DataAccess.DB.BaseUtilsInstance.ColName("Description") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("Mode") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("Position") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("Tdes") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("Tdirname") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("Title") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("Tkey") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("Tname") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("Tsort") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("Url") + ")");
            strSql.Append(" values (");
            strSql.Append("@Description,@Mode,@Position,@Tdes,@Tdirname,@Title,@Tkey,@Tname,@Tsort,@Url);select @@identity;");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Description", model.Description),
                new SqlParameter("@Mode",        model.Mode),
                new SqlParameter("@Position",    model.Position),
                new SqlParameter("@Tdes",        model.Tdes),
                new SqlParameter("@Tdirname",    model.Tdirname),
                new SqlParameter("@Title",       model.Title),
                new SqlParameter("@Tkey",        model.Tkey),
                new SqlParameter("@Tname",       model.Tname),
                new SqlParameter("@Tsort",       model.Tsort),
                new SqlParameter("@Url",         model.Url)
            };

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

            if (obj == null)
            {
                return(1);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Пример #3
0
 /// <summary>
 /// 安全方式绑定对象表单
 /// </summary>
 public Lebi_Tab SafeBindForm(Lebi_Tab model)
 {
     if (HttpContext.Current.Request["Description"] != null)
     {
         model.Description = LB.Tools.RequestTool.RequestSafeString("Description");
     }
     if (HttpContext.Current.Request["Mode"] != null)
     {
         model.Mode = LB.Tools.RequestTool.RequestInt("Mode", 0);
     }
     if (HttpContext.Current.Request["Position"] != null)
     {
         model.Position = LB.Tools.RequestTool.RequestInt("Position", 0);
     }
     if (HttpContext.Current.Request["Tdes"] != null)
     {
         model.Tdes = LB.Tools.RequestTool.RequestSafeString("Tdes");
     }
     if (HttpContext.Current.Request["Tdirname"] != null)
     {
         model.Tdirname = LB.Tools.RequestTool.RequestSafeString("Tdirname");
     }
     if (HttpContext.Current.Request["Title"] != null)
     {
         model.Title = LB.Tools.RequestTool.RequestSafeString("Title");
     }
     if (HttpContext.Current.Request["Tkey"] != null)
     {
         model.Tkey = LB.Tools.RequestTool.RequestSafeString("Tkey");
     }
     if (HttpContext.Current.Request["Tname"] != null)
     {
         model.Tname = LB.Tools.RequestTool.RequestSafeString("Tname");
     }
     if (HttpContext.Current.Request["Tsort"] != null)
     {
         model.Tsort = LB.Tools.RequestTool.RequestInt("Tsort", 0);
     }
     if (HttpContext.Current.Request["Url"] != null)
     {
         model.Url = LB.Tools.RequestTool.RequestSafeString("Url");
     }
     return(model);
 }
Пример #4
0
        /// <summary>
        /// 得到一个对象实体 by where条件
        /// </summary>
        public Lebi_Tab 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_Tab);
                }
            }
            Lebi_Tab 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_Tab", model.id, cachestr, seconds);
                    }
                    return(model);
                }
            }
            return(null);
        }
Пример #5
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Lebi_Tab model)
        {
            StringBuilder strSql = new StringBuilder();

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

            if (("," + model.UpdateCols + ",").IndexOf(",Description,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("Description") + "= @Description");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",Mode,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("Mode") + "= @Mode");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",Position,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("Position") + "= @Position");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",Tdes,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("Tdes") + "= @Tdes");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",Tdirname,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("Tdirname") + "= @Tdirname");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",Title,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("Title") + "= @Title");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",Tkey,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("Tkey") + "= @Tkey");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",Tname,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("Tname") + "= @Tname");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",Tsort,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("Tsort") + "= @Tsort");
            }
            if (("," + model.UpdateCols + ",").IndexOf(",Url,") > -1 || model.UpdateCols == "")
            {
                cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("Url") + "= @Url");
            }
            strSql.Append(string.Join(",", cols));
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id",          model.id),
                new SqlParameter("@Description", model.Description),
                new SqlParameter("@Mode",        model.Mode),
                new SqlParameter("@Position",    model.Position),
                new SqlParameter("@Tdes",        model.Tdes),
                new SqlParameter("@Tdirname",    model.Tdirname),
                new SqlParameter("@Title",       model.Title),
                new SqlParameter("@Tkey",        model.Tkey),
                new SqlParameter("@Tname",       model.Tname),
                new SqlParameter("@Tsort",       model.Tsort),
                new SqlParameter("@Url",         model.Url)
            };
            LB.DataAccess.DB.Instance.TextExecuteNonQuery(strSql.ToString().Replace(", where id=@id", " where id=@id"), parameters);
        }
Пример #6
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public static void Update(Lebi_Tab model)
 {
     D_Lebi_Tab.Instance.Update(model);
 }
Пример #7
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public static int Add(Lebi_Tab model)
 {
     return(D_Lebi_Tab.Instance.Add(model));
 }
Пример #8
0
 /// <summary>
 /// 安全方式绑定表单数据
 /// </summary>
 public static Lebi_Tab SafeBindForm(Lebi_Tab model)
 {
     return(D_Lebi_Tab.Instance.SafeBindForm(model));
 }