Example #1
0
        private void removeButton_Click(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand("UPDATE calendar SET employee_id = 0 WHERE day=@day AND shift=@shift", mydb.getConnection);

            cmd.Parameters.Add("@day", SqlDbType.Int).Value   = calendar.convertToInt(dayBox.Text);
            cmd.Parameters.Add("@shift", SqlDbType.Int).Value = Convert.ToInt32(shiftBox.Text);

            mydb.openConnection();

            if (cmd.ExecuteNonQuery() > 0)
            {
                MessageBox.Show("Removed Shift");
                if (salary.fined(400))
                {
                }

                mydb.closeConnection();
            }
            else
            {
                mydb.closeConnection();
            }
        }
Example #2
0
        private void checkInButton_Click(object sender, EventArgs e)
        {
            int      day     = calendar.convertToInt(DateTime.Now.DayOfWeek.ToString());
            DateTime checkin = DateTime.Now;

            SqlCommand cmd = new SqlCommand("UPDATE calendar SET checkin=@checkin WHERE shift=@shift AND day=@day", mydb.getConnection);

            cmd.Parameters.Add("@day", SqlDbType.Int).Value          = day;
            cmd.Parameters.Add("@checkin", SqlDbType.DateTime).Value = checkin;

            TimeSpan shift1Lower = new TimeSpan(7, 0, 0);
            TimeSpan shift1Upper = new TimeSpan(7, 5, 0);
            TimeSpan shift2Lower = new TimeSpan(11, 0, 0);
            TimeSpan shift2Upper = new TimeSpan(11, 5, 0);
            TimeSpan shift3Lower = new TimeSpan(18, 0, 0);
            TimeSpan shift3Upper = new TimeSpan(18, 5, 0);
            TimeSpan shift1End   = new TimeSpan(11, 0, 0);
            TimeSpan shift2End   = new TimeSpan(14, 0, 0);
            TimeSpan shift3End   = new TimeSpan(22, 0, 0);


            int shift;

            if (checkin.TimeOfDay < shift1Upper && checkin.TimeOfDay > shift1Lower)
            {
                shift = 1;
                cmd.Parameters.Add("@shift", SqlDbType.Int).Value = shift;

                mydb.openConnection();

                if (cmd.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("Checkin Completed");
                    mydb.closeConnection();
                }
                else
                {
                    MessageBox.Show("You Don't Have Shift Today");
                    mydb.closeConnection();
                }
            }
            else if (checkin.TimeOfDay < shift1End && checkin.TimeOfDay > shift1Lower)
            {
                shift = 1;
                cmd.Parameters.Add("@shift", SqlDbType.Int).Value = shift;

                mydb.openConnection();

                if (cmd.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("Checkin Completed");
                    MessageBox.Show("You are late !!!");

                    salary.fined(100);

                    mydb.closeConnection();
                }
                else
                {
                    MessageBox.Show("You Don't Have Shift Today");
                    mydb.closeConnection();
                }
            }
            else if (checkin.TimeOfDay < shift2Upper && checkin.TimeOfDay > shift2Lower)
            {
                shift = 2;
                cmd.Parameters.Add("@shift", SqlDbType.Int).Value = shift;

                mydb.openConnection();

                if (cmd.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("Checkin Completed");
                    mydb.closeConnection();
                }
                else
                {
                    MessageBox.Show("You Don't Have Shift Today");
                    mydb.closeConnection();
                }
            }
            else if (checkin.TimeOfDay < shift2End && checkin.TimeOfDay > shift2Lower)
            {
                shift = 2;
                cmd.Parameters.Add("@shift", SqlDbType.Int).Value = shift;

                mydb.openConnection();

                if (cmd.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("Checkin Completed");
                    MessageBox.Show("You are late !!!");

                    salary.fined(100);

                    mydb.closeConnection();
                }
                else
                {
                    MessageBox.Show("You Don't Have Shift Today");
                    mydb.closeConnection();
                }
            }
            else if (checkin.TimeOfDay < shift3Upper && checkin.TimeOfDay > shift3Lower)
            {
                shift = 3;
                cmd.Parameters.Add("@shift", SqlDbType.Int).Value = shift;

                mydb.openConnection();

                if (cmd.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("Checkin Completed");
                    mydb.closeConnection();
                }
                else
                {
                    MessageBox.Show("You Don't Have Shift Today");
                    mydb.closeConnection();
                }
            }
            else if (checkin.TimeOfDay < shift3End && checkin.TimeOfDay > shift3Lower)
            {
                shift = 3;
                cmd.Parameters.Add("@shift", SqlDbType.Int).Value = shift;

                mydb.openConnection();

                if (cmd.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("Checkin Completed");
                    MessageBox.Show("You are late !!!");

                    salary.fined(100);

                    mydb.closeConnection();
                }
                else
                {
                    MessageBox.Show("You Don't Have Shift Today");
                    mydb.closeConnection();
                }
            }
            else
            {
                MessageBox.Show("It's Not Time To Checkin");
            }
        }