示例#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();
        }
        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);
            }
        }