public static int Update(MGChooseAdvSlides o)
        {
            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[12];

            arrParams[0]  = new SqlParameter("@CASID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.CASID, o.CASID.GetTypeCode()));
            arrParams[1]  = new SqlParameter("@CAID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.CAID, o.CAID.GetTypeCode()));
            arrParams[2]  = new SqlParameter("@MGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MGID, o.MGID.GetTypeCode()));
            arrParams[3]  = new SqlParameter("@Difficulty", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Difficulty, o.Difficulty.GetTypeCode()));
            arrParams[4]  = new SqlParameter("@StepNumber", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.StepNumber, o.StepNumber.GetTypeCode()));
            arrParams[5]  = new SqlParameter("@SlideText", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SlideText, o.SlideText.GetTypeCode()));
            arrParams[6]  = new SqlParameter("@FirstImageGoToStep", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FirstImageGoToStep, o.FirstImageGoToStep.GetTypeCode()));
            arrParams[7]  = new SqlParameter("@SecondImageGoToStep", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SecondImageGoToStep, o.SecondImageGoToStep.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_MGChooseAdvSlides_Update", arrParams);
            }

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

            return(iReturn);
        }
        public static int Delete(MGChooseAdvSlides o)
        {
            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[1];

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

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

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

            return(iReturn);
        }
        public static int Insert(MGChooseAdvSlides o)
        {
            SqlParameter[] arrParams = new SqlParameter[12];

            arrParams[0]            = new SqlParameter("@CAID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.CAID, o.CAID.GetTypeCode()));
            arrParams[1]            = new SqlParameter("@MGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MGID, o.MGID.GetTypeCode()));
            arrParams[2]            = new SqlParameter("@Difficulty", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Difficulty, o.Difficulty.GetTypeCode()));
            arrParams[3]            = new SqlParameter("@StepNumber", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.StepNumber, o.StepNumber.GetTypeCode()));
            arrParams[4]            = new SqlParameter("@SlideText", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SlideText, o.SlideText.GetTypeCode()));
            arrParams[5]            = new SqlParameter("@FirstImageGoToStep", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FirstImageGoToStep, o.FirstImageGoToStep.GetTypeCode()));
            arrParams[6]            = new SqlParameter("@SecondImageGoToStep", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SecondImageGoToStep, o.SecondImageGoToStep.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("@CASID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.CASID, o.CASID.GetTypeCode()));
            arrParams[11].Direction = ParameterDirection.Output;

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

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

            return(o.CASID);
        }
        protected void DvItemCommand(object sender, DetailsViewCommandEventArgs e) {
            string returnURL = "~/ControlRoom/Modules/Setup/MGChooseAdvSlidesList.aspx?L=" + lblDiff.Text + "&MGID=" + lblMGID.Text;
            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 MGChooseAdvSlides();
                    var pk = int.Parse(((TextBox)((DetailsView)sender).FindControl("CASID")).Text);
                    obj.Fetch(pk);

                    obj.CAID = FormatHelper.SafeToInt(lblCAID.Text);
                    obj.MGID = FormatHelper.SafeToInt(lblMGID.Text);
                    //obj.Difficulty = FormatHelper.SafeToInt(lblDiff.Text);
                    //obj.StepNumber = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("StepNumber")).Text);
                    obj.SlideText = ((HtmlTextArea)((DetailsView)sender).FindControl("SlideText")).InnerHtml;
                    obj.FirstImageGoToStep = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("FirstImageGoToStep")).Text);
                    obj.SecondImageGoToStep = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("SecondImageGoToStep")).Text);

                    obj.LastModDate = DateTime.Now;
                    obj.LastModUser = ((SRPUser)Session[SessionData.UserProfile.ToString()]).Username;  //"N/A";  // Get from session

                    if(obj.IsValid(BusinessRulesValidationMode.UPDATE)) {
                        obj.Update();
                        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);
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e) {
            MasterPage.RequiredPermission = 4300;
            MasterPage.IsSecure = true;
            MasterPage.PageTitle = string.Format("{0}", "Choose Your Adventure Slides Edit");

            if(!IsPostBack) {
                SetPageRibbon(StandardModuleRibbons.SetupRibbon());

                if(Session["MGID"] == null) {
                    Response.Redirect("~/ControlRoom/Modules/Setup/MiniGameList.aspx");
                }

                if(string.IsNullOrEmpty(Request["PK"])) {
                    lblMGID.Text = Session["MGID"].ToString();
                    lblCAID.Text = Request["CAID"];
                    if(Request["L"] != null)
                        lblDiff.Text = Request["L"];
                    var s = (lblDiff.Text == "1"
                                 ? " - EASY Difficulty"
                                 : (lblDiff.Text == "2" ? " - MEDIUM Difficulty" : " - HARD Difficulty"));

                    var o = Minigame.FetchObject(int.Parse(lblMGID.Text));
                    AdminName.Text = o.AdminName + s;

                    var obj = new MGChooseAdvSlides();
                    obj.CAID = int.Parse(lblCAID.Text);
                    obj.MGID = int.Parse(lblMGID.Text);
                    obj.SecondImageGoToStep = obj.FirstImageGoToStep = 0;
                    obj.SlideText= string.Empty;
                    obj.Difficulty = int.Parse(lblDiff.Text);
                    obj.StepNumber = -1;
                    obj.AddedDate = DateTime.Now;
                    obj.AddedUser = ((SRPUser)Session[SessionData.UserProfile.ToString()]).Username;  //"N/A";  // Get from session
                    obj.LastModDate = obj.AddedDate;
                    obj.LastModUser = obj.AddedUser;
                    obj.Insert();
                    lblPK.Text = obj.CASID.ToString();

                    dv.ChangeMode(DetailsViewMode.Edit);

                } else {
                    lblPK.Text = Request["PK"];

                    var o1 = MGChooseAdvSlides.FetchObject(int.Parse(lblPK.Text));
                    lblMGID.Text = o1.MGID.ToString();
                    lblCAID.Text = o1.CAID.ToString();

                    if(Request["L"] != null)
                        lblDiff.Text = Request["L"];
                    var s = (lblDiff.Text == "1"
                                 ? " - EASY Difficulty"
                                 : (lblDiff.Text == "2" ? " - MEDIUM Difficulty" : " - HARD Difficulty"));

                    var o = Minigame.FetchObject(int.Parse(lblMGID.Text));
                    AdminName.Text = o.AdminName + s;

                    dv.ChangeMode(DetailsViewMode.Edit);
                }
                Page.DataBind();
            }

        }
        public bool Fetch(int CASID)
        {
            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

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

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

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

                MGChooseAdvSlides result = new MGChooseAdvSlides();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["CASID"].ToString(), out _int))
                {
                    this.CASID = _int;
                }
                if (int.TryParse(dr["CAID"].ToString(), out _int))
                {
                    this.CAID = _int;
                }
                if (int.TryParse(dr["MGID"].ToString(), out _int))
                {
                    this.MGID = _int;
                }
                if (int.TryParse(dr["Difficulty"].ToString(), out _int))
                {
                    this.Difficulty = _int;
                }
                if (int.TryParse(dr["StepNumber"].ToString(), out _int))
                {
                    this.StepNumber = _int;
                }
                this.SlideText = dr["SlideText"].ToString();
                if (int.TryParse(dr["FirstImageGoToStep"].ToString(), out _int))
                {
                    this.FirstImageGoToStep = _int;
                }
                if (int.TryParse(dr["SecondImageGoToStep"].ToString(), out _int))
                {
                    this.SecondImageGoToStep = _int;
                }
                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(MGChooseAdvSlides o)
        {

            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[1];

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

            try
            {

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

            }

            catch (SqlException exx)
            {

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

            }

            return iReturn;

        }
        public static MGChooseAdvSlides FetchPlaySlide(int CAID, int Step, int Difficulty)
        {
            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[3];

            arrParams[0] = new SqlParameter("@CAID", CAID);
            arrParams[1] = new SqlParameter("@Step", Step);
            arrParams[2] = new SqlParameter("@Difficulty", Difficulty);

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

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

                MGChooseAdvSlides result = new MGChooseAdvSlides();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["CASID"].ToString(), out _int))
                {
                    result.CASID = _int;
                }
                if (int.TryParse(dr["CAID"].ToString(), out _int))
                {
                    result.CAID = _int;
                }
                if (int.TryParse(dr["MGID"].ToString(), out _int))
                {
                    result.MGID = _int;
                }
                if (int.TryParse(dr["Difficulty"].ToString(), out _int))
                {
                    result.Difficulty = _int;
                }
                if (int.TryParse(dr["StepNumber"].ToString(), out _int))
                {
                    result.StepNumber = _int;
                }
                result.SlideText = dr["SlideText"].ToString();
                if (int.TryParse(dr["FirstImageGoToStep"].ToString(), out _int))
                {
                    result.FirstImageGoToStep = _int;
                }
                if (int.TryParse(dr["SecondImageGoToStep"].ToString(), out _int))
                {
                    result.SecondImageGoToStep = _int;
                }
                if (DateTime.TryParse(dr["LastModDate"].ToString(), out _datetime))
                {
                    result.LastModDate = _datetime;
                }
                result.LastModUser = dr["LastModUser"].ToString();
                if (DateTime.TryParse(dr["AddedDate"].ToString(), out _datetime))
                {
                    result.AddedDate = _datetime;
                }
                result.AddedUser = dr["AddedUser"].ToString();

                dr.Close();

                return(result);
            }

            dr.Close();

            return(null);
        }
        public static int Update(MGChooseAdvSlides o)
        {

            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[12];

            arrParams[0] = new SqlParameter("@CASID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.CASID, o.CASID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@CAID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.CAID, o.CAID.GetTypeCode()));
            arrParams[2] = new SqlParameter("@MGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MGID, o.MGID.GetTypeCode()));
            arrParams[3] = new SqlParameter("@Difficulty", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Difficulty, o.Difficulty.GetTypeCode()));
            arrParams[4] = new SqlParameter("@StepNumber", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.StepNumber, o.StepNumber.GetTypeCode()));
            arrParams[5] = new SqlParameter("@SlideText", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SlideText, o.SlideText.GetTypeCode()));
            arrParams[6] = new SqlParameter("@FirstImageGoToStep", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FirstImageGoToStep, o.FirstImageGoToStep.GetTypeCode()));
            arrParams[7] = new SqlParameter("@SecondImageGoToStep", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SecondImageGoToStep, o.SecondImageGoToStep.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_MGChooseAdvSlides_Update", arrParams);

            }

            catch (SqlException exx)
            {

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

            }

            return iReturn;

        }
        public static int Insert(MGChooseAdvSlides o)
        {

            SqlParameter[] arrParams = new SqlParameter[12];

            arrParams[0] = new SqlParameter("@CAID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.CAID, o.CAID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@MGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MGID, o.MGID.GetTypeCode()));
            arrParams[2] = new SqlParameter("@Difficulty", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Difficulty, o.Difficulty.GetTypeCode()));
            arrParams[3] = new SqlParameter("@StepNumber", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.StepNumber, o.StepNumber.GetTypeCode()));
            arrParams[4] = new SqlParameter("@SlideText", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SlideText, o.SlideText.GetTypeCode()));
            arrParams[5] = new SqlParameter("@FirstImageGoToStep", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FirstImageGoToStep, o.FirstImageGoToStep.GetTypeCode()));
            arrParams[6] = new SqlParameter("@SecondImageGoToStep", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SecondImageGoToStep, o.SecondImageGoToStep.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("@CASID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.CASID, o.CASID.GetTypeCode()));
            arrParams[11].Direction = ParameterDirection.Output;

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

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

            return o.CASID;

        }
        public bool Fetch(int CASID)
        {

            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

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

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

            if (dr.Read())
            {

                // declare return value

                MGChooseAdvSlides result = new MGChooseAdvSlides();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["CASID"].ToString(), out _int)) this.CASID = _int;
                if (int.TryParse(dr["CAID"].ToString(), out _int)) this.CAID = _int;
                if (int.TryParse(dr["MGID"].ToString(), out _int)) this.MGID = _int;
                if (int.TryParse(dr["Difficulty"].ToString(), out _int)) this.Difficulty = _int;
                if (int.TryParse(dr["StepNumber"].ToString(), out _int)) this.StepNumber = _int;
                this.SlideText = dr["SlideText"].ToString();
                if (int.TryParse(dr["FirstImageGoToStep"].ToString(), out _int)) this.FirstImageGoToStep = _int;
                if (int.TryParse(dr["SecondImageGoToStep"].ToString(), out _int)) this.SecondImageGoToStep = _int;
                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 MGChooseAdvSlides FetchPlaySlide(int CAID, int Step, int Difficulty)
        {

            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[3];

            arrParams[0] = new SqlParameter("@CAID", CAID);
            arrParams[1] = new SqlParameter("@Step", Step);
            arrParams[2] = new SqlParameter("@Difficulty", Difficulty);

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

            if (dr.Read())
            {

                // declare return value

                MGChooseAdvSlides result = new MGChooseAdvSlides();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["CASID"].ToString(), out _int)) result.CASID = _int;
                if (int.TryParse(dr["CAID"].ToString(), out _int)) result.CAID = _int;
                if (int.TryParse(dr["MGID"].ToString(), out _int)) result.MGID = _int;
                if (int.TryParse(dr["Difficulty"].ToString(), out _int)) result.Difficulty = _int;
                if (int.TryParse(dr["StepNumber"].ToString(), out _int)) result.StepNumber = _int;
                result.SlideText = dr["SlideText"].ToString();
                if (int.TryParse(dr["FirstImageGoToStep"].ToString(), out _int)) result.FirstImageGoToStep = _int;
                if (int.TryParse(dr["SecondImageGoToStep"].ToString(), out _int)) result.SecondImageGoToStep = _int;
                if (DateTime.TryParse(dr["LastModDate"].ToString(), out _datetime)) result.LastModDate = _datetime;
                result.LastModUser = dr["LastModUser"].ToString();
                if (DateTime.TryParse(dr["AddedDate"].ToString(), out _datetime)) result.AddedDate = _datetime;
                result.AddedUser = dr["AddedUser"].ToString();

                dr.Close();

                return result;

            }

            dr.Close();

            return null;

        }
        protected void GvRowCommand(object sender, GridViewCommandEventArgs e) {
            string editpage = "~/ControlRoom/Modules/Setup/MGChooseAdvSlidesAddEdit.aspx";
            if(e.CommandName.ToLower() == "addrecord") {
                //Response.Redirect(String.Format("{0}?MGID={1}&CAID={2}&L={3}", editpage, lblMGID.Text, lblCAID.Text, lblDiff.Text));
                Response.Redirect(String.Format("{0}?CAID={1}&L={2}", editpage, lblCAID.Text, lblDiff.Text));
            }

            if(e.CommandName.ToLower() == "editrecord") {
                int key = Convert.ToInt32(e.CommandArgument);
                Response.Redirect(String.Format("{0}?PK={1}&L={2}", editpage, key, lblDiff.Text));
            }

            if(e.CommandName.ToLower() == "back") {
                Response.Redirect(String.Format("~/ControlRoom/Modules/Setup/MGChooseAdvAddEdit.aspx?PK={0}", lblMGID.Text));
            }


            if(e.CommandName.ToLower() == "moveup") {
                var key = Convert.ToInt32(e.CommandArgument);
                DAL.MGChooseAdvSlides.MoveUp(key);
                var masterPage = (IControlRoomMaster)Master;
                masterPage.PageMessage = "Step Moved Up!";
                LoadData();
            }

            if(e.CommandName.ToLower() == "movedn") {
                var key = Convert.ToInt32(e.CommandArgument);
                DAL.MGChooseAdvSlides.MoveDn(key);
                var masterPage = (IControlRoomMaster)Master;
                masterPage.PageMessage = "Step Moved Down";
                LoadData();
            }




            if(e.CommandName.ToLower() == "deleterecord") {
                var key = Convert.ToInt32(e.CommandArgument);
                try {
                    var obj = new MGChooseAdvSlides();
                    if(obj.IsValid(BusinessRulesValidationMode.DELETE)) {
                        MGChooseAdvSlides.FetchObject(key).Delete();

                        LoadData();
                        var masterPage = (IControlRoomMaster)Master;
                        if(masterPage != null)
                            masterPage.PageMessage = SRPResources.DeleteOK;
                    } 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);
                        if(masterPage != null)
                            masterPage.PageError = message;
                    }
                } catch(Exception ex) {
                    var masterPage = (IControlRoomMaster)Master;
                    if(masterPage != null)
                        masterPage.PageError = String.Format(SRPResources.ApplicationError1, ex.Message);
                }
            }
        }