public void CheckStatus()
        {
            //This checks the status of the Employee from the database.
            //Sets the top menu bar values equal to the values in the database for the employee.
            using (StaffLogin login = new StaffLogin())
                using (SqlConnection myConnection = new SqlConnection(str))
                    using (SqlDataAdapter employeePin = new SqlDataAdapter($"SELECT * FROM Employees WHERE PIN = {login.pin}", myConnection))
                    {
                        DataTable userPin = new DataTable();

                        myConnection.Open();
                        employeePin.Fill(userPin);
                        myConnection.Close();
                        for (int row = 0; row < userPin.Rows.Count; row++)
                        {
                            string FirstName = (string)userPin.Rows[row]["FName"];
                            string LastName  = (string)userPin.Rows[row]["LName"];
                            bool   Status    = (bool)userPin.Rows[row]["Status"];

                            this.topInfoBar1.StaffNameLabel.Text = "Name: " + FirstName + " " + LastName;
                            if (Status == false)
                            {
                                this.topInfoBar1.StatusLabel.Text = "Status: " + "Clocked Out";
                            }
                            else if (Status == true)
                            {
                                this.topInfoBar1.StatusLabel.Text = "Status: " + "Clocked In";
                            }
                        }
                    }
        }
Esempio n. 2
0
        private void CreateEditSchedule_Load(object sender, EventArgs e)
        {
            CheckStatus();
            // adds new schedule and edit schedule to new and edit combo box
            newEditcmb.Items.Add("New Schedule");
            newEditcmb.Items.Add("Edit Schedule");
            using (StaffLogin login = new StaffLogin())
                using (SqlConnection myConnection = new SqlConnection(str))
                {
                    // selects from employees
                    using (SqlDataAdapter employeeInfo = new SqlDataAdapter($"SELECT * FROM Employees", myConnection))
                    {
                        // creates new empty table
                        DataTable employee = new DataTable();
                        // fills employee table with employee information
                        myConnection.Open();
                        employeeInfo.Fill(employee);
                        myConnection.Close();

                        for (int row = 0; row < employee.Rows.Count; row++)
                        {
                            // adds fristname and lastname to the select employee combobox
                            string FirstName = (string)employee.Rows[row]["FName"];
                            string LastName  = (string)employee.Rows[row]["LName"];
                            SelectEmployeeComboBox.Items.Add(FirstName + " " + LastName);
                        }
                    }
                }
        }
Esempio n. 3
0
        //This function grabs the employee information and populates the top status bar
        public void CheckStatus()
        {
            using (StaffLogin login = new StaffLogin())
                using (SqlConnection myConnection = new SqlConnection(str))
                    // select statement for grabbing employee login pin
                    using (SqlDataAdapter employeePin = new SqlDataAdapter($"SELECT * FROM Employees WHERE PIN = {login.pin}", myConnection))
                    {
                        DataTable userPin = new DataTable();

                        myConnection.Open();
                        employeePin.Fill(userPin);
                        myConnection.Close();
                        for (int row = 0; row < userPin.Rows.Count; row++)
                        {
                            string FirstName = (string)userPin.Rows[row]["FName"];
                            string LastName  = (string)userPin.Rows[row]["LName"];
                            bool   Status    = (bool)userPin.Rows[row]["Status"];

                            this.topInfoBar1.StaffNameLabel.Text = "Name: " + FirstName + " " + LastName;
                            if (Status == false)
                            {
                                this.topInfoBar1.StatusLabel.Text = "Status: " + "Clocked Out";
                            }
                            else if (Status == true)
                            {
                                this.topInfoBar1.StatusLabel.Text = "Status: " + "Clocked In";
                            }
                        }
                    }
        }
Esempio n. 4
0
 private void CreateEditEmployee_Load(object sender, EventArgs e)
 {
     // checks status on every load
     CheckStatus();
     using (StaffLogin login = new StaffLogin())
         using (SqlConnection myConnection = new SqlConnection(str))
         {
             // Adds a new Employee option to the combo box
             EmployeeNameComboBox.Items.Add("New Employee");
             // gets all employees from database
             using (SqlDataAdapter employeeInfo = new SqlDataAdapter($"SELECT * FROM Employees", myConnection))
             {
                 //creates empty table
                 DataTable employee = new DataTable();
                 // opens connection and populates table
                 myConnection.Open();
                 employeeInfo.Fill(employee);
                 myConnection.Close();
                 // for every employee in employees it adds to the employee combo box
                 for (int row = 0; row < employee.Rows.Count; row++)
                 {
                     string FirstName = (string)employee.Rows[row]["FName"];
                     string LastName  = (string)employee.Rows[row]["LName"];
                     EmployeeNameComboBox.Items.Add(FirstName + " " + LastName);
                 }
             }
         }
 }
Esempio n. 5
0
        public void CheckStatus()
        {
            //grabs the login though an instance of sStaff login
            using (StaffLogin login = new StaffLogin())
                using (SqlConnection myConnection = new SqlConnection(str))
                    // selects all from employees where employee pin is equal to login pin
                    using (SqlDataAdapter employeePin = new SqlDataAdapter($"SELECT * FROM Employees WHERE PIN = {login.pin}", myConnection))
                    {
                        // makes new empty table for userpin
                        DataTable userPin = new DataTable();

                        // opens and filll userpin with employee information
                        myConnection.Open();
                        employeePin.Fill(userPin);
                        myConnection.Close();
                        for (int row = 0; row < userPin.Rows.Count; row++)
                        {
                            //grabs first name, last name and status
                            string FirstName = (string)userPin.Rows[row]["FName"];
                            string LastName  = (string)userPin.Rows[row]["LName"];
                            bool   Status    = (bool)userPin.Rows[row]["Status"];
                            //puts the user information of first name, last name and status and changes the top info bar
                            this.topInfoBar1.StaffNameLabel.Text = "Name: " + FirstName + " " + LastName;
                            if (Status == false)
                            {
                                this.topInfoBar1.StatusLabel.Text = "Status: " + "Clocked Out";
                            }
                            else if (Status == true)
                            {
                                this.topInfoBar1.StatusLabel.Text = "Status: " + "Clocked In";
                            }
                        }
                    }
        }
Esempio n. 6
0
        private void ManagerMainMenuClosing(object sender, FormClosingEventArgs e)
        {
            var staffLogin = new StaffLogin();

            Hide();
            staffLogin.Show();
        }
Esempio n. 7
0
        //Run this code when ClockIn button is clicked.
        private void ClockInButton_Click(object sender, EventArgs e)
        {
            using (StaffLogin login = new StaffLogin())
                using (SqlConnection myConnection = new SqlConnection(str))
                    using (SqlDataAdapter ClockAdapter = new SqlDataAdapter($"SELECT * FROM ClockInClockOut", myConnection))
                        using (SqlDataAdapter employeePin = new SqlDataAdapter($"SELECT * FROM Employees WHERE PIN = {login.pin}", myConnection))
                        {
                            DataTable userPin = new DataTable();

                            myConnection.Open();
                            employeePin.Fill(userPin);
                            for (int row = 0; row < userPin.Rows.Count; row++)
                            {
                                int  EmployeeId = (int)userPin.Rows[row]["EmployeeId"];
                                bool Status     = (bool)userPin.Rows[row]["Status"];

                                if (Status == false)
                                {
                                    DateTime Clock = DateTime.Now;
                                    DateTime Date  = DateTime.Today;

                                    Label ClockIn = new Label();
                                    ClockIn.AutoSize = true;
                                    ClockIn.Dock     = DockStyle.Top;
                                    ClockIn.Text     = "Clock In At: " + Clock.ToString("MM/dd/yyyy" + " " + "HH:mm:ss");
                                    ClockInOutPanel.Controls.Add(ClockIn);

                                    //Inserting Data into database ClockInClockOut Table
                                    SqlCommand InsertClockinData = new SqlCommand("insert into ClockInClockOut (EmployeeID, StartTime, EndTime, Date) values ('" + EmployeeId + "', '" + Clock + "', '" + Clock.AddHours(8) + "', '" + Date + "');", myConnection);
                                    //Update Status Data In Database with New Data.
                                    SqlCommand UpdateEmployeeStatus = new SqlCommand("update Employees Set Status = '" + 1 + "' WHERE EmployeeID = '" + EmployeeId + "' ", myConnection);
                                    InsertClockinData.ExecuteNonQuery();
                                    UpdateEmployeeStatus.ExecuteNonQuery();
                                    myConnection.Close();
                                    CheckStatus();
                                }

                                else if (Status == true)
                                {
                                    DateTime Clock = DateTime.Now;
                                    DateTime Date  = DateTime.Today;

                                    Label ClockOut = new Label();
                                    ClockOut.AutoSize = true;
                                    ClockOut.Dock     = DockStyle.Top;
                                    ClockOut.Text     = "Clock Out At: " + Clock.ToString("MM/dd/yyyy" + " " + "HH:mm:ss");
                                    ClockInOutPanel.Controls.Add(ClockOut);

                                    //Update EndTime in database ClockInClockOut Table with new EndTime Data.
                                    SqlCommand UpdateEndTime = new SqlCommand("update ClockInClockOut Set EndTime = '" + Clock + "' WHERE EmployeeID = '" + EmployeeId + "' AND Date = '" + Date + "' ", myConnection);
                                    //Update Status in database Employee Table with new Status Data
                                    SqlCommand UpdateEmployeeStatus = new SqlCommand("update Employees Set Status = '" + 0 + "' WHERE EmployeeID = '" + EmployeeId + "' ", myConnection);
                                    UpdateEndTime.ExecuteNonQuery();
                                    UpdateEmployeeStatus.ExecuteNonQuery();
                                    CheckStatus();
                                }
                            }
                        }
        }
Esempio n. 8
0
        private void WorkSchedule_Load(object sender, EventArgs e)
        {
            using (SqlConnection myConnection = new SqlConnection(str))
            {
                CheckStatus();
                int employeeID = 0;
                using (StaffLogin login = new StaffLogin())
                    using (SqlDataAdapter employeePin = new SqlDataAdapter($"SELECT * FROM Employees WHERE PIN = {login.pin}", myConnection))
                    {
                        DataTable userPin = new DataTable();

                        myConnection.Open();
                        employeePin.Fill(userPin);
                        myConnection.Close();
                        for (int row = 0; row < userPin.Rows.Count; row++)
                        {
                            employeeID = (int)userPin.Rows[row]["EmployeeID"];
                            string FirstName = (string)userPin.Rows[row]["FName"];
                            string LastName  = (string)userPin.Rows[row]["LName"];
                            this.topInfoBar1.StaffNameLabel.Text = "Name: " + FirstName + " " + LastName;
                            nameLabel.Text = FirstName + " " + LastName;
                        }
                    }

                //Checks employee id to make sure only the employee who is currently signed in can view their pay stubs
                using (SqlDataAdapter clientPayStubAdapter = new SqlDataAdapter($"SELECT * FROM Schedule WHERE EmployeeID = {employeeID}", myConnection))
                {
                    DataTable clientPayStub = new DataTable();

                    myConnection.Open();
                    clientPayStubAdapter.Fill(clientPayStub);
                    myConnection.Close();
                    for (int row = 0; row < clientPayStub.Rows.Count; row++)
                    {
                        DateTime startDateTime = (DateTime)clientPayStub.Rows[row]["StartDateTime"];
                        DateTime endDateTime   = (DateTime)clientPayStub.Rows[row]["EndDateTime"];

                        //pushing pay stubs to list box
                        scheduleListBox.Items.Add($"Start: {startDateTime,-20} End: {endDateTime,-20}");
                    }
                }
            }
        }
Esempio n. 9
0
        private void RequestTimeOff_Load(object sender, EventArgs e)
        {
            CheckStatus();
            using (StaffLogin login = new StaffLogin())
                using (SqlConnection myConnection = new SqlConnection(str))
                    using (SqlDataAdapter employeePin = new SqlDataAdapter($"SELECT * FROM Employees WHERE PIN = {login.pin}", myConnection))
                    {
                        DataTable userPin = new DataTable();

                        myConnection.Open();
                        employeePin.Fill(userPin);
                        myConnection.Close();
                        for (int row = 0; row < userPin.Rows.Count; row++)
                        {
                            string FirstName = (string)userPin.Rows[row]["FName"];
                            string LastName  = (string)userPin.Rows[row]["LName"];
                            this.topInfoBar1.StaffNameLabel.Text = "Name: " + FirstName + " " + LastName;
                        }
                    }
        }
Esempio n. 10
0
        private void GetData()
        {
            dbConnectionString = ConfigurationManager.ConnectionStrings["WorkerPunchClock.Properties.Settings.WorkersConnectionString"].ConnectionString;
            using (StaffLogin login = new StaffLogin())
                using (SqlConnection myConnection = new SqlConnection(dbConnectionString))
                    using (SqlDataAdapter employeePin = new SqlDataAdapter($"SELECT * FROM Employees WHERE PIN = {login.pin}", myConnection))
                    {
                        DataTable userPin = new DataTable();

                        myConnection.Open();
                        employeePin.Fill(userPin);
                        myConnection.Close();
                        for (int row = 0; row < userPin.Rows.Count; row++)
                        {
                            string FirstName = (string)userPin.Rows[row]["FName"];
                            string LastName  = (string)userPin.Rows[row]["LName"];
                            StaffNameLabel.Text = "Name: " + FirstName + " " + LastName;
                        }
                    }
        }
        //On load calls checkstatus
        private void PayStub_Load(object sender, EventArgs e)
        {
            CheckStatus();
            using (SqlConnection myConnection = new SqlConnection(str))
            {
                int employeeID = 0;
                using (StaffLogin login = new StaffLogin())
                    using (SqlDataAdapter employeePin = new SqlDataAdapter($"SELECT * FROM Employees WHERE PIN = {login.pin}", myConnection))
                    {
                        DataTable userPin = new DataTable();

                        myConnection.Open();
                        employeePin.Fill(userPin);
                        myConnection.Close();
                        for (int row = 0; row < userPin.Rows.Count; row++)
                        {
                            employeeID = (int)userPin.Rows[row]["EmployeeID"];
                            string FirstName = (string)userPin.Rows[row]["FName"];
                            string LastName  = (string)userPin.Rows[row]["LName"];
                            this.topInfoBar1.StaffNameLabel.Text = "Name: " + FirstName + " " + LastName;
                        }
                    }
                using (SqlDataAdapter clientPayStubAdapter = new SqlDataAdapter($"SELECT * FROM Paystub WHERE EmployeeID = {employeeID}", myConnection))
                {
                    DataTable clientPayStub = new DataTable();

                    myConnection.Open();
                    clientPayStubAdapter.Fill(clientPayStub);
                    myConnection.Close();
                    for (int row = 0; row < clientPayStub.Rows.Count; row++)
                    {
                        int     payStubID  = (int)clientPayStub.Rows[row]["PayStubID"];
                        decimal totalHours = (decimal)clientPayStub.Rows[row]["TotalHours"];
                        decimal totalPay   = (decimal)clientPayStub.Rows[row]["TotalPay"];

                        payStubListBox.Items.Add($"ID: {payStubID, -20} Total Hours: {totalHours, -20} Total Pay: {totalPay, -20} ");
                    }
                }
            }
        }
Esempio n. 12
0
        private void Request_Click(object sender, EventArgs e)
        {
            using (StaffLogin login = new StaffLogin())
                using (SqlConnection myConnection = new SqlConnection(str))
                    using (SqlDataAdapter employeePin = new SqlDataAdapter($"SELECT * FROM Employees WHERE PIN = {login.pin}", myConnection))
                    {
                        DataTable userPin = new DataTable();

                        myConnection.Open();
                        employeePin.Fill(userPin);
                        myConnection.Close();

                        for (int i = 0; i < userPin.Rows.Count; i++)
                        {
                            int employeeID = (int)userPin.Rows[i]["EmployeeID"];
                            var startDate  = StartTimeOff.Value.Date;
                            var endDate    = EndTimeOff.Value.Date;
                            var status     = "false";

                            string insert = "INSERT into RequestTimeOff (EmployeeID, StartDate, EndDate, Status) " + "VALUES (" + employeeID + ", '" + startDate + "', '" + endDate + "', '" + status + "')";

                            var Days = (endDate - startDate).TotalDays;

                            MessageBox.Show("You have requested " + Days + " days off");


                            using (SqlCommand s = new SqlCommand(insert))
                            {
                                s.Connection = myConnection;
                                myConnection.Open();
                                s.ExecuteNonQuery();
                                myConnection.Close();
                            }
                        }
                    }
        }