예제 #1
0
 public void CreateAreaCountry(AreaCountry ac)
 {
     SqlParameter[] param = new SqlParameter[] {
         SqlUtilities.GenerateInputIntParameter("@carrier_area_id", ac.CarrierArea.Id),
         SqlUtilities.GenerateInputIntParameter("@country_id", ac.Country.Id)
     };
     string sql = "INSERT INTO area_countries(carrier_area_id, country_id) VALUES(@carrier_area_id, @country_id)";
     SqlHelper.ExecuteNonQuery(CommandType.Text, sql, param);
 }
예제 #2
0
        public List <Team> TeamProvide()
        {
            string playerRaw = System.IO.File.ReadAllText(filePlayerName);

            string[]      playerLines = playerRaw.Split('\n');
            List <Player> players     = new List <Player>();

            for (int i = 0; i < playerLines.Length; i++)
            {
                string[] tokens = playerLines[i].Split(';');
                players.Add(new Player()
                {
                    Name   = tokens[0],
                    Nation = tokens[1],
                    Score  = 0
                });
            }

            string data = System.IO.File.ReadAllText(fileCountriesName);

            string[]    lines    = data.Split('\n');
            List <Team> teamList = new List <Team>();

            for (int i = 0; i < lines.Length; i++)
            {
                string[]      tokens     = lines[i].Split(';');
                List <Player> listPlayer = players.Where(player => player.Nation.Trim().ToLower() == tokens[1].Trim().ToLower()).ToList();
                while (listPlayer.Count < MaximumPlayer)
                {
                    listPlayer.Add(new Player()
                    {
                        Name   = "PPlayer#" + (1000 + rand.Next(0, 9999)),
                        Nation = tokens[1],
                        Score  = 0
                    });
                }
                while (listPlayer.Count > MaximumPlayer)
                {
                    listPlayer.RemoveAt(rand.Next(0, listPlayer.Count));
                }
                Team team = new Team()
                {
                    Code       = tokens[0],
                    Name       = tokens[1],
                    Area       = AreaCountry.GetAreaFromString(tokens[2].Trim()),
                    TotalScore = 0,
                    PlayerList = listPlayer
                };
                teamList.Add(team);
            }
            return(teamList);
        }
예제 #3
0
        public List <Team> TeamProvide()
        {
            List <Team>   result  = new List <Team>();
            List <Player> players = new List <Player>();

            command    = new SQLiteCommand("SELECT * FROM Players", connection);
            dataReader = command.ExecuteReader();
            while (dataReader.Read())
            {
                players.Add(new Player()
                {
                    Name   = dataReader.GetValue(0).ToString(),
                    Nation = dataReader.GetValue(1).ToString(),
                });
            }

            command    = new SQLiteCommand("SELECT * FROM Countries", connection);
            dataReader = command.ExecuteReader();
            while (dataReader.Read())
            {
                string[]      tokens     = new string[] { dataReader.GetValue(0).ToString(), dataReader.GetValue(1).ToString(), dataReader.GetValue(2).ToString() };
                List <Player> listPlayer = players.Where(player => player.Nation.Trim().ToLower() == tokens[1].Trim().ToLower()).ToList();
                while (listPlayer.Count < MaximumPlayer)
                {
                    listPlayer.Add(new Player()
                    {
                        Name   = "PPlayer#" + (1000 + rand.Next(0, 9999)),
                        Nation = tokens[1],
                        Score  = 0
                    });
                }
                while (listPlayer.Count > MaximumPlayer)
                {
                    listPlayer.RemoveAt(rand.Next(0, listPlayer.Count));
                }
                Team team = new Team()
                {
                    Code       = tokens[0],
                    Name       = tokens[1],
                    Area       = AreaCountry.GetAreaFromString(tokens[2].Trim()),
                    TotalScore = 0,
                    PlayerList = listPlayer
                };
                result.Add(team);
            }

            connection.Close();

            return(result);
        }
예제 #4
0
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        AreaCountryOperation.DeleteAreaCountryByCarrierAreaId(id);

        CarrierArea ca = CarrierAreaOperation.GetCarrierAreaById(id);
        for (int i = 0; i < rpCountry.Items.Count; i++)
        {
            RepeaterItem ri = rpCountry.Items[i];
            CheckBox chkId = (CheckBox)ri.FindControl("chkId");
            Label lblId = (Label)ri.FindControl("lblId");
            if (chkId.Checked)
            {
                AreaCountry ac = new AreaCountry();
                Country country = CountryOperation.GetCountryById(int.Parse(lblId.Text));
                ac.Country = country;
                ac.CarrierArea = ca;
                AreaCountryOperation.CreateAreaCountry(ac);
            }
        }
        Response.Write("<script language='javascript'>alert('修改成功!');location.href='CarrierAreaList.aspx?id=" + ca.Carrier.Id + "';</script>");
    }
예제 #5
0
 public List<AreaCountry> GetAreaCountryByCarrierAreaId(int id)
 {
     List<AreaCountry> result = new List<AreaCountry>();
     SqlParameter[] param = new SqlParameter[] {
         SqlUtilities.GenerateInputIntParameter("@carrier_area_id", id)
     };
     string sql = "SELECT id, carrier_area_id, country_id FROM area_countries WHERE carrier_area_id = @carrier_area_id";
     using (SqlDataReader dr = SqlHelper.ExecuteReader(CommandType.Text, sql, param))
     {
         while (dr.Read())
         {
             AreaCountry ac = new AreaCountry();
             ac.Id = dr.GetInt32(0);
             CarrierArea ca = new CarrierAreaDAL().GetCarrierAreaById(dr.GetInt32(1));
             ac.CarrierArea = ca;
             Country country = new CountryDAL().GetCountryById(dr.GetInt32(2));
             ac.Country = country;
             result.Add(ac);
         }
     }
     return result;
 }
예제 #6
0
 public static void CreateAreaCountry(AreaCountry ac)
 {
     dal.CreateAreaCountry(ac);
 }
예제 #7
0
 public void OceaniaRateIsCorrect()
 {
     Assert.AreEqual(true, AreaCountry.GetRateFromArea(Area.Oceania) == 0.5d);
 }
예제 #8
0
 public void SouthAmericaRateIsCorrect()
 {
     Assert.AreEqual(true, AreaCountry.GetRateFromArea(Area.SouthAmerica) == 3.5d);
 }
예제 #9
0
 public void AfricaRateIsCorrect()
 {
     Assert.AreEqual(true, AreaCountry.GetRateFromArea(Area.Africa) == 5d);
 }
예제 #10
0
 public void EuropeRateIsCorrect()
 {
     Assert.AreEqual(true, AreaCountry.GetRateFromArea(Area.Europe) == 13d);
 }