Пример #1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.SubwayInfo DataRowToModel(DataRow row)
        {
            Model.SubwayInfo model = new Model.SubwayInfo();
            if (row != null)
            {
                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.id = int.Parse(row["id"].ToString());
                }
                if (row["pid"] != null && row["pid"].ToString() != "")
                {
                    model.pid = int.Parse(row["pid"].ToString());
                }
                if (row["cid"] != null && row["cid"].ToString() != "")
                {
                    model.cid = int.Parse(row["cid"].ToString());
                }
                model.subwayName = row["subwayName"].ToString();

                if (row["status"] != null && row["status"].ToString() != "")
                {
                    model.status = int.Parse(row["status"].ToString());
                }
                if (row["remark"] != null)
                {
                    model.remark = row["remark"].ToString();
                }
                if (row["infoType"] != null && row["infoType"].ToString() != "")
                {
                    model.infoType = int.Parse(row["infoType"].ToString());
                }
            }
            return(model);
        }
Пример #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static int Add(Model.SubwayInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into SubwayInfo(");
            strSql.Append("pid,cid,subwayName,status,remark,infoType)");
            strSql.Append(" values (");
            strSql.Append("@pid,@cid,@subwayName,@status,@remark,@infoType)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@pid",        SqlDbType.Int,       4),
                new SqlParameter("@cid",        SqlDbType.Int,       4),
                new SqlParameter("@subwayName", SqlDbType.VarChar,  54),
                new SqlParameter("@status",     SqlDbType.Int,       4),
                new SqlParameter("@remark",     SqlDbType.VarChar, 150),
                new SqlParameter("@infoType",   SqlDbType.Int, 4)
            };
            parameters[0].Value = model.pid;
            parameters[1].Value = model.cid;
            parameters[2].Value = model.subwayName;
            parameters[3].Value = model.status;
            parameters[4].Value = model.remark;
            parameters[5].Value = model.infoType;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Пример #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.SubwayInfo GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,pid,cid,subwayName,status,remark,infoType from SubwayInfo ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            Model.SubwayInfo model = new Model.SubwayInfo();
            DataSet          ds    = DBHelperSQL.Query(strSql.ToString(), parameters);

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