예제 #1
0
        public IList <ShiMiao.Model.TD_Shop_Goods> GetListByPage(string where, string orderby, IDictionary <string, object> dictParams, int startIndex, int pageSize)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("SELECT GoodsID, OrgID, Title, Image, Content, Amount, Balance, Price, CreateTime, OrderIndex, StateCode,Frozen,Unit FROM TD_Shop_Goods");
            if (!string.IsNullOrEmpty(where))
            {
                strSql.Append(" WHERE " + where);
            }
            if (!string.IsNullOrEmpty(orderby))
            {
                strSql.AppendFormat(" order by {0}", orderby);
            }
            strSql.AppendFormat(" limit {0}, {1}", startIndex, pageSize);
            List <MySqlParameter> parameters = new List <MySqlParameter>();

            if (dictParams != null)
            {
                foreach (var pair in dictParams)
                {
                    MySqlParameter parameter = new MySqlParameter("@" + pair.Key, pair.Value);
                    parameters.Add(parameter);
                }
            }
            IList <ShiMiao.Model.TD_Shop_Goods> list = new List <ShiMiao.Model.TD_Shop_Goods>();

            using (DbDataReader dr = MySqlHelperUtil.ExecuteReader(strSql.ToString(), parameters.ToArray()))
            {
                while (dr.Read())
                {
                    ShiMiao.Model.TD_Shop_Goods model = new ShiMiao.Model.TD_Shop_Goods();

                    if (dr[0] != DBNull.Value)
                    {
                        model.GoodsID = dr.GetString(0);
                    }
                    if (dr[1] != DBNull.Value)
                    {
                        model.OrgID = dr.GetInt32(1);
                    }
                    if (dr[2] != DBNull.Value)
                    {
                        model.Title = dr.GetString(2);
                    }
                    if (dr[3] != DBNull.Value)
                    {
                        model.Image = dr.GetString(3);
                    }
                    if (dr[4] != DBNull.Value)
                    {
                        model.Content = dr.GetString(4);
                    }
                    if (dr[5] != DBNull.Value)
                    {
                        model.Amount = dr.GetInt32(5);
                    }
                    if (dr[6] != DBNull.Value)
                    {
                        model.Balance = dr.GetInt32(6);
                    }
                    if (dr[7] != DBNull.Value)
                    {
                        model.Price = dr.GetDecimal(7);
                    }
                    if (dr[8] != DBNull.Value)
                    {
                        model.CreateTime = dr.GetDateTime(8);
                    }
                    if (dr[9] != DBNull.Value)
                    {
                        model.OrderIndex = dr.GetInt32(9);
                    }
                    if (dr[10] != DBNull.Value)
                    {
                        model.StateCode = dr.GetInt32(10);
                    }
                    if (dr[11] != DBNull.Value)
                    {
                        model.Frozen = dr.GetInt32(11);
                    }
                    if (dr[12] != DBNull.Value)
                    {
                        model.Unit = dr.GetString(12);
                    }
                    list.Add(model);
                }
                parameters.Clear();
                return(list);
            }
        }
예제 #2
0
        public ShiMiao.Model.TD_Shop_Goods GetModel(string goodsID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select GoodsID, OrgID, Title, Image, Content, Amount, Balance, Price, CreateTime, OrderIndex, StateCode,Frozen  ");
            strSql.Append("  from TD_Shop_Goods ");
            strSql.Append(" where GoodsID=@GoodsID ");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@GoodsID", goodsID)
            };

            ShiMiao.Model.TD_Shop_Goods model = null;
            using (DbDataReader dr = MySqlHelperUtil.ExecuteReader(strSql.ToString(), parameters))
            {
                while (dr.Read())
                {
                    model = new ShiMiao.Model.TD_Shop_Goods();
                    if (dr[0] != DBNull.Value)
                    {
                        model.GoodsID = dr.GetString(0);
                    }
                    if (dr[1] != DBNull.Value)
                    {
                        model.OrgID = dr.GetInt32(1);
                    }
                    if (dr[2] != DBNull.Value)
                    {
                        model.Title = dr.GetString(2);
                    }
                    if (dr[3] != DBNull.Value)
                    {
                        model.Image = dr.GetString(3);
                    }
                    if (dr[4] != DBNull.Value)
                    {
                        model.Content = dr.GetString(4);
                    }
                    if (dr[5] != DBNull.Value)
                    {
                        model.Amount = dr.GetInt32(5);
                    }
                    if (dr[6] != DBNull.Value)
                    {
                        model.Balance = dr.GetInt32(6);
                    }
                    if (dr[7] != DBNull.Value)
                    {
                        model.Price = dr.GetDecimal(7);
                    }
                    if (dr[8] != DBNull.Value)
                    {
                        model.CreateTime = dr.GetDateTime(8);
                    }
                    if (dr[9] != DBNull.Value)
                    {
                        model.OrderIndex = dr.GetInt32(9);
                    }
                    if (dr[10] != DBNull.Value)
                    {
                        model.StateCode = dr.GetInt32(10);
                    }
                    if (dr[11] != DBNull.Value)
                    {
                        model.Frozen = dr.GetInt32(11);
                    }
                }
                return(model);
            }
        }