Exemplo n.º 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(PubtypeEntity model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Pubtype(");
            strSql.Append("typename,enable");
            strSql.Append(") values (");
            strSql.Append("@typename,@enable");
            strSql.Append(") ");
            strSql.Append(";select SCOPE_IDENTITY()");
            SqlParameter[] parameters = {
                        new SqlParameter("@typename", SqlDbType.VarChar,50) ,
                        new SqlParameter("@enable", SqlDbType.Bit,1)

            };

            parameters[0].Value = model.typename;
            parameters[1].Value = model.enable;

            DataTable dt = DBExecuteUtil.querySqlTable(strSql.ToString(), parameters);
            if (dt.Rows.Count == 0)
            {

                return 0;

            }
            else
            {

                return Convert.ToInt32(dt.Rows[0][0].ToString());

            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<PubtypeEntity> DataTableToList(DataTable dt)
        {
            List<PubtypeEntity> modelList = new List<PubtypeEntity>();
            int rowsCount = dt.Rows.Count;
            int result;
            if (rowsCount > 0)
            {
                PubtypeEntity model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new PubtypeEntity();
                    if (dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    model.id = int.TryParse(dt.Rows[n]["id"].ToString(), out result) ? result : 0;
                    model.typename = dt.Rows[n]["typename"].ToString();
                    if (dt.Rows[n]["enable"].ToString() != "")
                    {
                        if ((dt.Rows[n]["enable"].ToString() == "1") || (dt.Rows[n]["enable"].ToString().ToLower() == "true"))
                        {
                            model.enable = true;
                        }
                        else
                        {
                            model.enable = false;
                        }
                    }

                    modelList.Add(model);
                }
            }
            return modelList;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(PubtypeEntity model)
        {
            StringBuilder strSql = new StringBuilder();
            List<SqlParameter> parameters = new List<SqlParameter>();
            strSql.Append("update Pubtype set ");

            if (!string.IsNullOrEmpty(model.typename))
            {
                strSql.Append(" typename = @typename , ");
                parameters.Add(new SqlParameter("@typename", model.typename));
            }
            strSql.Append(" enable = @enable , ");
            parameters.Add(new SqlParameter("@enable", model.enable));
            strSql = strSql.Remove(strSql.Length - 2, 2);
            strSql.Append(" where id=@id ");
            parameters.Add(new SqlParameter("@id", model.id));
            int rows = DBExecuteUtil.ExecuteSqlWithParams(strSql.ToString(), parameters.ToArray());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// 获取分页数据
 /// </summary>
 /// <returns></returns>
 public DataTable GetPage(int pageIndex, int pageSize, PubtypeEntity model, out int count)
 {
     count = 0;
     SqlParameter[] items = new SqlParameter[]{
         new SqlParameter("pageIndex",pageIndex),
         new SqlParameter("pageSize",pageSize),
         new SqlParameter("count",count)
     };
     items[2].Direction = ParameterDirection.Output;
     var dt = DBStoreProUtil.queryProTable4Params("proc_Pubtype_Pagedata", items);
     count = int.Parse(items[2].Value.ToString());
     return dt;
 }
Exemplo n.º 5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PubtypeEntity GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id, typename, enable  ");
            strSql.Append("  from Pubtype ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int,4)
            };
            parameters[0].Value = id;

            PubtypeEntity model = new PubtypeEntity();
            DataTable dt = DBExecuteUtil.querySqlTable(strSql.ToString(), parameters);

            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(dt.Rows[0]["id"].ToString());
                }
                model.typename = dt.Rows[0]["typename"].ToString();
                if (dt.Rows[0]["enable"].ToString() != "")
                {
                    if ((dt.Rows[0]["enable"].ToString() == "1") || (dt.Rows[0]["enable"].ToString().ToLower() == "true"))
                    {
                        model.enable = true;
                    }
                    else
                    {
                        model.enable = false;
                    }
                }

                return model;
            }
            else
            {
                return null;
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(PubtypeEntity model)
 {
     return dal.Add(model);
 }
Exemplo n.º 7
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(PubtypeEntity model)
 {
     return dal.Update(model);
 }
Exemplo n.º 8
0
 /// <summary>
 /// 获得分页数据
 /// </summary>
 /// <param name="pageIndex"></param>
 /// <param name="pageSize"></param>
 /// <param name="model"></param>
 /// <returns></returns>
 public DataTable GetPage(int pageIndex, int pageSize, PubtypeEntity model, out int count)
 {
     return dal.GetPage(pageIndex, pageSize, model, out count);
 }