コード例 #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(BCW.Model.Modata model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tb_Modata(");
            strSql.Append("Types,PhoneBrand,PhoneModel,PhoneSystem,PhoneSize,PhoneClick)");
            strSql.Append(" values (");
            strSql.Append("@Types,@PhoneBrand,@PhoneModel,@PhoneSystem,@PhoneSize,@PhoneClick)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Types",       SqlDbType.Int,       4),
                new SqlParameter("@PhoneBrand",  SqlDbType.NVarChar, 50),
                new SqlParameter("@PhoneModel",  SqlDbType.NVarChar, 50),
                new SqlParameter("@PhoneSystem", SqlDbType.NVarChar, 50),
                new SqlParameter("@PhoneSize",   SqlDbType.NVarChar, 50),
                new SqlParameter("@PhoneClick",  SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Types;
            parameters[1].Value = model.PhoneBrand;
            parameters[2].Value = model.PhoneModel;
            parameters[3].Value = model.PhoneSystem;
            parameters[4].Value = model.PhoneSize;
            parameters[5].Value = 0;

            SqlHelper.ExecuteSql(strSql.ToString(), parameters);
        }
コード例 #2
0
        /// <summary>
        /// 取得每页记录
        /// </summary>
        /// <param name="p_pageIndex">当前页</param>
        /// <param name="p_pageSize">分页大小</param>
        /// <param name="p_recordCount">返回总记录数</param>
        /// <param name="strWhere">查询条件</param>
        /// <returns>IList Modata</returns>
        public IList <BCW.Model.Modata> GetModatas(int p_pageIndex, int p_pageSize, string strWhere, out int p_recordCount)
        {
            IList <BCW.Model.Modata> listModatas = new List <BCW.Model.Modata>();
            string sTable     = "tb_Modata";
            string sPkey      = "id";
            string sField     = "ID,PhoneBrand,PhoneModel";
            string sCondition = strWhere;
            string sOrder     = "ID Desc";
            int    iSCounts   = 0;

            using (SqlDataReader reader = SqlHelper.RunProcedureMe(sTable, sPkey, sField, p_pageIndex, p_pageSize, sCondition, sOrder, iSCounts, out p_recordCount))
            {
                //计算总页数
                if (p_recordCount > 0)
                {
                    int pageCount = BasePage.CalcPageCount(p_recordCount, p_pageSize, ref p_pageIndex);
                }
                else
                {
                    return(listModatas);
                }
                while (reader.Read())
                {
                    BCW.Model.Modata objModata = new BCW.Model.Modata();
                    objModata.ID = reader.GetInt32(0);
                    if (!reader.IsDBNull(1))
                    {
                        objModata.PhoneBrand = reader.GetString(1);
                    }
                    objModata.PhoneModel = reader.GetString(2);
                    listModatas.Add(objModata);
                }
            }
            return(listModatas);
        }
コード例 #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BCW.Model.Modata GetModata(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,Types,PhoneBrand,PhoneModel,PhoneSystem,PhoneSize,PhoneClick from tb_Modata ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

            BCW.Model.Modata model = new BCW.Model.Modata();
            using (SqlDataReader reader = SqlHelper.ExecuteReader(strSql.ToString(), parameters))
            {
                if (reader.HasRows)
                {
                    reader.Read();
                    model.ID          = reader.GetInt32(0);
                    model.Types       = reader.GetInt32(1);
                    model.PhoneBrand  = reader.GetString(2);
                    model.PhoneModel  = reader.GetString(3);
                    model.PhoneSystem = reader.GetString(4);
                    model.PhoneSize   = reader.GetString(5);
                    model.PhoneClick  = reader.GetInt32(6);
                    return(model);
                }
                else
                {
                    return(null);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(BCW.Model.Modata model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update tb_Modata set ");
            strSql.Append("Types=@Types,");
            strSql.Append("PhoneBrand=@PhoneBrand,");
            strSql.Append("PhoneModel=@PhoneModel,");
            strSql.Append("PhoneSystem=@PhoneSystem,");
            strSql.Append("PhoneSize=@PhoneSize,");
            strSql.Append("PhoneClick=@PhoneClick");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID",          SqlDbType.Int,       4),
                new SqlParameter("@Types",       SqlDbType.Int,       4),
                new SqlParameter("@PhoneBrand",  SqlDbType.NVarChar, 50),
                new SqlParameter("@PhoneModel",  SqlDbType.NVarChar, 50),
                new SqlParameter("@PhoneSystem", SqlDbType.NVarChar, 50),
                new SqlParameter("@PhoneSize",   SqlDbType.NVarChar, 50),
                new SqlParameter("@PhoneClick",  SqlDbType.Int, 4)
            };
            parameters[0].Value = model.ID;
            parameters[1].Value = model.Types;
            parameters[2].Value = model.PhoneBrand;
            parameters[3].Value = model.PhoneModel;
            parameters[4].Value = model.PhoneSystem;
            parameters[5].Value = model.PhoneSize;
            parameters[6].Value = model.PhoneClick;

            SqlHelper.ExecuteSql(strSql.ToString(), parameters);
        }
コード例 #5
0
        /// <summary>
        /// 取得品牌记录
        /// </summary>
        /// <param name="p_pageIndex">当前页</param>
        /// <param name="p_pageSize">每页显示记录数</param>
        /// <param name="p_recordCount">返回总记录数</param>
        /// <returns>List</returns>
        public IList <BCW.Model.Modata> GetBrand(int p_pageIndex, int p_pageSize, string strWhere, out int p_recordCount)
        {
            IList <BCW.Model.Modata> listModatas = new List <BCW.Model.Modata>();

            // 计算记录数
            string countString = "SELECT COUNT(DISTINCT PhoneBrand) FROM tb_Modata where " + strWhere + "";

            p_recordCount = Convert.ToInt32(SqlHelper.GetSingle(countString));
            if (p_recordCount > 0)
            {
                int pageCount = BasePage.CalcPageCount(p_recordCount, p_pageSize, ref p_pageIndex);
            }
            else
            {
                return(listModatas);
            }
            // SQL
            string queryString = "SELECT PhoneBrand, COUNT(*)  FROM tb_Modata where " + strWhere + " GROUP BY PhoneBrand ORDER BY COUNT(*) DESC";

            using (SqlDataReader reader = SqlHelper.ExecuteReader(queryString))
            {
                int stratIndex = (p_pageIndex - 1) * p_pageSize;
                int endIndex   = p_pageIndex * p_pageSize;
                int k          = 0;
                while (reader.Read())
                {
                    if (k >= stratIndex && k < endIndex)
                    {
                        BCW.Model.Modata objModata = new BCW.Model.Modata();
                        if (!reader.IsDBNull(0))
                        {
                            objModata.PhoneBrand = reader.GetString(0);
                        }
                        else
                        {
                            objModata.PhoneBrand = "未知";
                        }

                        listModatas.Add(objModata);
                    }

                    if (k == endIndex)
                    {
                        break;
                    }
                    k++;
                }
            }
            return(listModatas);
        }
コード例 #6
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BCW.Model.Modata GetModata2(string Model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,Types,PhoneBrand,PhoneModel,PhoneSystem,PhoneSize,PhoneClick from tb_Modata ");
            strSql.Append(" where PhoneModel=@PhoneModel ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@PhoneModel", SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = Model;

            BCW.Model.Modata model = new BCW.Model.Modata();
            using (SqlDataReader reader = SqlHelper.ExecuteReader(strSql.ToString(), parameters))
            {
                if (reader.HasRows)
                {
                    reader.Read();
                    model.ID    = reader.GetInt32(0);
                    model.Types = reader.GetInt32(1);
                    if (!reader.IsDBNull(2))
                    {
                        model.PhoneBrand = reader.GetString(2);
                    }
                    model.PhoneModel = reader.GetString(3);
                    if (!reader.IsDBNull(4))
                    {
                        model.PhoneSystem = reader.GetString(4);
                    }
                    if (!reader.IsDBNull(5))
                    {
                        model.PhoneSize = reader.GetString(5);
                    }
                    model.PhoneClick = reader.GetInt32(6);
                    return(model);
                }
                else
                {
                    return(null);
                }
            }
        }