Beispiel #1
0
        public void WorkerWindow(ClientAccount ca, IWorkgroupService workgroupProxy, ConnectionHandler connectionHandler)
        {
            User u      = workgroupProxy.FindUser(ca.Username);
            int  choice = 0;
            bool ok     = false;

            do
            {
                Console.WriteLine("**********************************************");
                Console.WriteLine("Hello " + u.Username);
                Console.WriteLine("1. Request to get in the team");
                Console.WriteLine("2. Request for vacation");
                Console.WriteLine("3. Change password");
                Console.WriteLine("4. Logout");

                if (ca.ClientGroup == "Boss")
                {
                    Console.WriteLine("5. See list of requests");
                }

                do
                {
                    Console.Write("Choice: ");

                    if (!Int32.TryParse(Console.ReadLine(), out choice))
                    {
                        Console.WriteLine("Choice is a number!");
                    }
                    ok = true;
                } while (ok != true);

                switch (choice)
                {
                case 1:
                {
                    try
                    {
                        workgroupProxy.Ask(u.Username);
                        Console.WriteLine("Your request for joining group is sent");
                    }
                    catch (FaultException fe)
                    {
                        Console.WriteLine(fe.Message, fe.Reason);
                    }
                    break;
                }

                case 2:
                {
                    DateTime timeNow = DateTime.Now;
                    int      result = 0;
                    int      result2 = 0;
                    string   start, end;
                    do
                    {
                        Console.WriteLine("Starting date[mm/dd/yyyy]: ");
                        start = Console.ReadLine();
                        try
                        {
                            DateTime dt = Convert.ToDateTime(start);
                            result = DateTime.Compare(Convert.ToDateTime(start), timeNow);               //ako je start pre trenutka onda je result = -1
                        }
                        catch
                        {
                            Console.WriteLine("Not a good date format.");
                        }
                    } while (result <= 0);


                    do
                    {
                        Console.WriteLine("Ending date[mm/dd/yyyy]: ");
                        end = Console.ReadLine();
                        try
                        {
                            DateTime dt = Convert.ToDateTime(end);
                            result  = DateTime.Compare(Convert.ToDateTime(end), timeNow);
                            result2 = DateTime.Compare(Convert.ToDateTime(end), Convert.ToDateTime(start));
                        }
                        catch
                        {
                            Console.WriteLine("Not a good date format.");
                        }
                    } while (result <= 0 || result2 <= 0);

                    try
                    {
                        workgroupProxy.RequestVacation(u.Username, start, end);
                    }
                    catch (FaultException fe)
                    {
                        Console.WriteLine(fe.Reason);
                    }


                    break;
                }

                case 3:
                {
                    bool correctpass = false;
                    do
                    {
                        Console.WriteLine("Input old password");
                        string oldpass = Console.ReadLine();
                        if (u.Password != oldpass)
                        {
                            Console.WriteLine("You entered wrong password.");
                        }
                        Console.WriteLine("Input new password");
                        string newpass = Console.ReadLine();
                        try
                        {
                            correctpass = workgroupProxy.ChangePassword(u.Username, oldpass, newpass);
                        }
                        catch (FaultException fe)
                        {
                            Console.WriteLine(fe.Reason);
                        }
                    } while (correctpass == false);
                    break;
                }

                case 4:
                {
                    bool loggedout = false;
                    loggedout = workgroupProxy.Logout(u.Username);
                    Environment.Exit(0);
                    break;
                }

                case 5:
                {
                    List <Request> list = workgroupProxy.AllRequests(u.Username);
                    int            no   = list.Count;

                    if (no != 0)
                    {
                        Console.WriteLine("**********REQUESTS********");
                        foreach (Request r in list)
                        {
                            Console.WriteLine("User that asked for vacation: " + r.UserId);
                            Console.WriteLine("Id: " + r.Id);
                            Console.WriteLine("Starting date: " + r.StartDate);
                            Console.WriteLine("Ending date: " + r.EndDate);
                        }
                        Console.WriteLine("**********************");
                        Console.WriteLine("1. Approve request");
                        Console.WriteLine("2. Deny request");
                        Console.WriteLine("Choice: ");
                        int choice2 = Int32.Parse(Console.ReadLine());
                        if (choice2 == 1)
                        {
                            Console.WriteLine("Input ID of request you want to approve");
                            int id;

                            if (!Int32.TryParse(Console.ReadLine(), out id))
                            {
                                Console.WriteLine("ID is number!");
                                break;
                            }

                            try
                            {
                                workgroupProxy.ApproveRequest(id, ca.Username);
                            }
                            catch (FaultException fe)
                            {
                                Console.WriteLine(fe.Reason);
                            }
                        }
                        else if (choice2 == 2)
                        {
                            Console.WriteLine("Input ID of request you want to deny");
                            int id;

                            if (!Int32.TryParse(Console.ReadLine(), out id))
                            {
                                Console.WriteLine("ID is number!");
                                break;
                            }

                            try
                            {
                                workgroupProxy.DenyRequest(id, ca.Username);
                            }
                            catch (FaultException fe)
                            {
                                Console.WriteLine(fe.Reason);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("There are no requests for vacation.");
                    }

                    break;
                }
                }
            } while (choice != 4);
        }