Ejemplo n.º 1
0
        protected void rGridPlayer_UpdIns(object sender, GridCommandEventArgs e, string Action)
        {
            try
            {
                GridEditableItem          eeditedItem      = e.Item as GridEditableItem;
                PlayerDomainModel         PlayerDM         = new PlayerDomainModel();
                PlayerPositionDomainModel PlayerPositionDM = new PlayerPositionDomainModel();

                if (Action == "Update")
                {
                    PlayerDM.PlayerGUID = new Guid((eeditedItem.FindControl("lblPlayerGUID") as Label).Text.ToString());
                }
                PlayerDM.PlayerName = (eeditedItem.FindControl("rTBPlayerName") as RadTextBox).Text.Trim();

                // Deal with the image
                var aUpload = (eeditedItem.FindControl("AsyncUpload1") as RadAsyncUpload);
                if (aUpload.UploadedFiles.Count > 0)
                {
                    EditableImage img = new EditableImage((MemoryStream)Context.Cache.Get(Session.SessionID + "UploadedFile"));
                    MemoryStream  s   = new MemoryStream();
                    img.Image.Save(s, img.RawFormat);
                    byte[] imgData = s.ToArray();
                    PlayerDM.PlayerImage = imgData;
                }
                else
                {
                    PlayerDM.PlayerImage = null;
                }

                // Setup PlayerPositionDM
                if (Convert.ToInt32(((eeditedItem.FindControl("rDDPrimPos") as RadDropDownList)).SelectedValue) == 0)
                {
                    PlayerPositionDM.PrimaryPositionID = null;
                }
                else
                {
                    PlayerPositionDM.PrimaryPositionID = Convert.ToInt32(((eeditedItem.FindControl("rDDPrimPos") as RadDropDownList)).SelectedValue);
                }

                if (Convert.ToInt32(((eeditedItem.FindControl("rDDSecPos") as RadDropDownList)).SelectedValue) == 0)
                {
                    PlayerPositionDM.SecondaryPostiionID = null;
                }
                else
                {
                    PlayerPositionDM.SecondaryPostiionID = Convert.ToInt32(((eeditedItem.FindControl("rDDSecPos") as RadDropDownList)).SelectedValue);
                }

                if (Action == "Update")
                {
                    PlayerPositionDM.PlayerGUID = new Guid((eeditedItem.FindControl("lblPlayerGUID") as Label).Text.ToString());
                    PlayerPostionBLL.DeletePlayerPosition(PlayerPositionDM);
                    PlayerBLL.UpdatePlayer(PlayerDM);
                    PlayerPostionBLL.UpdatePlayerPosition(PlayerPositionDM);
                }
                else if (Action == "Insert")
                {
                    PlayerBLL.InsertPlayer(PlayerDM);
                    PlayerPositionDM.PlayerGUID = PlayerDM.PlayerGUID;
                    PlayerPostionBLL.InsertPlayerPosition(PlayerPositionDM);
                }

                //rGridPlayer.Rebind();
            }
            catch (Exception ex)
            {
                StackTrace st        = new StackTrace();
                StackFrame sf        = st.GetFrame(0);
                string     errMethod = sf.GetMethod().Name.ToString();                                           // Get the current method name
                string     errMsg    = "600";                                                                    // Gotta pass something, we're retro-fitting an existing method
                Session["LastException"] = ex;                                                                   // Throw the exception in the session variable, will be used in error page
                string url = string.Format(ConfigurationManager.AppSettings["ErrorPageURL"], errMethod, errMsg); //Set the URL
                Response.Redirect(url);                                                                          // Go to the error page.
            }
        }
Ejemplo n.º 2
0
        public static void HandlePitcher(List <clsPitcher> colPitchers)
        {
            PlayerBusinessLogic pBLL   = new PlayerBusinessLogic();
            PlayerDomainModel   player = new PlayerDomainModel();

            PlayerPostiionBusinessLogic ppBLL          = new PlayerPostiionBusinessLogic();
            PlayerPositionDomainModel   playerposition = new PlayerPositionDomainModel();

            StatBusinessLogic sBLL = new StatBusinessLogic();
            StatDomainModel   stat = new StatDomainModel();

            SeasonPlayerPositionStatBusinessLogic sppsBLL   = new SeasonPlayerPositionStatBusinessLogic();
            SeasonPlayerPositionStatDomainModel   statValue = new SeasonPlayerPositionStatDomainModel();

            SeasonPlayerBusinessLogic spBLL = new SeasonPlayerBusinessLogic();
            SeasonPlayerDomainModel   spDM  = new SeasonPlayerDomainModel();


            statValue.SeasonID   = C_SeasonID;
            statValue.PlayerGUID = player.PlayerGUID;
            sppsBLL.DeleteAllStatsForPlayer(statValue);

            foreach (clsPitcher cPitcher in colPitchers)
            {
                player.PlayerName = cPitcher.FirstName.Trim() + " " + cPitcher.LastName.Trim();
                pBLL.InsertPlayer(player);

                playerposition.PlayerGUID          = player.PlayerGUID;
                playerposition.PrimaryPositionID   = TransformPos(cPitcher.Pos);
                playerposition.SecondaryPostiionID = null;
                ppBLL.DeletePlayerPosition(playerposition);
                ppBLL.InsertPlayerPosition(playerposition);

                spDM.PlayerGUID = player.PlayerGUID;
                spDM.SeasonID   = C_SeasonID;
                spBLL.InsertSeasonPlayer(spDM);

                BindingFlags flags = BindingFlags.Instance |
                                     BindingFlags.Public | BindingFlags.NonPublic;


                foreach (FieldInfo f in cPitcher.GetType().GetFields(flags))
                {
                    Console.WriteLine("{0} = {1}", f.Name, f.GetValue(cPitcher));
                    System.Diagnostics.Debug.WriteLine("{0} = {1}", f.Name, f.GetValue(cPitcher));
                    string fieldName = _getBackingFieldName(f.Name.ToUpper());


                    if (fieldName != "FIRSTNAME" &&
                        fieldName != "LASTNAME" &&
                        fieldName != "PT" &&
                        fieldName != "POS")
                    {
                        stat.StatName       = fieldName;
                        stat.PositionTypeID = 2;    // 1 = hitter
                        stat = sBLL.InsertStat(stat);

                        statValue.SeasonID   = C_SeasonID;
                        statValue.PlayerGUID = player.PlayerGUID;
                        statValue.PositionID = TransformPos(cPitcher.Pos);
                        statValue.StatID     = stat.StatID;
                        if (f.GetValue(cPitcher) == null)
                        {
                            statValue.StatValue = null;
                        }
                        else
                        {
                            statValue.StatValue = f.GetValue(cPitcher).ToString();
                        }

                        sppsBLL.InsertStatValue(statValue);
                    }
                }
            }
        }