Ejemplo n.º 1
0
        public void getGameList(OrderBy order, string keyword)   //搜索列表
        {
            if (ItemGames.Count != 0)
            {
                ItemGames.Clear();
            }
            string cmdStr = "";

            if (keyword == "")
            {
                switch (order)
                {
                case OrderBy.Gname:
                    cmdStr = string.Format("select gid from games where gselling=1 order by gname");
                    break;

                case OrderBy.gissue:
                    cmdStr = string.Format("select gid from games where gselling=1 order by gissue");
                    break;

                case OrderBy.price:
                    cmdStr = string.Format("select gid from games where gselling=1 order by gcprice");
                    break;
                }
            }
            else
            {
                switch (order)
                {
                case OrderBy.Gname:
                    cmdStr = string.Format("select gid from games where gselling=1 and gname like '%{0}%' order by gname", keyword);
                    break;

                case OrderBy.gissue:
                    cmdStr = string.Format("select gid from games where gselling=1 and gname like '%{0}%' order by gissue", keyword);
                    break;

                case OrderBy.price:
                    cmdStr = string.Format("select gid from games where gselling=1 and gname like '%{0}%' order by gcprice", keyword);
                    break;
                }
            }
            SqlCommand cmd = new SqlCommand(cmdStr, sqlConn);

            try
            {
                SqlDataReader dataReader = cmd.ExecuteReader();
                List <string> gids       = new List <string>();
                if (dataReader.HasRows)
                {
                    while (dataReader.Read())
                    {
                        string gid = dataReader[0].ToString();
                        gids.Add(gid);
                    }
                }
                dataReader.Close();
                foreach (string gid in gids)
                {
                    string        gimagepath      = GetImages(gid)[0];
                    string        gname           = GetGameName(gid);
                    bool          gdiscountstatus = GetDiscountStatus(gid);
                    List <double> priceList       = GetPrice(gid);
                    double        goprice         = 0;
                    double        gcprice         = 0;
                    int           Gdiscout        = 0;
                    if (priceList.Count == 1)
                    {
                        goprice         = priceList[0];
                        gcprice         = 0;
                        Gdiscout        = 0;
                        gdiscountstatus = false;
                    }
                    else
                    {
                        goprice  = priceList[0];
                        gcprice  = priceList[1];
                        Gdiscout = (int)priceList[2];
                    }
                    ListItemGame item = new ListItemGame(gid, gname, gimagepath, goprice, gcprice, Gdiscout, gdiscountstatus);
                    ItemGames.Add(item);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Ejemplo n.º 2
0
        public void getGameList()
        {
            string cmdStr1 = string.Format("select gid from games where gselling=1 order by " +
                                           "(SELECT COUNT(*) FROM Purch WHERE Purch.gid=games.gid " +
                                           "AND (GETDATE()-Ptime)<=30 GROUP BY Purch.Gid) desc,Gname");                        //获取近30天销量最好的游戏

            string cmdStr2 = string.Format("select gid from games where gselling=1 order by " +
                                           "(SELECT COUNT(*) FROM Purch WHERE Purch.gid=games.gid " +
                                           "GROUP BY Purch.Gid) desc,Gname");                           //获取总销量最好的游戏



            string cmdStr3 = string.Format("select gid from games where gselling=1 " +
                                           "and dstart<GETDATE() AND dend>GETDATE() order by " +
                                           "(SELECT COUNT(*) FROM Purch WHERE Purch.gid=games.gid " +
                                           "AND (GETDATE()-Ptime)<=30 GROUP BY Purch.Gid) desc,Gname"); //获取近30天销量最好且打折的游戏

            SqlCommand    cmd1     = new SqlCommand(cmdStr1, sqlConn);
            SqlCommand    cmd2     = new SqlCommand(cmdStr2, sqlConn);
            SqlCommand    cmd3     = new SqlCommand(cmdStr3, sqlConn);
            List <string> gidList1 = new List <string>();
            List <string> gidList2 = new List <string>();
            List <string> gidList3 = new List <string>();

            if (ItemGames_discount.Count != 0)
            {
                ItemGames_discount.Clear();
            }
            if (ItemGames_recentsellwell.Count != 0)
            {
                ItemGames_recentsellwell.Clear();
            }
            if (ItemGames_sellwell.Count != 0)
            {
                ItemGames_sellwell.Clear();
            }

            try
            {
                SqlDataReader dataReader1 = cmd1.ExecuteReader();
                if (dataReader1.HasRows)
                {
                    while (dataReader1.Read())
                    {
                        string gid = dataReader1[0].ToString();
                        gidList1.Add(gid);
                    }
                }
                dataReader1.Close();

                SqlDataReader dataReader2 = cmd2.ExecuteReader();
                if (dataReader2.HasRows)
                {
                    while (dataReader2.Read())
                    {
                        string gid = dataReader2[0].ToString();
                        gidList2.Add(gid);
                    }
                }
                dataReader2.Close();

                SqlDataReader dataReader3 = cmd3.ExecuteReader();
                if (dataReader3.HasRows)
                {
                    while (dataReader3.Read())
                    {
                        string gid = dataReader3[0].ToString();
                        gidList3.Add(gid);
                    }
                }
                dataReader3.Close();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }

            foreach (string gid in gidList1)
            {
                List <string> gimagepath = GetImages(gid);
                string        gname      = GetGameName(gid);

                ListItemGameMain item = new ListItemGameMain(gid, gname, gimagepath);
                ItemGames_recentsellwell.Add(item);
            }

            foreach (string gid in gidList2)
            {
                string        gimagepath      = GetImages(gid)[0];
                string        gname           = GetGameName(gid);
                bool          gdiscountstatus = GetDiscountStatus(gid);
                List <double> priceList       = GetPrice(gid);
                double        goprice         = 0;
                double        gcprice         = 0;
                int           Gdiscout        = 0;
                if (priceList.Count == 1)
                {
                    goprice         = priceList[0];
                    gcprice         = 0;
                    Gdiscout        = 0;
                    gdiscountstatus = false;
                }
                else
                {
                    goprice  = priceList[0];
                    gcprice  = priceList[1];
                    Gdiscout = (int)priceList[2];
                }
                ListItemGame item = new ListItemGame(gid, gname, gimagepath, goprice, gcprice, Gdiscout, gdiscountstatus);
                ItemGames_sellwell.Add(item);
            }

            foreach (string gid in gidList3)
            {
                string        gimagepath      = GetImages(gid)[0];
                string        gname           = GetGameName(gid);
                bool          gdiscountstatus = GetDiscountStatus(gid);
                List <double> priceList       = GetPrice(gid);
                double        goprice         = 0;
                double        gcprice         = 0;
                int           Gdiscout        = 0;
                if (priceList.Count == 1)
                {
                    goprice         = priceList[0];
                    gcprice         = 0;
                    Gdiscout        = 0;
                    gdiscountstatus = false;
                }
                else
                {
                    goprice  = priceList[0];
                    gcprice  = priceList[1];
                    Gdiscout = (int)priceList[2];
                }
                ListItemGame item = new ListItemGame(gid, gname, gimagepath, goprice, gcprice, Gdiscout, gdiscountstatus);
                ItemGames_discount.Add(item);
            }
        }