示例#1
0
 private void ShowCardsTable()
 {
     cards          = cardsService.GetAllCards();
     Cache["Cards"] = cards;
     magicCardsGridView.DataSource = cards;
     magicCardsGridView.DataBind();
 }
示例#2
0
        protected void OnRowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            DataSet cardsDS       = (DataSet)Cache["Cards"];
            int     selectedIndex = e.RowIndex;
            string  temp          = magicCardsGridView.Rows[selectedIndex].Cells[0].Text;
            int     cardIds       = int.Parse(temp);
            DataRow row           = cardsDS.Tables["AllMagicCards"].Rows.Find(cardIds);

            for (int i = 1; i < magicCardsGridView.Rows[e.RowIndex].Cells.Count - 4; i++)
            {
                row[i] = ((TextBox)magicCardsGridView.Rows[e.RowIndex].Cells[i].Controls[0]).Text;
            }
            string     filename  = "";
            FileUpload cardImage = (FileUpload)magicCardsGridView.Rows[e.RowIndex].FindControl("cardImageFileUpload");

            if (cardImage.PostedFile.FileName != "")
            {
                filename = Path.GetFileName(cardImage.FileName);
                cardImage.PostedFile.SaveAs(Server.MapPath(filename));
            }
            CardType card = new CardType(row[1].ToString(), row[2].ToString(), int.Parse(row[3].ToString()), 1, filename);

            cardsService = new CardsService(card);
            int    rowUpdated;
            string cardName = row["cardName"].ToString();

            if (cardName.Length != 0)
            {
                if (!cardsService.CardAlreadyExists(cardIds, cardName))
                {
                    rowUpdated = cardsService.UpdateTableRow(int.Parse(row[0].ToString()));
                }
                else
                {
                    Response.Write("<script>alert('name already taken');</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('name can't be empty');</script>");
            }
            magicCardsGridView.EditIndex  = -1;
            magicCardsGridView.DataSource = cardsService.GetAllCards();
            magicCardsGridView.DataBind();
        }