private bool SetGroup(ONLGroup t) { if (t == null) { return(false); } panelEdit.Visible = true; SetCompVisible(); lblIid.Text = t.iid.ToString(); tbName.Text = t.name; tbOld.Text = t.oldYear.ToString(); tbYoung.Text = t.youngYear.ToString(); if (t.genderFemale) { cbGender.SelectedValue = "F"; } else { cbGender.SelectedValue = "M"; } if (cbUsedNow.Visible) { cbUsedNow.Checked = (t.ONLGroupsCompLinks.Count(lnk => lnk.comp_id == compID) > 0); if (cbUsedNow.Checked) { var lnk = t.ONLGroupsCompLinks.First(ln => ln.comp_id == compID); qfList.SelectedValue = lnk.minQf.ToString(); } else if (qfList.Items.Count > 0) { qfList.SelectedIndex = qfList.Items.Count - 1; } } lblError.Text = String.Empty; return(true); }
protected void btnSubmit_Click(object sender, EventArgs e) { try { if (String.IsNullOrWhiteSpace(tbName.Text)) { lblError.Text = "Название группы не введено"; return; } int oldYear, youngYear; if (String.IsNullOrWhiteSpace(tbOld.Text)) { oldYear = 99; tbOld.Text = "99"; } else if (!int.TryParse(tbOld.Text, out oldYear)) { lblError.Text = "Максимальный возраст введён неправильно"; return; } if (String.IsNullOrWhiteSpace(tbYoung.Text)) { youngYear = 0; tbYoung.Text = "0"; } else if (!int.TryParse(tbYoung.Text, out youngYear)) { lblError.Text = "Минимальный возраст введён неправильно"; return; } bool genderFemale = cbGender.SelectedValue == "F"; if (oldYear < youngYear) { lblError.Text = "Максимальный возраст меньше минимального"; return; } ONLGroup gNew; if (String.IsNullOrEmpty(lblIid.Text)) { gNew = ONLGroup.CreateONLGroup((int)SortingClass.GetNextIID("ONLGroups", "iid", cn, null), oldYear, youngYear, true); } else { gNew = GetGroupByIid(int.Parse(lblIid.Text)); } gNew.name = tbName.Text; gNew.oldYear = oldYear; gNew.youngYear = youngYear; gNew.genderFemale = genderFemale; if (cbUsedNow.Visible) { int qf = int.Parse(qfList.SelectedValue); if (cbUsedNow.Checked) { if (gNew.ONLGroupsCompLinks.Count(tlnk => tlnk.comp_id == compID) < 1) { ONLGroupsCompLink lnkNew = ONLGroupsCompLink.CreateONLGroupsCompLink( SortingClass.GetNextIID("ONLGroupsCompLink", "iid", cn, null), gNew.iid, compID, qf); gNew.ONLGroupsCompLinks.Add(lnkNew); } else { gNew.ONLGroupsCompLinks.First(tlk => tlk.comp_id == compID).minQf = qf; } } else { try { var lToDel = gNew.ONLGroupsCompLinks.First(tl => tl.comp_id == compID); dc.ONLGroupsCompLinks.DeleteObject(lToDel); } catch { } } } if (String.IsNullOrEmpty(lblIid.Text)) { dc.ONLGroups.AddObject(gNew); } dc.SaveChanges(); panelEdit.Visible = false; panelSelect.Enabled = true; LoadGroups(); lblError.Text = "Группа создана/обновлена"; } catch (Exception ex) { lblError.Text = "Ошибка добавления/обновления группы:\r\n" + ex.Message; } }
public ONLClimberCompLink createClimber(string teamId, out bool newClimber, out ONLclimber createdClm) { createdClm = null; newClimber = false; string errMessage = ""; try { int age; if (!int.TryParse(tbAge1.Text, out age)) { errMessage = "Год введён неправильно."; return(null); } if (age < 0) { errMessage = "Год введён неправильно."; return(null); } if (age <= 20) { age += 2000; } if (age <= 99) { age += 1900; } if (age > DateTime.Now.Year) { errMessage = "Год введён неправильно."; return(null); } string surname, name, srcName; srcName = tbName1.Text.Trim(); while (srcName.IndexOf(" ") > -1) { srcName = srcName.Replace(" ", " "); } srcName = srcName.Replace('ё', 'е'); tbName1.Text = srcName; if (String.IsNullOrEmpty(srcName)) { errMessage = "Фамилия не введена"; return(null); } int n = srcName.IndexOf(' '); if (n < 0) { surname = srcName; name = String.Empty; } else { surname = srcName.Substring(0, n); try { name = srcName.Substring(n + 1); } catch { name = String.Empty; } } bool genderFemale = (cbGender1.SelectedValue == "1"); var bp = Page as BasePage; long?grpID; if (bp != null) { grpID = bp.CurrentCompetition.GetClimbersGroup(age, genderFemale); } else { grpID = dc.ONLCompetitions.Where(c => c.iid == compID).First().GetClimbersGroup(age, genderFemale); } if (grpID == null || !grpID.HasValue) { errMessage = "Участник не входит ни в одну возрастную группу"; return(null); } ONLGroup gr = dc.ONLGroupsCompLinks.Where(grl => grl.iid == grpID.Value).First().ONLGroup; lblGroup.Text = gr.name; string t_id = (String.IsNullOrEmpty(hfTeamID.Value) ? teamId : hfTeamID.Value); int teamIDToSet; if (!int.TryParse(t_id, out teamIDToSet)) { teamIDToSet = -1; } ONLteam teamToSet; try { teamToSet = dc.ONLteams.First(t => t.iid == teamIDToSet); } catch { teamToSet = null; } if (teamToSet == null) { errMessage = "Команда выбрана не верно"; return(null); } try { createdClm = dc.ONLclimbers.First(c => c.surname == surname && c.name == name && c.age == age); createdClm.surname = surname; createdClm.name = name; dc.SaveChanges(); } catch { createdClm = ONLclimber.CreateONLclimber(0, genderFemale, new DateTime(age, 1, 5), false, false); createdClm.name = name; createdClm.surname = surname; newClimber = true; } if (cbSelectLead.SelectedIndex < 0) { cbSelectLead.SelectedIndex = 0; } if (cbSelectSpeed.SelectedIndex < 0) { cbSelectSpeed.SelectedIndex = 0; } if (cbSelectBoulder.SelectedIndex < 0) { cbSelectBoulder.SelectedIndex = 0; } string sQf = cbQf1.SelectedValue == null ? String.Empty : cbQf1.SelectedValue; ONLClimberCompLink lnk = ONLClimberCompLink.CreateONLClimberCompLink( iid: 0, climber_id: createdClm.iid, comp_id: compID, secretary_id: 0, group_id: gr.iid, team_id: teamIDToSet, qf: sQf, lead: (short)(Lead ? cbSelectLead.SelectedIndex : 0), speed: (short)(Speed ? cbSelectSpeed.SelectedIndex : 0), // (Speed && cbl1.Items[1].Selected), boulder: (short)(Boulder ? cbSelectBoulder.SelectedIndex : 0), // (Boulder && cbl1.Items[2].Selected), vk: false, nopoints: false, appl_type: String.Empty, is_changeble: true, queue_pos: 0, sys_date_create: DateTime.UtcNow, sys_date_update: DateTime.UtcNow, state: Constants.CLIMBER_PENDING_UPDATE, queue_Lead: 0, queue_Speed: 0, queue_Boulder: 0); lnk.ONLclimber = createdClm; try { if (lnk.EntityState != EntityState.Detached) { dc.ONLClimberCompLinks.Detach(lnk); } } catch { } try { if (newClimber && lnk.ONLclimber.EntityState != EntityState.Detached) { dc.ONLclimbers.Detach(lnk.ONLclimber); } } catch { } //if (!String.IsNullOrEmpty(hfIid.Value)) //{ // int nIid; // if (int.TryParse(hfIid.Value, out nIid)) // lnk.iid = nIid; //} if (lnk.lead == 0 && lnk.speed == 0 && lnk.boulder == 0) { errMessage = "Не выбраны виды для участия."; return(null); } return(lnk); } catch (Exception ex) { errMessage = "Ошибка создания объекта"; if (Page.User.IsInRole(Constants.ROLE_ADMIN, compID)) { errMessage += ": " + ex.Message; } return(null); } finally { lblMessage1.Text = errMessage; } }