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