private void FillTeamName()
        {
            clsTeamPlayer           ccm  = new clsTeamPlayer();
            clsTeamPlayerController ccmc = new clsTeamPlayerController();

            DataTable dt = new DataTable();

            dt = ccmc.GetTeamNameByTeamID(TeamID);

            if (dt.Rows.Count > 0)
            {
                lbl_Team_Player.Text = dt.Rows[0]["TeamName"].ToString();
            }
        }
        private void FillAllPlayer()
        {
            clsTeamPlayer           ccm  = new clsTeamPlayer();
            clsTeamPlayerController ccmc = new clsTeamPlayerController();
            DataTable dt = new DataTable();

            dt = ccmc.GetAllPlayerList();
            if (dt.Rows.Count > 0)
            {
                ddlSelectPlayer.DataSource     = dt;
                ddlSelectPlayer.DataTextField  = "PlayerName";
                ddlSelectPlayer.DataValueField = "RegistrationId";
                ddlSelectPlayer.DataBind();
                ddlSelectPlayer.Items.Insert(0, new ListItem("-- Select --", "0"));
            }
        }
        public void FillPlayerType()
        {
            clsTeamPlayer           ccm  = new clsTeamPlayer();
            clsTeamPlayerController ccmc = new clsTeamPlayerController();
            DataTable dt = new DataTable();

            dt = ccmc.GetTeamPlayerType();
            if (dt.Rows.Count > 0)
            {
                ddlPlayerType.DataSource     = dt;
                ddlPlayerType.DataTextField  = "PlayerTypeName";
                ddlPlayerType.DataValueField = "PlayerTypeID";
                ddlPlayerType.DataBind();
                ddlPlayerType.Items.Insert(0, new ListItem("-- Select --", "0"));
            }
        }
        protected void btnSaveTeamPlayer_Click(object sender, EventArgs e)
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "SaveSuccessfully();", true);

            clsTeamPlayer           ccm  = new clsTeamPlayer();
            clsTeamPlayerController ccmc = new clsTeamPlayerController();

            ccm.TeamId         = TeamID;
            ccm.RegistrationId = Convert.ToInt32(ddlSelectPlayer.SelectedValue);

            if (txtPlayerJerseyNo.Text == " ")
            {
                ccm.PlayerJerseyNo = 0;
            }
            else
            {
                ccm.PlayerJerseyNo = Convert.ToInt32(txtPlayerJerseyNo.Text);
            }

            ccm.PlayerJerseyName = txtPlayerJerseyName.Text.Trim();
            ccm.PlayerFamousName = txtPlayerFamousname.Text.Trim();
            ccm.PlayerTypeId     = Convert.ToInt32(ddlPlayerType.SelectedValue);
            ccm.PortalID         = PortalId;
            ccm.CreatedById      = currentUser.Username;
            ccm.ModifiedById     = currentUser.Username;
            ccm.PlayerPhoto      = imhpathDB + UserLogoFile.PostedFile.FileName.Replace(" ", "");

            SaveImage();

            // Call Save Method
            ccmc.InsertTeamPlayer(ccm);
            clsRegistration objclsRegistration = new clsRegistration();

            objclsRegistration.TeamId         = TeamID;
            objclsRegistration.RegistrationId = Convert.ToInt32(ddlSelectPlayer.SelectedValue);
            objclsRegistration.PlayerTypeId   = Convert.ToInt32(ddlPlayerType.SelectedValue);
            objclsRegistration.PortalID       = PortalId;
            int i = new clsRegistrationController().InsertTeamPlayer(objclsRegistration);

            btnAddTeamPlayer.Visible  = true;
            pnlGridTeamPlayer.Visible = true;
            FillTeamName();
            LoadDocumentsGrid(TeamID);
            ClearData();
            //Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "", "mctl=" + "frmClubMember", "ClubID=" + ClubID));
        }
        private void TransferPlayer()
        {
            Boolean FileOK    = false;
            Boolean FileSaved = false;

            Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "transferSuccessfully();", true);

            // Player ID Store
            int masterplayerid;

            int.TryParse(currentId, out masterplayerid);

            // Player Transfer Team Master ID
            int selectedteamid = 0;

            int.TryParse(ddlSelectTeam.SelectedValue, out selectedteamid);

            clsTeamPlayer           ctmpc  = new clsTeamPlayer();
            clsTeamPlayerController ctmpcc = new clsTeamPlayerController();
            DataTable dt  = new DataTable();
            DataTable dt2 = new DataTable();

            //Player Transfer Data Store In Table
            // Get Player Details

            dt2 = ctmpcc.GetPlayerDetailsBySelectedPlayerID(masterplayerid);

            if (dt2.Rows.Count > 0)
            {
                ctmpc.PlayerID       = Convert.ToInt32(dt2.Rows[0]["RegistrationID"].ToString());
                ctmpc.TOutID         = Convert.ToInt32(dt2.Rows[0]["TeamID"].ToString());
                ctmpc.TOutName       = dt2.Rows[0]["TeamName"].ToString();
                ctmpc.TInID          = selectedteamid;
                ctmpc.TInName        = ddlSelectTeam.SelectedItem.ToString();
                ctmpc.PortalID       = PortalId;
                ctmpc.CreatedById    = currentUser.Username;
                ctmpc.ModifiedById   = currentUser.Username;
                ctmpc.PlayerPosition = dt2.Rows[0]["PlayerPostition"].ToString();
            }

            ctmpcc.InsertTeamPlayerTransfer(ctmpc);

            ctmpcc.DeleteTransferPlayerToMatchPlayerPerformance(masterplayerid);

            dt = ctmpcc.GetMasterPlayerIDByUserID(masterplayerid);

            clsTeamPlayerController ctpcc = new clsTeamPlayerController();
            clsTeamPlayer           ctpc  = new clsTeamPlayer();

            dt = new clsTeamPlayerController().EditTeamMasterPlayerCoach(Convert.ToInt32(dt.Rows[0]["RegistrationID"].ToString()));

            ctmpc.TeamId   = selectedteamid;
            ctmpc.PlayerID = masterplayerid;

            ctmpc.PlayerPosition = ddlPlayerType.SelectedValue;
            //ViewState["Store_PlayerPosition"] = ddlPosition.SelectedItem.ToString();

            ctmpc.PortalID         = PortalId;
            ctmpc.CreatedById      = currentUser.Username;
            ctmpc.ModifiedById     = currentUser.Username;
            ctmpc.PlayerJerseyName = txtPlayerJerseyName.Text;
            ctmpc.PlayerJerseyNo   = Convert.ToInt32(txtPlayerJerseyNo.Text);
            ctmpc.RegistrationId   = Convert.ToInt32(dt.Rows[0]["RegistrationId"].ToString());
            ctmpc.PlayerTypeId     = Convert.ToInt32(ddlPlayerType.SelectedValue);
            if (UserLogoFile.PostedFile.FileName == "")
            {
                clsRegistration           objclsRegistration        = new clsRegistration();
                clsRegistrationController objRegistrationController = new clsRegistrationController();
                DataTable dtplayer = new DataTable();

                objclsRegistration.UserId = masterplayerid;
                dtplayer          = objRegistrationController.GetPhotoByPlayerID(masterplayerid);
                ctmpc.PlayerPhoto = dtplayer.Rows[0]["PlayerPhoto"].ToString();
                string ufname = dtplayer.Rows[0]["PlayerPhoto"].ToString().Replace(" ", "");
                //User_Reg.User_UploadPhoto = ufname;
                //FileOKForUpdate = true;
            }
            else
            {
                ctmpc.PlayerPhoto = ImageUploadFolder + UserLogoFile.PostedFile.FileName.Replace(" ", "");
                if (UserLogoFile.PostedFile != null)
                {
                    String   FileExtension     = Path.GetExtension(UserLogoFile.PostedFile.FileName.Replace(" ", "")).ToLower();
                    String[] allowedExtensions = { ".png", ".jpg", ".gif", ".jpeg" };
                    for (int i = 0; i < allowedExtensions.Length; i++)
                    {
                        if (FileExtension == allowedExtensions[i])
                        {
                            FileOK = true;
                            break;
                        }
                    }
                }

                if (!string.IsNullOrEmpty(UserLogoFile.PostedFile.FileName))
                {
                    if (!FileOK)
                    {
                        return;
                    }
                }

                if (FileOK)
                {
                    if (UserLogoFile.PostedFile.ContentLength > 10485760)
                    {
                        return;
                    }
                    else
                    {
                    }

                    try
                    {
                        UserLogoFile.PostedFile.SaveAs(physicalpath + ImageUploadFolder + UserLogoFile.PostedFile.FileName.Replace(" ", ""));
                        FileSaved = true;
                    }
                    catch (Exception ex)
                    {
                        FileSaved = false;
                    }
                }
            }
            int UserId = ctmpcc.InsertTeamPlayer(ctmpc);

            // Delete Master Player
            ctmpcc.DeleteTeamPlayer(Convert.ToInt32(dt.Rows[0]["TeamPlayerID"].ToString()));



            clsMatchResult           matchResult        = new clsMatchResult();
            clsMatchResultController matchResultControl = new clsMatchResultController();
            DataTable dt1 = new DataTable();

            dt1 = ctmpcc.MatchWisePlayerPerformancePlayerEntry(selectedteamid);

            if (dt1.Rows.Count != 0)
            {
                for (int j = 0; j < dt1.Rows.Count; j++)
                {
                    int matchid = 0;
                    int.TryParse(dt1.Rows[j]["MatchID"].ToString(), out matchid);

                    int competitionid = 0;
                    int.TryParse(dt1.Rows[j]["CompetitionID"].ToString(), out competitionid);

                    DataTable dt3 = new DataTable();
                    dt3 = ctmpcc.GetTeamIDByTeamMasterIDandCompetitionID(selectedteamid, competitionid);

                    int TeamIDByMasterIDAndCompetitionID = Convert.ToInt32((dt3.Rows[0]["TeamID"].ToString()));

                    matchResult.CompetitionID = competitionid;
                    matchResult.MatchID       = matchid;
                    matchResult.PlayerID      = masterplayerid;
                    matchResult.PortalID      = PortalId;
                    matchResult.CreatedBy     = currentUser.Username;
                    matchResult.ModifyBy      = currentUser.Username;
                    matchResult.Goal          = 0;
                    matchResult.Assist        = 0;
                    matchResult.IsPlayed      = 1;
                    matchResult.Yellow        = 0;
                    matchResult.Red           = 0;
                    matchResult.TeamID        = TeamIDByMasterIDAndCompetitionID;

                    matchResultControl.InsertMatchResultPlayerPerformance(matchResult);
                }
            }
        }
        protected void ddlAction_SelectedIndexChanged(object sender, EventArgs e)
        {
            string str = ((Label)((DropDownList)sender).Parent.FindControl("lblddlActionPlayerId")).Text;

            string ddlSelectedValue = ((DropDownList)sender).SelectedValue;

            if (ddlSelectedValue == "Edit")
            {
                ClearData();
                divTeam.Visible = false;
                FillAllPlayer();
                ddlSelectPlayer.Enabled = false;
                divTeam.Visible         = false;
                divPlayer.Visible       = true;
                int editid = 0;
                int.TryParse(str, out editid);
                ViewState["currentId"] = Convert.ToInt16(str);

                clsTeamPlayer           ccm  = new clsTeamPlayer();
                clsTeamPlayerController ccmc = new clsTeamPlayerController();

                DataTable dt = new DataTable();
                dt = ccmc.GetTeamNameByTeamID(TeamID);
                if (dt.Rows.Count > 0)
                {
                    lbl_Team_Player.Text = dt.Rows[0]["TeamName"].ToString();
                }

                FillPlayerType();


                DataTable dt1 = new clsTeamPlayerController().GetPlayerDetailByPlayerID(editid);

                if (dt1.Rows.Count > 0)
                {
                    ViewState["currentId"]        = Convert.ToInt32(dt1.Rows[0]["RegistrationId"].ToString());
                    ViewState["regiId"]           = Convert.ToInt32(dt1.Rows[0]["RegistrationId"].ToString());
                    ddlSelectPlayer.SelectedValue = dt1.Rows[0]["RegistrationId"].ToString();
                    txtPlayerJerseyNo.Text        = dt1.Rows[0]["PlayerJerseyNo"].ToString();
                    txtPlayerJerseyName.Text      = dt1.Rows[0]["PlayerJerseyName"].ToString();
                    txtPlayerFamousname.Text      = dt1.Rows[0]["PlayerFamousName"].ToString();
                    ddlPlayerType.SelectedValue   = dt1.Rows[0]["PlayerTypeId"].ToString();

                    UserLogoImage.ImageUrl = dt1.Rows[0]["PlayerPhoto"].ToString();
                    string ufname = dt1.Rows[0]["PlayerPhoto"].ToString().Replace(" ", "");
                    UserLogoFile.ResolveUrl("ufname");
                }

                btnUpdateTeamPlayer.Visible = true;
                btnSaveTeamPlayer.Visible   = false;
                pnlEntryTeamPlayer.Visible  = true;
                pnlGridTeamPlayer.Visible   = false;
            }
            else if (ddlSelectedValue == "Delete")
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "DeleteSuccessfully();", true);

                hidRegID.Value = str;

                clsTeamPlayer           tp  = new clsTeamPlayer();
                clsTeamPlayerController tpc = new clsTeamPlayerController();

                DataTable dt = new DataTable();

                // Delete Player in Match Player Performance
                tpc.DeleteTransferPlayerToMatchPlayerPerformance(Convert.ToInt32(str));

                // Delete Player in Team
                int PlayerID = 0;
                int.TryParse(hidRegID.Value, out PlayerID);
                new clsTeamPlayerController().DeleteTeamPlayer(PlayerID);

                LoadDocumentsGrid(TeamID);
            }
            else if (ddlSelectedValue == "Transfer")
            {
                pnlEntryTeamPlayer.Visible = true;
                pnlGridTeamPlayer.Visible  = false;
                ClearData();
                divTeam.Visible           = true;
                divPlayer.Visible         = false;
                btnTransferPlayer.Visible = true;
                FilTeams();
                int playerId = 0;
                int.TryParse(str, out playerId);
                FillPlayerType();
                ViewState["currentId"] = Convert.ToInt16(str);
            }
        }