private void viewScheduleToolStripMenuItem_Click(object sender, EventArgs e) { String id = lv.SelectedItems[0].SubItems[1].Text; //MessageBox.Show(id); Employee emp, emp1 = new Employee(); emp1.empid = id; emp = emp1.SELECT_BY_ID(); emp.GET_BASIC_PAY(); emp.GET_BRANCH_ASSIGNMENT(); emp.GET_EMPLOYMENT_STATUS(); emp.GET_IMAGE_BY_ID(); emp.GET_CURRENT_POSITION(); emp.LIST_BENEFITS(); pnlops.Controls.Clear(); Emp_Sched es = new Emp_Sched(); es.empid = emp.empid; emp.schedule = es.SELECT_BY_EMPID(); emp_view_sched c = new emp_view_sched(); c.emp = emp; c.Width = pnlops.Width; pnlops.Height = c.Height; pnlops.Controls.Add(c); }
private void tztpassword_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode.ToString().Equals("Return")) { Employee emp, emp1 = new Employee(); emp1.empid = txtid.Text; String hash; using (MD5 md5Hash = MD5.Create()) { hash = Global.GetMd5Hash(md5Hash, txtpassword.Text); } emp1.password = hash; emp = emp1.SELECT_BY_IDPASS(); //MessageBox.Show(hash); if (emp != null) { Global.CURRENT_USER.empid = emp.empid; Global.CURRENT_USER = emp; Global.CURRENT_USER.pic = emp.GET_IMAGE_BY_ID(); Global.CURRENT_USER.basic_pay = emp.GET_BASIC_PAY(); Global.CURRENT_USER.emp_status = emp.GET_EMPLOYMENT_STATUS(); Global.CURRENT_USER.position = emp.GET_CURRENT_POSITION(); Global.CURRENT_USER.branch = emp.GET_BRANCH_ASSIGNMENT(); //CREATE A RESTRICTION OBJECT Emp_Restriction r = new Emp_Restriction(); //SET CURRENT USER RESTRICTION r.empid = Global.CURRENT_USER.empid; Global.CURRENT_USER.restriction = r.SELECT_BY_ID(); Global.CURRENT_USER.LIST_BENEFITS(); //GET CURRENT USER LATEST SCHEDULE Emp_Sched es = new Emp_Sched(); es.empid = Global.CURRENT_USER.empid; Global.CURRENT_USER.schedule = es.SELECT_BY_EMPID(); Global.CURRENT_USER.ISLOGGEDIN = true; frmMain f = new frmMain(); f.Show(); this.Hide(); } else { MessageBox.Show("Nothing found"); } } }
//BGW asynchronously GET EMPLOYEE DETAILS //ASYNC GET IMAGE FROM DATABASE //ASYNC GET LASTEST POSITION private void bgw_DoWork(object sender, DoWorkEventArgs e) { Employee getter = new Employee(); getter.empid = empid; if (dbcon.CONNECT()) { emp = getter.SELECT_BY_ID(dbcon); emp.GET_IMAGE_BY_ID(dbcon); emp.GET_CURRENT_POSITION(dbcon); Emp_Sched es = new Emp_Sched(); es.empid = emp.empid; empsched = es.SELECT_BY_EMPID(dbcon); } }
//ONCE ASYNC GET OF ATTENDANCE IS DONE //1. LIST THE ATTENDANCE IN THE LISTBOX PROVIDED //2. START RETRIEVING THE EMPLOYEE'S SCHEDULE private void bgwattendance_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (dbcon.DISCONNECT()) { int ctr = 1; if (attendancedt != null) { foreach (DataRow dr in attendancedt.Rows) { DateTime d = Convert.ToDateTime(dr["date_"].ToString()); string time_attendance = dr["attendance"].ToString(); ListViewItem li = new ListViewItem(); li.Text = ctr.ToString(); li.SubItems.Add(d.ToLongDateString()); li.SubItems.Add(time_attendance); //========================================================//begin //RECONSTRUCT AND SHOW THE EMPLOYEE SCHEDULE //THEN COMPARE SCHEDULE WITH HIS/HERE BIOMETRICS ATTENDANCE Emp_Sched es = new Emp_Sched(); es.empid = empid;// EMPID OF THE EMPLOYEE empsched = es.SELECT_BY_EMPID(); String SCHEDULE_FOR_THE_DAY = ""; //GET SCHEDULE DEPENDING ON THE DAY OF THE WEEK switch (d.DayOfWeek) { case DayOfWeek.Monday: { SCHEDULE_FOR_THE_DAY = empsched.mon; break; } case DayOfWeek.Tuesday: { SCHEDULE_FOR_THE_DAY = empsched.tue; break; } case DayOfWeek.Wednesday: { SCHEDULE_FOR_THE_DAY = empsched.wed; break; } case DayOfWeek.Thursday: { SCHEDULE_FOR_THE_DAY = empsched.thu; break; } case DayOfWeek.Friday: { SCHEDULE_FOR_THE_DAY = empsched.fri; break; } case DayOfWeek.Saturday: { SCHEDULE_FOR_THE_DAY = empsched.sat; break; } case DayOfWeek.Sunday: { SCHEDULE_FOR_THE_DAY = empsched.sun; break; } } //IF ATTENDANCE IS MONDAY THEN COMPARE WITH MONDAY SCHEDULE //SO WE NEED TO RECONSTRUCT SCHEDULE FOR ALL DAYS OF THE WEEK //RECONSTRUCT SCHEDULE AND CREATE A DATETIME //WITH DATE SAME AS THE ATTENDANCE //BUT TIME IS FETCH FROM THE EMPLOYEE SCHEULE IN THE DATABASE String[] SPLITTED_SCHEDULE_ID = SCHEDULE_FOR_THE_DAY.Split('-'); //CHECK FOR TIME-IN-TIME-OUT-TIME-IN-TIME-OUT //KIND OF SCHEDULE if (SPLITTED_SCHEDULE_ID.Length == 8) { AM_IN_HOUR = Convert.ToInt32(SPLITTED_SCHEDULE_ID[0]); AM_IN_MIN = Convert.ToInt32(SPLITTED_SCHEDULE_ID[1]); AM_OUT_HOUR = Convert.ToInt32(SPLITTED_SCHEDULE_ID[2]); AM_OUT_MIN = Convert.ToInt32(SPLITTED_SCHEDULE_ID[3]); PM_IN_HOUR = Convert.ToInt32(SPLITTED_SCHEDULE_ID[4]); PM_IN_MIN = Convert.ToInt32(SPLITTED_SCHEDULE_ID[5]); PM_OUT_HOUR = Convert.ToInt32(SPLITTED_SCHEDULE_ID[6]); PM_OUT_MIN = Convert.ToInt32(SPLITTED_SCHEDULE_ID[7]); AM_IN_SCHED = new DateTime(d.Year, d.Month, d.Day, AM_IN_HOUR, AM_IN_MIN, 0); AM_OUT_SCHED = new DateTime(d.Year, d.Month, d.Day, AM_OUT_HOUR, AM_OUT_MIN, 0); PM_IN_SCHED = new DateTime(d.Year, d.Month, d.Day, PM_IN_HOUR, PM_IN_MIN, 0); PM_OUT_SCHED = new DateTime(d.Year, d.Month, d.Day, PM_OUT_HOUR, PM_OUT_MIN, 0); //NOW THAT THE SCHEDULE IS RECONSTRUCTED //WE NEED TO RECONSTRUCT ATTENDANCE COMPARE IT WITH THE SCHEDULE string[] SPLITTED_BIOMETRICS_ATTENDANCE = time_attendance.Split(','); //RECONSCTRUCT THE ATTENDANCE //4 HERE MEANS //TIME-IN, TIME-OUT, TIME-IN, TIME-OUT //THERE ARE 4 WORDS IN BETWEEN COMMA "," if ((SPLITTED_BIOMETRICS_ATTENDANCE.Length == 4)) { AM_IN_ATT = Convert.ToDateTime(d.ToShortDateString() + " " + SPLITTED_BIOMETRICS_ATTENDANCE[0]); AM_OUT_ATT = Convert.ToDateTime(d.ToShortDateString() + " " + SPLITTED_BIOMETRICS_ATTENDANCE[1]); PM_IN_ATT = Convert.ToDateTime(d.ToShortDateString() + " " + SPLITTED_BIOMETRICS_ATTENDANCE[2]); PM_OUT_ATT = Convert.ToDateTime(d.ToShortDateString() + " " + SPLITTED_BIOMETRICS_ATTENDANCE[3]); TimeSpan am_in_diff = AM_IN_ATT - AM_IN_SCHED; int am_late = ((int)am_in_diff.TotalMinutes > Properties.Settings.Default.MIN_LATE_GRACE_PERIOD)? (int)am_in_diff.TotalMinutes: 0; TimeSpan am_out_diff = AM_OUT_SCHED - AM_OUT_ATT; int am_ut = ((int)am_out_diff.TotalMinutes > 0) ? Math.Abs((int)am_out_diff.TotalMinutes) : 0; li.SubItems.Add((am_late + am_ut).ToString()); } else if ((SPLITTED_BIOMETRICS_ATTENDANCE.Length == 2)) { IN_ATT = Convert.ToDateTime(d.ToShortDateString() + " " + SPLITTED_BIOMETRICS_ATTENDANCE[0]); OUT_ATT = Convert.ToDateTime(d.ToShortDateString() + " " + SPLITTED_BIOMETRICS_ATTENDANCE[1]); //IF THE ATTENDANCE IS IN-OUT ONLY //DETERMINE IF IT IS AM/PM if (IN_ATT.ToString("tt", CultureInfo.InvariantCulture) == "AM") { //li.SubItems.Add("ATTENDANCE IS AM_ONLY"); //CHECK FOR HOURS_IN_SERVICE TimeSpan in_diff = IN_ATT - AM_IN_SCHED; int in_late = ((int)in_diff.TotalMinutes > Properties.Settings.Default.MIN_LATE_GRACE_PERIOD) ? (int)in_diff.TotalMinutes : 0; TimeSpan HOURS_IN_SERVICE = OUT_ATT.Subtract(AM_IN_SCHED); //CREATE A TIME_SPAN (1 HOUR LUNCH BREAK) TimeSpan LUNCH_BREAK = TimeSpan.FromHours(1); //SUBTRACT LUNCH BREAK FROMT HE HOURS_IN_SERVICE li.SubItems.Add("TOTAL_HOURS : " + HOURS_IN_SERVICE.Subtract(LUNCH_BREAK).ToString()); } else { li.SubItems.Add("ATTENDANCE IS PM_ONLY..."); //CHECK FOR HOURS_IN_SERVICE //li.SubItems.Add("INAPPROPRIATE ATTENDANCE..."); } } else if ((SPLITTED_BIOMETRICS_ATTENDANCE.Length == 3) || (SPLITTED_BIOMETRICS_ATTENDANCE.Length > 4)) { li.SubItems.Add("INAPPROPRIATE ATTENDANCE..."); } } else if (SPLITTED_SCHEDULE_ID.Length == 4) { //THIS WILL EXECUTE IF EMPLOYEE SCHEDULE IS LIKE 8-0-12-0 //LIKE TIME-IN, TIME-OUT KIND OF SCHEDULE li.SubItems.Add("SCHEDULE IS NOT SET TO TIME-IN, TIME-OUT, TIME-IN, TIME-OUT"); } else { //IF NO SCHEDULE FOR THIS DAY //YET THERE IS AN ATTENDANCE li.SubItems.Add("NO SCHEDULE FOR THIS DAY, CHECKING FOR OVERTIME..."); } //====================================================//end lbattendance.Items.Add(li); ctr++; } } else { lbattendance.Items.Add("No Attendance found..."); }//END IF ATTENDANCE != NULL lblaction.Text = "completed..."; pb.Value = pb.Value + 20; lblaction.Text = "retrieving employee schedule..."; TimeSpan span = TimeSpan.FromMinutes(TOTAL_LATES_FOR_THIS_CUTOFF); int total_hours_late = (int)span.TotalHours; lbltotallate.Text = (total_hours_late > 1)? total_hours_late.ToString() + " Hours " + span.Minutes.ToString() + " Minutes" : total_hours_late.ToString() + " Hour " + span.Minutes.ToString() + " Minutes"; //bgwschedule.RunWorkerAsync(); }//END IF DBCON.DISCONNECT }