Exemple #1
0
 public void SetClimber(ONLClimberCompLink lnk)
 {
     try
     {
         if (lnk == null)
         {
             lblMessage1.Text = "Участник не найден";
             return;
         }
         ONLclimber clm = lnk.ONLclimber;
         hfIid.Value                   = lnk.iid.ToString();
         hfTeamID.Value                = lnk.team_id.ToString();
         tbName1.Text                  = clm.surname + " " + clm.name;
         tbAge1.Text                   = clm.age.ToString();
         cbGender1.SelectedValue       = (clm.genderFemale ? "1" : "0");
         cbQf1.SelectedValue           = lnk.qf;
         cbSelectLead.SelectedIndex    = lnk.lead;
         cbSelectSpeed.SelectedIndex   = lnk.speed;
         cbSelectBoulder.SelectedIndex = lnk.boulder;
         //cbl1.Items[0].Selected = Lead && lnk.lead;
         //cbl1.Items[1].Selected = Speed && lnk.speed;
         //cbl1.Items[2].Selected = Boulder && lnk.boulder;
         lblGroup.Text = lnk.ONLGroup.name;
         SetEnabled();
     }
     catch (Exception ex)
     {
         lblMessage1.Text = "Ошибка установки участника";
         if (Page.User.IsInRole("ADM"))
         {
             lblMessage1.Text += ": " + ex.Message;
         }
     }
 }
 public ClimberData(ONLclimber clm)
 {
     this.Name   = clm.surname + " " + clm.name;
     this.Age    = ((clm.age == null || !clm.age.HasValue) ? clm.birthdate.Year : clm.age.Value).ToString();
     this.Gender = clm.genderFemale ? 1 : 0;
     try
     {
         var lastCompLink = clm.ONLClimberCompLinks.OrderByDescending(l => l.iid).First();
         this.Qf = lastCompLink.qf;
     }
     catch { this.Qf = String.Empty; }
     this.teamIDs = (from cl in clm.ONLClimberCompLinks
                     select cl.team_id).Distinct().ToArray();
     this.comps = (from cl in clm.ONLClimberCompLinks
                   select cl.comp_id).Distinct().ToArray();
 }
Exemple #3
0
        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; }
        }
Exemple #4
0
 public ClimberLink(ONLClimberCompLink lnk, ONLclimber clm, bool newClm)
 {
     this.Link       = lnk;
     this.Climber    = clm;
     this.NewClimber = newClm;
 }