/// <summary> /// 条件联动更新一条部分数据 ///Lid,Lshow,Ltitle /// </summary> public bool UpdateMenu(LearnSite.Model.ListMenu model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update ListMenu set "); strSql.Append("Lshow=@Lshow,"); strSql.Append("Ltitle=@Ltitle"); strSql.Append(" where Lid=@Lid "); SqlParameter[] parameters = { new SqlParameter("@Lid", SqlDbType.Int, 4), new SqlParameter("@Lshow", SqlDbType.Bit, 1), new SqlParameter("@Ltitle", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.Lid; parameters[1].Value = model.Lshow; parameters[2].Value = model.Ltitle; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public LearnSite.Model.ListMenu GetModel(int Lid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Lid,Lcid,Lsort,Ltype,Lxid,Lshow,Ltitle from ListMenu "); strSql.Append(" where Lid=@Lid"); SqlParameter[] parameters = { new SqlParameter("@Lid", SqlDbType.Int, 4) }; parameters[0].Value = Lid; LearnSite.Model.ListMenu model = new LearnSite.Model.ListMenu(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Lid"] != null && ds.Tables[0].Rows[0]["Lid"].ToString() != "") { model.Lid = int.Parse(ds.Tables[0].Rows[0]["Lid"].ToString()); } if (ds.Tables[0].Rows[0]["Lcid"] != null && ds.Tables[0].Rows[0]["Lcid"].ToString() != "") { model.Lcid = int.Parse(ds.Tables[0].Rows[0]["Lcid"].ToString()); } if (ds.Tables[0].Rows[0]["Lsort"] != null && ds.Tables[0].Rows[0]["Lsort"].ToString() != "") { model.Lsort = int.Parse(ds.Tables[0].Rows[0]["Lsort"].ToString()); } if (ds.Tables[0].Rows[0]["Ltype"] != null && ds.Tables[0].Rows[0]["Ltype"].ToString() != "") { model.Ltype = int.Parse(ds.Tables[0].Rows[0]["Ltype"].ToString()); } if (ds.Tables[0].Rows[0]["Lxid"] != null && ds.Tables[0].Rows[0]["Lxid"].ToString() != "") { model.Lxid = int.Parse(ds.Tables[0].Rows[0]["Lxid"].ToString()); } if (ds.Tables[0].Rows[0]["Lshow"] != null && ds.Tables[0].Rows[0]["Lshow"].ToString() != "") { if ((ds.Tables[0].Rows[0]["Lshow"].ToString() == "1") || (ds.Tables[0].Rows[0]["Lshow"].ToString().ToLower() == "true")) { model.Lshow = true; } else { model.Lshow = false; } } if (ds.Tables[0].Rows[0]["Ltitle"] != null && ds.Tables[0].Rows[0]["Ltitle"].ToString() != "") { model.Ltitle = ds.Tables[0].Rows[0]["Ltitle"].ToString(); } return(model); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public LearnSite.Model.ListMenu GetModel(DataTable dt, int Tsort) { LearnSite.Model.ListMenu model = new LearnSite.Model.ListMenu(); int Count = dt.Rows.Count; if (Count > 0) { if (Tsort < Count) { if (dt.Rows[Tsort]["Lid"] != null && dt.Rows[Tsort]["Lid"].ToString() != "") { model.Lid = int.Parse(dt.Rows[Tsort]["Lid"].ToString()); } if (dt.Rows[Tsort]["Lcid"] != null && dt.Rows[Tsort]["Lcid"].ToString() != "") { model.Lcid = int.Parse(dt.Rows[Tsort]["Lcid"].ToString()); } if (dt.Rows[Tsort]["Lsort"] != null && dt.Rows[Tsort]["Lsort"].ToString() != "") { model.Lsort = int.Parse(dt.Rows[Tsort]["Lsort"].ToString()); } if (dt.Rows[Tsort]["Ltype"] != null && dt.Rows[Tsort]["Ltype"].ToString() != "") { model.Ltype = int.Parse(dt.Rows[Tsort]["Ltype"].ToString()); } if (dt.Rows[Tsort]["Lxid"] != null && dt.Rows[Tsort]["Lxid"].ToString() != "") { model.Lxid = int.Parse(dt.Rows[Tsort]["Lxid"].ToString()); } if (dt.Rows[Tsort]["Lshow"] != null && dt.Rows[Tsort]["Lshow"].ToString() != "") { if ((dt.Rows[Tsort]["Lshow"].ToString() == "1") || (dt.Rows[Tsort]["Lshow"].ToString().ToLower() == "true")) { model.Lshow = true; } else { model.Lshow = false; } } if (dt.Rows[Tsort]["Ltitle"] != null && dt.Rows[Tsort]["Ltitle"].ToString() != "") { model.Ltitle = dt.Rows[Tsort]["Ltitle"].ToString(); } return(model); } else { return(null); } } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(LearnSite.Model.ListMenu model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into ListMenu("); strSql.Append("Lcid,Lsort,Ltype,Lxid,Lshow,Ltitle)"); strSql.Append(" values ("); strSql.Append("@Lcid,@Lsort,@Ltype,@Lxid,@Lshow,@Ltitle)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Lcid", SqlDbType.Int, 4), new SqlParameter("@Lsort", SqlDbType.Int, 4), new SqlParameter("@Ltype", SqlDbType.Int, 4), new SqlParameter("@Lxid", SqlDbType.Int, 4), new SqlParameter("@Lshow", SqlDbType.Bit, 1), new SqlParameter("@Ltitle", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.Lcid; parameters[1].Value = model.Lsort; parameters[2].Value = model.Ltype; parameters[3].Value = model.Lxid; parameters[4].Value = model.Lshow; parameters[5].Value = model.Ltitle; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }