예제 #1
0
        protected Model.SourceInfoModel AutoBindDataReader(SqlDataReader dr, params string[] fields)
        {
            var model = new Model.SourceInfoModel();

            if (DbTool.HasFields("Id", fields))
            {
                model.Id = DbTool.ConvertObject <System.Int32>(dr["Id"]);
            }
            if (DbTool.HasFields("Ip", fields))
            {
                model.Ip = DbTool.ConvertObject <System.String>(dr["Ip"]);
            }
            if (DbTool.HasFields("Pros", fields))
            {
                model.Pros = DbTool.ConvertObject <System.String>(dr["Pros"]);
            }
            if (DbTool.HasFields("City", fields))
            {
                model.City = DbTool.ConvertObject <System.String>(dr["City"]);
            }
            if (DbTool.HasFields("SourceUrl", fields))
            {
                model.SourceUrl = DbTool.ConvertObject <System.String>(dr["SourceUrl"]);
            }
            if (DbTool.HasFields("Dtime", fields))
            {
                model.Dtime = DbTool.ConvertObject <System.DateTime>(dr["Dtime"]);
            }
            if (DbTool.HasFields("Type", fields))
            {
                model.Type = DbTool.ConvertObject <System.String>(dr["Type"]);
            }

            return(model);
        }
예제 #2
0
 protected void BindDataReader(Model.SourceInfoModel model, SqlDataReader dr)
 {
     model.Id        = DbTool.ConvertObject <System.Int32>(dr["Id"]);
     model.Ip        = DbTool.ConvertObject <System.String>(dr["Ip"]);
     model.Pros      = DbTool.ConvertObject <System.String>(dr["Pros"]);
     model.City      = DbTool.ConvertObject <System.String>(dr["City"]);
     model.SourceUrl = DbTool.ConvertObject <System.String>(dr["SourceUrl"]);
     model.Dtime     = DbTool.ConvertObject <System.DateTime>(dr["Dtime"]);
     model.Type      = DbTool.ConvertObject <System.String>(dr["Type"]);
 }
예제 #3
0
        public Model.SourceInfoModel GetModel(int Id)
        {
            string sql = "select top 1 * from SourceInfo where Id =" + Id;

            Model.SourceInfoModel model = new Model.SourceInfoModel();
            SqlDataReader         dr    = SqlHelper.ExecuteReader(conn, CommandType.Text, sql.ToString());

            if (dr.Read())
            {
                //var fields = DbTool.GetReaderFieldNames(dr);
                //model = AutoBindDataReader(dr, fields);
                BindDataReader(model, dr);
            }
            dr.Close();
            return(model);
        }
예제 #4
0
        public List <Model.SourceInfoModel> GetModelList()
        {
            List <Model.SourceInfoModel> result = new List <Model.SourceInfoModel>();
            string sql = "select * from SourceInfo where 1=1";

            Model.SourceInfoModel model = new Model.SourceInfoModel();
            SqlDataReader         dr    = SqlHelper.ExecuteReader(conn, CommandType.Text, sql.ToString());

            //var fields = DbTool.GetReaderFieldNames(dr);
            while (dr.Read())
            {
                //model = AutoBindDataReader(dr, fields);
                model = new Model.SourceInfoModel();
                BindDataReader(model, dr);
                result.Add(model);
            }
            dr.Close();
            return(result);
        }
예제 #5
0
        public int Add(Model.SourceInfoModel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into  [SourceInfo]");
            strSql.Append("(Ip,Pros,City,SourceUrl,Dtime,Type)");
            strSql.Append(" values (@Ip,@Pros,@City,@SourceUrl,@Dtime,@Type)");
            strSql.Append(";select SCOPE_IDENTITY()");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Ip", DbTool.FixSqlParameter(model.Ip))
                ,                       new SqlParameter("@Pros", DbTool.FixSqlParameter(model.Pros))
                ,                       new SqlParameter("@City", DbTool.FixSqlParameter(model.City))
                ,                       new SqlParameter("@SourceUrl", DbTool.FixSqlParameter(model.SourceUrl))
                ,                       new SqlParameter("@Dtime", DbTool.FixSqlParameter(model.Dtime))
                ,                       new SqlParameter("@Type", DbTool.FixSqlParameter(model.Type))
            };


            return(DbTool.ConvertObject <int>(SqlHelper.ExecuteScalar(conn, CommandType.Text, strSql.ToString(), parameters), 0));
        }
예제 #6
0
        public int Update(Model.SourceInfoModel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update SourceInfo set ");
            strSql.Append("Ip=@Ip,Pros=@Pros,City=@City,SourceUrl=@SourceUrl,Dtime=@Dtime,Type=@Type ");
            strSql.Append(" where Id=@Id ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@Ip", DbTool.FixSqlParameter(model.Ip))
                ,                       new SqlParameter("@Pros", DbTool.FixSqlParameter(model.Pros))
                ,                       new SqlParameter("@City", DbTool.FixSqlParameter(model.City))
                ,                       new SqlParameter("@SourceUrl", DbTool.FixSqlParameter(model.SourceUrl))
                ,                       new SqlParameter("@Dtime", DbTool.FixSqlParameter(model.Dtime))
                ,                       new SqlParameter("@Type", DbTool.FixSqlParameter(model.Type))
                ,                       new SqlParameter("@Id", model.Id)
            };


            return(SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters));
        }