Beispiel #1
0
        public void getEmployee()
        {
            var emp = db.Employees.Find(EmployeeID);

            txtName.Text = emp.EmployeeName;
            txtJob.Text  = emp.Job.JobName;
            byte[]       img = emp.Photo;
            MemoryStream ms  = new MemoryStream(img);

            pBox.Image = Image.FromStream(ms);

            timer1.Enabled = true;

            var _emp = (from em in db.EmployeesDailies
                        where em.EmployeeID == EmployeeID
                        select em).ToList();

            if (_emp.Count == 0)
            {
                EDM.EmployeesDaily ed = new EDM.EmployeesDaily()
                {
                    EmployeeID = EmployeeID,
                    DateComing = DateTime.Now,
                    Editable   = true,
                };
                db.EmployeesDailies.Add(ed);
            }
            else
            {
                foreach (var item in _emp)
                {
                    if (item.Editable == true)
                    {
                        dtComing.EditValue  = item.DateComing;
                        dtLeaving.EditValue = DateTime.Now;
                        item.DateLeaving    = Convert.ToDateTime(dtLeaving.EditValue);
                        item.Editable       = false;
                        item.Hours          = (item.DateLeaving - item.DateComing).ToString();
                        add = false;
                    }
                }
                if (add)
                {
                    EDM.EmployeesDaily ed = new EDM.EmployeesDaily()
                    {
                        EmployeeID = EmployeeID,
                        DateComing = DateTime.Now,
                        Editable   = true,
                    };
                    db.EmployeesDailies.Add(ed);
                }
            }
            db.SaveChanges();
        }
Beispiel #2
0
        private void btnDaily_Click(object sender, EventArgs e)
        {
            var _emp = (from em in db.EmployeesDailies
                        where em.EmployeeID == EmployeeID
                        select em).ToList();

            if (_emp.Count == 0)
            {
                EDM.EmployeesDaily ed = new EDM.EmployeesDaily()
                {
                    EmployeeID = EmployeeID,
                    DateComing = DateTime.Now,
                    Editable   = true,
                };
                db.EmployeesDailies.Add(ed);
            }
            else
            {
                foreach (var item in _emp)
                {
                    if (item.Editable == true)
                    {
                        item.DateLeaving = Convert.ToDateTime(DateTime.Now);
                        item.Editable    = false;
                        item.Hours       = (item.DateLeaving - item.DateComing).ToString();
                        add = false;
                    }
                }
                if (add)
                {
                    EDM.EmployeesDaily ed = new EDM.EmployeesDaily()
                    {
                        EmployeeID = EmployeeID,
                        DateComing = DateTime.Now,
                        Editable   = true,
                    };
                    db.EmployeesDailies.Add(ed);
                }
            }
            db.SaveChanges();
            XtraMessageBox.Show("تم بنجاح", "حضور / إنصرف", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }