コード例 #1
0
        protected void OnReturn(object sender, EventArgs e)
        {
            if ((bool)Session["save"])
            {
                dtColors = (DataTable)Session["CardsColors"];
                DataTable initColors = (DataTable)Session["InitCardsColors"];
                foreach (DataRow row in dtColors.Rows)
                {
                    int selectedColor = Convert.ToInt32(row["colorName"]);
                    if (initColors.Rows.Find(new object[] { selectedCard, selectedColor }) == null)
                    {
                        if (cardsService.InsertColor(selectedCard, selectedColor) > 0)
                        {
                            Response.Write("<script>alert('Color successfully inserted');</script>");
                        }
                        else
                        {
                            Response.Write("<script>alert('Color insertion failed');</script>");
                        }
                    }
                }
                foreach (DataRow row in initColors.Rows)
                {
                    int selectedColor = Convert.ToInt32(row["colorName"]);
                    if (dtColors.Rows.Find(new object[] { selectedCard, selectedColor }) == null)
                    {
                        if (cardsService.DeleteCardsColor(selectedCard, selectedColor) > 0)
                        {
                            Response.Write("<script>alert('Color successfully inserted');</script>");
                        }
                        else
                        {
                            Response.Write("<script>alert('Color insertion failed');</script>");
                        }
                    }
                }
                dtKinds = (DataTable)Session["kindsDataTable"];
                DataTable initKinds      = (DataTable)Session["InitKinds"];
                int[]     attributes     = (int[])Session["Attributes"];
                int[]     initAttributes = (int[])Session["InitAttributes"];

                foreach (DataRow row in dtKinds.Rows)
                {
                    int selectedKind = Convert.ToInt32(row["kindName"]);
                    if (initKinds.Rows.Find(new object[] { selectedCard, selectedKind }) == null)
                    {
                        if (cardsService.InsertKind(selectedCard, selectedKind) > 0)
                        {
                            Response.Write("<script>alert('Kind successfully inserted');</script>");
                            if (int.Parse(kindsList.Items.FindByText("creature").Value) == selectedKind)
                            {
                                cardsService.InsertAttributes(selectedCard, attributes[0], attributes[1]);
                            }
                        }
                        else
                        {
                            Response.Write("<script>alert('Kind insertion Kind');</script>");
                        }
                    }
                }
                foreach (DataRow row in initKinds.Rows)
                {
                    int selectedKind = Convert.ToInt32(row["kindName"]);
                    if (dtKinds.Rows.Find(new object[] { selectedCard, selectedKind }) == null)
                    {
                        if (cardsService.DeleteCardsKinds(selectedCard, selectedKind) > 0)
                        {
                            Response.Write("<script>alert('Kind successfully inserted');</script>");
                        }
                        else
                        {
                            Response.Write("<script>alert('Kind insertion failed');</script>");
                        }
                    }
                    else
                    if (int.Parse(kindsList.Items.FindByText("creature").Value) == selectedKind && (initAttributes[0] != attributes[0] || initAttributes[1] != attributes[1]))
                    {
                        cardsService.UpdateCardAttributes(selectedCard, attributes[0], attributes[1]);
                    }
                }
            }
            Response.Redirect(Session["From"].ToString());
        }