/// <summary> /// 更新一条数据 /// </summary> public void Update(Lebi_Cnzz model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update " + TableName + " set "); List <string> cols = new List <string>(); if (("," + model.UpdateCols + ",").IndexOf(",Ccontent,") > -1 || model.UpdateCols == "") { cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("Ccontent") + "= @Ccontent"); } if (("," + model.UpdateCols + ",").IndexOf(",state,") > -1 || model.UpdateCols == "") { cols.Add(LB.DataAccess.DB.BaseUtilsInstance.ColName("state") + "= @state"); } strSql.Append(string.Join(",", cols)); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", model.id), new SqlParameter("@Ccontent", model.Ccontent), new SqlParameter("@state", model.state) }; LB.DataAccess.DB.Instance.TextExecuteNonQuery(strSql.ToString().Replace(", where id=@id", " where id=@id"), parameters); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Lebi_Cnzz model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into " + TableName + " ("); strSql.Append(LB.DataAccess.DB.BaseUtilsInstance.ColName("Ccontent") + "," + LB.DataAccess.DB.BaseUtilsInstance.ColName("state") + ")"); strSql.Append(" values ("); strSql.Append("@Ccontent,@state);select @@identity;"); SqlParameter[] parameters = { new SqlParameter("@Ccontent", model.Ccontent), new SqlParameter("@state", model.state) }; object obj = LB.DataAccess.DB.Instance.TextExecute(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 安全方式绑定对象表单 /// </summary> public Lebi_Cnzz SafeBindForm(Lebi_Cnzz model) { if (HttpContext.Current.Request["Ccontent"] != null) { model.Ccontent = LB.Tools.RequestTool.RequestSafeString("Ccontent"); } if (HttpContext.Current.Request["state"] != null) { model.state = LB.Tools.RequestTool.RequestInt("state", 0); } return(model); }
/// <summary> /// 对象实体绑定数据 /// </summary> public Lebi_Cnzz ReaderBind(IDataReader dataReader) { Lebi_Cnzz model = new Lebi_Cnzz(); object ojb; ojb = dataReader["id"]; if (ojb != null && ojb != DBNull.Value) { model.id = Convert.ToInt32(ojb); } model.Ccontent = dataReader["Ccontent"].ToString(); ojb = dataReader["state"]; if (ojb != null && ojb != DBNull.Value) { model.state = Convert.ToInt32(ojb); } return(model); }
/// <summary> /// 得到一个对象实体 by where条件 /// </summary> public Lebi_Cnzz 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_Cnzz); } } Lebi_Cnzz 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_Cnzz", model.id, cachestr, seconds); } return(model); } } return(null); }
/// <summary> /// 更新一条数据 /// </summary> public static void Update(Lebi_Cnzz model) { D_Lebi_Cnzz.Instance.Update(model); }
/// <summary> /// 增加一条数据 /// </summary> public static int Add(Lebi_Cnzz model) { return(D_Lebi_Cnzz.Instance.Add(model)); }
/// <summary> /// 安全方式绑定表单数据 /// </summary> public static Lebi_Cnzz SafeBindForm(Lebi_Cnzz model) { return(D_Lebi_Cnzz.Instance.SafeBindForm(model)); }