protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                string date = default_datetimepicker.Text;

                string[] words = date.Split('/');
                words[2] = words[2].Substring(0, 4);
                DateTime dt = new DateTime(Convert.ToInt32(words[2]), Convert.ToInt32(words[0]), Convert.ToInt32(words[1]));
                if (dt < DateTime.Now)
                {
                    Label lblMasterStatus = (Label)Master.FindControl("message");
                    lblMasterStatus.Visible = true;
                    lblMasterStatus.Text = "Please select a future date";
                }
                else
                {
                    Label lblMasterStatus = (Label)Master.FindControl("message");
                    lblMasterStatus.Visible = true;
                    lblMasterStatus.Text = "";
                    TweekPerformance_BT.Employee emp = new TweekPerformance_BT.Employee();
                    List<string> availableEmployees = emp.NumberOfAvailableEmployees(dt);
                    txtAvailableEmployees.Text = availableEmployees[0].ToString();
                }
            }
            catch (Exception x)
            {
                Label lblMasterStatus = (Label)Master.FindControl("message");
                lblMasterStatus.Visible = true;
                lblMasterStatus.Text = "Please Select a Valid Date";
            }
        }
 protected void a_Click(object sender, EventArgs e)
 {
     TweekPerformance_BT.Employee emp = new TweekPerformance_BT.Employee();
     EmployeeBindingList.EmployeeList.Clear();
     userNumbersList.Clear();
     Project newProject = (Project)Application["newProject"];
     emp.SearchEmployees(search.Text, newProject.ProjectStartDateTime);
     List<Employees> myList = new List<Employees>();
     foreach (TweekPerformance_BT.Employee inE in EmployeeBindingList.EmployeeList)
     {
         userNumbersList.Add(inE.UserNumber);
         Employees a = new Employees();
         a.FirstName = inE.FirstName;
         a.Surname = inE.Surname;
         a.ContactNumber = inE.ContactNumber;
         myList.Add(a);
     }
     gvwStudents.DataSource = myList;
     gvwStudents.DataBind();
 }
        protected void Unnamed_Click(object sender, EventArgs e)
        {
            User u = new User();
            string firstName = txtFirstName.Text;
            string surname = Surname.Text;
            string email = EmpEmailAddress.Text;
            string contactNumber = EmpContactNumber.Text;
            string address = PhysicalAddress.Text;
            string password = Password.Text;
            //Automatically assign as Client because a Dealer/Employee is added by a manager
            int securityRoleNumber = 2;
            int cityNumber = Convert.ToInt32(CityDDL.SelectedIndex)+1;

            string date = default_datetimepickers.Text;

            if (String.IsNullOrEmpty(date))
            {
                date = "10/10/2010";
            }

            string[] words = date.Split('/');

            DateTime birthday = new DateTime(Convert.ToInt32(words[2]), Convert.ToInt32(words[1]), Convert.ToInt32(words[0]));

            string gender = GenderDDL.Text;
            Boolean active = true;
            string idNumber = ID.Text;
            double salary = Convert.ToDouble(EmployeeSalary.Text);
            int typeNumber = Convert.ToInt32(EmployeeTypeDDL.SelectedIndex)+1;

            User newuser = new User(0, firstName, surname, email, contactNumber, address, password, securityRoleNumber, cityNumber, birthday, gender, active);
            asa.Text =  newuser.InsertNewUser(newuser);
            int newUserNumber = 0;
            foreach (string s in newuser.LastUserNumber())
            {
                newUserNumber = Convert.ToInt32(s);
            }
            TweekPerformance_BT.Employee newEmp = new TweekPerformance_BT.Employee();
            newEmp.InsertNewEmployee(newUserNumber, idNumber, salary, 0, typeNumber, true);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Application["ClientUN"].ToString().Equals("1"))
                {
                    txtName.Text = Application["FName"].ToString();
                    txtSurname.Text = Application["SName"].ToString();
                    txtContactNumber.Text = Application["ContactNum"].ToString();
                    txtDateRequestFor.Text = "No Request";
                }
                else
                {
                    foreach (Client c in ClientBindingList.MyClientList)
                    {
                        if (c.UserNumber == Convert.ToInt32(Application["ClientUN"]) && Convert.ToInt32(Application["ProjectRequest"]) == 0)
                        {
                            txtName.Text = c.FirstName;
                            txtSurname.Text = c.Surname;
                            txtContactNumber.Text = c.ContactNumber;
                            txtDateRequestFor.Text = "No Request";
                            break;
                        }
                        else if (c.UserNumber == Convert.ToInt32(Application["ClientUN"]))
                        {
                            txtName.Text = c.FirstName;
                            txtSurname.Text = c.Surname;
                            txtContactNumber.Text = c.ContactNumber;
                            break;
                        }

                    }
                }

                foreach (ClientVehicle cv in ClientVehicleBindingList.ClientVehicleList)
                {
                    if (cv.ClientVehicleNumber == Convert.ToInt32(Application["ClientVehicleNum"]))
                    {
                        txtModelNumber.Text = cv.ModelNumber;
                        break;
                    }
                }

                ProjectDDL.Items.Add("Modification");
                ProjectDDL.Items.Add("Minor Service");
                ProjectDDL.Items.Add("Major Service");
                ProjectDDL.Items.Add("Modification and Minor Service");
                ProjectDDL.Items.Add("Modification and Major Service");
                ProjectDDL.SelectedIndex = 0;

                foreach (ProjectRequest inPR in ProjectRequestBindingList.ProjectRequestList)
                {
                    if (inPR.ProjectRequestNumber == Convert.ToInt32(Application["ProjectRequest"]))
                    {
                        txtDateRequestFor.Text = inPR.DateRequestedFor.ToString();
                        txtDescription.Text = inPR.ProjectDescription;
                        string search = inPR.ProjectRequestType;

                        ProjectDDL.SelectedIndex = ProjectDDL.Items.IndexOf(ProjectDDL.Items.FindByValue(search));
                    }
                }

                try
                {
                    default_datetimepicker.Text = txtDateRequestFor.Text;
                    string date = default_datetimepicker.Text;
                    if (!txtDateRequestFor.Text.Equals("No Request"))
                    {
                        string[] words = date.Split('/');
                        words[2] = words[2].Substring(0, 4);
                        DateTime dt = new DateTime(Convert.ToInt32(words[2]), Convert.ToInt32(words[0]), Convert.ToInt32(words[1]));
                        if (dt < DateTime.Now)
                        {
                            Label lblMasterStatus = (Label)Master.FindControl("message");
                            lblMasterStatus.Visible = true;
                            lblMasterStatus.Text = "Please select a future date";
                        }
                        else
                        {
                            TweekPerformance_BT.Employee emp = new TweekPerformance_BT.Employee();
                            List<string> availableEmployees = emp.NumberOfAvailableEmployees(dt);
                            txtAvailableEmployees.Text = availableEmployees[0].ToString();
                        }
                    }
                }
                catch (Exception x)
                {
                    Label lblMasterStatus = (Label)Master.FindControl("message");
                    lblMasterStatus.Visible = true;
                    lblMasterStatus.Text = "Date is currently empty or invalid";
                }
            }
            //Load Avaliable Employees for Today

            #region Google-Calander Load
            UserCredential credential;

            using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);
                credPath = Path.Combine(credPath, ".credentials");

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
            }

            // Create Google Calendar API service.
            var service = new CalendarService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = ApplicationName,
            });

            // Define parameters of request.
            EventsResource.ListRequest request = service.Events.List("*****@*****.**");
            request.TimeMin = DateTime.Now;
            request.ShowDeleted = false;
            request.SingleEvents = true;
            request.MaxResults = 10;
            request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;

            // List events.
            try
            {
                Events events = request.Execute();
                if (events.Items != null && events.Items.Count > 0)
                {
                    foreach (var eventItem in events.Items)
                    {
                        string when = eventItem.Start.DateTime.ToString();
                        if (String.IsNullOrEmpty(when))
                        {
                            when = eventItem.Start.Date;
                        }
                    }
                }
                else
                {
                }
            }
            catch(Exception)
            {
                Response.Redirect(Request.RawUrl);
            }
            #endregion
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if(Application["newProject"] != null)
            {
                Project newProject = (Project)Application["newProject"];
                TweekPerformance_BT.Employee emp = new TweekPerformance_BT.Employee();
                emp.SearchEmployees("", newProject.ProjectStartDateTime);
                List<Employees> myList = new List<Employees>();

                //Loads the DataGridView
                foreach (TweekPerformance_BT.Employee inE in EmployeeBindingList.EmployeeList)
                {
                    userNumbersList.Add(inE.UserNumber);
                    Employees a = new Employees();
                    a.FirstName = inE.FirstName;
                    a.Surname = inE.Surname;
                    a.ContactNumber = inE.ContactNumber;
                    myList.Add(a);
                }
                gvwStudents.DataSource = myList;
                gvwStudents.DataBind();
            }
            else
            {
                Response.Redirect("./ViewProjectRequests");
            }
        }