private void btnOk_Click(object sender, EventArgs e) { if (_player != null) { try { // 檢查是團體或個人,團體先將其他隊員isLeader設成 false if (_isTeam) { // 當設定隊長 if (chkIsLeader.Checked) { if (_teamP.Count > 0) { foreach (UDT.Players p in _teamP) { p.IsTeamLeader = false; } _teamP.SaveAll(); } } else { // 取消隊長,需要檢查是否有其他人當隊長,如果沒有不能取消 bool hasTeamLeader = false; if (_teamP.Count > 0) { foreach (UDT.Players p in _teamP) { // 自己不算 if (p.UID == _uid) { continue; } hasTeamLeader = p.IsTeamLeader; } } if (hasTeamLeader == false) { FISCA.Presentation.Controls.MsgBox.Show("沒有其他隊員是隊長無法取消。"); return; } } } else { // 個人賽自己一定是隊長 chkIsLeader.Checked = true; } if (iptLotNo.IsEmpty) { _player.LotNo = null; } else { _player.LotNo = iptLotNo.Value; } _player.IsTeamLeader = chkIsLeader.Checked; _player.Save(); } catch (Exception ex) { FISCA.Presentation.Controls.MsgBox.Show("更新參賽人員失敗," + ex.Message); return; } } this.DialogResult = DialogResult.Yes; }