Esempio n. 1
0
        private static int GetNextNumber(Entities dc, long compID, int groupID)
        {
            var grpListQuery = from g in dc.ONLGroups
                               where g.ONLGroupsCompLinks.Count(gl => gl.comp_id == compID) > 0
                               orderby g.oldYear, g.genderFemale
            select g;
            List <ONLGroup> gList = new List <ONLGroup>();

            foreach (var g in grpListQuery)
            {
                gList.Add(g);
            }
            int gPos;

            for (gPos = 0; gPos < gList.Count; gPos++)
            {
                if (gList[gPos].iid == groupID)
                {
                    break;
                }
            }
            if (gPos < 0)
            {
                return((int)SortingClass.GetNextIID("ONLClimberCompLink", "secretary_id", staticCn, null));
            }
            var lst = from l in dc.ONLClimberCompLinks
                      where l.comp_id == compID &&
                      l.group_id == groupID
                      orderby l.comp_id descending
                      select l;
            int retVal;

            if (lst.Count() < 1)
            {
                retVal = (1 + (gPos * 100));
            }
            else
            {
                var lstPos = lst.First().secretary_id;
                if (lstPos % 100 == 99)
                {
                    retVal = lstPos - 99 + gList.Count * 100;
                }
                else
                {
                    retVal = lstPos + 1;
                }
            }
            if (dc.ONLClimberCompLinks.Count(ln => ln.comp_id == compID && ln.secretary_id == retVal) > 0)
            {
                return((int)SortingClass.GetNextIID("ONLClimberCompLink", "secretary_id", staticCn, null));
            }
            else
            {
                return(retVal);
            }
        }
Esempio n. 2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                if (String.IsNullOrWhiteSpace(tbName.Text))
                {
                    lblError.Text = "Название команды не введено";
                    return;
                }
                if (cbGroupToSet.SelectedIndex < 0 || cbGroupToSet.SelectedItem == null)
                {
                    lblError.Text = "Группа команд не выбрана";
                    return;
                }
                int?grIdToSet;
                if (cbGroupToSet.SelectedIndex == 0)
                {
                    grIdToSet = null;
                }
                else
                {
                    grIdToSet = new int?(int.Parse(cbGroupToSet.SelectedItem.Value));
                }
                ONLteam tNew;
                if (String.IsNullOrEmpty(lblIid.Text))
                {
                    tNew = ONLteam.CreateONLteam((int)SortingClass.GetNextIID("ONLTeams", "iid", cn, null));
                }
                else
                {
                    tNew = GetTeamByIid(int.Parse(lblIid.Text));
                }
                tNew.name = tbName.Text;

                if (String.IsNullOrEmpty(lblIid.Text))
                {
                    dc.ONLteams.AddObject(tNew);
                }
                tNew.group_id = grIdToSet;
                dc.SaveChanges();
                if (cbUsedNow.Visible)
                {
                    if (cbUsedNow.Checked)
                    {
                        int rankingPos;
                        if (!int.TryParse(tbRanking.Text, out rankingPos))
                        {
                            rankingPos = int.MaxValue;
                        }
                        tNew.AddTeamToCompetition(compID, new int?(rankingPos));
                        try
                        {
                            var uList = tNew.ONLusers.ToArray();
                            for (int i = 0; i < uList.Length; i++)
                            {
                                uList[i].AddUserToCompetition(compID);
                            }
                        }
                        catch { }
                    }
                    else
                    {
                        tNew.RemoveTeamFromCompetition(compID);
                    }
                }

                panelEdit.Visible       = false;
                panelSelect.Enabled     = true;
                panelTeamGroups.Visible = true;
                LoadTeams();
                lblError.Text = "Команда создана/обновлена";
            }
            catch (Exception ex)
            {
                lblError.Text = "Ошибка добавления/обновления команды:\r\n" +
                                ex.Message;
            }
        }
Esempio n. 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;
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                string         sStyles = String.Empty;
                ONLCompetition comp;
                if (String.IsNullOrEmpty(lblCompIid.Text))
                {
                    comp = ONLCompetition.CreateONLCompetition(SortingClass.GetNextIID("ONLCompetitions", "iid", cn, null));
                }
                else
                {
                    comp = GetCompByIid(long.Parse(lblCompIid.Text));
                }
                if (comp == null)
                {
                    lblErrMsg.Text = "Ошибка создания объекта";
                    return;
                }
                if (String.IsNullOrWhiteSpace(tbCompPlace.Text))
                {
                    lblErrMsg.Text = "Место проведения не введено";
                    return;
                }
                if (String.IsNullOrWhiteSpace(tbCompShort.Text))
                {
                    lblErrMsg.Text = "Краткое наименование соревнований не введено";
                    return;
                }
                if (String.IsNullOrWhiteSpace(tbCompTitle.Text))
                {
                    lblErrMsg.Text = "Наименование соревнований не введено";
                    return;
                }
                foreach (ListItem li in cbListStyles.Items)
                {
                    if (li.Selected)
                    {
                        sStyles += li.Value;
                    }
                }
                if (sStyles.Equals(String.Empty))
                {
                    lblErrMsg.Text = "Виды не выбраны";
                    return;
                }
                CultureInfo ci = new CultureInfo("ru-RU");
                string      dateTotal = String.Empty;
                DateTime    from = clndFrom.SelectedDate, to = clndTo.SelectedDate;
                if (from.Equals(to))
                {
                    dateTotal = from.ToString("d MMMM yyyy", ci);
                }
                else if (from.Year.Equals(to.Year))
                {
                    if (from.Month.Equals(to.Month))
                    {
                        dateTotal = from.Day.ToString() + " - " + to.ToString("d MMMM yyyy", ci) + " г.";
                    }
                    else
                    {
                        dateTotal = from.ToString("d MMMM", ci) + " - " +
                                    to.ToString("d MMMM yyyy", ci) + " г.";
                    }
                }
                else
                {
                    dateTotal = from.ToString("d MMMM yyyy", ci) + " г. - " +
                                to.ToString("d MMMM yyyy", ci) + " г.";
                }

                comp.name       = tbCompTitle.Text;
                comp.short_name = tbCompShort.Text;
                comp.place      = tbCompPlace.Text;
                comp.date       = dateTotal;

                long?nextIid = null;
                nextIid = comp.SetDateParam(Constants.PDB_COMP_START_DATE, from, nextIid);
                nextIid = (nextIid <= 0 ? null : new long?(nextIid.Value + 1));

                nextIid = comp.SetDateParam(Constants.PDB_COMP_END_DATE, to, nextIid);
                nextIid = (nextIid <= 0 ? null : new long?(nextIid.Value + 1));

                nextIid = comp.SetDateParam(Constants.PDB_COMP_DEADLINE, clndDeadLine.SelectedDate, nextIid);
                nextIid = (nextIid <= 0 ? null : new long?(nextIid.Value + 1));

                nextIid = comp.SetDateParam(Constants.PDB_COMP_DEADLINE_CHANGE, clndCorrectionDeadLine.SelectedDate, nextIid);
                nextIid = (nextIid <= 0 ? null : new long?(nextIid.Value + 1));

                nextIid = comp.SetStringParam(Constants.PDB_COMP_STYLES, sStyles, nextIid);
                nextIid = (nextIid <= 0 ? null : new long?(nextIid.Value + 1));

                nextIid = comp.SetObjectParam(Constants.PDB_COMP_ALLOW_AFTER_DEADLINE,
                                              cbAllowAfterDeadline.Checked, (o => ((bool)o).ToString()), nextIid);

                if (String.IsNullOrWhiteSpace(lblCompIid.Text))
                {
                    dc.ONLCompetitions.AddObject(comp);
                }
                dc.SaveChanges();
                LoadCompList();
                lblErrMsg.Text     = "Соревнования созданы/обновлены";
                panelComps.Visible = !(panelSelectedComp.Visible = false);
            }
            catch (Exception ex)
            {
                lblErrMsg.Text = "Ошибка обновления соревнований:\r\n" + ex.ToString();
            }
        }
Esempio n. 5
0
        protected void btnConfirm_Click(object sender, EventArgs e)
        {
            List <ClimberLink> uList = new List <ClimberLink>();
            ONLClimberCompLink c;
            ONLclimber         outClimber;
            bool newClm;

            try
            {
                if (!ClimberControl1.IsEmpty())
                {
                    c = ClimberControl1.createClimber(cbTeam.SelectedValue, out newClm, out outClimber);
                    if (c != null)
                    {
                        uList.Add(new ClimberLink(c, outClimber, newClm));
                    }
                }
                if (!ClimberControl2.IsEmpty())
                {
                    c = ClimberControl2.createClimber(cbTeam.SelectedValue, out newClm, out outClimber);
                    if (c != null)
                    {
                        uList.Add(new ClimberLink(c, outClimber, newClm));
                    }
                }
                if (!ClimberControl3.IsEmpty())
                {
                    c = ClimberControl3.createClimber(cbTeam.SelectedValue, out newClm, out outClimber);
                    if (c != null)
                    {
                        uList.Add(new ClimberLink(c, outClimber, newClm));
                    }
                }
                if (!ClimberControl4.IsEmpty())
                {
                    c = ClimberControl4.createClimber(cbTeam.SelectedValue, out newClm, out outClimber);
                    if (c != null)
                    {
                        uList.Add(new ClimberLink(c, outClimber, newClm));
                    }
                }

                if (User.IsInRole(Constants.ROLE_ADMIN, compID))
                {
                    foreach (var v in uList)
                    {
                        v.Link.state = Constants.CLIMBER_CONFIRMED;
                    }
                }
                else
                {
                    ONLoperation currentOp;
                    try { currentOp = dc.ONLoperations.First(op => op.user_id == User.Identity.Name && op.comp_id == compID && op.state == Constants.OP_STATE_NEW); }
                    catch
                    {
                        currentOp = ONLoperation.CreateONLoperation(
                            SortingClass.GetNextIID("ONLOperations", "iid", cn, null),
                            compID, User.Identity.Name, DateTime.UtcNow, Constants.OP_STATE_NEW);
                        dc.ONLoperations.AddObject(currentOp);
                        dc.SaveChanges();
                    }
                    foreach (var v in uList)
                    {
                        v.Link.updOpIid     = currentOp.iid;
                        v.Link.ONLoperation = currentOp;
                    }
                }
                foreach (var v in uList)
                {
                    try
                    {
                        if (v.Link.EntityState != System.Data.EntityState.Detached)
                        {
                            dc.ONLClimberCompLinks.Detach(v.Link);
                        }
                    }
                    catch { }
                    try
                    {
                        if (v.NewClimber && v.Climber.EntityState != System.Data.EntityState.Detached)
                        {
                            dc.ONLclimbers.Detach(v.Climber);
                        }
                    }
                    catch { }
                }
                int    nErr;
                string erMsg;
                InsertClimberLink(uList, dc, out nErr, out erMsg);

                lblMessageTop.Text = "Заявка на " + (uList.Count - nErr) + " человек принята.";
                if (nErr > 0)
                {
                    lblMessageTop.Text += "<br />Произошли ошибки при добавлении следующих участников:<br />" + erMsg;
                }

                if (User.IsInRole(Constants.ROLE_ADMIN, compID))
                {
                    panelConfirm.Visible = false;
                    ReloadData();
                    ClearForm();
                    panelClimbers.Enabled = true;
                    panelConfirm.Visible  = false;
                }
                else
                {
                    lblMessageTop.Text += "<br />Для окончательного подтверждения заявки, после ввода всех участников, нажмите на кнопку \"" +
                                          "Подтвердить все завки через e-mail\". Старший тренер Вашего региона подтвердит все введённые заявки.";
                    panelConfirm.Visible = false;
                    ReloadData();
                    uncClm.btnAddAppEnabled = true;
                    uncClm.LblMessageText   = "";
                }
            }
            catch (Exception ex)
            {
                lblConfMessage.Text = "Ошибка добавления участников";
                if (User.IsInRole(Constants.ROLE_ADMIN, compID))
                {
                    lblConfMessage.Text += ": " + ex.Message;
                }
            }
        }