Exemplo n.º 1
0
 public void InsertoDB(int empno, DateTime dtime, string mode)
 {
     try
     {
         BiometricsLogData biometricsLogData = new BiometricsLogData();
         biometricsLogData.MODE  = mode;
         biometricsLogData.EMPN  = empno;
         biometricsLogData.DTIME = dtime;
         db.BiometricsLogDatas.Add(biometricsLogData);
         db.SaveChanges();
     }
     catch (Exception)
     {
         MessageBox.Show("Something went wrong!", "System Error!", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
        private void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var db = new LetranIntegratedSystemEntities())
                {
                    BiometricsLogData bld = new BiometricsLogData();
                    var emp           = db.Employees.Where(m => m.EmployeeID == empid).FirstOrDefault();
                    var timeinentry   = db.BiometricsLogDatas.Where(m => m.Id == timeinID).FirstOrDefault();
                    var breakoutentry = db.BiometricsLogDatas.Where(m => m.Id == breakoutID).FirstOrDefault();
                    var breakinentry  = db.BiometricsLogDatas.Where(m => m.Id == breakinID).FirstOrDefault();
                    var timeoutentry  = db.BiometricsLogDatas.Where(m => m.Id == timeoutID).FirstOrDefault();


                    if (timeinentry == null && !String.IsNullOrEmpty(timeIn.Text))
                    {
                        DateTime timeindate = Convert.ToDateTime(dpDate.SelectedDate);
                        DateTime timeintime = Convert.ToDateTime(timeIn.Text);
                        bld.EMPN   = Convert.ToInt32(emp.bioid);
                        bld.DTIME  = timeindate.Date + timeintime.TimeOfDay;
                        bld.REMARK = txtRemark.Text;
                        bld.MODE   = "I";
                        bld.REMARK = txtRemark.Text = String.IsNullOrEmpty(txtRemark.Text) ? null : txtRemark.Text;
                        db.BiometricsLogDatas.Add(bld);
                        db.SaveChanges();
                    }

                    if (timeinentry != null)
                    {
                        if (String.IsNullOrEmpty(timeIn.Text))
                        {
                            db.BiometricsLogDatas.Remove(timeinentry);
                            db.SaveChanges();
                        }
                        else
                        {
                            DateTime timeindate = timeinentry.DTIME.Date;
                            DateTime timeintime = Convert.ToDateTime(timeIn.Text);
                            timeinentry.DTIME  = timeindate.Date + timeintime.TimeOfDay;
                            timeinentry.REMARK = txtRemark.Text = String.IsNullOrEmpty(txtRemark.Text) ? null : txtRemark.Text;
                            db.SaveChanges();
                        }
                    }

                    if (breakoutentry == null && !String.IsNullOrEmpty(breakOut.Text))
                    {
                        DateTime breakoutdate = Convert.ToDateTime(dpDate.SelectedDate);
                        DateTime breakouttime = Convert.ToDateTime(breakOut.Text);
                        bld.EMPN   = Convert.ToInt32(emp.bioid);
                        bld.DTIME  = breakoutdate.Date + breakouttime.TimeOfDay;
                        bld.REMARK = txtRemark.Text;
                        bld.MODE   = "BO";
                        bld.REMARK = txtRemark.Text = String.IsNullOrEmpty(txtRemark.Text) ? null : txtRemark.Text;
                        db.BiometricsLogDatas.Add(bld);
                        db.SaveChanges();
                    }

                    if (breakoutentry != null)
                    {
                        if (String.IsNullOrEmpty(breakOut.Text))
                        {
                            db.BiometricsLogDatas.Remove(breakoutentry);
                            db.SaveChanges();
                        }
                        else
                        {
                            DateTime breakoutdate = timeinentry.DTIME.Date;
                            DateTime breakouttime = Convert.ToDateTime(breakOut.Text);
                            breakoutentry.DTIME  = breakoutdate.Date + breakouttime.TimeOfDay;
                            breakoutentry.REMARK = txtRemark.Text = String.IsNullOrEmpty(txtRemark.Text) ? null : txtRemark.Text;
                            db.SaveChanges();
                        }
                    }


                    if (breakinentry == null && !String.IsNullOrEmpty(breakIn.Text))
                    {
                        DateTime breakindate = Convert.ToDateTime(dpDate.SelectedDate);
                        DateTime breakintime = Convert.ToDateTime(breakIn.Text);
                        bld.EMPN   = Convert.ToInt32(emp.bioid);
                        bld.DTIME  = breakindate.Date + breakintime.TimeOfDay;
                        bld.REMARK = txtRemark.Text;
                        bld.MODE   = "BI";
                        bld.REMARK = txtRemark.Text = String.IsNullOrEmpty(txtRemark.Text) ? null : txtRemark.Text;
                        db.BiometricsLogDatas.Add(bld);
                        db.SaveChanges();
                    }

                    if (breakinentry != null)
                    {
                        if (String.IsNullOrEmpty(breakIn.Text))
                        {
                            db.BiometricsLogDatas.Remove(breakinentry);
                            db.SaveChanges();
                        }
                        else
                        {
                            DateTime breakindate = timeinentry.DTIME.Date;
                            DateTime breakintime = Convert.ToDateTime(breakIn.Text);
                            breakinentry.DTIME  = breakindate.Date + breakintime.TimeOfDay;
                            breakinentry.REMARK = String.IsNullOrEmpty(txtRemark.Text) ? null : txtRemark.Text;
                            db.SaveChanges();
                        }
                    }


                    if (timeoutentry == null && !String.IsNullOrEmpty(timeOut.Text))
                    {
                        DateTime timeoutdate = Convert.ToDateTime(dpDate.SelectedDate);
                        DateTime timeouttime = Convert.ToDateTime(timeOut.Text);
                        bld.EMPN   = Convert.ToInt32(emp.bioid);
                        bld.DTIME  = timeoutdate.Date + timeouttime.TimeOfDay;
                        bld.MODE   = "O";
                        bld.REMARK = txtRemark.Text = String.IsNullOrEmpty(txtRemark.Text) ? null : txtRemark.Text;
                        db.BiometricsLogDatas.Add(bld);
                        db.SaveChanges();
                    }

                    if (timeoutentry != null)
                    {
                        if (String.IsNullOrEmpty(timeOut.Text))
                        {
                            db.BiometricsLogDatas.Remove(timeoutentry);
                            db.SaveChanges();
                        }
                        else
                        {
                            DateTime timeoutdate = timeinentry.DTIME.Date;
                            DateTime timeouttime = Convert.ToDateTime(timeOut.Text);
                            timeoutentry.DTIME  = timeoutdate.Date + timeouttime.TimeOfDay;
                            timeoutentry.REMARK = String.IsNullOrEmpty(txtRemark.Text) ? null : txtRemark.Text;
                            db.SaveChanges();
                        }
                    }

                    MessageBox.Show("Updating attendance was successful", "System Successs!", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Something went wrong.", "System Error!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 3
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var db = new LetranIntegratedSystemEntities())
                {
                    BiometricsLogData bld = new BiometricsLogData();
                    if (cbEmployee.SelectedItem != null && dpDate.SelectedDate != null)
                    {
                        var empid = Convert.ToInt32(cbEmployee.SelectedValue);
                        var emp   = db.Employees.Where(m => m.EmployeeID == empid).FirstOrDefault();

                        DateTime date = Convert.ToDateTime(dpDate.SelectedDate);



                        if (timeIn.Text != null)
                        {
                            DateTime time = Convert.ToDateTime(timeIn.Text);
                            bld.EMPN   = Convert.ToInt32(emp.bioid);
                            bld.DTIME  = date.Date + time.TimeOfDay;
                            bld.REMARK = String.IsNullOrEmpty(txtRemark.Text) ? null : txtRemark.Text;
                            bld.MODE   = "I";
                            db.BiometricsLogDatas.Add(bld);
                            db.SaveChanges();
                        }
                        if (breakOut.Text != null)
                        {
                            DateTime time = Convert.ToDateTime(breakOut.Text);
                            bld.EMPN   = Convert.ToInt32(emp.bioid);
                            bld.DTIME  = date.Date + time.TimeOfDay;
                            bld.MODE   = "BO";
                            bld.REMARK = String.IsNullOrEmpty(txtRemark.Text) ? null : txtRemark.Text;
                            db.BiometricsLogDatas.Add(bld);
                            db.SaveChanges();
                        }
                        if (breakIn.Text != null)
                        {
                            DateTime time = Convert.ToDateTime(breakIn.Text);
                            bld.EMPN   = Convert.ToInt32(emp.bioid);
                            bld.DTIME  = date.Date + time.TimeOfDay;
                            bld.REMARK = String.IsNullOrEmpty(txtRemark.Text) ? null : txtRemark.Text;
                            bld.MODE   = "BI";
                            db.BiometricsLogDatas.Add(bld);
                            db.SaveChanges();
                        }
                        if (timeOut.Text != null)
                        {
                            DateTime time = Convert.ToDateTime(timeOut.Text);
                            bld.EMPN   = Convert.ToInt32(emp.bioid);
                            bld.DTIME  = date.Date + time.TimeOfDay;
                            bld.REMARK = String.IsNullOrEmpty(txtRemark.Text) ? null : txtRemark.Text;
                            bld.MODE   = "O";
                            db.BiometricsLogDatas.Add(bld);
                            db.SaveChanges();
                        }


                        MessageBox.Show("Added Successfully.", "System Success", MessageBoxButton.OK, MessageBoxImage.Information);
                        Clear();
                    }
                    else
                    {
                        MessageBox.Show("Complete the required data.", "System Warning!", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Something went wrong.", "System Error!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }