Exemplo n.º 1
0
        public void TestAddCourseAndAssignMonitor()
        {
            Pool pool = service.FindPoolByZipCode(46122);

            service.AddCourse(pool, "TestCourse 1", new DateTime(2018, 1, 8), new DateTime(2018, 6, 25),
                              createTime(18, 0, 0), new TimeSpan(0, 45, 0), Days.Tuesday | Days.Thursday, 10, 20,
                              110, new List <int> {
                5, 6
            });

            // check course has been added to pool and is stored (can be found by Id)
            Course course = service.FindCourseByName("TestCourse 1");

            Assert.IsNotNull(course);
            Assert.IsTrue(pool.Courses.Contains(course));

            // check course details
            Assert.AreEqual(new DateTime(2018, 1, 8), course.StartDate);
            Assert.AreEqual(new DateTime(2018, 6, 25), course.FinishDate);
            Assert.AreEqual(createTime(18, 0, 0).TimeOfDay, course.StartHour.TimeOfDay);
            Assert.AreEqual(new TimeSpan(0, 45, 0), course.Duration);
            Assert.AreEqual(course.CourseDays & Days.Tuesday, Days.Tuesday);
            Assert.AreEqual(course.CourseDays & Days.Thursday, Days.Thursday);
            Assert.AreEqual(110, course.Price);
            Assert.IsNull(course.Monitor);

            // check lanes <--> course relationships
            Assert.AreEqual(2, course.Lanes.Count);
            Lane lane5 = pool.FindLaneByNumber(5);
            Lane lane6 = pool.FindLaneByNumber(6);

            Assert.IsTrue(course.Lanes.Contains(lane5));
            Assert.IsTrue(course.Lanes.Contains(lane6));
            Assert.IsTrue(lane5.Courses.Contains(course));
            Assert.IsTrue(lane6.Courses.Contains(course));

            // check monitor assignment
            Monitor monitor = service.GetAvailableMonitors(course).First();

            service.SetCourseMonitor(course, monitor);
            Assert.AreEqual(monitor, course.Monitor);
            Assert.IsTrue(monitor.Courses.Contains(course));
            service.AddCourse(pool, "TestCourse 2", new DateTime(2018, 2, 8), new DateTime(2018, 6, 25),
                              createTime(18, 30, 0), new TimeSpan(0, 45, 0), Days.Tuesday | Days.Friday, 10, 20,
                              110, new List <int> {
                8, 10
            });
            Course course2 = service.FindCourseByName("TestCourse 2");

            Assert.IsFalse(monitor.IsAvailableFor(course2));
            // He modificat les lanes del segon perque concidixen en les del primer i no es correcte el test
        }
Exemplo n.º 2
0
        private void bAcceptar_Click(object sender, EventArgs e)
        {
            string            message;
            string            caption = "Ha habido un error";
            MessageBoxButtons buttons;
            DialogResult      result;
            double            price;
            int minimAl, maxAl;

            if (dateini.Value > datefi.Value)
            {
                message = "La fecha de inicio no puede ser posterior a la fin";
                buttons = MessageBoxButtons.OK;
                result  = MessageBox.Show(message, caption, buttons);
            }
            else if (comboSelectPicina.SelectedIndex == -1)
            {
                message = "Tienes de seleccionar una picina";
                buttons = MessageBoxButtons.OK;
                result  = MessageBox.Show(message, caption, buttons);
            }
            else if (txtdescripcio.Text == "")
            {
                message = "Tienes de escribir una descripción";
                buttons = MessageBoxButtons.OK;
                result  = MessageBox.Show(message, caption, buttons);
            }
            else if (combohores.SelectedIndex == -1)
            {
                message = "Tienes de seleccionar una hora";
                buttons = MessageBoxButtons.OK;
                result  = MessageBox.Show(message, caption, buttons);
            }
            else if (!Double.TryParse(txtPreu.Text, out price) || price < 0)
            {
                message = "Tienes de incluir un precio";
                buttons = MessageBoxButtons.OK;
                result  = MessageBox.Show(message, caption, buttons);
            }
            else if (!Int32.TryParse(txtMinimAl.Text, out minimAl) || minimAl < 0)
            {
                message = "Numero de alumnos mínimo erroneo";
                buttons = MessageBoxButtons.OK;
                result  = MessageBox.Show(message, caption, buttons);
            }
            else if (!Int32.TryParse(txtMaxA.Text, out maxAl) || maxAl < 0)
            {
                message = "Numero de alumnos máximo erroneo";
                buttons = MessageBoxButtons.OK;
                result  = MessageBox.Show(message, caption, buttons);
            }
            else if (minimAl > maxAl)
            {
                message = "No puede ser menor el máximo que el mínimo número de alumnos";
                buttons = MessageBoxButtons.OK;
                result  = MessageBox.Show(message, caption, buttons);
            }
            else
            {
                Pool     pSelected = service.FindPoolByZipCode(Convert.ToInt32(comboSelectPicina.SelectedItem.ToString()));
                DateTime dStart    = dateini.Value;
                DateTime dfi       = datefi.Value;

                String   valhora    = combohores.SelectedItem.ToString();
                Char     delimiter  = ':';
                String[] substrings = valhora.Split(delimiter);

                Days daysCurs = new Days();
                int  cont     = 0;
                // Days daysCurs = Days.Wednesday | Days.Friday;
                if (cbdilluns.Checked)
                {
                    cont     = 1;
                    daysCurs = Days.Monday;
                }
                if (cbcdimarts.Checked)
                {
                    cont     = 1;
                    daysCurs = daysCurs | Days.Tuesday;
                }
                if (cbdimecres.Checked)
                {
                    cont     = 1;
                    daysCurs = daysCurs | Days.Wednesday;
                }
                if (cbdijous.Checked)
                {
                    cont     = 1;
                    daysCurs = daysCurs | Days.Thursday;
                }
                if (cbdivendres.Checked)
                {
                    cont     = 1;
                    daysCurs = daysCurs | Days.Friday;
                }
                if (cbdisapte.Checked)
                {
                    cont     = 1;
                    daysCurs = daysCurs | Days.Saturday;
                }
                if (cont == 1)
                {
                    List <int> lan = new List <int>();
                    foreach (int l in chekedLanes.CheckedItems.Cast <int>())
                    {
                        lan.Add(l);
                    }
                    if (lan.Count > 0)
                    {
                        bool inser = service.AddCourse(pSelected, txtdescripcio.Text, dStart, dfi, createTime(Int32.Parse(substrings[0]), Int32.Parse(substrings[1]), 0),
                                                       new TimeSpan(0, 45, 0), daysCurs, minimAl, maxAl, price, lan);

                        if (!inser)
                        {
                            message = "No se ha insertado el curso";
                            buttons = MessageBoxButtons.OK;
                            result  = MessageBox.Show(message, caption, buttons);
                        }
                        else
                        {
                            message = "Se ha insertado el curso correctamente";
                            buttons = MessageBoxButtons.OK;
                            result  = MessageBox.Show(message, caption, buttons);
                            this.Close();
                        }
                    }
                    else
                    {
                        message = "Tienes que seleccionar alguna linia";
                        buttons = MessageBoxButtons.OK;
                        result  = MessageBox.Show(message, caption, buttons);
                    }
                }
                else
                {
                    message = "Tienes que seleccionar al menos un día";
                    buttons = MessageBoxButtons.OK;
                    result  = MessageBox.Show(message, caption, buttons);
                }
            }
        }