public static int GetNextNumber(this ONLGroupsCompLink grp)
        {
            int lastSecr;
            var climbers = from c in dc.ONLClimberCompLinks
                           where c.comp_id == grp.comp_id &&
                           c.group_id == grp.group_id
                           orderby c.secretary_id
                           select c;
            var compGroups = (from g in dc.ONLGroupsCompLinks
                              where g.comp_id == grp.comp_id
                              orderby g.ONLGroup.oldYear, g.ONLGroup.genderFemale
                              select g).ToArray();
            int curGrPos;

            for (curGrPos = 0; curGrPos < compGroups.Length; curGrPos++)
            {
                if (grp.iid == compGroups[curGrPos].iid)
                {
                    break;
                }
            }

            lastSecr = climbers.Count() < 1 ? 0 : climbers.OrderByDescending(c => c.secretary_id).First().secretary_id;
            if (lastSecr == 0)
            {
                lastSecr = curGrPos * 100 + 1;
            }
            else if (lastSecr % 100 == 99)
            {
                int startSer = lastSecr - (lastSecr % 100);
                int nextSer  = (startSer / 100 == curGrPos) ? compGroups.Length * 100 : startSer + 100;
                for (int i = 0; i < 100; i++)
                {
                    if (!grp.ONLCompetition.CheckNumber(nextSer + 1))
                    {
                        lastSecr = nextSer + 1;
                        break;
                    }
                    else
                    {
                        nextSer += 100;
                    }
                }
            }
            else
            {
                bool refused = true;
                do
                {
                    refused = grp.ONLCompetition.CheckNumber(++lastSecr);
                } while (refused && lastSecr % 100 != 99);
                if (refused)
                {
                    lastSecr = grp.ONLCompetition.GetNextNumberGeneral();
                }
            }
            return(grp.ONLCompetition.CheckNumber(lastSecr) ? grp.ONLCompetition.GetNextNumberGeneral() : lastSecr);
        }
Example #2
0
 public static void InsertClimberLink(List <ClimberLink> clmList, Entities dc, out int errCount, out string errMessage)
 {
     errCount   = 0;
     errMessage = String.Empty;
     mInsertClimber.WaitOne();
     try
     {
         foreach (var clm in clmList)
         {
             try
             {
                 if (clm.NewClimber)
                 {
                     int newClimberIid;
                     if (dc.ONLclimbers.Count() < 1)
                     {
                         newClimberIid = 1;
                     }
                     else
                     {
                         newClimberIid = dc.ONLclimbers.OrderByDescending(c => c.iid).First().iid + 1;
                     }
                     clm.Climber.iid = newClimberIid;
                     dc.ONLclimbers.AddObject(clm.Climber);
                     clm.Link.climber_id = newClimberIid;
                     clm.Link.ONLclimber = clm.Climber;
                 }
                 long newLinkIid;
                 if (dc.ONLClimberCompLinks.Count() < 1)
                 {
                     newLinkIid = 1;
                 }
                 else
                 {
                     newLinkIid = dc.ONLClimberCompLinks.OrderByDescending(l => l.iid).First().iid + 1;
                 }
                 clm.Link.iid          = newLinkIid;
                 clm.Link.secretary_id = GetNextNumber(dc, clm.Link.comp_id, clm.Link.group_id);
                 ONLGroupsCompLink lnkGr = dc.ONLGroupsCompLinks.First(l => l.comp_id == clm.Link.comp_id &&
                                                                       l.group_id == clm.Link.group_id);
                 try { clm.Link.secretary_id = lnkGr.GetNextNumber(); }
                 catch { clm.Link.secretary_id = dc.ONLCompetitions.First(c => c.iid == clm.Link.comp_id).GetNextNumberGeneral(); }
                 dc.ONLClimberCompLinks.AddObject(clm.Link);
                 dc.SaveChanges();
             }
             catch
             {
                 errCount++;
                 if (errMessage != String.Empty)
                 {
                     errMessage += ", ";
                 }
                 errMessage += clm.Link.ONLclimber.surname + " " + clm.Link.ONLclimber.name;
             }
         }
     }
     finally { mInsertClimber.ReleaseMutex(); }
 }
Example #3
0
        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;
            }
        }