Beispiel #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.LandCustomer model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into LandCustomer(");
            strSql.Append("LId,CId,ZwName,Area)");

            strSql.Append(" values (");
            strSql.Append("@LId,@CId,@ZwName,@Area)");
            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, "CId", DbType.Int32, model.CId);
            db.AddInParameter(dbCommand, "ZwName", DbType.String, model.ZwName);
            db.AddInParameter(dbCommand, "Area", DbType.Double, model.Area);
            int    result;
            object obj = db.ExecuteScalar(dbCommand);

            if (!int.TryParse(obj.ToString(), out result))
            {
                return(0);
            }
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public Model.LandCustomer ReaderBind(IDataReader dataReader)
        {
            Model.LandCustomer model = new Model.LandCustomer();
            object             ojb;

            ojb = dataReader["LCId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.LCId = Convert.ToInt32(ojb);
            }
            ojb = dataReader["LId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.LId = Convert.ToInt32(ojb);
            }
            ojb = dataReader["CId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CId = Convert.ToInt32(ojb);
            }
            model.ZwName = dataReader["ZwName"].ToString();
            ojb          = dataReader["Area"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Area = Convert.ToDecimal(ojb);
            }
            return(model);
        }
Beispiel #3
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Model.LandCustomer DataRowToModel(DataRow row)
 {
     Model.LandCustomer model = new Model.LandCustomer();
     if (row != null)
     {
         if (row["LCId"] != null && row["LCId"].ToString() != "")
         {
             model.LCId = Convert.ToInt32(row["LCId"].ToString());
         }
         if (row["LId"] != null && row["LId"].ToString() != "")
         {
             model.LId = Convert.ToInt32(row["LId"].ToString());
         }
         if (row["CId"] != null && row["CId"].ToString() != "")
         {
             model.CId = Convert.ToInt32(row["CId"].ToString());
         }
         if (row["ZwName"] != null)
         {
             model.ZwName = row["ZwName"].ToString();
         }
         if (row["Area"] != null && row["Area"].ToString() != "")
         {
             model.Area = Convert.ToDecimal(row["Area"].ToString());
         }
     }
     return(model);
 }
Beispiel #4
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.LandCustomer model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update LandCustomer set ");
            strSql.Append("LId=@LId,");
            strSql.Append("CId=@CId,");
            strSql.Append("ZwName=@ZwName,");
            strSql.Append("Area=@Area");
            strSql.Append(" where LCId=@LCId ");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "LCId", DbType.Int32, model.LCId);
            db.AddInParameter(dbCommand, "LId", DbType.Int32, model.LId);
            db.AddInParameter(dbCommand, "CId", DbType.Int32, model.CId);
            db.AddInParameter(dbCommand, "ZwName", DbType.String, model.ZwName);
            db.AddInParameter(dbCommand, "Area", DbType.Double, model.Area);
            int rows = db.ExecuteNonQuery(dbCommand);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.LandCustomer GetModel(int LCId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select LCId,LId,CId,ZwName,Area from LandCustomer ");
            strSql.Append(" where LCId=@LCId ");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "LCId", DbType.Int32, LCId);
            Model.LandCustomer model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
            }
            return(model);
        }