Beispiel #1
0
        private void button_Click_Enroll(object sender, EventArgs e)
        {
            if (m_bitmap_Face != null)
            {
                if (!checkEmpty())
                {
                    if (checkValidate())
                    {
                        emp.IMG_FACE = per.IMG_FACE;
                        emp.ID_PS    = per.ID;
                        emp.ID       = DAL_EMPLOYEE.getIDNew();
                        emp.NAME     = txt_HoTen.Text;
                        emp.CMT      = txt_Cmt.Text;
                        emp.EMAIL    = txt_Email.Text;
                        if (rbn_Nam.Checked)
                        {
                            emp.GENDER = "Nam";
                        }
                        else
                        {
                            emp.GENDER = "Nữ";
                        }
                        emp.ADDRESS_EMP = txt_DiaChi.Text;
                        emp.BIRTHDAY    = dtp_Bỉthday.Value.Date;
                        emp.PHONE       = txt_SDT.Text;
                        emp.ISDELETE    = false;

                        if (saveImg(m_bitmap_Face))
                        {
                            getPer();
                            string rs = createEmp();

                            if (rs == "Lưu thành công")
                            {
                                m_name = emp.ID.ToString();
                                Thread t = new Thread(HuanluyenThem);
                                t.Start();
                                txt_HoTen.ResetText();
                                txt_DiaChi.ResetText();
                                pictureBox1.ResetText();
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(_message, "Lỗi");
                    }
                }
                else
                {
                    MessageBox.Show(_message, "Lỗi");
                }
            }
            else
            {
                MessageBox.Show("Chưa có ảnh mặt");
            }
        }
Beispiel #2
0
        public static DataTable getAll()
        {
            var lst = DAL_HISTORY.GetAll();
            var dt  = new DataTable();

            dt = BLL_ExtendList.ToDataTable(lst);
            DataColumn STT = new DataColumn();

            STT.ColumnName = "STT";
            dt.Columns.Add(STT);
            DataColumn NV = new DataColumn();

            NV.ColumnName = "NV";
            dt.Columns.Add(NV);
            DataColumn NGAY = new DataColumn();

            NGAY.ColumnName = "NGAY";
            dt.Columns.Add(NGAY);
            DataColumn TG = new DataColumn();

            TG.ColumnName = "TG";
            dt.Columns.Add(TG);
            DataColumn STATUS = new DataColumn();

            STATUS.ColumnName = "STATUS";
            dt.Columns.Add(STATUS);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i]["STT"] = i + 1;
                //PERSONAL per = DAL_PERSON.getPerByID(int.Parse(dt.Rows[i]["ID_PER"].ToString()));
                //if (per.TYPE_PS == 1)
                {
                    dt.Rows[i]["NV"] = DAL_EMPLOYEE.GetFullName(int.Parse(dt.Rows[i]["ID_PER"].ToString()));
                }
                //else
                //{
                //    dt.Rows[i]["NV"] = "Khách";
                //}
                DateTime time = (DateTime)dt.Rows[i]["TIME_UPDATE"];
                dt.Rows[i]["NGAY"] = time.ToShortDateString();
                dt.Rows[i]["TG"]   = time.ToShortTimeString();
                if (dt.Rows[i]["IN_OUT"] == "False")
                {
                    dt.Rows[i]["STATUS"] = "Ra";
                }
                else
                {
                    dt.Rows[i]["STATUS"] = "Ra";
                }
            }
            dt.Columns.Remove("TIME_UPDATE");
            dt.Columns.Remove("IN_OUT");
            return(dt);
        }
Beispiel #3
0
        public static DataTable getByMonth(int month, int year)
        {
            var lst     = DAL_ATTENDANCE.getByMonth(month, year);
            var lstName = DAL_EMPLOYEE.GetAll().Select(x => x.ID).Distinct().ToList();

            if (lst != null)
            {
                DataTable  rs  = new DataTable();
                DataColumn STT = new DataColumn();
                STT.ColumnName = "STT";
                rs.Columns.Add(STT);
                DataColumn ID = new DataColumn();
                ID.ColumnName = "ID";
                rs.Columns.Add(ID);
                DataColumn Name = new DataColumn();
                Name.ColumnName = "Name";
                rs.Columns.Add(Name);
                for (int i = 0; i < DateTime.DaysInMonth(year, month); i++)
                {
                    string     name = (i + 1).ToString();
                    DataColumn cl   = new DataColumn();
                    cl.ColumnName = name;
                    rs.Columns.Add(cl);
                }
                DataColumn Tong = new DataColumn();
                Tong.ColumnName = "Tong";
                rs.Columns.Add(Tong);
                for (int i = 0; i < lstName.Count; i++)
                {
                    DataRow row  = rs.NewRow();
                    int     tong = 0;
                    row[0] = i + 1;
                    row[1] = lstName[i];
                    row[2] = DAL_EMPLOYEE.GetFullName(int.Parse(lstName[i].ToString()));
                    for (int j = 2; j < DateTime.DaysInMonth(year, month) + 2; j++)
                    {
                        if (Check(lst, lstName[i], j, month, year))
                        {
                            row[j] = "x";
                            tong++;
                        }
                    }
                    row["Tong"] = tong.ToString();
                    rs.Rows.Add(row);
                }
                return(rs);
            }
            return(null);
        }
Beispiel #4
0
 private string saveImg(/*Bitmap bmp,*/ string name)
 {
     try
     {
         // Save Image
         string filename = BLL_PARA.PathHistory + Ultis.RemoveUnicode(DAL_EMPLOYEE.GetFullName(int.Parse(name))) + CODE.timeString(DateTime.Now) + ".Jpg";
         //FileStream fstream = new FileStream(filename, FileMode.Create);
         //bmp.Save(fstream, System.Drawing.Imaging.ImageFormat.Jpeg);
         //fstream.Close();
         return(filename);
     }
     catch (Exception)
     {
         return("");
     }
 }
Beispiel #5
0
        public static DataTable SearchEmp(string key)
        {
            var lst = DAL_EMPLOYEE.SearchEmp(key);
            var dt  = new DataTable();

            dt = BLL_ExtendList.ToDataTable(lst);
            DataColumn STT = new DataColumn();

            STT.ColumnName = "STT";
            dt.Columns.Add(STT);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i]["STT"] = i + 1;
            }
            dt.Columns.Remove("ATTENDANCEs");
            dt.Columns.Remove("PERSONAL");
            dt.Columns.Remove("ISDELETE");
            return(dt);
        }
Beispiel #6
0
        public static DataTable filterPage(DateTime s, DateTime e, int num)
        {
            var lst = DAL_HISTORY.filterPage(s, e, num);
            var dt  = new DataTable();

            dt = BLL_ExtendList.ToDataTable(lst);
            DataColumn STT = new DataColumn();

            STT.ColumnName = "STT";
            dt.Columns.Add(STT);
            DataColumn NV = new DataColumn();

            NV.ColumnName = "NV";
            dt.Columns.Add(NV);
            DataColumn NGAY = new DataColumn();

            NGAY.ColumnName = "NGAY";
            dt.Columns.Add(NGAY);
            DataColumn TG = new DataColumn();

            TG.ColumnName = "TG";
            dt.Columns.Add(TG);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i]["STT"] = (num - 1) * 5 + i + 1;
                //PERSONAL per = DAL_PERSON.getPerByID(int.Parse(dt.Rows[i]["ID_PER"].ToString()));
                //if (per.TYPE_PS == 1)
                {
                    dt.Rows[i]["NV"] = DAL_EMPLOYEE.GetFullName(int.Parse(dt.Rows[i]["ID_PER"].ToString()));
                }

                DateTime time = (DateTime)dt.Rows[i]["TIME_UPDATE"];
                dt.Rows[i]["NGAY"] = time.ToShortDateString();
                dt.Rows[i]["TG"]   = time.ToShortTimeString();
            }
            dt.Columns.Remove("TIME_UPDATE");
            dt.Columns.Remove("IN_OUT");


            return(dt);
        }
Beispiel #7
0
        public static DataTable getHisMonth(int id, int month, int year)
        {
            //EMPLOYEE emp = DAL_EMPLOYEE.SearchEmpByName(name);
            var lst = new List <ATTENDANCE>();
            var dt  = new DataTable();

            //if (emp!=null)
            //{
            //int id = emp.ID;
            lst = DAL_ATTENDANCE.getByMonthEmp(month, year, id);
            if (lst.Count > 0)
            {
                dt = BLL_ExtendList.ToDataTable(lst);
                DataColumn STT = new DataColumn();
                STT.ColumnName = "STT";
                dt.Columns.Add(STT);
                DataColumn NAME = new DataColumn();
                NAME.ColumnName = "NAME";
                dt.Columns.Add(NAME);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dt.Rows[i]["STT"]  = i + 1;
                    dt.Rows[i]["NAME"] = DAL_EMPLOYEE.GetFullName(int.Parse(dt.Rows[i]["ID_EMP"].ToString()));
                    var IN = (TimeSpan)dt.Rows[i]["TIME_IN"];
                    //string OUT = dt.Rows[i]["TIME_OUT"];
                    dt.Rows[i]["TIME_IN"] = IN.Hours + ":" + IN.Minutes + ":" + IN.Seconds;
                    try
                    {
                        var OUT = (TimeSpan)dt.Rows[i]["TIME_OUT"];
                        dt.Rows[i]["TIME_OUT"] = OUT.Hours + ":" + OUT.Minutes + ":" + OUT.Seconds;
                    }
                    catch (Exception ex) { }

                    //}
                }
                dt.Columns.Remove("EMPLOYEE");
            }
            return(dt);
        }
Beispiel #8
0
        private void dgv_AllEmp_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            txt_HoTen.Text = dgv_AllEmp.Rows[e.RowIndex].Cells["NAME"].Value.ToString();
            url_Face_Cur   = dgv_AllEmp.Rows[e.RowIndex].Cells["IMG_FACE"].Value.ToString();
            try
            {
                Bitmap img = new Bitmap(url_Face_Cur);
                ptb_ImageCustomer.Image = img;
            }
            catch (Exception)
            {
                ptb_ImageCustomer.Image = new Bitmap(Application.StartupPath + @"\File\noimagefound.Jpg");
            }

            ptb_ImageCustomer.SizeMode = PictureBoxSizeMode.StretchImage;
            txt_Cmt.Text    = dgv_AllEmp.Rows[e.RowIndex].Cells["CMT"].Value.ToString();
            txt_Email.Text  = dgv_AllEmp.Rows[e.RowIndex].Cells["EMAIL"].Value.ToString();
            txt_GhiChu.Text = dgv_AllEmp.Rows[e.RowIndex].Cells["GHICHU"].Value.ToString();
            txt_SDT.Text    = dgv_AllEmp.Rows[e.RowIndex].Cells["PHONE"].Value.ToString();
            if (dgv_AllEmp.Rows[e.RowIndex].Cells["GT"].Value.ToString() == "Nam")
            {
                rbn_Nam.Checked = true;
            }
            else
            {
                rbn_Nu.Checked = true;
            }
            dtp_birthday.Text = dgv_AllEmp.Rows[e.RowIndex].Cells["BIRTHDAY"].Value.ToString();
            txt_DiaChi.Text   = dgv_AllEmp.Rows[e.RowIndex].Cells["ADDRESS"].Value.ToString();
            idps = int.Parse(dgv_AllEmp.Rows[e.RowIndex].Cells["ID_PS"].Value.ToString());
            dgv_history.DataSource = BLL_HISTORY.getByEmp(idps);
            if (dgv_history.Rows.Count > 0)
            {
                dayEnd   = dgv_history.Rows[0].Cells["NGAY"].Value.ToString();
                dayStart = dgv_history.Rows[dgv_history.Rows.Count - 1].Cells["NGAY"].Value.ToString();
            }
            emp = DAL_EMPLOYEE.getEmpByIDPER(idps);
        }
Beispiel #9
0
        public void Recognize(/* Bitmap src*/)
        {
            //while (m_isReadCamera)
            //  {
            try
            {
                updatedTracking = false;
                if (m_isFaceTrack && m_bitmap_to_tracking != null)
                {
                    m_faceTracking.update(m_bitmap_to_tracking);
                    //nhan dang tai day
                    if (m_faceTracking.getSize() > 0)
                    {
                        for (int i = 0; i < m_faceTracking.getSize(); i++)
                        {
                            if (!m_faceTracking.getRecognize_status(i))
                            {
                                Bitmap bmp = null;
                                if (m_faceTracking.getFaceImage(i, ref bmp))
                                {
                                    m_faceTracking.setRecognize_status(i, true);
                                    m_time_list.Add(m_faceTracking.getStartTime(i));
                                    m_bitmap_list.Add(bmp);
                                    int n = 0;
                                }
                            }
                        }
                    }
                }
                if (m_bitmap_list.Count > 0)
                {
                    if (m_bitmap_face != null)
                    {
                        m_bitmap_face.Dispose();
                    }
                    m_bitmap_face = (Bitmap)m_bitmap_list[0].Clone();

                    double confident = 0;
                    String name      = "";
                    int    id        = -1;
                    m_face_recog.recognizeFromImage(m_bitmap_face, out confident, out id, out name);
                    m_panel_result.Invoke(new Action(() =>
                    {
                        Graphics g = Graphics.FromHwnd(m_panel_result.Handle);
                        g.DrawImage(m_bitmap_face, 4, 4, m_panel_result.Width - 8, m_panel_result.Height - 8);
                        g.Dispose();
                    }));
                    m_text_confident.Invoke(new Action(() =>
                    {
                        m_text_confident.Text = Math.Floor(confident * 100).ToString();
                    }));
                    m_text_name.Invoke(new Action(() =>
                    {
                        m_text_name.Text = name;
                    }));
                    m_text_time.Invoke(new Action(() =>
                    {
                        m_text_time.Text = m_time_list[0].ToString();
                    }));
                    if (confident < m_nguongphanloai)
                    {
                        name = "Unknown";
                    }
                    //luu tru tai day
                    if (name != "Unknown")
                    {
                        string fullname = DAL_EMPLOYEE.GetFullName(int.Parse(name));
                        m_text_name.Invoke(new Action(() =>
                        {
                            m_text_name.Text = fullname;
                        }));
                        DateTime time = m_time_list[0];
                        String   s    = m_folder_know_Image + "/" + time.Year.ToString();
                        if (!Directory.Exists(s))
                        {
                            Directory.CreateDirectory(s);
                        }
                        s += "/" + time.Month.ToString();
                        if (!Directory.Exists(s))
                        {
                            Directory.CreateDirectory(s);
                        }
                        s += "/" + time.Day.ToString();
                        if (!Directory.Exists(s))
                        {
                            Directory.CreateDirectory(s);
                        }
                        s += "/" + name + "_" + time.Hour.ToString("00") + time.Minute.ToString("00") + time.Second.ToString("00") + ".jpg";
                        //string imgSave = saveImg(/* Bitmap(s), */name);
                        m_bitmap_list[0].Save(s);

                        HISTORY his = new HISTORY();
                        his.ID          = DAL_HISTORY.getIDNew();
                        his.ID_PER      = int.Parse(name);
                        his.IMG_FACE    = s;
                        his.IMG         = s;
                        his.IN_OUT      = false;
                        his.TIME_UPDATE = DateTime.Now;
                        DAL_HISTORY.INSERT(his);
                        if (DAL_ATTENDANCE.Check(int.Parse(name), his.TIME_UPDATE))
                        {
                            ATTENDANCE att = new ATTENDANCE();
                            att.ID       = DAL_ATTENDANCE.getIDNew();
                            att.ID_EMP   = int.Parse(name);
                            att.DATE_ATT = DateTime.Now.Date;
                            att.TIME_IN  = DateTime.Now.TimeOfDay;
                            att.IMG_IN   = s;
                            DAL_ATTENDANCE.INSERT(att);
                        }
                        else
                        {
                            DAL_ATTENDANCE.updateTimeOut(int.Parse(name), s);
                        }
                        //m_bitmap_list[0].Save(s);
                        m_listView_Thumb.Invoke(new Action(() =>
                        {
                            Image img = Image.FromFile(s);
                            String s_ = "0";
                            imageList.Images.Add(s_, img);
                            ListViewItem lvitem = new ListViewItem();
                            lvitem.ImageIndex   = imageList.Images.Count - 1;
                            if (listItemCur.Count > 8)
                            {
                                listItemCur.Dequeue();
                            }
                            listItemCur.Enqueue(lvitem);
                            //lvitem.Text = name + ":" + confident.ToString();
                            lvitem.Text = fullname;
                            m_listView_Thumb.Items.Clear();
                            var rsv = listItemCur.ToArray();
                            for (int i = rsv.Length - 1; i >= 0; i--)
                            {
                                m_listView_Thumb.Items.Insert(0, (ListViewItem)rsv[i]);
                            }
                            m_listView_Thumb.Refresh();
                        }));

                        //add thong tin vao report
                        string[] arr = new string[6];
                        arr[0] = name;
                        arr[1] = fullname;
                        arr[2] = DateTime.Now.ToString("dd-MMM-yy");
                        arr[3] = DateTime.Now.Hour.ToString("00") + ":" + DateTime.Now.Minute.ToString("00");
                        arr[4] = "";
                        arr[5] = "1";
                        ListViewItem itm = new ListViewItem(arr);
                        //kiem tra ra

                        listView_report.Invoke(new Action(() =>
                        {
                            int index = -1;
                            for (int i = 0; i < listView_report.Items.Count; i++)
                            {
                                if (listView_report.Items[i].SubItems[0].Text == name)
                                {
                                    index = i;
                                    break;
                                }
                            }
                            if (index == -1)
                            {
                                listView_report.Items.Add(itm);
                            }
                            else
                            {
                                listView_report.Items[index].SubItems[4].Text = DateTime.Now.Hour.ToString("00") + ":" + DateTime.Now.Minute.ToString("00");
                            }
                        }));
                    }
                    else
                    {
                        DateTime time = m_time_list[0];
                        String   s    = m_folder_unknow_Image + "/" + time.Year.ToString();
                        if (!Directory.Exists(s))
                        {
                            Directory.CreateDirectory(s);
                        }
                        s += "/" + time.Month.ToString();
                        if (!Directory.Exists(s))
                        {
                            Directory.CreateDirectory(s);
                        }
                        s += "/" + time.Day.ToString();
                        if (!Directory.Exists(s))
                        {
                            Directory.CreateDirectory(s);
                        }
                        s += "/" + name + "_" + time.Hour.ToString("00") + time.Minute.ToString("00") + time.Second.ToString("00") + ".jpg";
                        m_bitmap_list[0].Save(s);
                        m_listView_Thumb.Invoke(new Action(() =>
                        {
                            Image img = Image.FromFile(s);
                            String s_ = "0";
                            imageList.Images.Add(s_, img);
                            //imageList.Images.Add()

                            ListViewItem lvitem = new ListViewItem();
                            lvitem.ImageIndex   = imageList.Images.Count - 1;
                            //lvitem.Text = name + ":" + confident.ToString();
                            lvitem.Text = name;
                            lvitem.Name = s;
                            if (listItemCur.Count > 8)
                            {
                                listItemCur.Dequeue();
                            }
                            listItemCur.Enqueue(lvitem);
                            m_listView_Thumb.Items.Clear();
                            var rsv = listItemCur.ToArray();
                            for (int i = rsv.Length - 1; i >= 0; i--)
                            {
                                m_listView_Thumb.Items.Insert(0, (ListViewItem)rsv[i]);
                            }
                            m_listView_Thumb.Refresh();
                        }));
                    }
                    m_time_list.RemoveAt(0);
                    m_bitmap_list.RemoveAt(0);
                }
            }
            catch (Exception ex)
            {
                updatedTracking = true;
            }
            updatedTracking = true;
            //}
            //bmp.Save("face.png");
            //bmp.Dispose();
        }