/// <summary> /// 得到一个对象实体 /// </summary> public Model.Infos GetModel(string strWhere, List <SqlParameter> parameters) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from Infos "); Database db = DatabaseFactory.CreateDatabase(); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); if (parameters.Count > 0) { foreach (SqlParameter sqlParameter in parameters) { dbCommand.Parameters.Add(sqlParameter); } } Model.Infos model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } return(model); }
public Model.Infos GetModel(int tiid, int sortnum) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from Infos join TmpInfoList on TmpInfoList.IID=Infos.IID where Infos.SortNum=" + sortnum + " and TmpInfoList.TIID=" + tiid); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); Model.Infos model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.Infos model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Infos("); strSql.Append("IName,PicAttID,IType,TIID,LID,SortNum,Status,CreateDate,Context,ConPosition,ConColor,ConSize,XPosition,YPosition,VideoAttID,NType,HotType,ADTime,ADPic,ADLink)"); strSql.Append(" values ("); strSql.Append("@IName,@PicAttID,@IType,@TIID,@LID,@SortNum,@Status,@CreateDate,@Context,@ConPosition,@ConColor,@ConSize,@XPosition,@YPosition,@VideoAttID,@NType,@HotType,@ADTime,@ADPic,@ADLink)"); strSql.Append(";select @@IDENTITY"); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "IName", DbType.String, model.IName); db.AddInParameter(dbCommand, "PicAttID", DbType.String, model.PicAttID); db.AddInParameter(dbCommand, "IType", DbType.Int32, model.IType); db.AddInParameter(dbCommand, "TIID", DbType.Int32, model.TIID); db.AddInParameter(dbCommand, "LID", DbType.Int32, model.LID); db.AddInParameter(dbCommand, "SortNum", DbType.Int32, model.SortNum); db.AddInParameter(dbCommand, "Status", DbType.Byte, model.Status); db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, model.CreateDate); db.AddInParameter(dbCommand, "Context", DbType.String, model.Context); db.AddInParameter(dbCommand, "ConPosition", DbType.String, model.ConPosition); db.AddInParameter(dbCommand, "ConColor", DbType.String, model.ConColor); db.AddInParameter(dbCommand, "ConSize", DbType.String, model.ConSize); db.AddInParameter(dbCommand, "XPosition", DbType.String, model.XPosition); db.AddInParameter(dbCommand, "YPosition", DbType.String, model.YPosition); db.AddInParameter(dbCommand, "VideoAttID", DbType.String, model.VideoAttID); db.AddInParameter(dbCommand, "NType", DbType.Byte, model.NType); db.AddInParameter(dbCommand, "HotType", DbType.Byte, model.HotType); db.AddInParameter(dbCommand, "ADTime", DbType.String, model.ADTime); db.AddInParameter(dbCommand, "ADPic", DbType.String, model.ADPic); db.AddInParameter(dbCommand, "ADLink", DbType.String, model.ADLink); int result; object obj = db.ExecuteScalar(dbCommand); if (!int.TryParse(obj.ToString(), out result)) { return(0); } return(result); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.Infos GetModel(int IID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select IID,IName,PicAttID,IType,TIID,LID,SortNum,Status,CreateDate,Context,ConPosition,ConColor,ConSize,XPosition,YPosition,VideoAttID,NType,HotType,ADTime,ADPic,ADLink from Infos "); strSql.Append(" where IID=@IID "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "IID", DbType.Int32, IID); Model.Infos model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } return(model); }
/// <summary> /// 对象实体绑定数据 /// </summary> public Model.Infos ReaderBind(IDataReader dataReader) { Model.Infos model = new Model.Infos(); object ojb; ojb = dataReader["IID"]; if (ojb != null && ojb != DBNull.Value) { model.IID = Convert.ToInt32(ojb); } model.IName = dataReader["IName"].ToString(); model.PicAttID = dataReader["PicAttID"].ToString(); ojb = dataReader["IType"]; if (ojb != null && ojb != DBNull.Value) { model.IType = Convert.ToInt32(ojb); } ojb = dataReader["TIID"]; if (ojb != null && ojb != DBNull.Value) { model.TIID = Convert.ToInt32(ojb); } ojb = dataReader["LID"]; if (ojb != null && ojb != DBNull.Value) { model.LID = Convert.ToInt32(ojb); } ojb = dataReader["SortNum"]; if (ojb != null && ojb != DBNull.Value) { model.SortNum = Convert.ToInt32(ojb); } ojb = dataReader["Status"]; if (ojb != null && ojb != DBNull.Value) { model.Status = Convert.ToInt32(ojb); } ojb = dataReader["CreateDate"]; if (ojb != null && ojb != DBNull.Value) { model.CreateDate = Convert.ToDateTime(ojb); } model.Context = dataReader["Context"].ToString(); model.ConPosition = dataReader["ConPosition"].ToString(); model.ConColor = dataReader["ConColor"].ToString(); model.ConSize = dataReader["ConSize"].ToString(); model.XPosition = dataReader["XPosition"].ToString(); model.YPosition = dataReader["YPosition"].ToString(); model.VideoAttID = dataReader["VideoAttID"].ToString(); ojb = dataReader["NType"]; if (ojb != null && ojb != DBNull.Value) { model.NType = Convert.ToInt32(ojb); } ojb = dataReader["HotType"]; if (ojb != null && ojb != DBNull.Value) { model.HotType = Convert.ToInt32(ojb); } model.ADTime = dataReader["ADTime"].ToString(); model.ADPic = dataReader["ADPic"].ToString(); model.ADLink = dataReader["ADLink"].ToString(); return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.Infos DataRowToModel(DataRow row) { Model.Infos model = new Model.Infos(); if (row != null) { if (row["IID"] != null && row["IID"].ToString() != "") { model.IID = Convert.ToInt32(row["IID"].ToString()); } if (row["IName"] != null) { model.IName = row["IName"].ToString(); } if (row["PicAttID"] != null) { model.PicAttID = row["PicAttID"].ToString(); } if (row["IType"] != null && row["IType"].ToString() != "") { model.IType = Convert.ToInt32(row["IType"].ToString()); } if (row["TIID"] != null && row["TIID"].ToString() != "") { model.TIID = Convert.ToInt32(row["TIID"].ToString()); } if (row["LID"] != null && row["LID"].ToString() != "") { model.LID = Convert.ToInt32(row["LID"].ToString()); } if (row["SortNum"] != null && row["SortNum"].ToString() != "") { model.SortNum = Convert.ToInt32(row["SortNum"].ToString()); } if (row["Status"] != null && row["Status"].ToString() != "") { model.Status = Convert.ToInt32(row["Status"].ToString()); } if (row["CreateDate"] != null && row["CreateDate"].ToString() != "") { model.CreateDate = Convert.ToDateTime(row["CreateDate"].ToString()); } if (row["Context"] != null) { model.Context = row["Context"].ToString(); } if (row["ConPosition"] != null) { model.ConPosition = row["ConPosition"].ToString(); } if (row["ConColor"] != null) { model.ConColor = row["ConColor"].ToString(); } if (row["ConSize"] != null) { model.ConSize = row["ConSize"].ToString(); } if (row["XPosition"] != null) { model.XPosition = row["XPosition"].ToString(); } if (row["YPosition"] != null) { model.YPosition = row["YPosition"].ToString(); } if (row["VideoAttID"] != null) { model.VideoAttID = row["VideoAttID"].ToString(); } if (row["NType"] != null && row["NType"].ToString() != "") { model.NType = Convert.ToInt32(row["NType"].ToString()); } if (row["HotType"] != null && row["HotType"].ToString() != "") { model.HotType = Convert.ToInt32(row["HotType"].ToString()); } if (row["ADTime"] != null) { model.ADTime = row["ADTime"].ToString(); } if (row["ADPic"] != null) { model.ADPic = row["ADPic"].ToString(); } if (row["ADLink"] != null) { model.ADLink = row["ADLink"].ToString(); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.Infos model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Infos set "); strSql.Append("IName=@IName,"); strSql.Append("PicAttID=@PicAttID,"); strSql.Append("IType=@IType,"); strSql.Append("TIID=@TIID,"); strSql.Append("LID=@LID,"); strSql.Append("SortNum=@SortNum,"); strSql.Append("Status=@Status,"); strSql.Append("CreateDate=@CreateDate,"); strSql.Append("Context=@Context,"); strSql.Append("ConPosition=@ConPosition,"); strSql.Append("ConColor=@ConColor,"); strSql.Append("ConSize=@ConSize,"); strSql.Append("XPosition=@XPosition,"); strSql.Append("YPosition=@YPosition,"); strSql.Append("VideoAttID=@VideoAttID,"); strSql.Append("NType=@NType,"); strSql.Append("HotType=@HotType,"); strSql.Append("ADTime=@ADTime,"); strSql.Append("ADPic=@ADPic,"); strSql.Append("ADLink=@ADLink"); strSql.Append(" where IID=@IID "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "IID", DbType.Int32, model.IID); db.AddInParameter(dbCommand, "IName", DbType.String, model.IName); db.AddInParameter(dbCommand, "PicAttID", DbType.String, model.PicAttID); db.AddInParameter(dbCommand, "IType", DbType.Int32, model.IType); db.AddInParameter(dbCommand, "TIID", DbType.Int32, model.TIID); db.AddInParameter(dbCommand, "LID", DbType.Int32, model.LID); db.AddInParameter(dbCommand, "SortNum", DbType.Int32, model.SortNum); db.AddInParameter(dbCommand, "Status", DbType.Byte, model.Status); db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, model.CreateDate); db.AddInParameter(dbCommand, "Context", DbType.String, model.Context); db.AddInParameter(dbCommand, "ConPosition", DbType.String, model.ConPosition); db.AddInParameter(dbCommand, "ConColor", DbType.String, model.ConColor); db.AddInParameter(dbCommand, "ConSize", DbType.String, model.ConSize); db.AddInParameter(dbCommand, "XPosition", DbType.String, model.XPosition); db.AddInParameter(dbCommand, "YPosition", DbType.String, model.YPosition); db.AddInParameter(dbCommand, "VideoAttID", DbType.String, model.VideoAttID); db.AddInParameter(dbCommand, "NType", DbType.Byte, model.NType); db.AddInParameter(dbCommand, "HotType", DbType.Byte, model.HotType); db.AddInParameter(dbCommand, "ADTime", DbType.String, model.ADTime); db.AddInParameter(dbCommand, "ADPic", DbType.String, model.ADPic); db.AddInParameter(dbCommand, "ADLink", DbType.String, model.ADLink); int rows = db.ExecuteNonQuery(dbCommand); if (rows > 0) { return(true); } else { return(false); } }