コード例 #1
0
        protected void gvTeam_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            var dataKey = gvTeam.DataKeys[e.RowIndex];
            if (dataKey != null)
            {
                var teamGuid = (Guid)dataKey.Value;

                try
                {
                    Guid leagueGuid;

                    if (!string.IsNullOrEmpty(ddlLeague.SelectedValue))
                        leagueGuid = new Guid(ddlLeague.SelectedValue);
                    else
                        throw new Exception("未选择比赛分类");

                    var rlt = new RelationLeagueTeam { TeamGuid = teamGuid, LeagueGuid = leagueGuid };

                    if (rlt.Any())
                    {
                        if (RelationLeagueTeam.QueryByTeamGuid(teamGuid).Count <= 1)
                        {
                            throw new Exception("该球队仅属于此分类,不能移除");
                        }
                        rlt.Delete();
                    }
                    else
                    {
                        throw new Exception("该球队未在此分类中");
                    }
                }
                catch (Exception ex)
                {
                    ClientScript.RegisterClientScriptBlock(typeof(string), "failed", $"alert('{ex.Message}');", true);
                }
            }

            BindData();
        }
コード例 #2
0
        private void BindData()
        {
            var list = _repo.All<Team>().ToList().FindAll(x =>
            {
                var returnValue = true;
                string tmpString;

                if (ViewState["LeagueGuid"] != null)
                {
                    tmpString = ViewState["LeagueGuid"].ToString();
                    if (!string.IsNullOrEmpty(tmpString))
                        returnValue = new RelationLeagueTeam { TeamGuid = x.ID, LeagueGuid = new Guid(tmpString) }.Any();
                }

                if (ViewState["TeamName"] != null)
                {
                    tmpString = ViewState["TeamName"].ToString();
                    if (!string.IsNullOrEmpty(tmpString))
                        returnValue = returnValue &&
                                      (x.TeamDisplayName.Contains(tmpString) || x.TeamEnglishName.Contains(tmpString));
                }

                return returnValue;
            });

            #region set GridView Selected PageIndex

            if (TeamGuid.HasValue && !TeamGuid.Equals(Guid.Empty))
            {
                var i = list.FindIndex(x => x.ID.Equals(TeamGuid));
                if (i >= 0)
                {
                    gvTeam.PageIndex = i / gvTeam.PageSize;
                    gvTeam.SelectedIndex = i % gvTeam.PageSize;
                }
                else
                {
                    gvTeam.PageIndex = 0;
                    gvTeam.SelectedIndex = -1;
                }
            }
            else
            {
                gvTeam.SelectedIndex = -1;
            }

            #endregion

            gvTeam.DataSource = list;
            gvTeam.DataBind();

            #region set Control Custom Pager

            if (gvTeam.BottomPagerRow != null)
            {
                gvTeam.BottomPagerRow.Visible = true;
                ctrlCustomPagerInfo.Visible = true;

                ctrlCustomPagerInfo.PageIndex = gvTeam.PageIndex;
                ctrlCustomPagerInfo.PageCount = gvTeam.PageCount;
                ctrlCustomPagerInfo.RowCount = list.Count;
                ctrlCustomPagerInfo.InitComponent();
            }
            else
            {
                ctrlCustomPagerInfo.Visible = false;
            }

            #endregion
        }
コード例 #3
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                var t = new Team();

                if (!TeamGuid.Equals(Guid.Empty))
                {
                    t = _repo.Single<Team>(TeamGuid);
                }

                t.TeamEnglishName = tbTeamEnglishName.Text.Trim();
                t.TeamDisplayName = tbTeamDisplayName.Text.Trim();
                t.TeamLogo = tbTeamLogo.Text.Trim();
                t.TeamNickName = tbTeamNickName.Text.Trim();
                t.Founded = tbTeamFounded.Text.Trim();
                t.Ground = tbGround.Text.Trim();
                t.Capacity = int.Parse(tbCapacity.Text.Trim());
                t.Chairman = tbChairMan.Text.Trim();
                t.Manager = tbManager.Text.Trim();

                // Insert Relation Team League
                if (!string.IsNullOrEmpty(ddlTeamLeague.SelectedValue))
                {
                    var leagueGuid = new Guid(ddlTeamLeague.SelectedValue);

                    var rlt = new RelationLeagueTeam { TeamGuid = TeamGuid, LeagueGuid = leagueGuid };

                    if (!rlt.Any())
                    {
                        rlt.Insert();
                    }
                }

                if (TeamGuid != Guid.Empty)
                {
                    _repo.Update(t);
                    ClientScript.RegisterClientScriptBlock(typeof(string), "succeed",
                        "alert('更新成功');window.location.href = window.location.href", true);
                }
                else
                {
                    _repo.Insert(t);
                    ClientScript.RegisterClientScriptBlock(typeof(string), "succeed",
                        "alert('添加成功');window.location.href = 'AdminTeam.aspx'", true);
                }
            }
            catch (Exception ex)
            {
                ClientScript.RegisterClientScriptBlock(typeof(string), "failed", $"alert('{ex.Message}')", true);
            }
        }