Exemplo n.º 1
0
        protected void GvRowCommand(object sender, GridViewCommandEventArgs e)
        {
            string editpage = "~/ControlRoom/Modules/Setup/MGMixAndMatchItemsAddEdit.aspx";

            if (e.CommandName.ToLower() == "addrecord")
            {
                Response.Redirect(String.Format("{0}?MGID={1}&MMID={2}", editpage, lblMGID.Text, lblMMID.Text));
                //Response.Redirect(editpage);
            }
            if (e.CommandName.ToLower() == "back")
            {
                Response.Redirect(String.Format("~/ControlRoom/Modules/Setup/MGMixAndMatchAddEdit.aspx?PK={0}", lblMGID.Text));
            }
            if (e.CommandName.ToLower() == "editrecord")
            {
                int key = Convert.ToInt32(e.CommandArgument);
                Response.Redirect(String.Format("{0}?PK={1}", editpage, key));
            }
            if (e.CommandName.ToLower() == "deleterecord")
            {
                var key = Convert.ToInt32(e.CommandArgument);
                try
                {
                    var obj = new MGMixAndMatchItems();
                    if (obj.IsValid(BusinessRulesValidationMode.DELETE))
                    {
                        MGMixAndMatchItems.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);
                    }
                }
            }
        }
        public void LoadPage()
        {
            var i1 = new MGMixAndMatchItems();
            var i2 = new MGMixAndMatchItems();
            var i3 = new MGMixAndMatchItems();

            MGMixAndMatch.Get3RandomItems(int.Parse(MMID.Text), out i1, out i2, out i3);

            MGMixAndMatchItems correctItem = null;
            var rnd   = new Random(DateTime.Now.Millisecond);
            var ticks = rnd.Next(1, 3);

            if (ticks == 1)
            {
                correctItem = i1;
            }
            if (ticks == 2)
            {
                correctItem = i2;
            }
            if (ticks == 3)
            {
                correctItem = i3;
            }

            if (correctItem != null)
            {
                MMIID.Text     = correctItem.MMIID.ToString();
                lblEasy.Text   = correctItem.EasyLabel;
                lblMedium.Text = correctItem.MediumLabel;
                lblHard.Text   = correctItem.HardLabel;
            }

            Correct.Text = ticks.ToString();

            btn1.ImageUrl = "/Images/Games/MixMatch/" + i1.MMIID.ToString() + ".png";
            btn2.ImageUrl = "/Images/Games/MixMatch/" + i2.MMIID.ToString() + ".png";
            btn3.ImageUrl = "/Images/Games/MixMatch/" + i3.MMIID.ToString() + ".png";


            var difficulty = int.Parse(Difficulty.Text);

            if (difficulty == 1)
            {
                pnlAudioEasy.Visible = System.IO.File.Exists(Server.MapPath(AudioEasy));
            }
            if (difficulty == 2)
            {
                pnlAudioMedium.Visible = System.IO.File.Exists(Server.MapPath(AudioMedium));
            }
            if (difficulty == 3)
            {
                pnlAudioHard.Visible = System.IO.File.Exists(Server.MapPath(AudioHard));
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetPageRibbon(StandardModuleRibbons.SetupRibbon());
            }

            //MasterPage.RequiredPermission = PERMISSIONID;
            MasterPage.IsSecure  = true;
            MasterPage.PageTitle = string.Format("{0}", "Mix-And-Match Item Add / Edit");

            if (!IsPostBack)
            {
                if (Request["MGID"] != null)
                {
                    lblMGID.Text = Request["MGID"];
                    lblMMID.Text = Request["MMID"];

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

                    lblPK.Text = "";
                    dv.ChangeMode(DetailsViewMode.Insert);
                }
                else
                {
                    lblPK.Text = Request["PK"];

                    var o1 = MGMixAndMatchItems.FetchObject(int.Parse(lblPK.Text));
                    lblMGID.Text = o1.MGID.ToString();
                    lblMMID.Text = o1.MMID.ToString();

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

                    dv.ChangeMode(DetailsViewMode.Edit);
                }
                Page.DataBind();
            }
        }
        protected void DvItemCommand(object sender, DetailsViewCommandEventArgs e)
        {
            //string returnURL = "~/ControlRoom/Modules/Setup/MGMixAndMatchItemsList.aspx?MGID=" + lblMGID.Text;
            string returnURL = "~/ControlRoom/Modules/Setup/MGMixAndMatchItemsList.aspx";

            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() == "add" || e.CommandName.ToLower() == "addandback")
            {
                try
                {
                    var obj = new MGMixAndMatchItems();

                    obj.MMID = FormatHelper.SafeToInt(lblMMID.Text);
                    obj.MGID = FormatHelper.SafeToInt(lblMGID.Text);

                    //obj.ItemImage = ((TextBox)((DetailsView)sender).FindControl("ItemImage")).Text;
                    obj.EasyLabel   = ((TextBox)((DetailsView)sender).FindControl("EasyLabel")).Text;
                    obj.MediumLabel = ((TextBox)((DetailsView)sender).FindControl("MediumLabel")).Text;
                    obj.HardLabel   = ((TextBox)((DetailsView)sender).FindControl("HardLabel")).Text;
                    //obj.AudioEasy = ((TextBox)((DetailsView)sender).FindControl("AudioEasy")).Text;
                    //obj.AudioMedium = ((TextBox)((DetailsView)sender).FindControl("AudioMedium")).Text;
                    //obj.AudioHard = ((TextBox)((DetailsView)sender).FindControl("AudioHard")).Text;

                    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;

                    if (obj.IsValid(BusinessRulesValidationMode.INSERT))
                    {
                        obj.Insert();
                        if (e.CommandName.ToLower() == "addandback")
                        {
                            Response.Redirect(returnURL);
                        }

                        lblPK.Text = obj.MMIID.ToString();

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

                        var masterPage = (IControlRoomMaster)Master;
                        masterPage.PageMessage = SRPResources.AddedOK;
                    }
                    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);
                }
            }
            if (e.CommandName.ToLower() == "save" || e.CommandName.ToLower() == "saveandback")
            {
                try
                {
                    var obj = new MGMixAndMatchItems();
                    int pk  = int.Parse(((TextBox)((DetailsView)sender).FindControl("MMIID")).Text);
                    obj.Fetch(pk);

                    obj.MMID = FormatHelper.SafeToInt(lblMMID.Text);
                    obj.MGID = FormatHelper.SafeToInt(lblMGID.Text);

                    //obj.ItemImage = ((TextBox)((DetailsView)sender).FindControl("ItemImage")).Text;
                    obj.EasyLabel   = ((TextBox)((DetailsView)sender).FindControl("EasyLabel")).Text;
                    obj.MediumLabel = ((TextBox)((DetailsView)sender).FindControl("MediumLabel")).Text;
                    obj.HardLabel   = ((TextBox)((DetailsView)sender).FindControl("HardLabel")).Text;
                    //obj.AudioEasy = ((TextBox)((DetailsView)sender).FindControl("AudioEasy")).Text;
                    //obj.AudioMedium = ((TextBox)((DetailsView)sender).FindControl("AudioMedium")).Text;
                    //obj.AudioHard = ((TextBox)((DetailsView)sender).FindControl("AudioHard")).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);
                }
            }
        }
Exemplo n.º 5
0
        public void LoadPage()
        {
            var i1 = new MGMixAndMatchItems();
            var i2 = new MGMixAndMatchItems();
            var i3 = new MGMixAndMatchItems();

            MGMixAndMatch.Get3RandomItems(int.Parse(MMID.Text), out i1, out i2, out i3);

            MGMixAndMatchItems correctItem = null;
            var correctItemNumber          = new Random(DateTime.Now.Millisecond).Next(1, 3);

            switch (correctItemNumber)
            {
            case 1:
                correctItem = i1;
                break;

            case 2:
                correctItem = i2;
                break;

            case 3:
                correctItem = i3;
                break;
            }

            var difficulty = int.Parse(Difficulty.Text);

            if (correctItem != null)
            {
                MMIID.Text = correctItem.MMIID.ToString();
                StringBuilder audio = new StringBuilder(MixMatchBasePath);

                switch (difficulty)
                {
                case 2:
                    //medium
                    lblMixMatch.Text = correctItem.MediumLabel;
                    audio.AppendFormat("m_{0}.mp3", MMIID.Text);
                    break;

                case 3:
                    //hard
                    lblMixMatch.Text = correctItem.HardLabel;
                    audio.AppendFormat("h_{0}.mp3", MMIID.Text);
                    break;

                default:
                    lblMixMatch.Text = correctItem.EasyLabel;
                    audio.AppendFormat("e_{0}.mp3", MMIID.Text);
                    break;
                }

                if (System.IO.File.Exists(Server.MapPath(audio.ToString())))
                {
                    lblSound.Text = string.Format(
                        "<audio controls><source src='{0}' type='audio/mpeg'>Your browser does not support this audio format.</audio>",
                        VirtualPathUtility.ToAbsolute(audio.ToString()));
                    pnlAudio.Visible = true;
                }
            }

            Correct.Text = correctItemNumber.ToString();

            btn1.ImageUrl = string.Format("{0}{1}.png", MixMatchBasePath, i1.MMIID);
            btn2.ImageUrl = string.Format("{0}{1}.png", MixMatchBasePath, i2.MMIID);
            btn3.ImageUrl = string.Format("{0}{1}.png", MixMatchBasePath, i3.MMIID);
        }