/// <summary> /// 更新一条数据 /// </summary> public bool Update(SM.YuQing.Model.Menu model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Menu set "); strSql.Append("Name=@Name,"); strSql.Append("ParentID=@ParentID,"); strSql.Append("Url=@Url,"); strSql.Append("Icons=@Icons,"); strSql.Append("Sort=@Sort,"); strSql.Append("CreateTime=@CreateTime,"); strSql.Append("CreatePerson=@CreatePerson,"); strSql.Append("UpdateTime=@UpdateTime,"); strSql.Append("UpdatePerson=@UpdatePerson"); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4), new SqlParameter("@Name", SqlDbType.NVarChar, 50), new SqlParameter("@ParentID", SqlDbType.Int, 4), new SqlParameter("@Url", SqlDbType.NVarChar, 200), new SqlParameter("@Icons", SqlDbType.NVarChar, 50), new SqlParameter("@Sort", SqlDbType.Int, 4), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@CreatePerson", SqlDbType.NVarChar, 50), new SqlParameter("@UpdateTime", SqlDbType.DateTime), new SqlParameter("@UpdatePerson", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.ID; parameters[1].Value = model.Name; parameters[2].Value = model.ParentID; parameters[3].Value = model.Url; parameters[4].Value = model.Icons; parameters[5].Value = model.Sort; parameters[6].Value = model.CreateTime; parameters[7].Value = model.CreatePerson; parameters[8].Value = model.UpdateTime; parameters[9].Value = model.UpdatePerson; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public SM.YuQing.Model.Menu DataRowToModel(DataRow row) { SM.YuQing.Model.Menu model = new SM.YuQing.Model.Menu(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["Name"] != null) { model.Name = row["Name"].ToString(); } if (row["ParentID"] != null && row["ParentID"].ToString() != "") { model.ParentID = int.Parse(row["ParentID"].ToString()); } if (row["Url"] != null) { model.Url = row["Url"].ToString(); } if (row["Icons"] != null) { model.Icons = row["Icons"].ToString(); } if (row["Sort"] != null && row["Sort"].ToString() != "") { model.Sort = int.Parse(row["Sort"].ToString()); } if (row["CreateTime"] != null && row["CreateTime"].ToString() != "") { model.CreateTime = DateTime.Parse(row["CreateTime"].ToString()); } if (row["CreatePerson"] != null) { model.CreatePerson = row["CreatePerson"].ToString(); } if (row["UpdateTime"] != null && row["UpdateTime"].ToString() != "") { model.UpdateTime = DateTime.Parse(row["UpdateTime"].ToString()); } if (row["UpdatePerson"] != null) { model.UpdatePerson = row["UpdatePerson"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(SM.YuQing.Model.Menu model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Menu("); strSql.Append("Name,ParentID,Url,Icons,Sort,CreateTime,CreatePerson,UpdateTime,UpdatePerson)"); strSql.Append(" values ("); strSql.Append("@Name,@ParentID,@Url,@Icons,@Sort,@CreateTime,@CreatePerson,@UpdateTime,@UpdatePerson)"); SqlParameter[] parameters = { new SqlParameter("@Name", SqlDbType.NVarChar, 50), new SqlParameter("@ParentID", SqlDbType.Int, 4), new SqlParameter("@Url", SqlDbType.NVarChar, 200), new SqlParameter("@Icons", SqlDbType.NVarChar, 50), new SqlParameter("@Sort", SqlDbType.Int, 4), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@CreatePerson", SqlDbType.NVarChar, 50), new SqlParameter("@UpdateTime", SqlDbType.DateTime), new SqlParameter("@UpdatePerson", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.Name; parameters[1].Value = model.ParentID; parameters[2].Value = model.Url; parameters[3].Value = model.Icons; parameters[4].Value = model.Sort; parameters[5].Value = model.CreateTime; parameters[6].Value = model.CreatePerson; parameters[7].Value = model.UpdateTime; parameters[8].Value = model.UpdatePerson; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public SM.YuQing.Model.Menu GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,Name,ParentID,Url,Icons,Sort,CreateTime,CreatePerson,UpdateTime,UpdatePerson from Menu "); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; SM.YuQing.Model.Menu model = new SM.YuQing.Model.Menu(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }