Пример #1
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Com_busitypeEntity> DataTableToList(DataTable dt)
        {
            List<Com_busitypeEntity> modelList = new List<Com_busitypeEntity>();
            int rowsCount = dt.Rows.Count;
            int result;
            if (rowsCount > 0)
            {
                Com_busitypeEntity model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Com_busitypeEntity();
                    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;
                    if (dt.Rows[n]["pid"].ToString() != "")
                    {
                        model.pid = int.Parse(dt.Rows[n]["pid"].ToString());
                    }
                    model.pid = int.TryParse(dt.Rows[n]["pid"].ToString(), out result) ? result : 0;
                    model.name = dt.Rows[n]["name"].ToString();
                    model.value = dt.Rows[n]["value"].ToString();

                    modelList.Add(model);
                }
            }
            return modelList;
        }
Пример #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Com_busitypeEntity model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Com_busitype(");
            strSql.Append("pid,name,value");
            strSql.Append(") values (");
            strSql.Append("@pid,@name,@value");
            strSql.Append(") ");
            strSql.Append(";select SCOPE_IDENTITY()");
            SqlParameter[] parameters = {
                        new SqlParameter("@pid", SqlDbType.Int,4) ,
                        new SqlParameter("@name", SqlDbType.NVarChar,50) ,
                        new SqlParameter("@value", SqlDbType.VarChar,300)

            };

            parameters[0].Value = model.pid;
            parameters[1].Value = model.name;
            parameters[2].Value = model.value;

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

                return 0;

            }
            else
            {

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

            }
        }
Пример #3
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Com_busitypeEntity model)
 {
     return dal.Add(model);
 }
Пример #4
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Com_busitypeEntity model)
 {
     return dal.Update(model);
 }
Пример #5
0
 /// <summary>
 /// 获得分页数据
 /// </summary>
 /// <param name="pageIndex"></param>
 /// <param name="pageSize"></param>
 /// <param name="model"></param>
 /// <returns></returns>
 public DataTable GetPage(int pageIndex, int pageSize, Com_busitypeEntity model, out int count)
 {
     return dal.GetPage(pageIndex, pageSize, model, out count);
 }
Пример #6
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Com_busitypeEntity model)
        {
            StringBuilder strSql = new StringBuilder();
            List<SqlParameter> parameters = new List<SqlParameter>();
            strSql.Append("update Com_busitype set ");

            if (true)
            {
                strSql.Append(" pid = @pid , ");
                parameters.Add(new SqlParameter("@pid", model.pid));
            }

            if (!string.IsNullOrEmpty(model.name))
            {
                strSql.Append(" name = @name , ");
                parameters.Add(new SqlParameter("@name", model.name));
            }
            if (!string.IsNullOrEmpty(model.value))
            {
                strSql.Append(" value = @value , ");
                parameters.Add(new SqlParameter("@value", model.value));
            } 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;
            }
        }
Пример #7
0
 /// <summary>
 /// 获取分页数据
 /// </summary>
 /// <returns></returns>
 public DataTable GetPage(int pageIndex, int pageSize, Com_busitypeEntity 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_Com_busitype_Pagedata", items);
     count = int.Parse(items[2].Value.ToString());
     return dt;
 }
Пример #8
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Com_busitypeEntity GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id, pid, name, value  ");
            strSql.Append("  from Com_busitype ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int,4)
            };
            parameters[0].Value = id;

            Com_busitypeEntity model = new Com_busitypeEntity();
            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());
                }
                if (dt.Rows[0]["pid"].ToString() != "")
                {
                    model.pid = int.Parse(dt.Rows[0]["pid"].ToString());
                }
                model.name = dt.Rows[0]["name"].ToString();
                model.value = dt.Rows[0]["value"].ToString();

                return model;
            }
            else
            {
                return null;
            }
        }