/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.LandAttributeValue model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into LandAttributeValue("); strSql.Append("LId,LAId,EmplId,LAValue,Addtime)"); strSql.Append(" values ("); strSql.Append("@LId,@LAId,@EmplId,@LAValue,@Addtime)"); strSql.Append(";select @@IDENTITY"); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "LId", DbType.Int32, model.LId); db.AddInParameter(dbCommand, "LAId", DbType.Int32, model.LAId); db.AddInParameter(dbCommand, "EmplId", DbType.Int32, model.EmplId); db.AddInParameter(dbCommand, "LAValue", DbType.String, model.LAValue); db.AddInParameter(dbCommand, "Addtime", DbType.DateTime, model.Addtime); int result; object obj = db.ExecuteScalar(dbCommand); if (!int.TryParse(obj.ToString(), out result)) { return(0); } return(result); }
/// <summary> /// 对象实体绑定数据 /// </summary> public Model.LandAttributeValue ReaderBind(IDataReader dataReader) { Model.LandAttributeValue model = new Model.LandAttributeValue(); object ojb; ojb = dataReader["LAVId"]; if (ojb != null && ojb != DBNull.Value) { model.LAVId = Convert.ToInt32(ojb); } ojb = dataReader["LId"]; if (ojb != null && ojb != DBNull.Value) { model.LId = Convert.ToInt32(ojb); } ojb = dataReader["LAId"]; if (ojb != null && ojb != DBNull.Value) { model.LAId = Convert.ToInt32(ojb); } ojb = dataReader["EmplId"]; if (ojb != null && ojb != DBNull.Value) { model.EmplId = Convert.ToInt32(ojb); } model.LAValue = dataReader["LAValue"].ToString(); ojb = dataReader["Addtime"]; if (ojb != null && ojb != DBNull.Value) { model.Addtime = Convert.ToDateTime(ojb); } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.LandAttributeValue DataRowToModel(DataRow row) { Model.LandAttributeValue model = new Model.LandAttributeValue(); if (row != null) { if (row["LAVId"] != null && row["LAVId"].ToString() != "") { model.LAVId = Convert.ToInt32(row["LAVId"].ToString()); } if (row["LId"] != null && row["LId"].ToString() != "") { model.LId = Convert.ToInt32(row["LId"].ToString()); } if (row["LAId"] != null && row["LAId"].ToString() != "") { model.LAId = Convert.ToInt32(row["LAId"].ToString()); } if (row["EmplId"] != null && row["EmplId"].ToString() != "") { model.EmplId = Convert.ToInt32(row["EmplId"].ToString()); } if (row["LAValue"] != null) { model.LAValue = row["LAValue"].ToString(); } if (row["Addtime"] != null && row["Addtime"].ToString() != "") { model.Addtime = Convert.ToDateTime(row["Addtime"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.LandAttributeValue model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update LandAttributeValue set "); strSql.Append("LId=@LId,"); strSql.Append("LAId=@LAId,"); strSql.Append("EmplId=@EmplId,"); strSql.Append("LAValue=@LAValue,"); strSql.Append("Addtime=@Addtime"); strSql.Append(" where LAVId=@LAVId "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "LAVId", DbType.Int32, model.LAVId); db.AddInParameter(dbCommand, "LId", DbType.Int32, model.LId); db.AddInParameter(dbCommand, "LAId", DbType.Int32, model.LAId); db.AddInParameter(dbCommand, "EmplId", DbType.Int32, model.EmplId); db.AddInParameter(dbCommand, "LAValue", DbType.String, model.LAValue); db.AddInParameter(dbCommand, "Addtime", DbType.DateTime, model.Addtime); int rows = db.ExecuteNonQuery(dbCommand); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.LandAttributeValue GetModel(int LAVId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select LAVId,LId,LAId,EmplId,LAValue,Addtime from LandAttributeValue "); strSql.Append(" where LAVId=@LAVId "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "LAVId", DbType.Int32, LAVId); Model.LandAttributeValue model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } return(model); }