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); }
private void button1_Click(object sender, EventArgs e) { s = (DateTime)dateTimePicker1.Value; end = (DateTime)dateTimePicker2.Value; if (s > end) { MessageBox.Show("Vui lòng điều chỉnh lại thời gian bắt đầu và kết thúc", "Thông báo"); } else { PageCount = DAL_HISTORY.PageCount(s, end); button3.Enabled = false; if (PageCount > 1) { button2.Enabled = true; } else { button2.Enabled = false; } dgv_History.DataSource = BLL_HISTORY.filterPage(s, end, 1); if (dgv_History.Rows.Count > 0) { DataGridViewImageColumn img = (DataGridViewImageColumn)dgv_History.Columns["AnhNV"]; img.ImageLayout = DataGridViewImageCellLayout.Stretch; PageCur = 1; for (int i = 0; i < dgv_History.Rows.Count; i++) { try { Bitmap imgv = new Bitmap(dgv_History.Rows[i].Cells["IMG_FACE"].Value.ToString()); img.Image = imgv; } catch (Exception) { img.Image = new Bitmap(Application.StartupPath + @"\File\noimagefound.Jpg"); } dgv_History.Rows[i].MinimumHeight = 80; } } } }
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); }
private void loadDGV() { DateTime now = DateTime.Today; s = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0); end = new DateTime(now.Year, now.Month, now.Day, 23, 59, 0); PageCount = DAL_HISTORY.PageCount(s, end); button3.Enabled = false; if (PageCount > 1) { button2.Enabled = true; } else { button2.Enabled = false; } dgv_History.DataSource = BLL_HISTORY.filterPage(s, end, 1); if (dgv_History.Rows.Count > 0) { DataGridViewImageColumn img = (DataGridViewImageColumn)dgv_History.Columns["AnhNV"]; img.ImageLayout = DataGridViewImageCellLayout.Stretch; PageCur = 1; for (int i = 0; i < dgv_History.Rows.Count; i++) { try { Bitmap imgv = new Bitmap(dgv_History.Rows[i].Cells["IMG_FACE"].Value.ToString()); img.Image = imgv; } catch (Exception) { img.Image = new Bitmap(Application.StartupPath + @"\File\noimagefound.Jpg"); } dgv_History.Rows[i].MinimumHeight = 80; } } }
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(); }