Esempio n. 1
0
        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            dateTimePicker1.Value.ToString("yyyy-MM-dd");
            int compNum = DateTime.Compare(dateTimePicker1.Value.Date, DateTime.Now);

            if (compNum > 0)
            {
                MessageBox.Show("查询错误,请选择比当前日期小的时间。");
                button1.Enabled = false;
            }
            else
            {
                DataMysql data = new DataMysql();
                data.dataCon();
                //查询数据库
                string           cmdStr = "Select signlog.id,user.name,signlog.signtime from user,signlog where daytime='" + dateTimePicker1.Value.ToString("yyyy-MM-dd") + "' and signlog.id=user.id ";
                MySqlConnection  con    = new MySqlConnection("server=你的ip;port=3306;user=用户名;password=密码;database=数据库名");
                MySqlCommand     sqlCmd = new MySqlCommand(cmdStr, con);
                MySqlDataAdapter sda    = new MySqlDataAdapter(sqlCmd);
                DataSet          ds     = new DataSet();
                sda.Fill(ds, "sign");
                ds = data.getDataSet(cmdStr);
                if (ds.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show(dateTimePicker1.Value.ToString("yyyy-MM-dd") + "当天没有人员签到哦");
                    button1.Enabled = false;
                }
                else
                {
                    dataGridView1.DataSource = ds.Tables[0];
                    button1.Enabled          = true;
                }
            }
        }
Esempio n. 2
0
 private void idtb_KeyUp(object sender, KeyEventArgs e)
 {
     if (idtb.Text == "请输入员工数字ID")
     {
         MessageBox.Show("您还没有输入员工数字ID");
     }
     else
     {
         DataMysql data = new DataMysql();
         data.dataCon();
         string  cmdStr = "Select * from user where id='" + idtb.Text + "'";
         DataSet ds;
         ds = data.getDataSet(cmdStr);
         if (ds.Tables[0].Rows.Count == 1)
         {
             button1.Enabled = true;
         }
         else
         {
             if (!(String.IsNullOrEmpty(idtb.Text)))
             {
                 MessageBox.Show("未找到此员工信息,请添加!");
             }
         }
     }
 }
Esempio n. 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (pwd.Text.Trim() != "")
            {
                //连接数据库
                DataMysql data = new DataMysql();
                data.dataCon();

                //查询数据库
                string  cmdStr = "Select * from admin where pwd='" + pwd.Text + "'";
                DataSet ds;
                ds = data.getDataSet(cmdStr);
                if (ds.Tables[0].Rows.Count == 1)
                {
                    //FaceForm faceForm = new FaceForm();
                    //faceForm.Show();
                    Form_Admin form_Admin = new Form_Admin();
                    form_Admin.StartPosition = FormStartPosition.CenterScreen;
                    form_Admin.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("密码错误!");
                }
            }
            else
            {
                MessageBox.Show("密码不能为空!");
            }
        }
Esempio n. 4
0
        //执行数据库操作
        private void SignSql(int id)
        {
            int       flag    = 0;
            DataMysql datasql = new DataMysql();

            datasql.dataCon();
            //    string cmdStr = "Select time from signlog";
            string  cmdStr = "Select * from signlog where id = '" + id.ToString() + "'";
            DataSet ds;

            ds = datasql.getDataSet(cmdStr);
            int j = 0;

            j = ds.Tables[0].Rows.Count;
            string[] timedata = new string[j];
            j = 0;
            foreach (DataRow Row in ds.Tables[0].Rows)
            {
                timedata[j] = Convert.ToString(Row["signid"]);
                j++;
            }
            string time = id.ToString() + DateTime.Now.ToString("yyyy-MM-dd");

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                if (timedata[i].Equals(time))
                {
                    flag = 1;
                }
            }
            string  cmdStrname = "Select name from user where id = '" + id.ToString() + "'";
            DataSet dsa;

            dsa = datasql.getDataSet(cmdStrname);
            if (flag == 0)
            {
                string sign     = id.ToString() + DateTime.Now.ToString("yyyy-MM-dd");
                string signtime = DateTime.Now.ToLocalTime().ToString();
                string insert   = "insert into signlog (id,signid,flag,signtime,daytime) values ( '" + id.ToString() + "','" + sign + "','1','" + signtime + "','" + DateTime.Now.ToString("yyyy-MM-dd") + "')";


                if (datasql.sqlExec(insert))
                {
                    MessageBox.Show("恭喜您:" + dsa.Tables[0].Rows[0][0].ToString() + " 签到成功");
                }
            }
            else
            {
                MessageBox.Show("尊敬的用户:" + dsa.Tables[0].Rows[0][0].ToString() + " 您今天已经签到无需再次签到");
            }
        }
Esempio n. 5
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            if (!(String.IsNullOrEmpty(path[0])))
            {
                string url = "https://www.ylesb.com/csimg/pound.php";
                try
                {
                    WebClient client = new WebClient();
                    client.Credentials = CredentialCache.DefaultCredentials;
                    client.Headers.Add("Content-Type", "application/form-data");        //注意头部必须是form-data
                    string filename = idtb.Text + Path.GetFileName(path[0]);
                    client.QueryString["file_name"] = filename;
                    byte[] fileb = client.UploadFile(new Uri(url), "POST", path[0]);
                    string res   = Encoding.UTF8.GetString(fileb);
                }
                catch (Exception ex)
                {
                    AppendText(ex.Message);
                }

                DataMysql datasql = new DataMysql();
                datasql.dataCon();
                string imgname = "https://www.ylesb.com/csimg/" + idtb.Text + Path.GetFileName(path[0]);
                string update  = "update user set faceimg ='" + imgname + "' where id='" + idtb.Text + "'";
                if (datasql.sqlExec(update))
                {
                    AppendText("更新成功,请访问'" + imgname + "'查看是否本人\n");
                    imageLists.Images.Clear();
                    imageList.Items.Clear();
                    imagesFeatureList.Clear();
                    imagePathList.Clear();
                    idtb.Text = "";
                }
                else
                {
                    AppendText("录入失败,网络出现异常,请稍后再试!");
                    imageLists.Images.Clear();
                    imageList.Items.Clear();
                    imagesFeatureList.Clear();
                    imagePathList.Clear();
                    idtb.Text = "";
                }
            }
            else
            {
                MessageBox.Show("您未选择录入图片,请选择后提交!");
            }
        }
Esempio n. 6
0
        private void Form_User_Load(object sender, EventArgs e)
        {
            //必须保证有可用摄像头
            if (filterInfoCollection.Count == 0)
            {
                MessageBox.Show("未检测到摄像头,请确保已安装摄像头或驱动!");
                Dispose();
                Application.Exit();
            }
            if (videoSource.IsRunning)
            {
                videoSource.SignalToStop();
                videoSource.Hide();
            }
            else
            {
                if (isCompare)
                {
                    //比对结果清除
                    for (int i = 0; i < imagesFeatureList.Count; i++)
                    {
                        imageList.Items[i].Text = string.Format("{0}号", i);
                    }
                    isCompare = false;
                }
                videoSource.Show();
                deviceVideo = new VideoCaptureDevice(filterInfoCollection[0].MonikerString);
                deviceVideo.VideoResolution = deviceVideo.VideoCapabilities[0];
                videoSource.VideoSource     = deviceVideo;
                videoSource.Start();
            }
            lock (locker)
            {
                List <string> imagePathListTemp = new List <string>();
                var           numStart          = imagePathList.Count;
                //查询数据库
                DataMysql datasql = new DataMysql();
                datasql.dataCon();
                string  cmdStr = "Select faceimg from user";
                DataSet ds;
                ds = datasql.getDataSet(cmdStr);
                int j = 0;
                j = ds.Tables[0].Rows.Count;
                string[] fileNames = new string[j];
                j = 0;
                foreach (DataRow Row in ds.Tables[0].Rows)
                {
                    fileNames[j] = Convert.ToString(Row["faceimg"]);
                    j++;
                }

                for (int i = 0; i < fileNames.Length; i++)
                {
                    imagePathListTemp.Add(fileNames[i]);
                }

                //人脸检测以及提取人脸特征
                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
                {
                    //人脸检测和剪裁
                    for (int i = 0; i < imagePathListTemp.Count; i++)
                    {
                        WebRequest request   = WebRequest.Create(imagePathListTemp[i]);
                        WebResponse response = request.GetResponse();
                        Stream s             = response.GetResponseStream();
                        byte[] data          = new byte[1024];
                        int length           = 0;
                        MemoryStream ms      = new MemoryStream();
                        while ((length = s.Read(data, 0, data.Length)) > 0)
                        {
                            ms.Write(data, 0, length);
                        }
                        ms.Seek(0, SeekOrigin.Begin);
                        //    pictureBox1.Image = Image.FromStream(ms);
                        Image image = Image.FromStream(ms);
                        if (image.Width % 4 != 0)
                        {
                            image = ImageUtil.ScaleImage(image, image.Width - (image.Width % 4), image.Height);
                        }
                        ASF_MultiFaceInfo multiFaceInfo = FaceUtil.DetectFace(pImageEngine, image);

                        if (multiFaceInfo.faceNum > 0)
                        {
                            imagePathList.Add(imagePathListTemp[i]);
                            MRECT rect = MemoryUtil.PtrToStructure <MRECT>(multiFaceInfo.faceRects);
                            image      = ImageUtil.CutImage(image, rect.left, rect.top, rect.right, rect.bottom);
                        }
                        else
                        {
                            continue;
                        }
                    }


                    //提取人脸特征
                    for (int i = numStart; i < imagePathList.Count; i++)
                    {
                        WebRequest request   = WebRequest.Create(imagePathListTemp[i]);
                        WebResponse response = request.GetResponse();
                        Stream s             = response.GetResponseStream();
                        byte[] data          = new byte[1024];
                        int length           = 0;
                        MemoryStream ms      = new MemoryStream();
                        while ((length = s.Read(data, 0, data.Length)) > 0)
                        {
                            ms.Write(data, 0, length);
                        }
                        ms.Seek(0, SeekOrigin.Begin);
                        ASF_SingleFaceInfo singleFaceInfo = new ASF_SingleFaceInfo();
                        IntPtr feature = FaceUtil.ExtractFeature(pImageEngine, Image.FromStream(ms), out singleFaceInfo);
                        this.Invoke(new Action(delegate
                        {
                            if (singleFaceInfo.faceRect.left == 0 && singleFaceInfo.faceRect.right == 0)
                            {
                                AppendText(string.Format("{0}号未检测到人脸\r\n", i));
                            }
                            else
                            {
                                AppendText(string.Format("已提取{0}号人脸特征值,[left:{1},right:{2},top:{3},bottom:{4},orient:{5}]\r\n", i, singleFaceInfo.faceRect.left, singleFaceInfo.faceRect.right, singleFaceInfo.faceRect.top, singleFaceInfo.faceRect.bottom, singleFaceInfo.faceOrient));
                                imagesFeatureList.Add(feature);
                            }
                        }));
                    }
                }));
            }
            LoadingHelper.ShowLoading("加载中请稍后。", this, o =>
            {
                //这里写处理耗时的代码,代码处理完成则自动关闭该窗口
                Thread.Sleep(4000);
            });
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (!(String.IsNullOrEmpty(path[0])))
            {
                if (!(String.IsNullOrEmpty(idtb.Text)))
                {
                    if (!(String.IsNullOrEmpty(nametb.Text)))
                    {
                        DataMysql data = new DataMysql();
                        data.dataCon();
                        string  cmdStr = "Select * from user where id='" + idtb.Text + "'";
                        DataSet ds;
                        ds = data.getDataSet(cmdStr);
                        if (ds.Tables[0].Rows.Count == 1)
                        {
                            MessageBox.Show("已经添加过此员工了,请勿重复添加!");
                            AppendText("已经添加过此员工了,请勿重复添加!");
                            imageLists.Images.Clear();
                            imageList.Items.Clear();
                            imagesFeatureList.Clear();
                            imagePathList.Clear();
                            idtb.Text   = "";
                            nametb.Text = "";
                        }
                        else
                        {
                            string url = "https://www.ylesb.com/csimg/pound.php";
                            try
                            {
                                WebClient client = new WebClient();
                                client.Credentials = CredentialCache.DefaultCredentials;
                                client.Headers.Add("Content-Type", "application/form-data");//注意头部必须是form-data
                                string filename = idtb.Text + Path.GetFileName(path[0]);
                                client.QueryString["file_name"] = filename;
                                byte[] fileb = client.UploadFile(new Uri(url), "POST", path[0]);
                                string res   = Encoding.UTF8.GetString(fileb);
                            }
                            catch (Exception ex)
                            {
                                AppendText(ex.Message);
                            }

                            DataMysql datasql = new DataMysql();
                            datasql.dataCon();
                            string imgname = "https://www.ylesb.com/csimg/" + idtb.Text + Path.GetFileName(path[0]);
                            string insert  = "insert into user (id,name,faceimg) values ( '" + idtb.Text + "','" + nametb.Text + "','" + imgname + "')";
                            if (datasql.sqlExec(insert))
                            {
                                AppendText("录入成功,请访问'" + imgname + "'查看是否本人\n");
                                imageLists.Images.Clear();
                                imageList.Items.Clear();
                                imagesFeatureList.Clear();
                                imagePathList.Clear();
                                idtb.Text   = "";
                                nametb.Text = "";
                            }
                            else
                            {
                                AppendText("录入失败,网络出现异常,请稍后再试!");
                                imageLists.Images.Clear();
                                imageList.Items.Clear();
                                imagesFeatureList.Clear();
                                imagePathList.Clear();
                                idtb.Text   = "";
                                nametb.Text = "";
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("您未输入员工姓名,请输入后提交!");
                    }
                }
                else
                {
                    MessageBox.Show("您未输入员工ID,请输入后提交!");
                }
            }
            else
            {
                MessageBox.Show("您未选择录入图片,请选择后提交!");
            }
        }