Esempio n. 1
0
        public void staffMenuActive()
        {
            StaffManager stfManager = new StaffManager();

            do
            {
                Console.WriteLine("\n------------------------------------------------------------" +
                                  "\nStaff menu:  1.List staff    2.Room availability    3.Create slot    4.Remove slot   5.Exit");
                Console.WriteLine("Enter option: ");
                var option = int.Parse(Console.ReadLine());
                switch (option)
                {
                case 1:
                    stfManager.ListStaff();
                    break;

                case 2:
                    stfManager.RoomAvaliability();
                    break;

                case 3:
                    stfManager.CreateSlot();
                    break;

                case 4:
                    stfManager.RemoveSlot();
                    break;

                case 5:
                    return;

                default:
                    Console.WriteLine("Invalid input, please enter again");
                    break;
                }
            } while (true);
        }
Esempio n. 2
0
        public void CreateSlot()
        {
            using (SqlConnection conn = new SqlConnection("server=wdt2019.australiasoutheast.cloudapp.azure.com;" +
                                                          "uid=s3655108;database=s3655108;pwd=abc123;"))
            {
                try
                {
                    SqlDataAdapter daUser = new SqlDataAdapter();
                    SqlDataAdapter daSlot = new SqlDataAdapter();
                    DataTable      userTable;
                    DataTable      slotTable;
                    DataSet        ds         = new DataSet();
                    StaffManager   stfManager = new StaffManager();
                    daUser.SelectCommand = new SqlCommand("select * from [User] where UserID like 'e%'", conn);
                    daSlot.SelectCommand = new SqlCommand("select * from Slot", conn);
                    SqlCommandBuilder cb = new SqlCommandBuilder(daSlot);
                    daUser.Fill(ds, "userTable");
                    daSlot.Fill(ds, "slotTable");
                    userTable = ds.Tables["userTable"];
                    slotTable = ds.Tables["slotTable"];
                    conn.Open();
                    Console.WriteLine("--- Create slot ---");

                    Console.WriteLine("Enter room name:");
                    var roomID = (Console.ReadLine()).ToUpper();
                    fm.RoomIsValid(roomID);

                    //enter the date and convert to Date
                    Console.WriteLine("Enter date for slot(dd - mm - yyyy):");
                    var selectedDate = Console.ReadLine();
                    fm.DateIsValid(selectedDate);
                    DateTime dt = DateTime.ParseExact(selectedDate, "dd-MM-yyyy", CultureInfo.InvariantCulture);

                    //enter the time and get start time and end time
                    Console.WriteLine(" Enter time for slot(HH: mm)");
                    var timeInput = Console.ReadLine();
                    fm.TimeIsValid(timeInput);
                    DateTime time       = DateTime.ParseExact(timeInput, "HH:mm", CultureInfo.InvariantCulture);
                    DateTime open       = DateTime.ParseExact("09:00", "HH:mm", CultureInfo.InvariantCulture);
                    DateTime close      = DateTime.ParseExact("14:00", "HH:mm", CultureInfo.InvariantCulture);
                    DateTime actualTime = DateTime.ParseExact(selectedDate + " " + timeInput, "dd-MM-yyyy HH:mm", CultureInfo.InvariantCulture);

                    Console.WriteLine(" Enter staff ID:");
                    var id = (Console.ReadLine()).ToLower();
                    fm.StaffIdIsValid(id);
                    var countrRoom = 0;
                    var occupied   = false;
                    var countStaff = 0;
                    foreach (DataRow row in slotTable.Rows)
                    {
                        if (dt.Equals(row["Date"]))
                        {
                            if ((string)row["RoomID"] == roomID)
                            {
                                countrRoom++;
                            }

                            if ((string)row["RoomID"] == roomID && row["StaffID"] != null && row["StartTime"].Equals(actualTime))
                            {
                                occupied = true;
                            }

                            if ((string)row["StaffID"] == id)
                            {
                                countStaff++;
                            }
                        }
                    }
                    var overtime1 = DateTime.Compare(open, time);
                    var overtime2 = DateTime.Compare(close, time);

                    if (countrRoom >= 2 || countStaff >= 4 || occupied == true || overtime1 == 1 || overtime2 == -1)
                    {
                        Console.WriteLine("Unable to create slot.");
                    }
                    else
                    {
                        DataRow newRow = slotTable.NewRow();
                        newRow["RoomID"]    = roomID;
                        newRow["StartTime"] = actualTime;
                        newRow["EndTime"]   = actualTime.AddHours(1);
                        newRow["StaffID"]   = id;
                        newRow["Date"]      = dt;
                        slotTable.Rows.Add(newRow);
                        daSlot.Update(ds, "slotTable");
                        Console.WriteLine("Slot created successfully.");
                    }
                }
                catch (SqlException se)
                {
                    Console.WriteLine("SQL Exception: {0}", se.Message);
                }catch (RoomIdException re)
                {
                    Console.WriteLine(re.Message);
                }catch (UserIdException ue)
                {
                    Console.WriteLine(ue.Message);
                }catch (DateException de)
                {
                    Console.WriteLine(de.Message);
                }
                finally
                {
                    conn.Close();
                }
            }
        }