예제 #1
0
        public bool checkIn()
        {
            var date = DateTime.Now;

            hotelDB.CheckIns.Add(new CheckIn()
            {
                empId       = CurrentUser.Id,
                checkInDate = date
            });
            hotelDB.SaveChanges();
            return(true);
        }
예제 #2
0
        public bool addCustomer(Customer customer)
        {
            try
            {
                hotelDB.Customers.Add(customer);
                hotelDB.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
예제 #3
0
        public bool addProduct(Product product)
        {
            try
            {
                hotelDB.Products.Add(product);
                hotelDB.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
예제 #4
0
        public bool addEmp(Employee emp)
        {
            try
            {
                hotelDB.Employees.Add(emp);
                hotelDB.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
예제 #5
0
        public bool addRoom(Room room)
        {
            try
            {
                hotelDB.Rooms.Add(room);
                hotelDB.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
예제 #6
0
        public bool addConsume(Consume consume)
        {
            try
            {
                hotelDB.Consumes.Add(consume);
                hotelDB.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
예제 #7
0
        public bool AddNewAccount(string username, string password, int user_id)
        {
            try
            {
                if (ExistUsernamCheck(username) == false)
                {
                    return(false);
                }

                Account account = new Account()
                {
                    username = username,
                    password = password,
                    userID   = user_id
                };
                hotelDB.Accounts.Add(account);
                hotelDB.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #8
0
        public void Scheduling()
        {
            maxWork = 7;

            var empQ = getEmpQueue();

            ResetSchedule();

            Queue <int> workday = new Queue <int>();

            for (int i = 0; i < empQ.Count; i++)
            {
                workday.Enqueue(0);
            }

            if (empQ == null)
            {
                return;
            }

            // xep lich cho thu 2 tới thu 6
            for (int i = 1; i < 6; i++)
            {
                // ca 1
                int managerSlot1 = 1;
                int receptSlot1  = 2;
                int laborSlot1   = 2;

                // ca 2
                int managerSlot2 = 1;
                int receptSlot2  = 1;
                int laborSlot2   = 2;

                // ca 3
                int receptSlot3 = 1;
                int laborSlot3  = 1;

                // ca 1
                int checkedEmp = 0;
                while ((managerSlot1 + receptSlot1 + laborSlot1) > 0 && (checkedEmp <= empQ.Count))
                {
                    Employee temp   = empQ.Dequeue();
                    int      worked = workday.Dequeue();
                    checkedEmp++;

                    if (hotelDB.empSchedules.Find(temp.Id, i) != null)
                    {
                        empQ.Enqueue(temp);
                        workday.Enqueue(worked);
                        continue;
                    }

                    //manager
                    if (temp.posId == 1 && managerSlot1 > 0 && worked < maxWork)
                    {
                        hotelDB.empSchedules.Add(new HotelAPP.empSchedule
                        {
                            empID   = temp.Id,
                            weekDay = i,
                            shift   = 1
                        });
                        workday.Enqueue(worked + 1);
                        empQ.Enqueue(temp);
                        managerSlot1--;
                        continue;
                    }
                    //reception
                    if (temp.posId == 2 && receptSlot1 > 0 && worked < maxWork)
                    {
                        hotelDB.empSchedules.Add(new HotelAPP.empSchedule
                        {
                            empID   = temp.Id,
                            weekDay = i,
                            shift   = 1
                        });
                        workday.Enqueue(worked + 1);
                        empQ.Enqueue(temp);
                        receptSlot1--;
                        continue;
                    }
                    //labor
                    if (temp.posId == 3 && laborSlot1 > 0 && worked < maxWork)
                    {
                        hotelDB.empSchedules.Add(new HotelAPP.empSchedule
                        {
                            empID   = temp.Id,
                            weekDay = i,
                            shift   = 1
                        });
                        workday.Enqueue(worked + 1);
                        empQ.Enqueue(temp);
                        laborSlot1--;
                        continue;
                    }

                    workday.Enqueue(worked);
                    empQ.Enqueue(temp);
                }

                // ca 2
                checkedEmp = 0;
                while ((managerSlot2 + receptSlot2 + laborSlot2) > 0 && (checkedEmp <= empQ.Count))
                {
                    Employee temp   = empQ.Dequeue();
                    int      worked = workday.Dequeue();
                    checkedEmp++;

                    if (hotelDB.empSchedules.Find(temp.Id, i) != null)
                    {
                        empQ.Enqueue(temp);
                        workday.Enqueue(worked);
                        continue;
                    }

                    //manager
                    if (temp.posId == 1 && managerSlot2 > 0 && worked < maxWork)
                    {
                        hotelDB.empSchedules.Add(new HotelAPP.empSchedule
                        {
                            empID   = temp.Id,
                            weekDay = i,
                            shift   = 2
                        });
                        workday.Enqueue(worked + 1);
                        empQ.Enqueue(temp);
                        managerSlot2--;
                        continue;
                    }
                    //reception
                    if (temp.posId == 2 && receptSlot2 > 0 && worked < maxWork)
                    {
                        hotelDB.empSchedules.Add(new HotelAPP.empSchedule
                        {
                            empID   = temp.Id,
                            weekDay = i,
                            shift   = 2
                        });
                        workday.Enqueue(worked + 1);
                        empQ.Enqueue(temp);
                        receptSlot2--;
                        continue;
                    }
                    //labor
                    if (temp.posId == 3 && laborSlot2 > 0 && worked < maxWork)
                    {
                        hotelDB.empSchedules.Add(new HotelAPP.empSchedule
                        {
                            empID   = temp.Id,
                            weekDay = i,
                            shift   = 2
                        });
                        workday.Enqueue(worked + 1);
                        empQ.Enqueue(temp);
                        laborSlot2--;
                        continue;
                    }

                    workday.Enqueue(worked);
                    empQ.Enqueue(temp);
                }

                //ca 3
                checkedEmp = 0;
                while ((receptSlot3 + laborSlot3) > 0 && (checkedEmp <= empQ.Count))
                {
                    Employee temp   = empQ.Dequeue();
                    int      worked = workday.Dequeue();
                    checkedEmp++;

                    if (hotelDB.empSchedules.Find(temp.Id, i) != null)
                    {
                        empQ.Enqueue(temp);
                        workday.Enqueue(worked);
                        continue;
                    }

                    //manager or reception
                    if (temp.posId == 2 && receptSlot3 > 0 && worked < maxWork)
                    {
                        hotelDB.empSchedules.Add(new HotelAPP.empSchedule
                        {
                            empID   = temp.Id,
                            weekDay = i,
                            shift   = 3
                        });
                        workday.Enqueue(worked + 1);
                        empQ.Enqueue(temp);
                        receptSlot3--;
                        continue;
                    }
                    //labor
                    if (temp.posId == 3 && laborSlot3 > 0 && worked < maxWork)
                    {
                        hotelDB.empSchedules.Add(new HotelAPP.empSchedule
                        {
                            empID   = temp.Id,
                            weekDay = i,
                            shift   = 3
                        });
                        workday.Enqueue(worked + 1);
                        empQ.Enqueue(temp);
                        laborSlot3--;
                        continue;
                    }

                    workday.Enqueue(worked);
                    empQ.Enqueue(temp);
                }
            }

            // xep lich cho thu 7 CN
            for (int i = 0; i < 2; i++)
            {
                int day;
                if (i == 0)
                {
                    day = (int)DayOfWeek.Saturday;
                }
                else
                {
                    day = (int)DayOfWeek.Sunday;
                }

                // ca 1
                int receptSlot1 = 1;
                int laborSlot1  = 1;

                // ca 2
                int receptSlot2 = 1;
                int laborSlot2  = 1;

                // ca 3
                int receptSlot3 = 1;
                int laborSlot3  = 1;

                //ca 1
                int checkedEmp = 0;
                while ((receptSlot1 + laborSlot1) > 0 && (checkedEmp <= empQ.Count))
                {
                    Employee temp   = empQ.Dequeue();
                    int      worked = workday.Dequeue();
                    checkedEmp++;

                    if (hotelDB.empSchedules.Find(temp.Id, day) != null)
                    {
                        empQ.Enqueue(temp);
                        workday.Enqueue(worked);
                        continue;
                    }

                    //reception
                    if (temp.posId == 2 && receptSlot1 > 0 && worked < maxWork)
                    {
                        hotelDB.empSchedules.Add(new HotelAPP.empSchedule
                        {
                            empID   = temp.Id,
                            weekDay = day,
                            shift   = 1
                        });
                        workday.Enqueue(worked + 1);
                        empQ.Enqueue(temp);
                        receptSlot1--;
                        continue;
                    }
                    //labor
                    if (temp.posId == 3 && laborSlot1 > 0 && worked < maxWork)
                    {
                        hotelDB.empSchedules.Add(new HotelAPP.empSchedule
                        {
                            empID   = temp.Id,
                            weekDay = day,
                            shift   = 1
                        });
                        workday.Enqueue(worked + 1);
                        empQ.Enqueue(temp);
                        laborSlot1--;
                        continue;
                    }

                    workday.Enqueue(worked);
                    empQ.Enqueue(temp);
                }

                //ca 2
                checkedEmp = 0;
                while ((receptSlot2 + laborSlot2) > 0 && (checkedEmp <= empQ.Count))
                {
                    Employee temp   = empQ.Dequeue();
                    int      worked = workday.Dequeue();
                    checkedEmp++;

                    if (hotelDB.empSchedules.Find(temp.Id, day) != null)
                    {
                        empQ.Enqueue(temp);
                        workday.Enqueue(worked);
                        continue;
                    }

                    //reception
                    if (temp.posId == 2 && receptSlot2 > 0 && worked < maxWork)
                    {
                        hotelDB.empSchedules.Add(new HotelAPP.empSchedule
                        {
                            empID   = temp.Id,
                            weekDay = day,
                            shift   = 2
                        });
                        workday.Enqueue(worked + 1);
                        empQ.Enqueue(temp);
                        receptSlot2--;
                        continue;
                    }
                    //labor
                    if (temp.posId == 3 && laborSlot2 > 0 && worked < maxWork)
                    {
                        hotelDB.empSchedules.Add(new HotelAPP.empSchedule
                        {
                            empID   = temp.Id,
                            weekDay = day,
                            shift   = 2
                        });
                        workday.Enqueue(worked + 1);
                        empQ.Enqueue(temp);
                        laborSlot2--;
                        continue;
                    }

                    workday.Enqueue(worked);
                    empQ.Enqueue(temp);
                }

                //ca 3
                checkedEmp = 0;
                while ((receptSlot3 + laborSlot3) > 0 && (checkedEmp <= empQ.Count))
                {
                    Employee temp   = empQ.Dequeue();
                    int      worked = workday.Dequeue();
                    checkedEmp++;

                    if (hotelDB.empSchedules.Find(temp.Id, day) != null)
                    {
                        empQ.Enqueue(temp);
                        workday.Enqueue(worked);
                        continue;
                    }

                    //reception
                    if (temp.posId == 2 && receptSlot3 > 0 && worked < maxWork)
                    {
                        hotelDB.empSchedules.Add(new HotelAPP.empSchedule
                        {
                            empID   = temp.Id,
                            weekDay = day,
                            shift   = 3
                        });
                        workday.Enqueue(worked + 1);
                        empQ.Enqueue(temp);
                        receptSlot3--;
                        continue;
                    }
                    //labor
                    if (temp.posId == 3 && laborSlot3 > 0 && worked < maxWork)
                    {
                        hotelDB.empSchedules.Add(new HotelAPP.empSchedule
                        {
                            empID   = temp.Id,
                            weekDay = day,
                            shift   = 3
                        });
                        workday.Enqueue(worked + 1);
                        empQ.Enqueue(temp);
                        laborSlot3--;
                        continue;
                    }

                    workday.Enqueue(worked);
                    empQ.Enqueue(temp);
                }
            }

            try
            {
                hotelDB.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }