示例#1
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Lythen.Model.schools DataRowToModel(DataRow row)
 {
     Lythen.Model.schools model = new Lythen.Model.schools();
     if (row != null)
     {
         if (row["School_id"] != null && row["School_id"].ToString() != "")
         {
             model.School_id = int.Parse(row["School_id"].ToString());
         }
         if (row["School_name"] != null)
         {
             model.School_name = row["School_name"].ToString();
         }
         if (row["School_address"] != null)
         {
             model.School_address = row["School_address"].ToString();
         }
         if (row["School_contact_man"] != null)
         {
             model.School_contact_man = row["School_contact_man"].ToString();
         }
         if (row["School_contact_phone"] != null)
         {
             model.School_contact_phone = row["School_contact_phone"].ToString();
         }
         if (row["School_info"] != null)
         {
             model.School_info = row["School_info"].ToString();
         }
     }
     return(model);
 }
示例#2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Lythen.Model.schools model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into schools(");
            strSql.Append("School_name,School_address,School_contact_man,School_contact_phone,School_info)");
            strSql.Append(" values (");
            strSql.Append("@School_name,@School_address,@School_contact_man,@School_contact_phone,@School_info)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@School_name",          SqlDbType.VarChar,  50),
                new SqlParameter("@School_address",       SqlDbType.VarChar, 250),
                new SqlParameter("@School_contact_man",   SqlDbType.VarChar,  20),
                new SqlParameter("@School_contact_phone", SqlDbType.VarChar,  12),
                new SqlParameter("@School_info",          SqlDbType.VarChar, 500)
            };
            parameters[0].Value = model.School_name;
            parameters[1].Value = model.School_address;
            parameters[2].Value = model.School_contact_man;
            parameters[3].Value = model.School_contact_phone;
            parameters[4].Value = model.School_info;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
示例#3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Lythen.Model.schools model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update schools set ");
            strSql.Append("School_name=@School_name,");
            strSql.Append("School_address=@School_address,");
            strSql.Append("School_contact_man=@School_contact_man,");
            strSql.Append("School_contact_phone=@School_contact_phone,");
            strSql.Append("School_info=@School_info");
            strSql.Append(" where School_id=@School_id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@School_name",          SqlDbType.VarChar,  50),
                new SqlParameter("@School_address",       SqlDbType.VarChar, 250),
                new SqlParameter("@School_contact_man",   SqlDbType.VarChar,  20),
                new SqlParameter("@School_contact_phone", SqlDbType.VarChar,  12),
                new SqlParameter("@School_info",          SqlDbType.VarChar, 500),
                new SqlParameter("@School_id",            SqlDbType.Int, 4)
            };
            parameters[0].Value = model.School_name;
            parameters[1].Value = model.School_address;
            parameters[2].Value = model.School_contact_man;
            parameters[3].Value = model.School_contact_phone;
            parameters[4].Value = model.School_info;
            parameters[5].Value = model.School_id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Lythen.Model.schools GetModel(int School_id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 School_id,School_name,School_address,School_contact_man,School_contact_phone,School_info from schools ");
            strSql.Append(" where School_id=@School_id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@School_id", SqlDbType.Int, 4)
            };
            parameters[0].Value = School_id;

            Lythen.Model.schools model = new Lythen.Model.schools();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }