예제 #1
0
        protected void newPlayerSubmit_Click(object sender, EventArgs e)
        {
            bool flag = false;

            if (npid.Text.Equals(""))
            {
                npid.Text = "FILL ME";
                flag      = true;
            }
            if (npname.Text.Equals(""))
            {
                npname.Text = "FILL ME";
                flag        = true;
            }
            if (npteam.Text.Equals(""))
            {
                npteam.Text = "FILL ME";
                flag        = true;
            }
            if (npheight.Text.Equals(""))
            {
                npheight.Text = "FILL ME";
                flag          = true;
            }
            if (npsgoals.Text.Equals(""))
            {
                npsgoals.Text = "FILL ME";
                flag          = true;
            }
            if (npfgoals.Text.Equals(""))
            {
                npfgoals.Text = "FILL ME";
                flag          = true;
            }
            if (npage.Text.Equals(""))
            {
                npage.Text = "FILL ME";
                flag       = true;
            }
            if (npposition.Text.Equals(""))
            {
                npposition.Text = "FILL ME";
                flag            = true;
            }
            if (npcountry.Text.Equals(""))
            {
                npcountry.Text = "FILL ME";
                flag           = true;
            }
            if (npsapps.Text.Equals(""))
            {
                npsapps.Text = "FILL ME";
                flag         = true;
            }
            if (npfapps.Text.Equals(""))
            {
                npfapps.Text = "FILL ME";
                flag         = true;
            }
            if (nploanedby.Text.Equals(""))
            {
                nploanedby.Text = "FILL ME";
                flag            = true;
            }
            if (npspapps.Text.Equals(""))
            {
                npspapps.Text = "FILL ME";
                flag          = true;
            }
            if (npfpapps.Text.Equals(""))
            {
                npfpapps.Text = "FILL ME";
                flag          = true;
            }
            if (npspgoals.Text.Equals(""))
            {
                npspgoals.Text = "FILL ME";
                flag           = true;
            }
            if (npfpgoals.Text.Equals(""))
            {
                npfpgoals.Text = "FILL ME";
                flag           = true;
            }
            if (npptnumber.Text.Equals(""))
            {
                npptnumber.Text = "FILL ME";
                flag            = true;
            }
            if (flag)
            {
                return;
            }
            using (TransactionScope tran = new TransactionScope())
            {
                float h = float.Parse(npheight.Text);

                /*float hei = (float)h;
                 * if (h.ToString().Length == 3)
                 * {
                 *  hei =(float) (h * 0.01f);
                 * }
                 * else if ((h.ToString().Length == 2))
                 * {
                 *  hei = (double) (h * 0.1f);
                 * }*/
                Player player = new Player(npid.Text, npname.Text, npteam.Text, h, Convert.ToInt16(npsgoals.Text)
                                           , Convert.ToInt16(npfgoals.Text), Convert.ToInt16(npage.Text), npposition.Text, npcountry.Text, Convert.ToInt16(npsapps.Text),
                                           Convert.ToInt16(npfapps.Text), nploanedby.Text, Convert.ToInt16(npspapps.Text), Convert.ToInt16(npfpapps.Text), Convert.ToInt16(npspgoals.Text),
                                           Convert.ToInt16(npfpgoals.Text));
                int res = TeamsConnection.addNewPlayer(player);


                if (res == -1)
                {
                    newPlayerWarnings.Text = "An error occured while inserting the players' personal data";
                    return;
                }

                int ptnum = Convert.ToInt16(npptnumber.Text);

                if (ptnum == 0)
                {
                    tran.Complete();
                    Response.Redirect(Request.RawUrl);
                    return;
                }
                List <PastTeams> psts    = new List <PastTeams>();
                bool             fl      = false;
                String           team    = null;
                String           country = null;

                foreach (TextBox t in ts)
                {
                    if (!fl)
                    {
                        team = GetValue(t.ID);
                        fl   = true;
                    }
                    else
                    {
                        country = GetValue(t.ID);
                        psts.Add(new PastTeams(npid.Text, team, country));
                        fl = false;
                    }
                }

                /*int counter = 0;
                 * foreach (TableRow row in table.Rows)
                 * {
                 *  bool fl = false;
                 *  string team = null;
                 *  string country = null;
                 *  TextBox t = null;
                 *  foreach (TableCell cell in row.Cells)
                 *  {
                 *      if (!cell.Text.Equals("TEAM") && !cell.Text.Equals("COUNTRY"))
                 *      {
                 *          if (!fl) {
                 *              t = cell.FindControl("pt" + counter) as TextBox;
                 *              team = t.Text;
                 *          }
                 *          else
                 *          {
                 *              t = cell.FindControl("ptc" + counter) as TextBox;
                 *              country = t.Text;
                 *              psts.Add(new PastTeams(npid.Text, team, country));
                 *              counter++;
                 *          }
                 *          fl = true;
                 *      }
                 *  }
                 * }*/

                res = TeamsConnection.addPastTeamsOfNewPlayer(psts);
                if (res == -1)
                {
                    newPlayerWarnings.Text = "An error occured while inserting the players' past teams' data";
                    return;
                }
                tran.Complete();
            }
            Response.Redirect(Request.RawUrl);
        }