private void DataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            AttendanceClass a = new AttendanceClass();

            if (e.ColumnIndex == dataGridView.Columns["Edit"].Index && e.RowIndex >= 0)
            {
                ID = Convert.ToInt32(dataGridView.Rows[dataGridView.CurrentRow.Index].Cells[2].Value);
                UpdateAttendance update = new UpdateAttendance();
                update.ShowDialog();
            }

            if (e.ColumnIndex == dataGridView.Columns["Delete"].Index && e.RowIndex >= 0)
            {
                DialogResult result = MessageBox.Show("Are you sure you want to delete this record?", "Confirm Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

                if (result == DialogResult.Yes)
                {
                    ID = Convert.ToInt32(dataGridView.Rows[dataGridView.CurrentRow.Index].Cells[2].Value);

                    bool success = a.Delete(ID);


                    if (success == true)
                    {
                        MessageBox.Show("Deleted successfully");
                    }
                    else
                    {
                        MessageBox.Show("Cannot delete");
                    }
                }
            }
        }
예제 #2
0
        public bool Insert(AttendanceClass a)
        {
            bool isSuccess = false;

            SqlConnection conn = new SqlConnection(myConnectionString);

            try
            {
                string     sql = "INSERT INTO Attendance(EmpID,date,inTime) VALUES (@EmpID,@date,@inTime)";
                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@AttendID", a.AttendId);
                cmd.Parameters.AddWithValue("@EmpID", a.EmployeeId);
                cmd.Parameters.AddWithValue("@date", a.Date);
                cmd.Parameters.AddWithValue("@inTime", a.ArrivedTime);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception e)
            {
            }
            finally
            {
            }
            return(isSuccess);
        }
예제 #3
0
        private void UpdateAttendance_Load(object sender, EventArgs e)
        {
            dateTimePickerUpdate.Format       = DateTimePickerFormat.Custom;
            dateTimePickerUpdate.CustomFormat = "dd-MM-yyyy";


            lblOutTime.Text = DateTime.Now.ToString("HH:mm");
            a.LeftTime      = lblOutTime.Text;

            AttendanceClass cl = new AttendanceClass();
            DataTable       dt = cl.SelectByID(AttendanceUserControl1.ID);

            foreach (DataRow row in dt.Rows)
            {
                try
                {
                    txtUpdateEmpID.Text = row["EmpID"].ToString();
                    lblInTime.Text      = row["inTime"].ToString();
                    //lblLeftTime.Text = row["outTime"].ToString();
                    //dateTimePickerUpdate.Text = row["date"].ToString();

                    DateTime d    = Convert.ToDateTime(row["date"].ToString());
                    DateTime newD = d.Date;
                    dateTimePickerUpdate.Value = newD;
                }
                catch (Exception exx)
                {
                }
            }
        }
        private void TabPage3_Click(object sender, EventArgs e)
        {
            AttendanceClass a  = new AttendanceClass();
            DataTable       dt = a.Select();

            dataGridView.DataSource = dt;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            AttendanceClass ac = new AttendanceClass();

            String[] time = { "08:15", "08:25", "08:55", "09:15", "08:00", "08:22", "09:05", "08:05", "09:20", "08:35" };
            String[] date = { "9-10-2019", "11-10-2019", "15-10-2019", "12-11-2019", "12-10-2019", "10-09-2019", "27-10-2019", "25-11-2019", "5-11-2019", "12-12-2019" };
            int[]    id   = { 1, 2, 1, 4, 5, 3, 7, 4, 2, 1 };

            for (int x = 0; x < 10; x++)
            {
                ac.Insert(id[x], date[x], time[x]);
            }
        }
        private void AttendanceUserControl_Load(object sender, EventArgs e)
        {
            dateTimePickerSearch.Format       = DateTimePickerFormat.Custom;
            dateTimePickerSearch.CustomFormat = "dd-MM-yyyy";

            dateTimePicker1.Format       = DateTimePickerFormat.Custom;
            dateTimePicker1.CustomFormat = "dd-MM-yyyy";

            AttendanceClass a  = new AttendanceClass();
            DataTable       dt = a.Select();

            dataGridView.DataSource = dt;

            lblInTime.Text = DateTime.Now.ToString("HH:mm");
            a.ArrivedTime  = lblInTime.Text;
        }
        private void BtnDownload_Click(object sender, EventArgs e)
        {
            if (getReport == null)
            {
                MessageBox.Show("No data for a report");
                return;
            }
            AttendanceClass reports = new AttendanceClass();

            if (reports.createPDF(getReport, "D:\\Reports\\AttendanceReport.pdf"))
            {
                MessageBox.Show("Report was downloaded");
            }
            else
            {
                MessageBox.Show("Something went wrong");
            }
        }
예제 #8
0
        public bool Update(AttendanceClass a, int id, String minutes)
        {
            bool isSuccess = false;

            SqlConnection conn = new SqlConnection(myConnectionString);

            try
            {
                string     sql = "UPDATE Attendance SET EmpID=@EmpID,date=@date,inTime=@inTime,outTime=@outTime,hoursWorked=@workedTime WHERE AttendID=@AttendID";
                SqlCommand cmd = new SqlCommand(sql, conn);


                cmd.Parameters.AddWithValue("@EmpID", a.EmployeeId);
                cmd.Parameters.AddWithValue("@date", a.Date);
                cmd.Parameters.AddWithValue("@inTime", a.ArrivedTime);
                cmd.Parameters.AddWithValue("@outTime", a.LeftTime);
                cmd.Parameters.AddWithValue("@AttendID", id);
                cmd.Parameters.AddWithValue("@workedTime", Int32.Parse(minutes));


                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception e)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
 private void DisplayAttendanceReport_Load(object sender, EventArgs e)
 {
     if (AttendanceUserControl1.clickedSortType.Equals("EmpID"))
     {
         AttendanceClass a   = new AttendanceClass();
         DataTable       dts = a.SortByID(AttendanceUserControl1.sortID);
         dataGridView.DataSource = dts;
         getReport = dts;
     }
     else if (AttendanceUserControl1.clickedSortType.Equals("Date"))
     {
         AttendanceClass a  = new AttendanceClass();
         DataTable       dt = a.SortByDate(AttendanceUserControl1.date);
         dataGridView.DataSource = dt;
         getReport = dt;
     }
     else if (AttendanceUserControl1.clickedSortType.Equals("MonthYear"))
     {
         AttendanceClass a  = new AttendanceClass();
         DataTable       dt = a.SortByIDDate(AttendanceUserControl1.month, AttendanceUserControl1.year);
         dataGridView.DataSource = dt;
         getReport = dt;
     }
 }