예제 #1
0
        protected void btnUpdateReservation_Click(object sender, EventArgs e)
        {
            Pet            p  = new Pet();
            Service        s  = new Service();
            PetReservation pr = new PetReservation();
            Reservation    r  = new Reservation();

            int resNumber = Convert.ToInt16(Session["RESERVATION_NUMBER"]);

            Reservation curr = r.ListReservations().Find(rr => rr.number == resNumber);
            List <Pet>  pets = p.listPets((int)curr.ownerNumber);

            List <PetReservation> petRes = pr.ListPetReservations().FindAll(pr2 => pr2.reservationNum == resNumber);
            List <Service>        prs    = s.ListServices().FindAll(ss => petRes.Any(pr2 => pr2.petResNum == s.petResNumber));

            r.ChangeReservation(curr.number, DateTime.Parse(txtStartDate.Text), DateTime.Parse(txtEndDate.Text));

            int currPet = 0;

            for (int x = 0; x < pets.Count; x++)
            {
                PetReservation thisPetRes  = petRes.Find(pr2 => pr2.petNum == pets[x].number);
                List <Service> thisSerList = thisPetRes != null?s.ListServices().FindAll(prs2 => prs2.petResNumber == thisPetRes.petResNum) : null;

                switch (currPet)
                {
                case 0: {
                    Pet p2 = pets.Find(pp => pp.name == pet1.PetName && pp.ownerNumber == curr.ownerNumber);
                    if (p2 != null)
                    {
                        if (thisPetRes != null)
                        {
                            if (pet1.Included == false)
                            {
                                pr.RemovePetFromRes(p2.number, resNumber);
                            }
                            else
                            {
                                if (thisSerList.Any(q => q.number == 2))
                                {
                                    if (!pet1.Walking)
                                    {
                                        s.DeleteServ(thisPetRes.petResNum, 2);
                                    }
                                }
                                else
                                {
                                    if (pet1.Walking)
                                    {
                                        s.Add(thisPetRes.petResNum, 2);
                                    }
                                }

                                if (thisSerList.Any(q => q.number == 5))
                                {
                                    if (!pet1.Playtime)
                                    {
                                        s.DeleteServ(thisPetRes.petResNum, 5);
                                    }
                                }
                                else
                                {
                                    if (pet1.Playtime)
                                    {
                                        s.Add(thisPetRes.petResNum, 5);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (pet1.Included)
                            {
                                int petResNum = pr.Add(p2.number, resNumber)[1];
                                s.Add(petResNum, 1);
                                if (pet1.Walking)
                                {
                                    s.Add(petResNum, 2);
                                }
                                if (pet1.Playtime)
                                {
                                    s.Add(petResNum, 5);
                                }
                            }
                        }
                    }
                }
                break;

                case 1: {
                    Pet p2 = pets.Find(pp => pp.name == pet2.PetName && pp.ownerNumber == curr.ownerNumber);
                    if (p2 != null)
                    {
                        if (thisPetRes != null)
                        {
                            if (pet2.Included == false)
                            {
                                pr.RemovePetFromRes(p2.number, resNumber);
                            }
                            else
                            {
                                if (thisSerList.Any(q => q.number == 2))
                                {
                                    if (!pet2.Walking)
                                    {
                                        s.DeleteServ(thisPetRes.petResNum, 2);
                                    }
                                }
                                else
                                {
                                    if (pet2.Walking)
                                    {
                                        s.Add(thisPetRes.petResNum, 2);
                                    }
                                }

                                if (thisSerList.Any(q => q.number == 5))
                                {
                                    if (!pet2.Playtime)
                                    {
                                        s.DeleteServ(thisPetRes.petResNum, 5);
                                    }
                                }
                                else
                                {
                                    if (pet2.Playtime)
                                    {
                                        s.Add(thisPetRes.petResNum, 5);
                                    }
                                }
                            }
                        }
                        else
                        {
                            int petResNum = pr.Add(p2.number, resNumber)[1];
                            s.Add(petResNum, 1);
                            if (pet2.Walking)
                            {
                                s.Add(petResNum, 2);
                            }
                            if (pet2.Playtime)
                            {
                                s.Add(petResNum, 5);
                            }
                        }
                    }
                }
                break;

                case 2: {
                    Pet p2 = pets.Find(pp => pp.name == pet3.PetName && pp.ownerNumber == curr.ownerNumber);
                    if (p2 != null)
                    {
                        if (thisPetRes != null)
                        {
                            if (pet3.Included == false)
                            {
                                pr.RemovePetFromRes(p2.number, resNumber);
                            }
                            else
                            {
                                if (thisSerList.Any(q => q.number == 2))
                                {
                                    if (!pet3.Walking)
                                    {
                                        s.DeleteServ(thisPetRes.petResNum, 2);
                                    }
                                }
                                else
                                {
                                    if (pet3.Walking)
                                    {
                                        s.Add(thisPetRes.petResNum, 2);
                                    }
                                }

                                if (thisSerList.Any(q => q.number == 5))
                                {
                                    if (!pet3.Playtime)
                                    {
                                        s.DeleteServ(thisPetRes.petResNum, 5);
                                    }
                                }
                                else
                                {
                                    if (pet3.Playtime)
                                    {
                                        s.Add(thisPetRes.petResNum, 5);
                                    }
                                }
                            }
                        }
                        else
                        {
                            int petResNum = pr.Add(p2.number, resNumber)[1];
                            s.Add(petResNum, 1);
                            if (pet3.Walking)
                            {
                                s.Add(petResNum, 2);
                            }
                            if (pet3.Playtime)
                            {
                                s.Add(petResNum, 5);
                            }
                        }
                    }
                }
                break;

                case 3: {
                    Pet p2 = pets.Find(pp => pp.name == pet4.PetName && pp.ownerNumber == curr.ownerNumber);
                    if (p2 != null)
                    {
                        if (thisPetRes != null)
                        {
                            if (pet4.Included == false)
                            {
                                pr.RemovePetFromRes(p2.number, resNumber);
                            }
                            else
                            {
                                if (thisSerList.Any(q => q.number == 2))
                                {
                                    if (!pet4.Walking)
                                    {
                                        s.DeleteServ(thisPetRes.petResNum, 2);
                                    }
                                }
                                else
                                {
                                    if (pet4.Walking)
                                    {
                                        s.Add(thisPetRes.petResNum, 2);
                                    }
                                }

                                if (thisSerList.Any(q => q.number == 5))
                                {
                                    if (!pet4.Playtime)
                                    {
                                        s.DeleteServ(thisPetRes.petResNum, 5);
                                    }
                                }
                                else
                                {
                                    if (pet4.Playtime)
                                    {
                                        s.Add(thisPetRes.petResNum, 5);
                                    }
                                }
                            }
                        }
                        else
                        {
                            int petResNum = pr.Add(p2.number, resNumber)[1];
                            s.Add(petResNum, 1);
                            if (pet4.Walking)
                            {
                                s.Add(petResNum, 2);
                            }
                            if (pet4.Playtime)
                            {
                                s.Add(petResNum, 5);
                            }
                        }
                    }
                }
                break;
                }

                if (resNumber < 0)
                {
                    Errors.Add("The reservation could not be added.");
                    break;
                }
                currPet++;
            }
        }
예제 #2
0
        protected void btnMakeReservation_Click(object sender, EventArgs e)
        {
            Pet            p    = new Pet();
            Service        s    = new Service();
            PetReservation pr   = new PetReservation();
            Reservation    r    = new Reservation();
            List <Pet>     pets = p.listPets(((userType)Session["UserType"] == userType.Clerk) ? Convert.ToInt16(Session["OWNER_NUMBER"]) : ((Owner)Session["OWNER"]).number);

            int resNumber = 0;
            int currPet   = 0;

            for (int x = 0; x < 4; x++)
            {
                switch (currPet)
                {
                case 0: {
                    Pet p2 = pets.Find(pp => pp.name == pet1.PetName && pp.ownerNumber == (((userType)Session["UserType"] == userType.Clerk) ? Convert.ToInt16(Session["OWNER_NUMBER"]) : ((Owner)Session["OWNER"]).number));
                    if (p2 != null)
                    {
                        resNumber = r.AddReservation(p2.number, DateTime.Parse(txtStartDate.Text), DateTime.Parse(txtEndDate.Text))[1];
                        if (resNumber < 0)
                        {
                            break;
                        }
                        int petResNum = pr.Add(p2.number, resNumber)[1];
                        s.Add(petResNum, 1);
                        if (pet1.Walking)
                        {
                            s.Add(petResNum, 2);
                        }
                        if (pet1.Playtime)
                        {
                            s.Add(petResNum, 5);
                        }
                    }
                }
                break;

                case 1: {
                    Pet p2 = pets.Find(pp => pp.name == pet2.PetName && pp.ownerNumber == (((userType)Session["UserType"] == userType.Clerk) ? Convert.ToInt16(Session["OWNER_NUMBER"]) : ((Owner)Session["OWNER"]).number));
                    try {
                        if (pet2.Included)
                        {
                            if (p2 != null)
                            {
                                int petResNum = pr.Add(p2.number, resNumber)[1];
                                s.Add(petResNum, 1);
                                if (pet2.Walking)
                                {
                                    s.Add(petResNum, 2);
                                }
                                if (pet2.Playtime)
                                {
                                    s.Add(petResNum, 5);
                                }
                            }
                        }
                    } catch {
                        Errors.Add("Your second pet could not be added to the reservation.");
                    }
                }
                break;

                case 2: {
                    Pet p2 = pets.Find(pp => pp.name == pet3.PetName && pp.ownerNumber == (((userType)Session["UserType"] == userType.Clerk) ? Convert.ToInt16(Session["OWNER_NUMBER"]) : ((Owner)Session["OWNER"]).number));
                    try {
                        if (pet3.Included)
                        {
                            if (p2 != null)
                            {
                                int petResNum = pr.Add(p2.number, resNumber)[1];
                                s.Add(petResNum, 1);
                                if (pet3.Walking)
                                {
                                    s.Add(petResNum, 2);
                                }
                                if (pet3.Playtime)
                                {
                                    s.Add(petResNum, 5);
                                }
                            }
                        }
                    } catch {
                        Errors.Add("Your third pet could not be added to the reservation.");
                    }
                }
                break;

                case 3: {
                    Pet p2 = pets.Find(pp => pp.name == pet4.PetName && pp.ownerNumber == (((userType)Session["UserType"] == userType.Clerk) ? Convert.ToInt16(Session["OWNER_NUMBER"]) : ((Owner)Session["OWNER"]).number));
                    try {
                        if (pet4.Included)
                        {
                            if (p2 != null)
                            {
                                int petResNum = pr.Add(p2.number, resNumber)[1];
                                s.Add(petResNum, 1);
                                if (pet4.Walking)
                                {
                                    s.Add(petResNum, 2);
                                }
                                if (pet4.Playtime)
                                {
                                    s.Add(petResNum, 5);
                                }
                            }
                        }
                    } catch {
                        Errors.Add("Your fourth pet could not be added to the reservation.");
                    }
                }
                break;
                }



                currPet++;
            }
            if (resNumber > 0)
            {
                Session["RESERVATION_NUMBER"] = resNumber;
                state = viewingMode.update;
            }
            else
            {
                Errors.Add("The reservation could not be added.");
                state = viewingMode.insert;
            }
        }