Ejemplo 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);
            }
        }
        public void MergeSortingTest2()
        {
            // Arrange
            int[] unsorted = { 1 };

            // Act
            int[] sortedByMergeSort = SortingClass.MergeSorting(unsorted);

            // Assert
            CollectionAssert.AreEqual(new int[] { 1 }, sortedByMergeSort);
        }
        public void MergeSortingTest1()
        {
            // Arrange
            int[] unsorted = { 1, -5, 0, 15, -4, 27 };

            // Act
            int[] sortedByMergeSort = SortingClass.MergeSorting(unsorted);

            // Assert
            CollectionAssert.AreEqual(new int[] { -5, -4, 0, 1, 15, 27 }, sortedByMergeSort);
        }
        public void MergeSortingTest3()
        {
            // Arrange
            int[]  unsorted = new int[100];
            Random random   = new Random();

            for (int i = 0; i < unsorted.Length; ++i)
            {
                unsorted[i] = random.Next(int.MinValue, int.MaxValue);
            }

            // Act
            int[] sortedByMergeSort = SortingClass.MergeSorting(unsorted);

            // Assert
            Assert.IsTrue(IsArraySorted(sortedByMergeSort));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Board()
        {
            List <Sale>    sales = Repository.Sales.ToList();
            List <AppUser> users = new List <AppUser>();

            IdentityRole role = await roleManager.FindByNameAsync("User");

            if (role != null)
            {
                foreach (var user in userManager.Users.ToList())
                {
                    if (user != null &&
                        await userManager.IsInRoleAsync(user, role.Name))
                    {
                        users.Add(user);
                    }
                }

                if (users.Count > 0)
                {
                    SortingClass.SortByMonthToDate(users);

                    ViewBag.Controller       = "Admin";
                    ViewBag.Action           = "BoardSort";
                    ViewBag.CurrentMonthAll  = Repository.CalcMonthYearSales(DateTime.Now.Month, DateTime.Now.Year).ToString("c");
                    ViewBag.LastMonthAll     = Repository.CalcMonthYearSales(DateTime.Now.AddMonths(-1).Month, DateTime.Now.AddMonths(-1).Year).ToString("c");
                    ViewBag.LastYearMonthAll = Repository.CalcMonthLastYearSales().ToString("c");
                    ViewBag.TodaySalesCount  = Repository.CalcTodaySales().ToString("c");

                    return(View(users));
                }
                else
                {
                    return(View(users));
                }
            }
            else
            {
                return(View(users));
            }
        }
 public void MergeSortingTest_AcceptsEmptyArray_ThrowsArgumentException()
 {
     int[] unsorted = new int[0];
     Assert.ThrowsException <ArgumentException>(() => SortingClass.MergeSorting(unsorted));
 }
 public void QuickSortingTest_AcceptsEmptyArray_ThrowsArgumentException()
 {
     int[] unsorted = new int[0];
     Assert.ThrowsException <ArgumentException>(() => SortingClass.QuickSorting(unsorted, 0, unsorted.Length - 1));
 }
 public void QuickSortingTest_AcceptsNullArray_ThrowsNullReferenceException()
 {
     int[] unsorted = null;
     Assert.ThrowsException <NullReferenceException>(() => SortingClass.QuickSorting(unsorted, 0, unsorted.Length - 1));
 }
 public void MergeSortingTest_AcceptsNullArray_ThrowsNullReferenceException()
 {
     int[] unsorted = null;
     Assert.ThrowsException <NullReferenceException>(() => SortingClass.MergeSorting(unsorted));
 }
Ejemplo n.º 10
0
        public async Task <IActionResult> BoardSort(string title)
        {
            List <Sale>    sales = Repository.Sales.ToList();
            List <AppUser> users = new List <AppUser>();

            IdentityRole role = await roleManager.FindByNameAsync("User");

            if (role != null)
            {
                foreach (var user in userManager.Users.ToList())
                {
                    if (user != null &&
                        await userManager.IsInRoleAsync(user, role.Name))
                    {
                        users.Add(user);
                    }
                }

                if (users.Count > 0)
                {
                    if (title == "Today")
                    {
                        ViewBag.SortedBy = title;
                        SortingClass.SortByToday(users);
                    }
                    else if (title == "cWeek")
                    {
                        ViewBag.SortedBy = title;
                        SortingClass.SortByCurrentWeek(users);
                    }
                    else if (title == "lWeek")
                    {
                        ViewBag.SortedBy = title;
                        SortingClass.SortByLastWeek(users);
                    }
                    else if (title == "2Week")
                    {
                        ViewBag.SortedBy = title;
                        SortingClass.SortByLastTwoWeeks(users);
                    }
                    else if (title == "3Week")
                    {
                        ViewBag.SortedBy = title;
                        SortingClass.SortByLastThreeWeeks(users);
                    }
                    else if (title == "4Week")
                    {
                        ViewBag.SortedBy = title;
                        SortingClass.SortByLastFourWeeks(users);
                    }
                    else if (title == "Month")
                    {
                        ViewBag.SortedBy = title;
                        SortingClass.SortByMonthToDate(users);
                    }
                    else if (title == "YTD")
                    {
                        ViewBag.SortedBy = title;
                        SortingClass.SortByYearToDate(users);
                    }
                    else
                    {
                        SortingClass.SortByMonthToDate(users);
                    }

                    ViewBag.Controller       = "Admin";
                    ViewBag.Action           = "BoardSort";
                    ViewBag.CurrentMonthAll  = Repository.CalcMonthYearSales(DateTime.Now.Month, DateTime.Now.Year).ToString("c");
                    ViewBag.LastMonthAll     = Repository.CalcMonthYearSales(DateTime.Now.AddMonths(-1).Month, DateTime.Now.AddMonths(-1).Year).ToString("c");
                    ViewBag.LastYearMonthAll = Repository.CalcMonthLastYearSales().ToString("c");
                    ViewBag.TodaySalesCount  = Repository.CalcTodaySales().ToString("c");

                    return(View("Board", users));
                }
                else
                {
                    return(View("Board", users));
                }
            }
            else
            {
                return(View(users));
            }
        }
Ejemplo n.º 11
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;
                }
            }
        }