예제 #1
0
        public static int Update(MGMatchingGame o)
        {
            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[12];

            arrParams[0]  = new SqlParameter("@MAGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MAGID, o.MAGID.GetTypeCode()));
            arrParams[1]  = new SqlParameter("@MGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MGID, o.MGID.GetTypeCode()));
            arrParams[2]  = new SqlParameter("@CorrectRoundsToWinCount", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.CorrectRoundsToWinCount, o.CorrectRoundsToWinCount.GetTypeCode()));
            arrParams[3]  = new SqlParameter("@EasyGameSize", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EasyGameSize, o.EasyGameSize.GetTypeCode()));
            arrParams[4]  = new SqlParameter("@MediumGameSize", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MediumGameSize, o.MediumGameSize.GetTypeCode()));
            arrParams[5]  = new SqlParameter("@HardGameSize", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.HardGameSize, o.HardGameSize.GetTypeCode()));
            arrParams[6]  = new SqlParameter("@EnableMediumDifficulty", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EnableMediumDifficulty, o.EnableMediumDifficulty.GetTypeCode()));
            arrParams[7]  = new SqlParameter("@EnableHardDifficulty", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EnableHardDifficulty, o.EnableHardDifficulty.GetTypeCode()));
            arrParams[8]  = new SqlParameter("@LastModDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModDate, o.LastModDate.GetTypeCode()));
            arrParams[9]  = new SqlParameter("@LastModUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModUser, o.LastModUser.GetTypeCode()));
            arrParams[10] = new SqlParameter("@AddedDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedDate, o.AddedDate.GetTypeCode()));
            arrParams[11] = new SqlParameter("@AddedUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedUser, o.AddedUser.GetTypeCode()));

            try
            {
                iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_MGMatchingGame_Update", arrParams);
            }

            catch (SqlException exx)
            {
                System.Diagnostics.Debug.Write(exx.Message);
            }

            return(iReturn);
        }
예제 #2
0
        public static int Delete(MGMatchingGame o)
        {
            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[1];

            arrParams[0] = new SqlParameter("@MAGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MAGID, o.MAGID.GetTypeCode()));

            try
            {
                iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_MGMatchingGame_Delete", arrParams);
            }

            catch (SqlException exx)
            {
                System.Diagnostics.Debug.Write(exx.Message);
            }

            return(iReturn);
        }
예제 #3
0
        public static int Insert(MGMatchingGame o)
        {
            SqlParameter[] arrParams = new SqlParameter[12];

            arrParams[0]            = new SqlParameter("@MGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MGID, o.MGID.GetTypeCode()));
            arrParams[1]            = new SqlParameter("@CorrectRoundsToWinCount", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.CorrectRoundsToWinCount, o.CorrectRoundsToWinCount.GetTypeCode()));
            arrParams[2]            = new SqlParameter("@EasyGameSize", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EasyGameSize, o.EasyGameSize.GetTypeCode()));
            arrParams[3]            = new SqlParameter("@MediumGameSize", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MediumGameSize, o.MediumGameSize.GetTypeCode()));
            arrParams[4]            = new SqlParameter("@HardGameSize", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.HardGameSize, o.HardGameSize.GetTypeCode()));
            arrParams[5]            = new SqlParameter("@EnableMediumDifficulty", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EnableMediumDifficulty, o.EnableMediumDifficulty.GetTypeCode()));
            arrParams[6]            = new SqlParameter("@EnableHardDifficulty", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EnableHardDifficulty, o.EnableHardDifficulty.GetTypeCode()));
            arrParams[7]            = new SqlParameter("@LastModDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModDate, o.LastModDate.GetTypeCode()));
            arrParams[8]            = new SqlParameter("@LastModUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModUser, o.LastModUser.GetTypeCode()));
            arrParams[9]            = new SqlParameter("@AddedDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedDate, o.AddedDate.GetTypeCode()));
            arrParams[10]           = new SqlParameter("@AddedUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedUser, o.AddedUser.GetTypeCode()));
            arrParams[11]           = new SqlParameter("@MAGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MAGID, o.MAGID.GetTypeCode()));
            arrParams[11].Direction = ParameterDirection.Output;

            SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_MGMatchingGame_Insert", arrParams);

            o.MAGID = int.Parse(arrParams[11].Value.ToString());

            return(o.MAGID);
        }
예제 #4
0
        public static int Insert(Minigame o)
        {

            SqlParameter[] arrParams = new SqlParameter[23];

            arrParams[0] = new SqlParameter("@MiniGameType", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MiniGameType, o.MiniGameType.GetTypeCode()));
            arrParams[1] = new SqlParameter("@MiniGameTypeName", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MiniGameTypeName, o.MiniGameTypeName.GetTypeCode()));
            arrParams[2] = new SqlParameter("@AdminName", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AdminName, o.AdminName.GetTypeCode()));
            arrParams[3] = new SqlParameter("@GameName", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.GameName, o.GameName.GetTypeCode()));
            arrParams[4] = new SqlParameter("@isActive", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isActive, o.isActive.GetTypeCode()));
            arrParams[5] = new SqlParameter("@NumberPoints", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.NumberPoints, o.NumberPoints.GetTypeCode()));
            arrParams[6] = new SqlParameter("@AwardedBadgeID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AwardedBadgeID, o.AwardedBadgeID.GetTypeCode()));
            arrParams[7] = new SqlParameter("@Acknowledgements", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Acknowledgements, o.Acknowledgements.GetTypeCode())); 
            arrParams[8] = new SqlParameter("@LastModDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModDate, o.LastModDate.GetTypeCode()));
            arrParams[9] = new SqlParameter("@LastModUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModUser, o.LastModUser.GetTypeCode()));
            arrParams[10] = new SqlParameter("@AddedDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedDate, o.AddedDate.GetTypeCode()));
            arrParams[11] = new SqlParameter("@AddedUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedUser, o.AddedUser.GetTypeCode()));

            arrParams[12] = new SqlParameter("@TenID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.TenID, o.TenID.GetTypeCode()));
            arrParams[13] = new SqlParameter("@FldInt1", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldInt1, o.FldInt1.GetTypeCode()));
            arrParams[14] = new SqlParameter("@FldInt2", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldInt2, o.FldInt2.GetTypeCode()));
            arrParams[15] = new SqlParameter("@FldInt3", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldInt3, o.FldInt3.GetTypeCode()));
            arrParams[16] = new SqlParameter("@FldBit1", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldBit1, o.FldBit1.GetTypeCode()));
            arrParams[17] = new SqlParameter("@FldBit2", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldBit2, o.FldBit2.GetTypeCode()));
            arrParams[18] = new SqlParameter("@FldBit3", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldBit3, o.FldBit3.GetTypeCode()));
            arrParams[19] = new SqlParameter("@FldText1", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldText1, o.FldText1.GetTypeCode()));
            arrParams[20] = new SqlParameter("@FldText2", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldText2, o.FldText2.GetTypeCode()));
            arrParams[21] = new SqlParameter("@FldText3", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldText3, o.FldText3.GetTypeCode()));

            arrParams[22] = new SqlParameter("@MGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MGID, o.MGID.GetTypeCode()));
            arrParams[22].Direction = ParameterDirection.Output;

            SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_Minigame_Insert", arrParams);

            o.MGID = int.Parse(arrParams[22].Value.ToString());


            if (o.MiniGameType == 1)
            {
                var o2 = new MGOnlineBook {MGID = o.MGID, AddedDate = o.AddedDate, AddedUser = o.AddedUser, LastModDate = o.LastModDate,LastModUser = o.LastModUser };
                o2.Insert();
            }
            if (o.MiniGameType == 2)
            {
                var o2 = new MGMixAndMatch() { MGID = o.MGID, AddedDate = o.AddedDate, AddedUser = o.AddedUser, LastModDate = o.LastModDate, LastModUser = o.LastModUser };
                o2.Insert();
            }
            if (o.MiniGameType == 3)
            {
                var o2 = new MGCodeBreaker() { MGID = o.MGID, AddedDate = o.AddedDate, AddedUser = o.AddedUser, LastModDate = o.LastModDate, LastModUser = o.LastModUser };
                o2.Insert();
            }            
            
            if (o.MiniGameType == 4)
            {
                var o2 = new MGWordMatch() { MGID = o.MGID, AddedDate = o.AddedDate, AddedUser = o.AddedUser, LastModDate = o.LastModDate, LastModUser = o.LastModUser };
                o2.Insert();
            }


            if (o.MiniGameType == 5)
            {
                var o2 = new MGMatchingGame() { MGID = o.MGID, AddedDate = o.AddedDate, AddedUser = o.AddedUser, LastModDate = o.LastModDate, LastModUser = o.LastModUser };
                o2.Insert();
            }


            if (o.MiniGameType == 6)
            {
                var o2 = new MGHiddenPic() { MGID = o.MGID, AddedDate = o.AddedDate, AddedUser = o.AddedUser, LastModDate = o.LastModDate, LastModUser = o.LastModUser };
                o2.Insert();
            }


            if (o.MiniGameType == 7)
            {
                var o2 = new MGChooseAdv() { MGID = o.MGID, AddedDate = o.AddedDate, AddedUser = o.AddedUser, LastModDate = o.LastModDate, LastModUser = o.LastModUser };
                o2.Insert();
            }
            

            return o.MGID;

        }
예제 #5
0
        public static int Insert(Minigame o)
        {
            SqlParameter[] arrParams = new SqlParameter[23];

            arrParams[0]  = new SqlParameter("@MiniGameType", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MiniGameType, o.MiniGameType.GetTypeCode()));
            arrParams[1]  = new SqlParameter("@MiniGameTypeName", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MiniGameTypeName, o.MiniGameTypeName.GetTypeCode()));
            arrParams[2]  = new SqlParameter("@AdminName", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AdminName, o.AdminName.GetTypeCode()));
            arrParams[3]  = new SqlParameter("@GameName", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.GameName, o.GameName.GetTypeCode()));
            arrParams[4]  = new SqlParameter("@isActive", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isActive, o.isActive.GetTypeCode()));
            arrParams[5]  = new SqlParameter("@NumberPoints", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.NumberPoints, o.NumberPoints.GetTypeCode()));
            arrParams[6]  = new SqlParameter("@AwardedBadgeID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AwardedBadgeID, o.AwardedBadgeID.GetTypeCode()));
            arrParams[7]  = new SqlParameter("@Acknowledgements", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Acknowledgements, o.Acknowledgements.GetTypeCode()));
            arrParams[8]  = new SqlParameter("@LastModDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModDate, o.LastModDate.GetTypeCode()));
            arrParams[9]  = new SqlParameter("@LastModUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModUser, o.LastModUser.GetTypeCode()));
            arrParams[10] = new SqlParameter("@AddedDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedDate, o.AddedDate.GetTypeCode()));
            arrParams[11] = new SqlParameter("@AddedUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedUser, o.AddedUser.GetTypeCode()));

            arrParams[12] = new SqlParameter("@TenID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.TenID, o.TenID.GetTypeCode()));
            arrParams[13] = new SqlParameter("@FldInt1", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldInt1, o.FldInt1.GetTypeCode()));
            arrParams[14] = new SqlParameter("@FldInt2", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldInt2, o.FldInt2.GetTypeCode()));
            arrParams[15] = new SqlParameter("@FldInt3", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldInt3, o.FldInt3.GetTypeCode()));
            arrParams[16] = new SqlParameter("@FldBit1", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldBit1, o.FldBit1.GetTypeCode()));
            arrParams[17] = new SqlParameter("@FldBit2", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldBit2, o.FldBit2.GetTypeCode()));
            arrParams[18] = new SqlParameter("@FldBit3", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldBit3, o.FldBit3.GetTypeCode()));
            arrParams[19] = new SqlParameter("@FldText1", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldText1, o.FldText1.GetTypeCode()));
            arrParams[20] = new SqlParameter("@FldText2", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldText2, o.FldText2.GetTypeCode()));
            arrParams[21] = new SqlParameter("@FldText3", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldText3, o.FldText3.GetTypeCode()));

            arrParams[22]           = new SqlParameter("@MGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MGID, o.MGID.GetTypeCode()));
            arrParams[22].Direction = ParameterDirection.Output;

            SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_Minigame_Insert", arrParams);

            o.MGID = int.Parse(arrParams[22].Value.ToString());


            if (o.MiniGameType == 1)
            {
                var o2 = new MGOnlineBook {
                    MGID = o.MGID, AddedDate = o.AddedDate, AddedUser = o.AddedUser, LastModDate = o.LastModDate, LastModUser = o.LastModUser
                };
                o2.Insert();
            }
            if (o.MiniGameType == 2)
            {
                var o2 = new MGMixAndMatch()
                {
                    MGID = o.MGID, AddedDate = o.AddedDate, AddedUser = o.AddedUser, LastModDate = o.LastModDate, LastModUser = o.LastModUser
                };
                o2.Insert();
            }
            if (o.MiniGameType == 3)
            {
                var o2 = new MGCodeBreaker()
                {
                    MGID = o.MGID, AddedDate = o.AddedDate, AddedUser = o.AddedUser, LastModDate = o.LastModDate, LastModUser = o.LastModUser
                };
                o2.Insert();
            }

            if (o.MiniGameType == 4)
            {
                var o2 = new MGWordMatch()
                {
                    MGID = o.MGID, AddedDate = o.AddedDate, AddedUser = o.AddedUser, LastModDate = o.LastModDate, LastModUser = o.LastModUser
                };
                o2.Insert();
            }


            if (o.MiniGameType == 5)
            {
                var o2 = new MGMatchingGame()
                {
                    MGID = o.MGID, AddedDate = o.AddedDate, AddedUser = o.AddedUser, LastModDate = o.LastModDate, LastModUser = o.LastModUser
                };
                o2.Insert();
            }


            if (o.MiniGameType == 6)
            {
                var o2 = new MGHiddenPic()
                {
                    MGID = o.MGID, AddedDate = o.AddedDate, AddedUser = o.AddedUser, LastModDate = o.LastModDate, LastModUser = o.LastModUser
                };
                o2.Insert();
            }


            if (o.MiniGameType == 7)
            {
                var o2 = new MGChooseAdv()
                {
                    MGID = o.MGID, AddedDate = o.AddedDate, AddedUser = o.AddedUser, LastModDate = o.LastModDate, LastModUser = o.LastModUser
                };
                o2.Insert();
            }


            return(o.MGID);
        }
예제 #6
0
        public bool Fetch(int MAGID)
        {
            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

            arrParams[0] = new SqlParameter("@MAGID", MAGID);

            dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "app_MGMatchingGame_GetByID", arrParams);

            if (dr.Read())
            {
                // declare return value

                MGMatchingGame result = new MGMatchingGame();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["MAGID"].ToString(), out _int))
                {
                    this.MAGID = _int;
                }
                if (int.TryParse(dr["MGID"].ToString(), out _int))
                {
                    this.MGID = _int;
                }
                if (int.TryParse(dr["CorrectRoundsToWinCount"].ToString(), out _int))
                {
                    this.CorrectRoundsToWinCount = _int;
                }
                if (int.TryParse(dr["EasyGameSize"].ToString(), out _int))
                {
                    this.EasyGameSize = _int;
                }
                if (int.TryParse(dr["MediumGameSize"].ToString(), out _int))
                {
                    this.MediumGameSize = _int;
                }
                if (int.TryParse(dr["HardGameSize"].ToString(), out _int))
                {
                    this.HardGameSize = _int;
                }
                this.EnableMediumDifficulty = bool.Parse(dr["EnableMediumDifficulty"].ToString());
                this.EnableHardDifficulty   = bool.Parse(dr["EnableHardDifficulty"].ToString());
                if (DateTime.TryParse(dr["LastModDate"].ToString(), out _datetime))
                {
                    this.LastModDate = _datetime;
                }
                this.LastModUser = dr["LastModUser"].ToString();
                if (DateTime.TryParse(dr["AddedDate"].ToString(), out _datetime))
                {
                    this.AddedDate = _datetime;
                }
                this.AddedUser = dr["AddedUser"].ToString();

                dr.Close();

                return(true);
            }

            dr.Close();

            return(false);
        }
        public static int Delete(MGMatchingGame o)
        {

            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[1];

            arrParams[0] = new SqlParameter("@MAGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MAGID, o.MAGID.GetTypeCode()));

            try
            {

                iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_MGMatchingGame_Delete", arrParams);

            }

            catch (SqlException exx)
            {

                System.Diagnostics.Debug.Write(exx.Message);

            }

            return iReturn;

        }
        public static int Update(MGMatchingGame o)
        {

            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[12];

            arrParams[0] = new SqlParameter("@MAGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MAGID, o.MAGID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@MGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MGID, o.MGID.GetTypeCode()));
            arrParams[2] = new SqlParameter("@CorrectRoundsToWinCount", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.CorrectRoundsToWinCount, o.CorrectRoundsToWinCount.GetTypeCode()));
            arrParams[3] = new SqlParameter("@EasyGameSize", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EasyGameSize, o.EasyGameSize.GetTypeCode()));
            arrParams[4] = new SqlParameter("@MediumGameSize", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MediumGameSize, o.MediumGameSize.GetTypeCode()));
            arrParams[5] = new SqlParameter("@HardGameSize", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.HardGameSize, o.HardGameSize.GetTypeCode()));
            arrParams[6] = new SqlParameter("@EnableMediumDifficulty", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EnableMediumDifficulty, o.EnableMediumDifficulty.GetTypeCode()));
            arrParams[7] = new SqlParameter("@EnableHardDifficulty", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EnableHardDifficulty, o.EnableHardDifficulty.GetTypeCode()));
            arrParams[8] = new SqlParameter("@LastModDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModDate, o.LastModDate.GetTypeCode()));
            arrParams[9] = new SqlParameter("@LastModUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModUser, o.LastModUser.GetTypeCode()));
            arrParams[10] = new SqlParameter("@AddedDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedDate, o.AddedDate.GetTypeCode()));
            arrParams[11] = new SqlParameter("@AddedUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedUser, o.AddedUser.GetTypeCode()));

            try
            {

                iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_MGMatchingGame_Update", arrParams);

            }

            catch (SqlException exx)
            {

                System.Diagnostics.Debug.Write(exx.Message);

            }

            return iReturn;

        }
        public static int Insert(MGMatchingGame o)
        {

            SqlParameter[] arrParams = new SqlParameter[12];

            arrParams[0] = new SqlParameter("@MGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MGID, o.MGID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@CorrectRoundsToWinCount", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.CorrectRoundsToWinCount, o.CorrectRoundsToWinCount.GetTypeCode()));
            arrParams[2] = new SqlParameter("@EasyGameSize", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EasyGameSize, o.EasyGameSize.GetTypeCode()));
            arrParams[3] = new SqlParameter("@MediumGameSize", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MediumGameSize, o.MediumGameSize.GetTypeCode()));
            arrParams[4] = new SqlParameter("@HardGameSize", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.HardGameSize, o.HardGameSize.GetTypeCode()));
            arrParams[5] = new SqlParameter("@EnableMediumDifficulty", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EnableMediumDifficulty, o.EnableMediumDifficulty.GetTypeCode()));
            arrParams[6] = new SqlParameter("@EnableHardDifficulty", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EnableHardDifficulty, o.EnableHardDifficulty.GetTypeCode()));
            arrParams[7] = new SqlParameter("@LastModDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModDate, o.LastModDate.GetTypeCode()));
            arrParams[8] = new SqlParameter("@LastModUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModUser, o.LastModUser.GetTypeCode()));
            arrParams[9] = new SqlParameter("@AddedDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedDate, o.AddedDate.GetTypeCode()));
            arrParams[10] = new SqlParameter("@AddedUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedUser, o.AddedUser.GetTypeCode()));
            arrParams[11] = new SqlParameter("@MAGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MAGID, o.MAGID.GetTypeCode()));
            arrParams[11].Direction = ParameterDirection.Output;

            SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_MGMatchingGame_Insert", arrParams);

            o.MAGID = int.Parse(arrParams[11].Value.ToString());

            return o.MAGID;

        }
        public bool Fetch(int MAGID)
        {

            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

            arrParams[0] = new SqlParameter("@MAGID", MAGID);

            dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "app_MGMatchingGame_GetByID", arrParams);

            if (dr.Read())
            {

                // declare return value

                MGMatchingGame result = new MGMatchingGame();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["MAGID"].ToString(), out _int)) this.MAGID = _int;
                if (int.TryParse(dr["MGID"].ToString(), out _int)) this.MGID = _int;
                if (int.TryParse(dr["CorrectRoundsToWinCount"].ToString(), out _int)) this.CorrectRoundsToWinCount = _int;
                if (int.TryParse(dr["EasyGameSize"].ToString(), out _int)) this.EasyGameSize = _int;
                if (int.TryParse(dr["MediumGameSize"].ToString(), out _int)) this.MediumGameSize = _int;
                if (int.TryParse(dr["HardGameSize"].ToString(), out _int)) this.HardGameSize = _int;
                this.EnableMediumDifficulty = bool.Parse(dr["EnableMediumDifficulty"].ToString());
                this.EnableHardDifficulty = bool.Parse(dr["EnableHardDifficulty"].ToString());
                if (DateTime.TryParse(dr["LastModDate"].ToString(), out _datetime)) this.LastModDate = _datetime;
                this.LastModUser = dr["LastModUser"].ToString();
                if (DateTime.TryParse(dr["AddedDate"].ToString(), out _datetime)) this.AddedDate = _datetime;
                this.AddedUser = dr["AddedUser"].ToString();

                dr.Close();

                return true;

            }

            dr.Close();

            return false;

        }
        protected void DvItemCommand(object sender, DetailsViewCommandEventArgs e)
        {
            string returnURL = "~/ControlRoom/Modules/Setup/MiniGameList.aspx";
            if (e.CommandName.ToLower() == "more")
            {
                //Response.Redirect("~/ControlRoom/Modules/Setup/MGMatchingGameTilesList.aspx?MGID=" + e.CommandArgument);
                Response.Redirect("~/ControlRoom/Modules/Setup/MGMatchingGameTilesList.aspx");
            }

            if (e.CommandName.ToLower() == "preview")
            {
                Session["MGID"] = e.CommandArgument;
                int key = Convert.ToInt32(e.CommandArgument);
                var obj = Minigame.FetchObject(key);
                Session["CRGoToUrl"] = Minigame.GetEditPage(obj.MiniGameType) + "?PK=" + e.CommandArgument;
                Response.Redirect("~/ControlRoom/Modules/Setup/MinigamePreview.aspx?MGID=" + e.CommandArgument);
            }

            if (e.CommandName.ToLower() == "back")
            {
                Response.Redirect(returnURL);
            }
            if (e.CommandName.ToLower() == "refresh")
            {
                try
                {          
                    odsData.DataBind();
                    dv.DataBind();
                    dv.ChangeMode(DetailsViewMode.Edit);

                    var masterPage = (IControlRoomMaster)Master;
                    if (masterPage != null) masterPage.PageMessage = SRPResources.RefreshOK;
                }
                catch (Exception ex)
                {
                    var masterPage = (IControlRoomMaster)Master;
                    masterPage.PageError = String.Format(SRPResources.ApplicationError1, ex.Message);
                }
            }

            if (e.CommandName.ToLower() == "save" || e.CommandName.ToLower() == "saveandback")
            {
                try
                {
                    var obj = new MGMatchingGame();
                    //int pk = int.Parse(((DetailsView)sender).Rows[0].Cells[1].Text);
                    int pk = int.Parse(((TextBox)((DetailsView)sender).FindControl("MAGID")).Text);
                    obj.Fetch(pk);

                    var obj2 = Minigame.FetchObject(obj.MGID);

                    obj2.AdminName = ((TextBox)((DetailsView)sender).FindControl("AdminName")).Text;
                    obj2.GameName = ((TextBox)((DetailsView)sender).FindControl("GameName")).Text;
                    obj2.isActive = ((CheckBox)((DetailsView)sender).FindControl("isActive")).Checked;
                    obj2.NumberPoints = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("NumberPoints")).Text);
                    obj2.AwardedBadgeID = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("AwardedBadgeID")).SelectedValue);
                    obj2.Acknowledgements = ((HtmlTextArea)((DetailsView)sender).FindControl("Acknowledgements")).InnerHtml;

                    obj.CorrectRoundsToWinCount = 1;// FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("CorrectRoundsToWinCount")).Text);
                    obj.EnableMediumDifficulty = ((CheckBox)((DetailsView)sender).FindControl("EnableMediumDifficulty")).Checked;
                    obj.EnableHardDifficulty = ((CheckBox)((DetailsView)sender).FindControl("EnableHardDifficulty")).Checked;

                    obj.EasyGameSize = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("EasyGameSize")).SelectedValue);
                    obj.MediumGameSize = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("MediumGameSize")).SelectedValue);
                    obj.HardGameSize = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("HardGameSize")).SelectedValue);
                    
                    obj2.LastModDate = obj.LastModDate = DateTime.Now;
                    obj2.LastModUser = obj.LastModUser = ((SRPUser)Session[SessionData.UserProfile.ToString()]).Username;  //"N/A";  // Get from session

                    if (obj.IsValid(BusinessRulesValidationMode.UPDATE) && obj2.IsValid(BusinessRulesValidationMode.UPDATE))
                    {
                        obj.Update();
                        obj2.Update();
                        new SessionTools(Session).RemoveCache(Cache, CacheKey.AdventuresActive);

                        if (e.CommandName.ToLower() == "saveandback")
                        {
                            Response.Redirect(returnURL);
                        }

                        odsData.DataBind();
                        dv.DataBind();
                        dv.ChangeMode(DetailsViewMode.Edit);

                        var masterPage = (IControlRoomMaster)Master;
                        masterPage.PageMessage = SRPResources.SaveOK;
                    }
                    else
                    {
                        var masterPage = (IControlRoomMaster)Master;
                        string message = String.Format(SRPResources.ApplicationError1, "<ul>");
                        foreach (BusinessRulesValidationMessage m in obj.ErrorCodes)
                        {
                            message = string.Format(String.Format("{0}<li>{{0}}</li>", message), m.ErrorMessage);
                        }
                        message = string.Format("{0}</ul>", message);
                        masterPage.PageError = message;
                    }     
                }
                catch (Exception ex)
                {
                    var masterPage = (IControlRoomMaster)Master;
                    masterPage.PageError = String.Format(SRPResources.ApplicationError1, ex.Message);
                }
            }
        }