コード例 #1
0
        protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
        {
            if (e.Argument == "true")
            {
                if (!StoredData.User.AccessExpired.Value && !StoredData.User.TempDivision.Value)
                {
                    bool success = false;
                    using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext())
                    {
                        int?     matchPointLogId  = 0;
                        int?     matchId          = null;
                        int?     opponentId       = null;
                        DateTime selectedDateTime = Convert.ToDateTime(RadDatePicker1.SelectedDate.Value.ToShortDateString() + " " + RadTimePicker1.SelectedDate.Value.ToShortTimeString());
                        using (TransactionScope transactionScope = new TransactionScope())
                        {
                            if (string.IsNullOrEmpty(matchIdHiddenField.Value))
                            {
                                opponentId = Convert.ToInt32(opponentDropDownList.SelectedItem.Value);
                                dataContext.InsertMatch(selectedDateTime, Convert.ToInt32(locationDropDownList.Text), StoredData.User.UserId, Convert.ToInt32(opponentDropDownList.SelectedItem.Value), 2, "0-0,0-0", ref matchId);
                            }
                            else
                            {
                                matchId    = Convert.ToInt32(matchIdHiddenField.Value);
                                opponentId = Convert.ToInt32(opponentIdHiddenField.Value);
                                dataContext.UpdateMatch(matchId.Value, selectedDateTime, Convert.ToInt32(locationDropDownList.Text), Convert.ToInt32(MatchStatus.Completed), "0-0,0-0");
                            }

                            dataContext.InsertMatchPointLog(matchId.Value, StoredData.User.UserId, true, 1, 0, 0, 3, ref matchPointLogId);
                            dataContext.InsertMatchPointLog(matchId.Value, opponentId.Value, false, 0, 0, 0, 0, ref matchPointLogId);

                            dataContext.UpdatePerformance(StoredData.User.UserId, 1, 0, 4, 0);
                            dataContext.UpdatePerformance(opponentId.Value, 0, 1, 0, 0);

                            dataContext.UpdateUserWarningByUserId(opponentId.Value, 2);

                            transactionScope.Complete();
                            success = true;
                        }
                    }
                    if (success)
                    {
                        string closingScript = "<script type='text/javascript'>Sys.Application.add_load(function () {closeRadWindowAndShowAlert('No show successfully recorded.');}); </script> ";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert", closingScript, false);
                    }
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "EnableButton", "changeButtonState('false');", true);
            }
        }
コード例 #2
0
        private void UpdateMatch()
        {
            int?     matchId          = 0;
            int?     apptId           = 0;
            bool     success          = false;
            int      opponentId       = Convert.ToInt32(Request.QueryString["opponentId"]);
            DateTime selectedDateTime = Convert.ToDateTime(RadDatePicker1.SelectedDate.Value.ToShortDateString() + " " + RadTimePicker1.SelectedDate.Value.ToShortTimeString());

            using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext())
            {
                using (TransactionScope transactionScope = new TransactionScope())
                {
                    if (string.IsNullOrEmpty(HiddenField1.Value))
                    {
                        dataContext.InsertMatch(selectedDateTime, StoredData.User.HomeCourt, StoredData.User.UserId, opponentId, 1, string.Empty, ref matchId);
                        dataContext.InsertAppointment(StoredData.User.UserId, matchId, string.Format("vs {0} at {1}", opponentLabel.Text, ViewState["UserCourtName"]), selectedDateTime, selectedDateTime.AddHours(3), string.Empty, null, StoredData.User.UserId.ToString(), ref apptId);
                        dataContext.InsertAppointment(opponentId, matchId, string.Format("vs {0} at {1}", StoredData.User.FirstName + " " + StoredData.User.LastName, ViewState["UserCourtName"]), selectedDateTime, selectedDateTime.AddHours(3), string.Empty, null, StoredData.User.UserId.ToString(), ref apptId);
                    }
                    else
                    {
                        dataContext.InsertMatch(selectedDateTime, Convert.ToInt32(HiddenField1.Value), StoredData.User.UserId, opponentId, 1, string.Empty, ref matchId);
                        dataContext.InsertAppointment(StoredData.User.UserId, matchId, string.Format("vs {0} at {1}", opponentLabel.Text, HiddenField2.Value), selectedDateTime, selectedDateTime.AddHours(3), string.Empty, null, StoredData.User.UserId.ToString(), ref apptId);
                        dataContext.InsertAppointment(opponentId, matchId, string.Format("vs {0} at {1}", StoredData.User.FirstName + " " + StoredData.User.LastName, HiddenField2.Value), selectedDateTime, selectedDateTime.AddHours(3), string.Empty, null, StoredData.User.UserId.ToString(), ref apptId);
                    }



                    transactionScope.Complete();
                    success = true;
                }
                if (success)
                {
                    submitButton.Enabled = false;
                    List <SelectUserPublicProfileResult> opponents = dataContext.SelectUserPublicProfile(opponentId).ToList();
                    StringBuilder message = new StringBuilder();
                    message.Append(string.Format("{0} has requested to play a Tennis match with you.\r\n", StoredData.User.FirstName + " " + StoredData.User.LastName));
                    message.Append(string.Format("Following are the details of the match:\r\n\r\n"));
                    message.Append(string.Format("Players: {0} vs {1}\r\n", StoredData.User.FirstName + " " + StoredData.User.LastName, opponents[0].FirstName + " " + opponents[0].LastName));
                    message.Append(string.Format("Date & Time: {0} @ {1}\r\n", selectedDateTime.ToShortDateString(), selectedDateTime.ToShortTimeString()));
                    if (string.IsNullOrEmpty(HiddenField1.Value))
                    {
                        message.Append(string.Format("Location: {0}\r\n", locationDropDownList.SelectedItem.Text));
                    }
                    else
                    {
                        message.Append(string.Format("Location: {0}\r\n", HiddenField2.Value.ToString()));
                    }
                    message.Append(string.Format("Your opponent's Phone Number: {0}\r\n", StoredData.User.Phone));
                    message.Append(string.Format("Your opponent's Email Id: {0}\r\n\r\n", StoredData.User.EmailId));
                    message.Append("Please reply to your opponent and let them know, if you can or cannot play this match.\r\n\r\n");


                    //if (!SendEmail(opponents[0].EmailId, message, "New Tennis match request"))
                    //{
                    //    StringBuilder stringBuilder = new StringBuilder();
                    //    stringBuilder.Append("radalert('The system was unable to send an email to your opponent about this match request.<br>Please contact you opponent about this match.',250,150,'Match Cancelled!!')");
                    //    ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert", "(function(){var f = function(){" + stringBuilder.ToString() + ";Sys.Application.remove_load(f);};Sys.Application.add_load(f);})()", true);
                    //}
                    SendEmail(opponents[0].EmailId, message, "New Tennis match request");

                    string closingScript = "<script type='text/javascript'>Sys.Application.add_load(function () {closeRadWindowAndShowAlert();}); </script> ";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert", closingScript, false);
                }
            }
        }
コード例 #3
0
        protected void submitButton_Click(object sender, EventArgs e)
        {
            if (validate() && !Convert.ToBoolean(ViewState["Submitted"]))
            {
                if (!noShowCheckBox.Checked)
                {
                    ViewState["Submitted"] = true;
                    int  userTravelPoints     = 0;
                    int  opponentTravelPoints = 0;
                    int  userScorePoints      = 0;
                    int  opponentScorePoints  = 0;
                    int  userWinPoints        = 0;
                    int  opponentWinPoints    = 0;
                    bool userWin            = false;
                    bool opponentWin        = false;
                    int  userWinNumber      = 0;
                    int  userLossNumber     = 0;
                    int  opponentWinNumber  = 0;
                    int  opponentLossNumber = 0;

                    //ScorePoints
                    if (Convert.ToInt32(playerSet3DropDownListSet.SelectedValue) > 0 || Convert.ToInt32(opponentSet3DropDownList.SelectedValue) > 0)
                    {
                        if (Convert.ToInt32(winnerDropDownList.SelectedValue) == StoredData.User.UserId)
                        {
                            userWinPoints      = 3;
                            userWin            = true;
                            userWinNumber      = 1;
                            opponentLossNumber = 1;
                        }
                        else
                        {
                            opponentWinPoints = 3;
                            opponentWin       = true;
                            opponentWinNumber = 1;
                            userLossNumber    = 1;
                        }
                    }
                    else
                    {
                        if (Convert.ToInt32(winnerDropDownList.SelectedValue) == StoredData.User.UserId)
                        {
                            userWinPoints      = 3;
                            userScorePoints    = 1;
                            userWin            = true;
                            userWinNumber      = 1;
                            opponentLossNumber = 1;
                        }
                        else
                        {
                            opponentWinPoints   = 3;
                            opponentScorePoints = 1;
                            opponentWin         = true;
                            opponentWinNumber   = 1;
                            userLossNumber      = 1;
                        }
                    }
                    //Convert match score to string
                    StringBuilder scoreString = new StringBuilder();
                    scoreString.Append(string.Format("{0}-{1},{2}-{3}", playerSet1DropDownListSet.SelectedValue, opponentSet1DropDownList.SelectedValue, playerSet2DropDownListSet.SelectedValue, opponentSet2DropDownList.SelectedValue));
                    if (Convert.ToInt32(playerSet3DropDownListSet.SelectedValue) > 0 || Convert.ToInt32(opponentSet3DropDownList.SelectedValue) > 0)
                    {
                        scoreString.Append(string.Format(",{0}-{1}", playerSet3DropDownListSet.SelectedValue, opponentSet3DropDownList.SelectedValue, playerSet2DropDownListSet.SelectedValue, opponentSet2DropDownList.SelectedValue));
                    }

                    DateTime selectedDateTime = Convert.ToDateTime(RadDatePicker1.SelectedDate.Value.ToShortDateString() + " " + RadTimePicker1.SelectedDate.Value.ToShortTimeString());
                    bool     success          = false;
                    using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext())
                    {
                        List <SelectUserPublicProfileResult> selectUserPublicProfileResult = dataContext.SelectUserPublicProfile(Convert.ToInt32(opponentIdHiddenField.Value)).ToList();

                        //TravelPoints
                        int selectedCourtId = Convert.ToInt32(locationDropDownList.SelectedItem.Value);
                        if (selectedCourtId != StoredData.User.HomeCourt)
                        {
                            userTravelPoints = 1;
                        }
                        if (selectedCourtId != selectUserPublicProfileResult[0].HomeCourt)
                        {
                            opponentTravelPoints = 1;
                        }


                        //Check travel points
                        int?oppponentTotalTravelPoints = 0;
                        List <SelectTotalTravelPointsByUserIdResult> pastTravelPoints = dataContext.SelectTotalTravelPointsByUserId(StoredData.User.UserId, Convert.ToInt32(opponentIdHiddenField.Value), StoredData.User.Division, ref oppponentTotalTravelPoints).ToList();

                        if (pastTravelPoints.Count > 0)
                        {
                            if (pastTravelPoints[0].TotalTravelPoints == 4)
                            {
                                userTravelPoints = 0;
                            }
                        }
                        if (oppponentTotalTravelPoints.Value == 4)
                        {
                            opponentTravelPoints = 0;
                        }



                        int?matchPointLogId = 0;
                        int?matchId         = null;
                        int?opponentId      = null;
                        using (TransactionScope transactionScope = new TransactionScope())
                        {
                            if (string.IsNullOrEmpty(matchIdHiddenField.Value))
                            {
                                opponentId = Convert.ToInt32(opponentDropDownList.SelectedItem.Value);
                                dataContext.InsertMatch(selectedDateTime, selectedCourtId, StoredData.User.UserId, Convert.ToInt32(opponentDropDownList.SelectedItem.Value), 2, scoreString.ToString(), ref matchId);
                            }
                            else
                            {
                                matchId    = Convert.ToInt32(matchIdHiddenField.Value);
                                opponentId = Convert.ToInt32(opponentIdHiddenField.Value);
                                dataContext.UpdateMatch(matchId.Value, selectedDateTime, selectedCourtId, Convert.ToInt32(MatchStatus.Completed), scoreString.ToString());
                            }

                            dataContext.InsertMatchPointLog(matchId.Value, StoredData.User.UserId, userWin, 1, userTravelPoints, userScorePoints, userWinPoints, ref matchPointLogId);
                            dataContext.InsertMatchPointLog(matchId.Value, opponentId.Value, opponentWin, 1, opponentTravelPoints, opponentScorePoints, opponentWinPoints, ref matchPointLogId);

                            dataContext.UpdatePerformance(StoredData.User.UserId, userWinNumber, userLossNumber, userScorePoints + userTravelPoints + userWinPoints + 1, userTravelPoints);
                            dataContext.UpdatePerformance(opponentId.Value, opponentWinNumber, opponentLossNumber, opponentScorePoints + opponentTravelPoints + opponentWinPoints + 1, opponentTravelPoints);

                            transactionScope.Complete();
                            success = true;
                        }

                        if (selectUserPublicProfileResult.Count > 0)
                        {
                            if (userWin)
                            {
                                SendEmail(selectUserPublicProfileResult[0].EmailId, StoredData.User.FirstName + " " + StoredData.User.LastName, scoreString.ToString());
                            }
                            else
                            {
                                SendEmail(selectUserPublicProfileResult[0].EmailId, opponentDropDownList.SelectedItem.Text, scoreString.ToString());
                            }
                        }
                    }
                    if (success)
                    {
                        string closingScript = "closeRadWindowAndShowAlert('Score successfully submited.')";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert", "(function(){var f = function(){" + closingScript + ";Sys.Application.remove_load(f);};Sys.Application.add_load(f);})()", true);
                    }
                }
                else
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.Append("radconfirm('We are sorry to hear that your opponent did not show up.<br/> We take such incidents very seriously.<br/> Your opponent will receive two penalty points.<br/>Do you want to continue?");

                    stringBuilder.Append("',confirmCallBackFn,400,null,null,'No Show!!')");
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "radconfirm", "(function(){var f = function(){" + stringBuilder.ToString() + ";Sys.Application.remove_load(f);};Sys.Application.add_load(f);})()", true);
                }
            }
        }