Example #1
0
        private void btn_commit_Click(object sender, EventArgs e)
        {
            //call placement
            if (cmbDept.SelectedItem != null)
            {
                dept = cmbDept.Text;
            }
            else
            {
                MessageBox.Show("Please select a new department before updating.");
                return;
            }



            DialogResult result = MessageBox.Show("Would you like to perform this operation over multiple dates?", "Multiple Dates?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                //INSERTS THE CURRENT DAY
                Placement p = new Placement(date, staffID, dept, PT, hours);
                p.addPlacment();


                //INSERTS REST OF WEEK
                string staffName;

                SqlConnection conn = new SqlConnection(connectionStrings.ConnectionStringUser);
                conn.Open();
                SqlCommand cmd = new SqlCommand("SELECT forename + ' '  + surname from dbo.[user] where id = @staffId", conn);
                cmd.Parameters.AddWithValue("@staffId", staffID);
                staffName = cmd.ExecuteScalar().ToString();;
                conn.Close();

                frmWeeklyInsert wi = new frmWeeklyInsert(staffID, staffName, date, dept);
                wi.ShowDialog();
            }
            else
            {
                Placement p = new Placement(date, staffID, dept, PT, hours);
                p.addPlacment();
            }


            this.Close();
        }
        private void lstStaff_DoubleClick(object sender, EventArgs e)
        {
            double remainingHours;
            //string remainingPlacementType;

            Staff s = new Staff(lstStaff.SelectedItem.ToString());

            getStandardHours(s._staffID);

            Placement p = new Placement(_selectedDate, s._staffID, _department, "Full Day", _standardHours);

            p.notPresent();
            p.checkPlacement();

            p.getWeldTeamUserID();
            p.checkWeldTeamAbsence();


            //CHECKS IF STAFF MEMBERS IN WELD TEAM 2 ARE CURRENTLY ON HOLIDAY OR ABSENT
            if (s._staffID == 165)
            {
                if (p._weldTeamMembersPresent == 1)
                {
                    p._hours = _standardHours / 2;
                    MessageBox.Show("One member of this weld team is either absent or on holiday. Adding half the hours", "Half Placement", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                if (p._weldTeamMembersPresent == 2)
                {
                    p._hours = _standardHours * 0;
                    MessageBox.Show("Both members of this team are either absent or on holiday", "Zero Placement", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }


            if (p._notPresentType == 5 || p._notPresentType == 2)
            {
                MessageBox.Show("This staff member is either absent today or has a full day holiday!", "Cannot Place", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (p._notPresentType == 3)
            {
                MessageBox.Show("This staff member has half day holiday so can only be placed for half day", "Half Day Placement", MessageBoxButtons.OK, MessageBoxIcon.Error);
                remainingHours = _standardHours / 2;
                Placement p3 = new Placement(_selectedDate, s._staffID, _department, "Half Day", remainingHours);
                p3.addPlacment();
            }
            else
            {
                if (p._alreadyPlaced == true)
                {
                    if (p._existingPlacementHours == _standardHours)
                    {
                        MessageBox.Show("Staff member already has a full day placement for this day!", "Already Placed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        if (p._existingPlacementHours != _standardHours && p._existingPlacementHours > 0)
                        {
                            remainingHours = _standardHours - p._existingPlacementHours;
                            MessageBox.Show("Staff member already placed for " + p._existingPlacementHours.ToString(), "Staff member part placed", MessageBoxButtons.OK, MessageBoxIcon.Information);


                            Placement p2 = new Placement(_selectedDate, s._staffID, _department, p._existingPlacementType, remainingHours);
                            p2.addPlacment();
                        }
                        else
                        {
                            DialogResult weekly = MessageBox.Show("Would you like to assign '" + s._fullname + "' more days in " + _department + " this week?", "Weekly Placement", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (weekly == DialogResult.Yes)
                            {
                                //run procedure to populate all the dates for this week --
                                dateInsert di = new dateInsert();
                                di.check_date(_selectedDate);
                                //open form
                                frmWeeklyInsert frm = new frmWeeklyInsert(s._staffID, s._fullname, _selectedDate, _department);
                                frm.ShowDialog();
                            }
                            else
                            {
                                p.addPlacment(); // add placement is here so there is no way it should be the reason for changing the placements  on the next form close
                            }
                        }
                    }
                }
            }



            checkExistingSelections();
        }